diff options
author | 2012-06-04 12:27:37 -0700 | |
---|---|---|
committer | 2012-06-06 20:42:01 -0700 | |
commit | 724bc479f7d796d6ce5d5e200216bea855b818b2 (patch) | |
tree | 29e47c0a068844aa677f5e7ecdd7131c8ab0857e /java/src/com/android/inputmethod/latin/ResearchLogger.java | |
parent | f739119f3ff54d7c37b67b873373b236a45e47e4 (diff) | |
download | latinime-724bc479f7d796d6ce5d5e200216bea855b818b2.tar.gz latinime-724bc479f7d796d6ce5d5e200216bea855b818b2.tar.xz latinime-724bc479f7d796d6ce5d5e200216bea855b818b2.zip |
add research log ui control
- lets users flag a particular time in the research log
- lets users delete the log for this session
also makes the UsabilityLog setting control whether the ResearchLog logs or not.
multi-project commit with I89067e7d3b8daca7179333f1dbe82224c26920fe
Bug: 6188932
Change-Id: I89864ef3ab53b0efe1ea8d75247be08712f0c399
Diffstat (limited to 'java/src/com/android/inputmethod/latin/ResearchLogger.java')
-rw-r--r-- | java/src/com/android/inputmethod/latin/ResearchLogger.java | 114 |
1 files changed, 102 insertions, 12 deletions
diff --git a/java/src/com/android/inputmethod/latin/ResearchLogger.java b/java/src/com/android/inputmethod/latin/ResearchLogger.java index 16285091b..bb003f766 100644 --- a/java/src/com/android/inputmethod/latin/ResearchLogger.java +++ b/java/src/com/android/inputmethod/latin/ResearchLogger.java @@ -18,6 +18,8 @@ package com.android.inputmethod.latin; import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.inputmethodservice.InputMethodService; @@ -33,9 +35,9 @@ import android.view.MotionEvent; import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputConnection; +import android.widget.Toast; import com.android.inputmethod.keyboard.Key; -import com.android.inputmethod.keyboard.KeyDetector; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.keyboard.KeyboardId; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; @@ -134,12 +136,16 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } if (prefs != null) { sIsLogging = prefs.getBoolean(PREF_USABILITY_STUDY_MODE, false); - prefs.registerOnSharedPreferenceChangeListener(sInstance); + prefs.registerOnSharedPreferenceChangeListener(this); } } public synchronized void start() { Log.d(TAG, "start called"); + if (!sIsLogging) { + // Log.w(TAG, "not in usability mode; not logging"); + return; + } if (mFilesDir == null || !mFilesDir.exists()) { Log.w(TAG, "IME storage directory does not exist. Cannot start logging."); } else { @@ -192,16 +198,17 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); - } - mJsonWriter = NULL_JSON_WRITER; - mFile = null; - mLoggingState = LOGGING_STATE_OFF; - if (DEBUG) { - Log.d(TAG, "logfile closed"); - } - Log.d(TAG, "finished stop(), notifying"); - synchronized (ResearchLogger.this) { - ResearchLogger.this.notify(); + } finally { + mJsonWriter = NULL_JSON_WRITER; + mFile = null; + mLoggingState = LOGGING_STATE_OFF; + if (DEBUG) { + Log.d(TAG, "logfile closed"); + } + Log.d(TAG, "finished stop(), notifying"); + synchronized (ResearchLogger.this) { + ResearchLogger.this.notify(); + } } } }); @@ -213,6 +220,38 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } } + public synchronized boolean abort() { + Log.d(TAG, "abort called"); + boolean isLogFileDeleted = false; + if (mLoggingHandler != null && mLoggingState == LOGGING_STATE_ON) { + mLoggingState = LOGGING_STATE_STOPPING; + try { + Log.d(TAG, "closing jsonwriter"); + mJsonWriter.endArray(); + mJsonWriter.close(); + } catch (IllegalStateException e1) { + // assume that this is just the json not being terminated properly. + // ignore + e1.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + mJsonWriter = NULL_JSON_WRITER; + // delete file + final boolean isDeleted = mFile.delete(); + if (isDeleted) { + isLogFileDeleted = true; + } + mFile = null; + mLoggingState = LOGGING_STATE_OFF; + if (DEBUG) { + Log.d(TAG, "logfile closed"); + } + } + } + return isLogFileDeleted; + } + /* package */ synchronized void flush() { try { mJsonWriter.flush(); @@ -227,6 +266,50 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang return; } sIsLogging = prefs.getBoolean(PREF_USABILITY_STUDY_MODE, false); + if (sIsLogging == false) { + abort(); + } + } + + /* package */ void presentResearchDialog(final LatinIME latinIME) { + final CharSequence title = latinIME.getString(R.string.english_ime_research_log); + final CharSequence[] items = new CharSequence[] { + latinIME.getString(R.string.note_timestamp_for_researchlog), + latinIME.getString(R.string.do_not_log_this_session), + }; + final DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface di, int position) { + di.dismiss(); + switch (position) { + case 0: + ResearchLogger.getInstance().userTimestamp(); + Toast.makeText(latinIME, R.string.notify_recorded_timestamp, + Toast.LENGTH_LONG).show(); + break; + case 1: + Toast toast = Toast.makeText(latinIME, + R.string.notify_session_log_deleting, Toast.LENGTH_LONG); + toast.show(); + final ResearchLogger logger = ResearchLogger.getInstance(); + boolean isLogDeleted = logger.abort(); + toast.cancel(); + if (isLogDeleted) { + Toast.makeText(latinIME, R.string.notify_session_log_deleted, + Toast.LENGTH_LONG).show(); + } else { + Toast.makeText(latinIME, + R.string.notify_session_log_not_deleted, Toast.LENGTH_LONG) + .show(); + } + break; + } + } + }; + final AlertDialog.Builder builder = new AlertDialog.Builder(latinIME) + .setItems(items, listener) + .setTitle(title); + latinIME.showOptionDialog(builder.create()); } private static final String CURRENT_TIME_KEY = "_ct"; @@ -756,4 +839,11 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang getInstance().writeEvent(EVENTKEYS_SUGGESTIONSVIEW_SETSUGGESTIONS, values); } } + + private static final String[] EVENTKEYS_USER_TIMESTAMP = { + "UserTimestamp" + }; + public void userTimestamp() { + getInstance().writeEvent(EVENTKEYS_USER_TIMESTAMP, EVENTKEYS_NULLVALUES); + } } |