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
main
Yohei Yukawa 2014-05-14 14:26:29 +09:00
parent 83be21a563
commit 9aa7f66a15
4 changed files with 13 additions and 27 deletions

View File

@ -480,6 +480,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
KeyboardSwitcher.init(this); KeyboardSwitcher.init(this);
AudioAndHapticFeedbackManager.init(this); AudioAndHapticFeedbackManager.init(this);
AccessibilityUtils.init(this); AccessibilityUtils.init(this);
StatsUtils.init(this);
super.onCreate(); super.onCreate();
@ -519,7 +520,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
DictionaryDecayBroadcastReciever.setUpIntervalAlarmForDictionaryDecaying(this); DictionaryDecayBroadcastReciever.setUpIntervalAlarmForDictionaryDecaying(this);
StatsUtils.onCreateCompleted(this); StatsUtils.onCreate(mSettings.getCurrent());
} }
// Has to be package-visible for unit tests // Has to be package-visible for unit tests
@ -538,6 +539,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
resetSuggestForLocale(locale); resetSuggestForLocale(locale);
} }
refreshPersonalizationDictionarySession(); refreshPersonalizationDictionarySession();
StatsUtils.onLoadSettings(currentSettingsValues);
} }
private void refreshPersonalizationDictionarySession() { private void refreshPersonalizationDictionarySession() {

View File

@ -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_DEBUG_SETTINGS = "debug_settings";
public static final String PREF_KEY_IS_INTERNAL = "pref_key_is_internal"; 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 preference key is deprecated. Use {@link #PREF_SHOW_LANGUAGE_SWITCH_KEY} instead.
// This is being used only for the backward compatibility. // This is being used only for the backward compatibility.
private static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY = private static final String PREF_SUPPRESS_LANGUAGE_SWITCH_KEY =

View File

@ -73,6 +73,7 @@ public final class SettingsValues {
public final boolean mPhraseGestureEnabled; public final boolean mPhraseGestureEnabled;
public final int mKeyLongpressTimeout; public final int mKeyLongpressTimeout;
public final Locale mLocale; public final Locale mLocale;
public final boolean mEnableMetricsLogging;
// From the input box // From the input box
public final InputAttributes mInputAttributes; public final InputAttributes mInputAttributes;
@ -134,7 +135,7 @@ public final class SettingsValues {
mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res); mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res);
mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res); mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);
mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout);
mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true);
// Compute other readable settings // Compute other readable settings
mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res); mKeyLongpressTimeout = Settings.readKeyLongpressTimeout(prefs, res);
mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res); mKeypressVibrationDuration = Settings.readKeypressVibrationDuration(prefs, res);

View File

@ -17,37 +17,18 @@
package com.android.inputmethod.latin.utils; package com.android.inputmethod.latin.utils;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import com.android.inputmethod.latin.settings.SettingsValues;
import android.preference.PreferenceManager;
import android.util.Log;
import com.android.inputmethod.latin.settings.Settings;
public final class StatsUtils { public final class StatsUtils {
private static final String TAG = StatsUtils.class.getSimpleName(); public static void init(final Context context) {
private static final StatsUtils sInstance = new StatsUtils();
public static void onCreateCompleted(final Context context) {
sInstance.onCreateCompletedInternal(context);
} }
private void onCreateCompletedInternal(final Context context) { public static void onCreate(final SettingsValues settingsValues) {
mContext = context; }
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
final Boolean usePersonalizedDict = public static void onLoadSettings(final SettingsValues settingsValues) {
prefs.getBoolean(Settings.PREF_KEY_USE_PERSONALIZED_DICTS, true);
Log.d(TAG, "onCreateCompleted. context: " + context.toString() + "usePersonalizedDict: "
+ usePersonalizedDict);
} }
public static void onDestroy() { public static void onDestroy() {
sInstance.onDestroyInternal();
} }
private void onDestroyInternal() {
Log.d(TAG, "onDestroy. context: " + mContext.toString());
mContext = null;
}
private Context mContext;
} }