Merge "Clean up logic in onUserLoggingConsent"

main
Kurt Partridge 2013-03-05 16:43:07 +00:00 committed by Android (Google) Code Review
commit 60f51684f1
2 changed files with 17 additions and 17 deletions

View File

@ -125,7 +125,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
/* 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";
private static final String PREF_RESEARCH_HAS_SEEN_SPLASH = "pref_research_has_seen_splash";
/* package */ static final String LOG_FILENAME_PREFIX = "researchLog"; /* package */ static final String LOG_FILENAME_PREFIX = "researchLog";
private static final String LOG_FILENAME_SUFFIX = ".txt"; private static final String LOG_FILENAME_SUFFIX = ".txt";
/* package */ static final String USER_RECORDING_FILENAME_PREFIX = "recording"; /* package */ static final String USER_RECORDING_FILENAME_PREFIX = "recording";
@ -321,14 +320,10 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
} }
} }
private boolean hasSeenSplash() {
return mPrefs.getBoolean(PREF_RESEARCH_HAS_SEEN_SPLASH, false);
}
private Dialog mSplashDialog = null; private Dialog mSplashDialog = null;
private void maybeShowSplashScreen() { private void maybeShowSplashScreen() {
if (hasSeenSplash()) { if (ResearchSettings.readHasSeenSplash(mPrefs)) {
return; return;
} }
if (mSplashDialog != null && mSplashDialog.isShowing()) { if (mSplashDialog != null && mSplashDialog.isShowing()) {
@ -381,22 +376,16 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
} }
public void onUserLoggingConsent() { public void onUserLoggingConsent() {
setLoggingAllowed(true);
if (mPrefs == null) { if (mPrefs == null) {
return; mPrefs = PreferenceManager.getDefaultSharedPreferences(mLatinIME);
if (mPrefs == null) return;
} }
final Editor e = mPrefs.edit(); sIsLogging = true;
e.putBoolean(PREF_RESEARCH_HAS_SEEN_SPLASH, true); ResearchSettings.writeResearchLoggerEnabledFlag(mPrefs, true);
e.apply(); ResearchSettings.writeHasSeenSplash(mPrefs, true);
restart(); restart();
} }
private void setLoggingAllowed(final boolean enableLogging) {
if (mPrefs == null) return;
ResearchSettings.writeResearchLoggerEnabledFlag(mPrefs, enableLogging);
sIsLogging = enableLogging;
}
private static int sLogFileCounter = 0; private static int sLogFileCounter = 0;
private File createLogFile(final File filesDir) { private File createLogFile(final File filesDir) {

View File

@ -24,6 +24,8 @@ 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 = public static final String PREF_RESEARCH_LOGGER_ENABLED_FLAG =
"pref_research_logger_enabled_flag"; "pref_research_logger_enabled_flag";
public static final String PREF_RESEARCH_LOGGER_HAS_SEEN_SPLASH =
"pref_research_logger_has_seen_splash";
private ResearchSettings() { private ResearchSettings() {
// Intentional empty constructor for singleton. // Intentional empty constructor for singleton.
@ -47,4 +49,13 @@ public final class ResearchSettings {
final boolean isEnabled) { final boolean isEnabled) {
prefs.edit().putBoolean(PREF_RESEARCH_LOGGER_ENABLED_FLAG, isEnabled).apply(); prefs.edit().putBoolean(PREF_RESEARCH_LOGGER_ENABLED_FLAG, isEnabled).apply();
} }
public static boolean readHasSeenSplash(final SharedPreferences prefs) {
return prefs.getBoolean(PREF_RESEARCH_LOGGER_HAS_SEEN_SPLASH, false);
}
public static void writeHasSeenSplash(final SharedPreferences prefs,
final boolean hasSeenSplash) {
prefs.edit().putBoolean(PREF_RESEARCH_LOGGER_HAS_SEEN_SPLASH, hasSeenSplash).apply();
}
} }