Clean up PREF_USABILITY_STUDY_MODE

- Refer to a common default value in DebugSettings
- Make PREF_USABILITY_STUDY_MODE independent of the ResearchLogger
- ResearchLogger uses its own preference through ResearchSettings

multi-project commit with Ie0df836c9d779eba484b522666ec357f4e234823

Change-Id: I88547a2f619db6e7364abbbec12f9f76855dd11a
main
Kurt Partridge 2013-02-28 11:18:42 -08:00
parent 788dc55662
commit 75e6fb68e9
4 changed files with 20 additions and 15 deletions

View File

@ -57,7 +57,7 @@ public final class DebugSettings extends PreferenceFragment
if (usabilityStudyPref instanceof CheckBoxPreference) { if (usabilityStudyPref instanceof CheckBoxPreference) {
final CheckBoxPreference checkbox = (CheckBoxPreference)usabilityStudyPref; final CheckBoxPreference checkbox = (CheckBoxPreference)usabilityStudyPref;
checkbox.setChecked(prefs.getBoolean(PREF_USABILITY_STUDY_MODE, checkbox.setChecked(prefs.getBoolean(PREF_USABILITY_STUDY_MODE,
ResearchLogger.DEFAULT_USABILITY_STUDY_MODE)); LatinImeLogger.getUsabilityStudyMode(prefs)));
checkbox.setSummary(R.string.settings_warning_researcher_mode); checkbox.setSummary(R.string.settings_warning_researcher_mode);
} }
final Preference statisticsLoggingPref = findPreference(PREF_STATISTICS_LOGGING); final Preference statisticsLoggingPref = findPreference(PREF_STATISTICS_LOGGING);

View File

@ -37,6 +37,10 @@ public final class LatinImeLogger implements SharedPreferences.OnSharedPreferenc
public static void commit() { public static void commit() {
} }
public static boolean getUsabilityStudyMode(final SharedPreferences prefs) {
return false;
}
public static void onDestroy() { public static void onDestroy() {
} }

View File

@ -122,7 +122,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
// field holds a channel name, the developer does not have to re-enter it when using the // field holds a channel name, the developer does not have to re-enter it when using the
// feedback mechanism to generate multiple tests. // feedback mechanism to generate multiple tests.
private static final boolean FEEDBACK_DIALOG_SHOULD_PRESERVE_TEXT_FIELD = false; private static final boolean FEEDBACK_DIALOG_SHOULD_PRESERVE_TEXT_FIELD = false;
public static final boolean DEFAULT_USABILITY_STUDY_MODE = false;
/* package */ static boolean sIsLogging = false; /* package */ static boolean sIsLogging = false;
private static final int OUTPUT_FORMAT_VERSION = 5; private static final int OUTPUT_FORMAT_VERSION = 5;
private static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; private static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
@ -249,12 +248,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
mSuggest = suggest; mSuggest = suggest;
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(latinIME); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(latinIME);
if (prefs != null) { if (prefs != null) {
if (!prefs.contains(PREF_USABILITY_STUDY_MODE)) { sIsLogging = ResearchSettings.readResearchLoggerEnabledFlag(prefs);
Editor e = prefs.edit();
e.putBoolean(PREF_USABILITY_STUDY_MODE, DEFAULT_USABILITY_STUDY_MODE);
e.apply();
}
sIsLogging = prefs.getBoolean(PREF_USABILITY_STUDY_MODE, false);
prefs.registerOnSharedPreferenceChangeListener(this); prefs.registerOnSharedPreferenceChangeListener(this);
final long lastCleanupTime = prefs.getLong(PREF_LAST_CLEANUP_TIME, 0L); final long lastCleanupTime = prefs.getLong(PREF_LAST_CLEANUP_TIME, 0L);
@ -397,13 +391,9 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
restart(); restart();
} }
private void setLoggingAllowed(boolean enableLogging) { private void setLoggingAllowed(final boolean enableLogging) {
if (mPrefs == null) { if (mPrefs == null) return;
return; ResearchSettings.writeResearchLoggerEnabledFlag(mPrefs, enableLogging);
}
Editor e = mPrefs.edit();
e.putBoolean(PREF_USABILITY_STUDY_MODE, enableLogging);
e.apply();
sIsLogging = enableLogging; sIsLogging = enableLogging;
} }

View File

@ -22,6 +22,8 @@ import java.util.UUID;
public final class ResearchSettings { public final class ResearchSettings {
public static final String PREF_RESEARCH_LOGGER_UUID = "pref_research_logger_uuid"; public static final String PREF_RESEARCH_LOGGER_UUID = "pref_research_logger_uuid";
public static final String PREF_RESEARCH_LOGGER_ENABLED_FLAG =
"pref_research_logger_enabled_flag";
private ResearchSettings() { private ResearchSettings() {
// Intentional empty constructor for singleton. // Intentional empty constructor for singleton.
@ -36,4 +38,13 @@ public final class ResearchSettings {
prefs.edit().putString(PREF_RESEARCH_LOGGER_UUID, newUuid).apply(); prefs.edit().putString(PREF_RESEARCH_LOGGER_UUID, newUuid).apply();
return newUuid; return newUuid;
} }
public static boolean readResearchLoggerEnabledFlag(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_RESEARCH_LOGGER_ENABLED_FLAG, false);
}
public static void writeResearchLoggerEnabledFlag(final SharedPreferences prefs,
final boolean isEnabled) {
prefs.edit().putBoolean(PREF_RESEARCH_LOGGER_ENABLED_FLAG, isEnabled).apply();
}
} }