Codebase list mozc / 1068570
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
9 changed file(s) with 118 addition(s) and 61 deletion(s). Raw diff Collapse all Expand all
214214 resources.getDisplayMetrics(), resources.getConfiguration().orientation);
215215 storeDefaultFullscreenMode(
216216 sharedPreferences, portraitMetrics.heightPixels, portraitMetrics.widthPixels,
217 (int) Math.ceil(getDimensionForOrientation(
217 (int) Math.ceil(MozcUtil.getDimensionForOrientation(
218218 resources, R.dimen.input_frame_height, Configuration.ORIENTATION_PORTRAIT)),
219 (int) Math.ceil(getDimensionForOrientation(
219 (int) Math.ceil(MozcUtil.getDimensionForOrientation(
220220 resources, R.dimen.input_frame_height, Configuration.ORIENTATION_LANDSCAPE)),
221221 resources.getDimensionPixelOffset(R.dimen.fullscreen_threshold));
222222
286286 }
287287
288288 /**
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 /**
310289 * Stores the default value of "fullscreen mode" to the shared preference.
311290 */
312291 @VisibleForTesting
934934 public static float clamp(float value, float min, float max) {
935935 return Math.max(Math.min(value, max), min);
936936 }
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 }
937957 }
3131 import org.mozc.android.inputmethod.japanese.KeycodeConverter.KeyEventInterface;
3232 import org.mozc.android.inputmethod.japanese.MozcLog;
3333 import org.mozc.android.inputmethod.japanese.MozcUtil;
34 import org.mozc.android.inputmethod.japanese.R;
35 import org.mozc.android.inputmethod.japanese.ViewManagerInterface.LayoutAdjustment;
3436 import org.mozc.android.inputmethod.japanese.preference.ClientSidePreference;
3537 import org.mozc.android.inputmethod.japanese.protobuf.ProtoCommands;
3638 import org.mozc.android.inputmethod.japanese.protobuf.ProtoCommands.Capability;
876878 Preconditions.checkNotNull(sharedPreferences);
877879 Preconditions.checkNotNull(resources);
878880
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(
881891 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)),
901922 Optional.<KeyEventInterface>absent(), Optional.<EvaluationCallback>absent());
902923 }
903924
259259 }
260260
261261 @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
277262 public void testStoreDefaultFullscreenMode() throws IllegalArgumentException {
278263 class TestParameter extends Parameter {
279264 final int displayHeightInPixels;
347332 testParameter.displayHeightInPixels,
348333 testParameter.displayWidthInPixels,
349334 resources.getDimensionPixelOffset(R.dimen.input_frame_height),
350 (int) Math.ceil(ApplicationInitializer.getDimensionForOrientation(
335 (int) Math.ceil(MozcUtil.getDimensionForOrientation(
351336 resources, R.dimen.input_frame_height, Configuration.ORIENTATION_LANDSCAPE)),
352337 resources.getDimensionPixelOffset(R.dimen.fullscreen_threshold));
353338 assertEquals("portrait check failed: " + testParameter.toString(),
321321 testData.expectPreffered, MozcUtil.isVoiceInputPreferred(editorInfo));
322322 }
323323 }
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 }
324339 }
537537 KeyboardFoldEvent
538538 KeyboardExpandEvent
539539 MushroomSelectionDialogOpen
540 SoftwareKeyboardHeightDipLandscape
541 SoftwareKeyboardHeightDipPortrait
542 SoftwareKeyboardLayoutAdjustmentEnabledLandscape
543 SoftwareKeyboardLayoutAdjustmentEnabledPortrait
540544
541545 # for windows
542546
00 MAJOR=2
11 MINOR=17
2 BUILD=2184
2 BUILD=2185
33 REVISION=102
44 # NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
55 # downloaded by NaCl Mozc.
481481 KEYBOARD_FOLD_EVENT = 20;
482482 KEYBOARD_EXPAND_EVENT = 21;
483483 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;
484488 }
485489 optional UsageStatsEvent usage_stats_event = 7;
486490 optional int32 usage_stats_event_int_value = 9;
369369 case commands::SessionCommand::MUSHROOM_SELECTION_DIALOG_OPEN_EVENT:
370370 UsageStats::IncrementCount("MushroomSelectionDialogOpen");
371371 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;
372401 default:
373402 LOG(DFATAL) << "client side usage stats event has invalid category";
374403 break;