Stats: keyboard height and layout adjustment.
This CL adds new usage stats entries regarding keyboard height and
layout adjustment.
- SoftwareKeyboardHeightDipLandscape
- SoftwareKeyboardHeightDipPortrait
- SoftwareKeyboardLayoutAdjustmentEnabledLandscape
- SoftwareKeyboardLayoutAdjustmentEnabledPortrait
Note that usage stats has never been enabled in OSS Mozc. Hence this CL
has no user-visible behavior change in practice.
BUG=
TEST=compile
REF_BUG=
REF_CL=86255049
Hiroshi Sumita authored 8 years ago
Yohei Yukawa committed 8 years ago
+2
-23
214 | 214 | resources.getDisplayMetrics(), resources.getConfiguration().orientation); |
215 | 215 | storeDefaultFullscreenMode( |
216 | 216 | sharedPreferences, portraitMetrics.heightPixels, portraitMetrics.widthPixels, |
217 | (int) Math.ceil(getDimensionForOrientation( | |
217 | (int) Math.ceil(MozcUtil.getDimensionForOrientation( | |
218 | 218 | resources, R.dimen.input_frame_height, Configuration.ORIENTATION_PORTRAIT)), |
219 | (int) Math.ceil(getDimensionForOrientation( | |
219 | (int) Math.ceil(MozcUtil.getDimensionForOrientation( | |
220 | 220 | resources, R.dimen.input_frame_height, Configuration.ORIENTATION_LANDSCAPE)), |
221 | 221 | resources.getDimensionPixelOffset(R.dimen.fullscreen_threshold)); |
222 | 222 | |
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
289 | * Get a dimension for the specified orientation. | |
290 | * This method may be heavy since it updates the {@code resources} twice. | |
291 | */ | |
292 | @VisibleForTesting | |
293 | static float getDimensionForOrientation(Resources resources, int id, int orientation) { | |
294 | Configuration configuration = resources.getConfiguration(); | |
295 | if (configuration.orientation == orientation) { | |
296 | return resources.getDimension(id); | |
297 | } | |
298 | ||
299 | Configuration originalConfiguration = new Configuration(resources.getConfiguration()); | |
300 | try { | |
301 | configuration.orientation = orientation; | |
302 | resources.updateConfiguration(configuration, null); | |
303 | return resources.getDimension(id); | |
304 | } finally { | |
305 | resources.updateConfiguration(originalConfiguration, null); | |
306 | } | |
307 | } | |
308 | ||
309 | /** | |
310 | 289 | * Stores the default value of "fullscreen mode" to the shared preference. |
311 | 290 | */ |
312 | 291 | @VisibleForTesting |
934 | 934 | public static float clamp(float value, float min, float max) { |
935 | 935 | return Math.max(Math.min(value, max), min); |
936 | 936 | } |
937 | ||
938 | /** | |
939 | * Get a dimension for the specified orientation. | |
940 | * This method may be heavy since it updates the {@code resources} twice. | |
941 | */ | |
942 | public static float getDimensionForOrientation(Resources resources, int id, int orientation) { | |
943 | Configuration configuration = resources.getConfiguration(); | |
944 | if (configuration.orientation == orientation) { | |
945 | return resources.getDimension(id); | |
946 | } | |
947 | ||
948 | Configuration originalConfiguration = new Configuration(resources.getConfiguration()); | |
949 | try { | |
950 | configuration.orientation = orientation; | |
951 | resources.updateConfiguration(configuration, null); | |
952 | return resources.getDimension(id); | |
953 | } finally { | |
954 | resources.updateConfiguration(originalConfiguration, null); | |
955 | } | |
956 | } | |
937 | 957 | } |
+42
-21
31 | 31 | import org.mozc.android.inputmethod.japanese.KeycodeConverter.KeyEventInterface; |
32 | 32 | import org.mozc.android.inputmethod.japanese.MozcLog; |
33 | 33 | import org.mozc.android.inputmethod.japanese.MozcUtil; |
34 | import org.mozc.android.inputmethod.japanese.R; | |
35 | import org.mozc.android.inputmethod.japanese.ViewManagerInterface.LayoutAdjustment; | |
34 | 36 | import org.mozc.android.inputmethod.japanese.preference.ClientSidePreference; |
35 | 37 | import org.mozc.android.inputmethod.japanese.protobuf.ProtoCommands; |
36 | 38 | import org.mozc.android.inputmethod.japanese.protobuf.ProtoCommands.Capability; |
876 | 878 | Preconditions.checkNotNull(sharedPreferences); |
877 | 879 | Preconditions.checkNotNull(resources); |
878 | 880 | |
879 | ClientSidePreference landscapePreference = | |
880 | new ClientSidePreference( | |
881 | sendIntegerUsageStatsUsageStatsEvent( | |
882 | UsageStatsEvent.SOFTWARE_KEYBOARD_HEIGHT_DIP_LANDSCAPE, | |
883 | (int) Math.ceil(MozcUtil.getDimensionForOrientation( | |
884 | resources, R.dimen.ime_window_height, Configuration.ORIENTATION_LANDSCAPE))); | |
885 | sendIntegerUsageStatsUsageStatsEvent( | |
886 | UsageStatsEvent.SOFTWARE_KEYBOARD_HEIGHT_DIP_PORTRAIT, | |
887 | (int) Math.ceil(MozcUtil.getDimensionForOrientation( | |
888 | resources, R.dimen.ime_window_height, Configuration.ORIENTATION_PORTRAIT))); | |
889 | ||
890 | ClientSidePreference landscapePreference = new ClientSidePreference( | |
881 | 891 | sharedPreferences, resources, Configuration.ORIENTATION_LANDSCAPE); |
882 | evaluateAsynchronously( | |
883 | Input.newBuilder() | |
884 | .setType(CommandType.SEND_COMMAND) | |
885 | .setCommand(SessionCommand.newBuilder() | |
886 | .setType(SessionCommand.CommandType.USAGE_STATS_EVENT) | |
887 | .setUsageStatsEvent(UsageStatsEvent.SOFTWARE_KEYBOARD_LAYOUT_LANDSCAPE) | |
888 | .setUsageStatsEventIntValue(landscapePreference.getKeyboardLayout().getId())), | |
889 | Optional.<KeyEventInterface>absent(), Optional.<EvaluationCallback>absent()); | |
890 | ||
891 | ClientSidePreference portraitPreference = | |
892 | new ClientSidePreference( | |
893 | sharedPreferences, resources, Configuration.ORIENTATION_PORTRAIT); | |
894 | evaluateAsynchronously( | |
895 | Input.newBuilder() | |
896 | .setType(CommandType.SEND_COMMAND) | |
897 | .setCommand(SessionCommand.newBuilder() | |
898 | .setType(SessionCommand.CommandType.USAGE_STATS_EVENT) | |
899 | .setUsageStatsEvent(UsageStatsEvent.SOFTWARE_KEYBOARD_LAYOUT_PORTRAIT) | |
900 | .setUsageStatsEventIntValue(portraitPreference.getKeyboardLayout().getId())), | |
892 | ClientSidePreference portraitPreference = new ClientSidePreference( | |
893 | sharedPreferences, resources, Configuration.ORIENTATION_PORTRAIT); | |
894 | ||
895 | sendIntegerUsageStatsUsageStatsEvent( | |
896 | UsageStatsEvent.SOFTWARE_KEYBOARD_LAYOUT_LANDSCAPE, | |
897 | landscapePreference.getKeyboardLayout().getId()); | |
898 | sendIntegerUsageStatsUsageStatsEvent( | |
899 | UsageStatsEvent.SOFTWARE_KEYBOARD_LAYOUT_PORTRAIT, | |
900 | portraitPreference.getKeyboardLayout().getId()); | |
901 | ||
902 | boolean layoutAdjustmentEnabledInLandscape = | |
903 | landscapePreference.getLayoutAdjustment() != LayoutAdjustment.FILL; | |
904 | boolean layoutAdjustmentEnabledInPortrait = | |
905 | portraitPreference.getLayoutAdjustment() != LayoutAdjustment.FILL; | |
906 | ||
907 | sendIntegerUsageStatsUsageStatsEvent( | |
908 | UsageStatsEvent.SOFTWARE_KEYBOARD_LAYOUT_ADJUSTMENT_ENABLED_LANDSCAPE, | |
909 | layoutAdjustmentEnabledInLandscape ? 1 : 0); | |
910 | sendIntegerUsageStatsUsageStatsEvent( | |
911 | UsageStatsEvent.SOFTWARE_KEYBOARD_LAYOUT_ADJUSTMENT_ENABLED_PORTRAIT, | |
912 | layoutAdjustmentEnabledInPortrait ? 1 : 0); | |
913 | } | |
914 | ||
915 | private void sendIntegerUsageStatsUsageStatsEvent(UsageStatsEvent event, int value) { | |
916 | evaluateAsynchronously(Input.newBuilder() | |
917 | .setType(CommandType.SEND_COMMAND) | |
918 | .setCommand(SessionCommand.newBuilder() | |
919 | .setType(SessionCommand.CommandType.USAGE_STATS_EVENT) | |
920 | .setUsageStatsEvent(event) | |
921 | .setUsageStatsEventIntValue(value)), | |
901 | 922 | Optional.<KeyEventInterface>absent(), Optional.<EvaluationCallback>absent()); |
902 | 923 | } |
903 | 924 |
+1
-16
259 | 259 | } |
260 | 260 | |
261 | 261 | @SmallTest |
262 | public void testGetDimensionForOrientation() { | |
263 | float portraitValue = ApplicationInitializer.getDimensionForOrientation( | |
264 | getInstrumentation().getContext().getResources(), | |
265 | org.mozc.android.inputmethod.japanese.tests.R.dimen.value_for_testing_port_1dip_land_2dip, | |
266 | Configuration.ORIENTATION_PORTRAIT); | |
267 | float landscapeValue = ApplicationInitializer.getDimensionForOrientation( | |
268 | getInstrumentation().getContext().getResources(), | |
269 | org.mozc.android.inputmethod.japanese.tests.R.dimen.value_for_testing_port_1dip_land_2dip, | |
270 | Configuration.ORIENTATION_LANDSCAPE); | |
271 | ||
272 | assertTrue("portrait:" + portraitValue + ", landscape:" + landscapeValue, | |
273 | portraitValue != landscapeValue); | |
274 | } | |
275 | ||
276 | @SmallTest | |
277 | 262 | public void testStoreDefaultFullscreenMode() throws IllegalArgumentException { |
278 | 263 | class TestParameter extends Parameter { |
279 | 264 | final int displayHeightInPixels; |
347 | 332 | testParameter.displayHeightInPixels, |
348 | 333 | testParameter.displayWidthInPixels, |
349 | 334 | resources.getDimensionPixelOffset(R.dimen.input_frame_height), |
350 | (int) Math.ceil(ApplicationInitializer.getDimensionForOrientation( | |
335 | (int) Math.ceil(MozcUtil.getDimensionForOrientation( | |
351 | 336 | resources, R.dimen.input_frame_height, Configuration.ORIENTATION_LANDSCAPE)), |
352 | 337 | resources.getDimensionPixelOffset(R.dimen.fullscreen_threshold)); |
353 | 338 | assertEquals("portrait check failed: " + testParameter.toString(), |
321 | 321 | testData.expectPreffered, MozcUtil.isVoiceInputPreferred(editorInfo)); |
322 | 322 | } |
323 | 323 | } |
324 | ||
325 | @SmallTest | |
326 | public void testGetDimensionForOrientation() { | |
327 | float portraitValue = MozcUtil.getDimensionForOrientation( | |
328 | getInstrumentation().getContext().getResources(), | |
329 | org.mozc.android.inputmethod.japanese.tests.R.dimen.value_for_testing_port_1dip_land_2dip, | |
330 | Configuration.ORIENTATION_PORTRAIT); | |
331 | float landscapeValue = MozcUtil.getDimensionForOrientation( | |
332 | getInstrumentation().getContext().getResources(), | |
333 | org.mozc.android.inputmethod.japanese.tests.R.dimen.value_for_testing_port_1dip_land_2dip, | |
334 | Configuration.ORIENTATION_LANDSCAPE); | |
335 | ||
336 | assertTrue("portrait:" + portraitValue + ", landscape:" + landscapeValue, | |
337 | portraitValue != landscapeValue); | |
338 | } | |
324 | 339 | } |
537 | 537 | KeyboardFoldEvent |
538 | 538 | KeyboardExpandEvent |
539 | 539 | MushroomSelectionDialogOpen |
540 | SoftwareKeyboardHeightDipLandscape | |
541 | SoftwareKeyboardHeightDipPortrait | |
542 | SoftwareKeyboardLayoutAdjustmentEnabledLandscape | |
543 | SoftwareKeyboardLayoutAdjustmentEnabledPortrait | |
540 | 544 | |
541 | 545 | # for windows |
542 | 546 |
0 | 0 | MAJOR=2 |
1 | 1 | MINOR=17 |
2 | BUILD=2184 | |
2 | BUILD=2185 | |
3 | 3 | REVISION=102 |
4 | 4 | # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be |
5 | 5 | # downloaded by NaCl Mozc. |
481 | 481 | KEYBOARD_FOLD_EVENT = 20; |
482 | 482 | KEYBOARD_EXPAND_EVENT = 21; |
483 | 483 | MUSHROOM_SELECTION_DIALOG_OPEN_EVENT = 22; |
484 | SOFTWARE_KEYBOARD_HEIGHT_DIP_LANDSCAPE = 23; | |
485 | SOFTWARE_KEYBOARD_HEIGHT_DIP_PORTRAIT = 24; | |
486 | SOFTWARE_KEYBOARD_LAYOUT_ADJUSTMENT_ENABLED_LANDSCAPE = 25; | |
487 | SOFTWARE_KEYBOARD_LAYOUT_ADJUSTMENT_ENABLED_PORTRAIT = 26; | |
484 | 488 | } |
485 | 489 | optional UsageStatsEvent usage_stats_event = 7; |
486 | 490 | optional int32 usage_stats_event_int_value = 9; |
369 | 369 | case commands::SessionCommand::MUSHROOM_SELECTION_DIALOG_OPEN_EVENT: |
370 | 370 | UsageStats::IncrementCount("MushroomSelectionDialogOpen"); |
371 | 371 | break; |
372 | case commands::SessionCommand::SOFTWARE_KEYBOARD_HEIGHT_DIP_LANDSCAPE: | |
373 | LOG_IF(DFATAL, !input.command().has_usage_stats_event_int_value()) | |
374 | << "SOFTWARE_KEYBOARD_HEIGHT_DIP_LANDSCAPE stats" | |
375 | << " must have int value."; | |
376 | UsageStats::SetInteger("SoftwareKeyboardHeightDipLandscape", | |
377 | input.command().usage_stats_event_int_value()); | |
378 | break; | |
379 | case commands::SessionCommand::SOFTWARE_KEYBOARD_HEIGHT_DIP_PORTRAIT: | |
380 | LOG_IF(DFATAL, !input.command().has_usage_stats_event_int_value()) | |
381 | << "SOFTWARE_KEYBOARD_HEIGHT_DIP_PORTRAIT stats must have int value."; | |
382 | UsageStats::SetInteger("SoftwareKeyboardHeightDipPortrait", | |
383 | input.command().usage_stats_event_int_value()); | |
384 | break; | |
385 | case commands::SessionCommand | |
386 | ::SOFTWARE_KEYBOARD_LAYOUT_ADJUSTMENT_ENABLED_LANDSCAPE: | |
387 | LOG_IF(DFATAL, !input.command().has_usage_stats_event_int_value()) | |
388 | << "SOFTWARE_KEYBOARD_LAYOUT_ADJUSTMENT_ENABLED_LANDSCAPE stats" | |
389 | << " must have int value."; | |
390 | UsageStats::SetBoolean("SoftwareKeyboardLayoutAdjustmentEnabledLandscape", | |
391 | input.command().usage_stats_event_int_value() > 0); | |
392 | break; | |
393 | case commands::SessionCommand | |
394 | ::SOFTWARE_KEYBOARD_LAYOUT_ADJUSTMENT_ENABLED_PORTRAIT: | |
395 | LOG_IF(DFATAL, !input.command().has_usage_stats_event_int_value()) | |
396 | << "SOFTWARE_KEYBOARD_LAYOUT_ADJUSTMENT_ENABLED_PORTRAIT stats" | |
397 | << " must have int value."; | |
398 | UsageStats::SetBoolean("SoftwareKeyboardLayoutAdjustmentEnabledPortrait", | |
399 | input.command().usage_stats_event_int_value() > 0); | |
400 | break; | |
372 | 401 | default: |
373 | 402 | LOG(DFATAL) << "client side usage stats event has invalid category"; |
374 | 403 | break; |