Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9aa7f66a authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

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
parent 83be21a5
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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() {
+2 −0
Original line number Diff line number Diff line
@@ -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 =
+2 −1
Original line number Diff line number Diff line
@@ -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);
+5 −24
Original line number Diff line number Diff line
@@ -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 onDestroy() {
        sInstance.onDestroyInternal();
    public static void onLoadSettings(final SettingsValues settingsValues) {
    }

    private void onDestroyInternal() {
        Log.d(TAG, "onDestroy. context: " + mContext.toString());
        mContext = null;
    public static void onDestroy() {
    }

    private Context mContext;
}