Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 244c825c authored by Tadashi G. Takaoka's avatar Tadashi G. Takaoka Committed by Android (Google) Code Review
Browse files

Merge "Cleanup EditorInfoCompatUtils"

parents 7a0779a4 0d1a5d5b
Loading
Loading
Loading
Loading
+5 −41
Original line number Diff line number Diff line
@@ -17,41 +17,14 @@
package com.android.inputmethod.compat;

import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;

import java.lang.reflect.Field;

public class EditorInfoCompatUtils {
    private static final Field FIELD_IME_FLAG_NAVIGATE_NEXT = CompatUtils.getField(
            EditorInfo.class, "IME_FLAG_NAVIGATE_NEXT");
    private static final Field FIELD_IME_FLAG_NAVIGATE_PREVIOUS = CompatUtils.getField(
            EditorInfo.class, "IME_FLAG_NAVIGATE_PREVIOUS");
    private static final Field FIELD_IME_FLAG_FORCE_ASCII = CompatUtils.getField(
            EditorInfo.class, "IME_FLAG_FORCE_ASCII");
    private static final Field FIELD_IME_ACTION_PREVIOUS = CompatUtils.getField(
            EditorInfo.class, "IME_ACTION_PREVIOUS");
    private static final Integer OBJ_IME_FLAG_NAVIGATE_NEXT = (Integer) CompatUtils
            .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_NEXT);
    private static final Integer OBJ_IME_FLAG_NAVIGATE_PREVIOUS = (Integer) CompatUtils
            .getFieldValue(null, null, FIELD_IME_FLAG_NAVIGATE_PREVIOUS);
    private static final Integer OBJ_IME_FLAG_FORCE_ASCII = (Integer) CompatUtils
            .getFieldValue(null, null, FIELD_IME_FLAG_FORCE_ASCII);
    private static final Integer OBJ_IME_ACTION_PREVIOUS = (Integer) CompatUtils
            .getFieldValue(null, null, FIELD_IME_ACTION_PREVIOUS);

    // EditorInfo.IME_FLAG_NAVIGATE_NEXT has been introduced since API#11 (Honeycomb).
    public static boolean hasFlagNavigateNext(int imeOptions) {
        if (OBJ_IME_FLAG_NAVIGATE_NEXT == null)
            return false;
        return (imeOptions & OBJ_IME_FLAG_NAVIGATE_NEXT) != 0;
    }

    // EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS has been introduced since API#11 (Honeycomb).
    public static boolean hasFlagNavigatePrevious(int imeOptions) {
        if (OBJ_IME_FLAG_NAVIGATE_PREVIOUS == null)
            return false;
        return (imeOptions & OBJ_IME_FLAG_NAVIGATE_PREVIOUS) != 0;
    }

    // EditorInfo.IME_FLAG_FORCE_ASCII has been introduced since API#16 (JellyBean).
    public static boolean hasFlagForceAscii(int imeOptions) {
@@ -60,13 +33,6 @@ public class EditorInfoCompatUtils {
        return (imeOptions & OBJ_IME_FLAG_FORCE_ASCII) != 0;
    }

    // EditorInfo.IME_ACTION_PREVIOUS has been introduced since API#11 (Honeycomb).
    public static void performEditorActionPrevious(InputConnection ic) {
        if (OBJ_IME_ACTION_PREVIOUS == null || ic == null)
            return;
        ic.performEditorAction(OBJ_IME_ACTION_PREVIOUS);
    }

    public static String imeActionName(int imeOptions) {
        final int actionId = imeOptions & EditorInfo.IME_MASK_ACTION;
        switch (actionId) {
@@ -84,14 +50,12 @@ public class EditorInfoCompatUtils {
            return "actionNext";
        case EditorInfo.IME_ACTION_DONE:
            return "actionDone";
        default:
            if (OBJ_IME_ACTION_PREVIOUS != null && actionId == OBJ_IME_ACTION_PREVIOUS) {
        case EditorInfo.IME_ACTION_PREVIOUS:
            return "actionPrevious";
            } else {
        default:
            return "actionUnknown(" + actionId + ")";
        }
    }
    }

    public static String imeOptionsName(int imeOptions) {
        final String action = imeActionName(imeOptions);
@@ -99,10 +63,10 @@ public class EditorInfoCompatUtils {
        if ((imeOptions & EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) {
            flags.append("flagNoEnterAction|");
        }
        if (hasFlagNavigateNext(imeOptions)) {
        if ((imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0) {
            flags.append("flagNavigateNext|");
        }
        if (hasFlagNavigatePrevious(imeOptions)) {
        if ((imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != 0) {
            flags.append("flagNavigatePrevious|");
        }
        if (hasFlagForceAscii(imeOptions)) {
+2 −2
Original line number Diff line number Diff line
@@ -131,11 +131,11 @@ public class KeyboardId {
    }

    public boolean navigateNext() {
        return EditorInfoCompatUtils.hasFlagNavigateNext(mEditorInfo.imeOptions);
        return (mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0;
    }

    public boolean navigatePrevious() {
        return EditorInfoCompatUtils.hasFlagNavigatePrevious(mEditorInfo.imeOptions);
        return (mEditorInfo.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != 0;
    }

    public boolean passwordInput() {
+1 −2
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.compat.EditorInfoCompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.keyboard.Keyboard;
@@ -1273,7 +1272,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
            performeEditorAction(EditorInfo.IME_ACTION_NEXT);
            break;
        case Keyboard.CODE_ACTION_PREVIOUS:
            EditorInfoCompatUtils.performEditorActionPrevious(getCurrentInputConnection());
            performeEditorAction(EditorInfo.IME_ACTION_PREVIOUS);
            break;
        case Keyboard.CODE_LANGUAGE_SWITCH:
            handleLanguageSwitchKey();