From 9aa7f66a15b7db2c0bf8924ba17ae9fe463441b5 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 14 May 2014 14:26:29 +0900 Subject: [PATCH] Simplify StatsUtils With this CL, the implementation of StatsUtils no longer needs to know how to read settings from the system. Insted, the LatinIME class is now responsible for notifying StatsUtils whenever the settings is changed. BUG: 14324207 Change-Id: Ic3d26ec31c8d2c082d3e7487b578b323aad2f960 --- .../android/inputmethod/latin/LatinIME.java | 4 ++- .../inputmethod/latin/settings/Settings.java | 2 ++ .../latin/settings/SettingsValues.java | 3 +- .../inputmethod/latin/utils/StatsUtils.java | 31 ++++--------------- 4 files changed, 13 insertions(+), 27 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 8a2ed1088..499d22c3f 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -480,6 +480,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen KeyboardSwitcher.init(this); AudioAndHapticFeedbackManager.init(this); AccessibilityUtils.init(this); + StatsUtils.init(this); super.onCreate(); @@ -519,7 +520,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen DictionaryDecayBroadcastReciever.setUpIntervalAlarmForDictionaryDecaying(this); - StatsUtils.onCreateCompleted(this); + StatsUtils.onCreate(mSettings.getCurrent()); } // Has to be package-visible for unit tests @@ -538,6 +539,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen resetSuggestForLocale(locale); } refreshPersonalizationDictionarySession(); + StatsUtils.onLoadSettings(currentSettingsValues); } private void refreshPersonalizationDictionarySession() { diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 4e4c8885c..d4f6bcd10 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -87,6 +87,8 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_DEBUG_SETTINGS = "debug_settings"; public static final String PREF_KEY_IS_INTERNAL = "pref_key_is_internal"; + public static final String PREF_ENABLE_METRICS_LOGGING = "pref_enable_metrics_logging"; + // This preference key is deprecated. Use {@link #PREF_SHOW_LANGUAGE_SWITCH_KEY} instead. // This is being used only for the backward compatibility. private static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY = diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java index de2eb951e..16fd05877 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -73,6 +73,7 @@ public final class SettingsValues { public final boolean mPhraseGestureEnabled; public final int mKeyLongpressTimeout; public final Locale mLocale; + public final boolean mEnableMetricsLogging; // From the input box public final InputAttributes mInputAttributes; @@ -134,7 +135,7 @@ public final class SettingsValues { mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res); mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res); mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); - + mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true); // Compute other readable settings mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res); mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res); diff --git a/java/src/com/android/inputmethod/latin/utils/StatsUtils.java b/java/src/com/android/inputmethod/latin/utils/StatsUtils.java index a059f877b..79c19d077 100644 --- a/java/src/com/android/inputmethod/latin/utils/StatsUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/StatsUtils.java @@ -17,37 +17,18 @@ package com.android.inputmethod.latin.utils; import android.content.Context; -import android.content.SharedPreferences; -import android.preference.PreferenceManager; -import android.util.Log; - -import com.android.inputmethod.latin.settings.Settings; +import com.android.inputmethod.latin.settings.SettingsValues; public final class StatsUtils { - private static final String TAG = StatsUtils.class.getSimpleName(); - private static final StatsUtils sInstance = new StatsUtils(); - - public static void onCreateCompleted(final Context context) { - sInstance.onCreateCompletedInternal(context); + public static void init(final Context context) { } - private void onCreateCompletedInternal(final Context context) { - mContext = context; - final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext); - final Boolean usePersonalizedDict = - prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true); - Log.d(TAG, "onCreateCompleted. context: " + context.toString() + "usePersonalizedDict: " - + usePersonalizedDict); + public static void onCreate(final SettingsValues settingsValues) { + } + + public static void onLoadSettings(final SettingsValues settingsValues) { } public static void onDestroy() { - sInstance.onDestroyInternal(); } - - private void onDestroyInternal() { - Log.d(TAG, "onDestroy. context: " + mContext.toString()); - mContext = null; - } - - private Context mContext; }