summaryrefslogtreecommitdiffstats
path: root/java/src/com
diff options
context:
space:
mode:
authorKurt Partridge <kep@google.com>2012-07-22 18:53:34 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-07-22 18:53:38 -0700
commit74c95d6d18331e80e35f0417c5204a0a050b3890 (patch)
tree25c9ada8f982f2a1a8a0fb5147c8a97598bf1009 /java/src/com
parentf0c6606807740dcd35ec249ad90c923d50f6640f (diff)
parent4331012a9e7779ff7c8359a443dc5815ee6ea8d9 (diff)
downloadandroid_packages_inputmethods_LatinIME-74c95d6d18331e80e35f0417c5204a0a050b3890.tar.gz
android_packages_inputmethods_LatinIME-74c95d6d18331e80e35f0417c5204a0a050b3890.tar.bz2
android_packages_inputmethods_LatinIME-74c95d6d18331e80e35f0417c5204a0a050b3890.zip
Merge "ResearchLog splash screen"
Diffstat (limited to 'java/src/com')
-rw-r--r--java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java11
-rw-r--r--java/src/com/android/inputmethod/research/ResearchLogger.java89
2 files changed, 93 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
index cf196638d..0a7e7a2e3 100644
--- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java
@@ -509,6 +509,17 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
}
@Override
+ protected void onAttachedToWindow() {
+ super.onAttachedToWindow();
+ // Notify the research logger that the keyboard view has been attached. This is needed
+ // to properly show the splash screen, which requires that the window token of the
+ // KeyboardView be non-null.
+ if (ProductionFlag.IS_EXPERIMENTAL) {
+ ResearchLogger.getInstance().latinKeyboardView_onAttachedToWindow();
+ }
+ }
+
+ @Override
public void cancelAllMessages() {
mKeyTimerHandler.cancelAllMessages();
super.cancelAllMessages();
diff --git a/java/src/com/android/inputmethod/research/ResearchLogger.java b/java/src/com/android/inputmethod/research/ResearchLogger.java
index e6828da50..a4234a940 100644
--- a/java/src/com/android/inputmethod/research/ResearchLogger.java
+++ b/java/src/com/android/inputmethod/research/ResearchLogger.java
@@ -19,27 +19,36 @@ package com.android.inputmethod.research;
import static com.android.inputmethod.latin.Constants.Subtype.ExtraValue.KEYBOARD_LAYOUT_SET;
import android.app.AlertDialog;
+import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.DialogInterface.OnCancelListener;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.inputmethodservice.InputMethodService;
import android.os.Build;
+import android.os.IBinder;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
import android.view.MotionEvent;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.Window;
+import android.view.WindowManager;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;
+import android.widget.Button;
import android.widget.Toast;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardSwitcher;
+import com.android.inputmethod.keyboard.LatinKeyboardView;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.R;
@@ -73,6 +82,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
/* package */ static boolean sIsLogging = false;
private static final int OUTPUT_FORMAT_VERSION = 1;
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 FILENAME_PREFIX = "researchLog";
private static final String FILENAME_SUFFIX = ".txt";
private static final SimpleDateFormat TIMESTAMP_DATEFORMAT =
@@ -118,7 +128,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
private Suggest mSuggest;
private Dictionary mDictionary;
private KeyboardSwitcher mKeyboardSwitcher;
- private Context mContext;
+ private InputMethodService mInputMethodService;
private ResearchLogUploader mResearchLogUploader;
@@ -163,11 +173,8 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
mResearchLogUploader = new ResearchLogUploader(ims, mFilesDir);
mResearchLogUploader.start();
mKeyboardSwitcher = keyboardSwitcher;
- mContext = ims;
+ mInputMethodService = ims;
mPrefs = prefs;
-
- // TODO: force user to decide at splash screen instead of defaulting to on.
- setLoggingAllowed(true);
}
private void cleanupLoggingDir(final File dir, final long time) {
@@ -179,6 +186,73 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
}
}
+ public void latinKeyboardView_onAttachedToWindow() {
+ maybeShowSplashScreen();
+ }
+
+ private boolean hasSeenSplash() {
+ return mPrefs.getBoolean(PREF_RESEARCH_HAS_SEEN_SPLASH, false);
+ }
+
+ private Dialog mSplashDialog = null;
+
+ private void maybeShowSplashScreen() {
+ if (hasSeenSplash()) {
+ return;
+ }
+ if (mSplashDialog != null && mSplashDialog.isShowing()) {
+ return;
+ }
+ final IBinder windowToken = mKeyboardSwitcher.getKeyboardView().getWindowToken();
+ if (windowToken == null) {
+ return;
+ }
+ mSplashDialog = new Dialog(mInputMethodService, android.R.style.Theme_Holo_Dialog);
+ mSplashDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
+ mSplashDialog.setContentView(R.layout.research_splash);
+ mSplashDialog.setCancelable(true);
+ final Window w = mSplashDialog.getWindow();
+ final WindowManager.LayoutParams lp = w.getAttributes();
+ lp.token = windowToken;
+ lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
+ w.setAttributes(lp);
+ w.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
+ mSplashDialog.setOnCancelListener(new OnCancelListener() {
+ @Override
+ public void onCancel(DialogInterface dialog) {
+ mInputMethodService.requestHideSelf(0);
+ }
+ });
+ final Button doNotLogButton = (Button) mSplashDialog.findViewById(
+ R.id.research_do_not_log_button);
+ doNotLogButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onUserLoggingElection(false);
+ mSplashDialog.dismiss();
+ }
+ });
+ final Button doLogButton = (Button) mSplashDialog.findViewById(R.id.research_do_log_button);
+ doLogButton.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onUserLoggingElection(true);
+ mSplashDialog.dismiss();
+ }
+ });
+ mSplashDialog.show();
+ }
+
+ public void onUserLoggingElection(final boolean enableLogging) {
+ setLoggingAllowed(enableLogging);
+ if (mPrefs == null) {
+ return;
+ }
+ final Editor e = mPrefs.edit();
+ e.putBoolean(PREF_RESEARCH_HAS_SEEN_SPLASH, true);
+ e.apply();
+ }
+
private File createLogFile(File filesDir) {
final StringBuilder sb = new StringBuilder();
sb.append(FILENAME_PREFIX).append('-');
@@ -189,6 +263,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
}
private void start() {
+ maybeShowSplashScreen();
updateSuspendedState();
requestIndicatorRedraw();
if (!isAllowedToLog()) {
@@ -705,7 +780,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
}
researchLogger.start();
if (editorInfo != null) {
- final Context context = researchLogger.mContext;
+ final Context context = researchLogger.mInputMethodService;
try {
final PackageInfo packageInfo;
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(),
@@ -900,7 +975,7 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang
// Play it safe. Remove privacy-sensitive events.
researchLogger.publishLogUnit(researchLogger.mCurrentLogUnit, true);
researchLogger.mCurrentLogUnit = new LogUnit();
- getInstance().restart();
+ getInstance().stop();
}
}