Bug 767597 - Part 2: Move autocomplete IME blocklist and use new InputMethods class. r=blassey

This commit is contained in:
Chris Peterson 2012-07-22 00:18:14 -07:00
parent ef77a6fab2
commit f3e81789f1
3 changed files with 26 additions and 34 deletions

View File

@ -30,9 +30,12 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Arrays;
import java.util.Collection;
public class FormAssistPopup extends RelativeLayout implements GeckoEventListener {
private Context mContext;
private Animation mAnimation;
private Animation mAnimation;
private ListView mAutoCompleteList;
private RelativeLayout mValidationMessage;
@ -61,6 +64,15 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
private static final String LOGTAG = "FormAssistPopup";
// The blocklist is so short that ArrayList is probably cheaper than HashSet.
private static final Collection<String> sInputMethodBlocklist = Arrays.asList(new String[] {
InputMethods.METHOD_GOOGLE_JAPANESE_INPUT, // bug 775850
InputMethods.METHOD_OPENWNN_PLUS, // bug 768108
InputMethods.METHOD_SIMEJI, // bug 768108
InputMethods.METHOD_SWYPE, // bug 755909
InputMethods.METHOD_SWYPE_BETA, // bug 755909
});
public FormAssistPopup(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
@ -297,8 +309,9 @@ public class FormAssistPopup extends RelativeLayout implements GeckoEventListene
}
}
void block(boolean blocking) {
broadcastGeckoEvent("FormAssist:Blocklisted", String.valueOf(blocking));
void onInputMethodChanged(String newInputMethod) {
boolean blocklisted = sInputMethodBlocklist.contains(newInputMethod);
broadcastGeckoEvent("FormAssist:Blocklisted", String.valueOf(blocklisted));
}
private static void broadcastGeckoEvent(String eventName, String eventData) {

View File

@ -41,8 +41,6 @@ import android.view.inputmethod.InputMethodManager;
import org.mozilla.gecko.gfx.InputConnectionHandler;
import org.mozilla.gecko.gfx.LayerController;
import java.util.Arrays;
import java.util.Collection;
import java.util.Timer;
import java.util.TimerTask;
@ -92,15 +90,6 @@ public class GeckoInputConnection
private static String mIMETypeHint;
private static String mIMEActionHint;
// The blocklist is so short that ArrayList is probably cheaper than HashSet.
private final Collection<String> sFormAutoCompleteBlocklist = Arrays.asList(new String[] {
"com.adamrocker.android.input.simeji/.OpenWnnSimeji", // Simeji (bug 768108)
"com.google.android.inputmethod.japanese/.MozcService", // Google Japanese Input (bug 775850)
"com.nuance.swype.input/.IME", // Swype Beta (bug 755909)
"com.owplus.ime.openwnnplus/.OpenWnnJAJP", // OpenWnn Plus (bug 768108)
"com.swype.android.inputmethod/.SwypeInputMethod" // Swype (bug 755909)
});
private String mCurrentInputMethod;
// Is a composition active?
@ -448,7 +437,7 @@ public class GeckoInputConnection
private static InputMethodManager getInputMethodManager() {
Context context = getView().getContext();
return (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
return InputMethods.getInputMethodManager(context);
}
protected void notifyTextChange(InputMethodManager imm, String text,
@ -847,7 +836,8 @@ public class GeckoInputConnection
else if (mIMEActionHint != null && mIMEActionHint.length() != 0)
outAttrs.actionLabel = mIMEActionHint;
DisplayMetrics metrics = GeckoApp.mAppContext.getDisplayMetrics();
GeckoApp app = GeckoApp.mAppContext;
DisplayMetrics metrics = app.getDisplayMetrics();
if (Math.min(metrics.widthPixels, metrics.heightPixels) > INLINE_IME_MIN_DISPLAY_SIZE) {
// prevent showing full-screen keyboard only when the screen is tall enough
// to show some reasonable amount of the page (see bug 752709)
@ -863,18 +853,13 @@ public class GeckoInputConnection
}
String prevInputMethod = mCurrentInputMethod;
mCurrentInputMethod = getCurrentInputMethod();
mCurrentInputMethod = InputMethods.getCurrentInputMethod(app);
// If the user has changed IMEs, check whether the new IME is blocklisted.
// If the user has changed IMEs, then notify input method observers.
if (mCurrentInputMethod != prevInputMethod) {
FormAssistPopup popup = GeckoApp.mAppContext.mFormAssistPopup;
FormAssistPopup popup = app.mFormAssistPopup;
if (popup != null) {
boolean blocklisted = mCurrentInputMethod != null &&
sFormAutoCompleteBlocklist.contains(mCurrentInputMethod);
if (DEBUG && blocklisted) {
Log.d(LOGTAG, "FormAssist: Blocklisting \"" + mCurrentInputMethod + "\" IME");
}
popup.block(blocklisted);
popup.onInputMethodChanged(mCurrentInputMethod);
}
}
@ -1188,12 +1173,6 @@ public class GeckoInputConnection
return new Span(start, end, content);
}
private String getCurrentInputMethod() {
return Secure.getString(GeckoApp.mAppContext.getContentResolver(),
Secure.DEFAULT_INPUT_METHOD);
}
private static String prettyPrintString(CharSequence s) {
// Quote string and replace newlines with CR arrows.
return "\"" + s.toString().replace('\n', UNICODE_CRARR) + "\"";

View File

@ -14,19 +14,19 @@ import java.util.Collection;
final class InputMethods {
public static final String METHOD_GOOGLE_JAPANESE_INPUT = "com.google.android.inputmethod.japanese/.MozcService";
public static final String METHOD_OPENWNN_PLUS = "com.owplus.ime.openwnnplus/.OpenWnnJAJP";
public static final String METHOD_SIMEJI = "com.adamrocker.android.input.simeji/.OpenWnnSimeji";
public static final String METHOD_SWYPE = "com.swype.android.inputmethod/.SwypeInputMethod";
public static final String METHOD_SWYPE_BETA = "com.nuance.swype.input/.IME";
/* These input method names are currently unused, but kept here for future reference:
public static final String METHOD_EYES_FREE_KEYBOARD = "com.googlecode.eyesfree.inputmethod.latin/.LatinIME";
public static final String METHOD_GO_KEYBOARD = "com.jb.gokeyboard/.GoKeyboard";
public static final String METHOD_GOOGLE_JAPANESE_INPUT = "com.google.android.inputmethod.japanese/.MozcService";
public static final String METHOD_GOOGLE_PINYIN = "com.google.android.inputmethod.pinyin/.PinyinIME";
public static final String METHOD_GOOGLE_TALKBACK = "com.google.android.marvin.talkback/com.googlecode.eyesfree.inputmethod.latin.LatinIME";
public static final String METHOD_HACKERS_KEYBOARD = "org.pocketworkstation.pckeyboard/.LatinIME";
public static final String METHOD_OPENWNN_PLUS = "com.owplus.ime.openwnnplus/.OpenWnnJAJP";
public static final String METHOD_SAMSUNG_GALAXY_NOTE = "com.samsung.sec.android.inputmethod.axt9/.AxT9IME";
public static final String METHOD_SIMEJI = "com.adamrocker.android.input.simeji/.OpenWnnSimeji";
public static final String METHOD_SLIDE_IT_KEYBOARD = "com.dasur.slideit.vt.lite/com.dasur.slideit.SlideITIME";
public static final String METHOD_SWIFTKEY_TRIAL = "com.touchtype.swiftkey.phone.trial/com.touchtype.KeyboardService";
public static final String METHOD_TOUCHPAL_KEYBOARD = "com.cootek.smartinputv5/.TouchPalIME";