From ab008844c005de5d4029c0ff1f0ea87702d32158 Mon Sep 17 00:00:00 2001
From: conlan <42314275@qq.com>
Date: Tue, 27 Jul 2021 12:16:39 +0800
Subject: [PATCH] =?UTF-8?q?add=20keyboard=20remote=20,=E5=A2=9E=E5=8A=A0?=
=?UTF-8?q?=E9=94=AE=E7=9B=98=E9=81=A5=E6=8E=A7=E6=93=8D=E4=BD=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../btn_keyboard_key_functional_lxx_light.xml | 2 +-
.../LatinIME/java/res/values/colors.xml | 1 +
.../com/android/inputmethod/keyboard/Key.java | 25 +-
.../keyboard/KeyboardSwitcher.java | 63 ++++-
.../inputmethod/keyboard/KeyboardView.java | 45 +++-
.../keyboard/MainKeyboardView.java | 226 +++++++++++++++++-
.../keyboard/emoji/EmojiPalettesView.java | 73 +++++-
.../android/inputmethod/latin/LatinIME.java | 53 +++-
.../suggestions/SuggestionStripView.java | 37 ++-
9 files changed, 507 insertions(+), 18 deletions(-)
mode change 100644 => 100755 packages/inputmethods/LatinIME/java/res/drawable/btn_keyboard_key_functional_lxx_light.xml
mode change 100644 => 100755 packages/inputmethods/LatinIME/java/res/values/colors.xml
mode change 100644 => 100755 packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/Key.java
mode change 100644 => 100755 packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
mode change 100644 => 100755 packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardView.java
mode change 100644 => 100755 packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
mode change 100644 => 100755 packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java
mode change 100644 => 100755 packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/LatinIME.java
mode change 100644 => 100755 packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
diff --git a/packages/inputmethods/LatinIME/java/res/drawable/btn_keyboard_key_functional_lxx_light.xml b/packages/inputmethods/LatinIME/java/res/drawable/btn_keyboard_key_functional_lxx_light.xml
old mode 100644
new mode 100755
index e518ca11d8..c92568f6c1
--- a/packages/inputmethods/LatinIME/java/res/drawable/btn_keyboard_key_functional_lxx_light.xml
+++ b/packages/inputmethods/LatinIME/java/res/drawable/btn_keyboard_key_functional_lxx_light.xml
@@ -17,6 +17,6 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Functional keys. -->
<item android:state_pressed="true"
- android:drawable="@color/key_background_pressed_lxx_light" />
+ android:drawable="@color/key_focus_orange" />
<item android:drawable="@color/key_background_lxx_light" />
</selector>
diff --git a/packages/inputmethods/LatinIME/java/res/values/colors.xml b/packages/inputmethods/LatinIME/java/res/values/colors.xml
old mode 100644
new mode 100755
index 5453d51c17..25aa53da15
--- a/packages/inputmethods/LatinIME/java/res/values/colors.xml
+++ b/packages/inputmethods/LatinIME/java/res/values/colors.xml
@@ -84,4 +84,5 @@
<color name="setup_welcome_video_margin_color">#FFCCCCCC</color>
<!-- Accent color for the notification. We need to match this to the OS build -->
<color name="notification_accent_color">#FF607D8B</color>
+ <color name="key_focus_orange">#fa6f14</color>
</resources>
diff --git a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/Key.java b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/Key.java
old mode 100644
new mode 100755
index 299d1b7c5e..883f55260f
--- a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/Key.java
@@ -27,7 +27,7 @@ import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
-
+import android.util.Log;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.keyboard.internal.KeyStyle;
@@ -204,6 +204,7 @@ public class Key implements Comparable<Key> {
/** The current pressed state of this key */
private boolean mPressed;
+ private boolean mFocus;
/** Key is enabled and responds on press */
private boolean mEnabled = true;
@@ -439,6 +440,7 @@ public class Key implements Comparable<Key> {
// Key state.
mPressed = key.mPressed;
mEnabled = key.mEnabled;
+ mFocus = key.mFocus;
}
@Nonnull
@@ -905,6 +907,13 @@ public class Key implements Comparable<Key> {
public void onReleased() {
mPressed = false;
}
+ public void onFocus() {
+ mFocus = true;
+ }
+
+ public void onUnFocus() {
+ mFocus = false;
+ }
public final boolean isEnabled() {
return mEnabled;
@@ -1002,6 +1011,20 @@ public class Key implements Comparable<Key> {
background.setState(state);
return background;
}
+ public final Drawable selectFocusDrawable(final Drawable keyBackground,
+ final Drawable functionalKeyBackground, final Drawable spacebarBackground) {
+ final Drawable background;
+ if (mBackgroundType == BACKGROUND_TYPE_FUNCTIONAL) {
+ background = functionalKeyBackground;
+ } else if (mBackgroundType == BACKGROUND_TYPE_SPACEBAR) {
+ background = spacebarBackground;
+ } else {
+ background = keyBackground;
+ }
+ final int[] state = KeyBackgroundState.STATES[mBackgroundType].getState(mFocus);
+ background.setState(state);
+ return background;
+ }
public static class Spacer extends Key {
public Spacer(final TypedArray keyAttr, final KeyStyle keyStyle,
diff --git a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
old mode 100644
new mode 100755
index 4d337b6f31..7bc80ecc7c
--- a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
+++ b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java
@@ -43,12 +43,14 @@ import com.android.inputmethod.latin.utils.LanguageOnSpacebarUtils;
import com.android.inputmethod.latin.utils.RecapitalizeStatus;
import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.ScriptUtils;
-
+import android.view.KeyEvent;
+import com.android.inputmethod.keyboard.Key;
+import com.android.inputmethod.latin.common.Constants;
import javax.annotation.Nonnull;
public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
private static final String TAG = KeyboardSwitcher.class.getSimpleName();
-
+ private static final boolean DEBUG = false;
private InputView mCurrentInputView;
private View mMainKeyboardFrame;
private MainKeyboardView mKeyboardView;
@@ -285,6 +287,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mMainKeyboardFrame.setVisibility(visibility);
mEmojiPalettesView.setVisibility(View.GONE);
mEmojiPalettesView.stopEmojiPalettes();
+ mEmojiPalettesView.clearFocus();
}
// Implements {@link KeyboardState.SwitchActions}.
@@ -295,6 +298,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
}
final Keyboard keyboard = mKeyboardLayoutSet.getKeyboard(KeyboardId.ELEMENT_ALPHABET);
mMainKeyboardFrame.setVisibility(View.GONE);
+ mMainKeyboardFrame.clearFocus();
// The visibility of {@link #mKeyboardView} must be aligned with {@link #MainKeyboardFrame}.
// @see #getVisibleKeyboardView() and
// @see LatinIME#onComputeInset(android.inputmethodservice.InputMethodService.Insets)
@@ -408,6 +412,61 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
final int currentRecapitalizeState) {
mState.onEvent(event, currentAutoCapsState, currentRecapitalizeState);
}
+
+ public boolean processFunctionKey(int keyCode) {
+ boolean ret = false;
+ if (isShowingEmojiPalettes()) {
+ Key key = mEmojiPalettesView.processFunctionKey(keyCode);
+ if (key != null) {
+ responseForEmojboard(key);
+ }
+ return true;
+ } else {
+ final MainKeyboardView mainKeyboardView = getMainKeyboardView();
+ if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
+ Key key = mainKeyboardView.processFunctionKey(keyCode);
+ if (key != null) {
+ responseForMainboard(key);
+ return true;
+ }
+ }
+ if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT ||
+ keyCode == KeyEvent.KEYCODE_DPAD_RIGHT ||
+ keyCode == KeyEvent.KEYCODE_DPAD_UP ||
+ keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
+ mainKeyboardView.processFunctionKey(keyCode);
+ return true;
+ }
+ }
+ return ret;
+ }
+
+
+ private void responseForMainboard(Key k) {
+ final MainKeyboardView mainKeyboardView = getMainKeyboardView();
+ int keyCode= k.getCode();
+ if (DEBUG)
+ Log.d(TAG, "Trace_key, response k.getCode:" + keyCode);
+ if (Constants.CODE_SHIFT == keyCode || //-1
+ Constants.CODE_SWITCH_ALPHA_SYMBOL == keyCode) {
+ this.onPressKey(keyCode, true, 0, -1);
+ this.onReleaseKey(keyCode, false, 0, -1);
+ mainKeyboardView.goFirstKey();
+ return;
+ } else if (Constants.CODE_OUTPUT_TEXT == keyCode) {
+ mLatinIME.onTextInput(k.getLabel());
+ return;
+ } else if (Constants.CODE_EMOJI == keyCode) {
+ return;
+ }
+ mLatinIME.doInputSoftKey(k);
+ if (!mainKeyboardView.checkLastKey())
+ mainKeyboardView.goFirstKey();
+ }
+
+
+ private void responseForEmojboard(Key k) {
+ }
public boolean isShowingKeyboardId(@Nonnull int... keyboardIds) {
if (mKeyboardView == null || !mKeyboardView.isShown()) {
diff --git a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardView.java
old mode 100644
new mode 100755
index 27e538cb71..0649bf0dde
--- a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -31,7 +31,7 @@ import android.graphics.drawable.NinePatchDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
-
+import android.util.Log;
import com.android.inputmethod.keyboard.internal.KeyDrawParams;
import com.android.inputmethod.keyboard.internal.KeyVisualAttributes;
import com.android.inputmethod.latin.R;
@@ -82,6 +82,8 @@ public class KeyboardView extends View {
private final KeyVisualAttributes mKeyVisualAttributes;
// Default keyLabelFlags from {@link KeyboardTheme}.
// Currently only "alignHintLabelToBottom" is supported.
+ private final static String TAG = "KeyboardView";
+ private final static boolean DEBUG = false;
private final int mDefaultKeyLabelFlags;
private final float mKeyHintLetterPadding;
private final String mKeyPopupHintLetter;
@@ -340,11 +342,52 @@ public class KeyboardView extends View {
if (background != null) {
onDrawKeyBackground(key, canvas, background);
}
+ if (isControlByKey()) {
+ final Drawable focusBackground = key.selectFocusDrawable(mKeyBackground, mFunctionalKeyBackground, mSpacebarBackground);
+ onDrawKeyFocus(key, canvas, focusBackground);
+ }
}
onDrawKeyTopVisuals(key, canvas, paint, params);
canvas.translate(-keyDrawX, -keyDrawY);
}
+ private void onDrawKeyFocus(final Key key, final Canvas canvas,
+ final Drawable background) {
+ if (DEBUG)
+ Log.d(TAG, "Trace_key, now onDrawKeyFocus, keyLabel:" + key.getLabel());
+ final int keyWidth = key.getDrawWidth();
+ final int keyHeight = key.getHeight();
+ final int bgWidth, bgHeight, bgX, bgY;
+ if (key.needsToKeepBackgroundAspectRatio(mDefaultKeyLabelFlags)
+ // HACK: To disable expanding normal/functional key background.
+ && !key.hasCustomActionLabel()) {
+ final int intrinsicWidth = background.getIntrinsicWidth();
+ final int intrinsicHeight = background.getIntrinsicHeight();
+ final float minScale = Math.min(
+ keyWidth / (float)intrinsicWidth, keyHeight / (float)intrinsicHeight);
+ bgWidth = (int)(intrinsicWidth * minScale);
+ bgHeight = (int)(intrinsicHeight * minScale);
+ bgX = (keyWidth - bgWidth) / 2;
+ bgY = (keyHeight - bgHeight) / 2;
+ } else {
+ final Rect padding = mKeyBackgroundPadding;
+ bgWidth = keyWidth + padding.left + padding.right;
+ bgHeight = keyHeight + padding.top + padding.bottom;
+ bgX = -padding.left;
+ bgY = -padding.top;
+ }
+ final Rect bounds = background.getBounds();
+ if (bgWidth != bounds.right || bgHeight != bounds.bottom) {
+ background.setBounds(0, 0, bgWidth, bgHeight);
+ }
+ canvas.translate(bgX, bgY);
+ background.draw(canvas);
+ canvas.translate(-bgX, -bgY);
+ }
+
+ protected boolean isControlByKey() {
+ return false;
+ }
// Draw key background.
protected void onDrawKeyBackground(@Nonnull final Key key, @Nonnull final Canvas canvas,
diff --git a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
old mode 100644
new mode 100755
index 00d4fa236f..df42c50383
--- a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -59,10 +59,12 @@ import com.android.inputmethod.latin.common.CoordinateUtils;
import com.android.inputmethod.latin.settings.DebugSettings;
import com.android.inputmethod.latin.utils.LanguageOnSpacebarUtils;
import com.android.inputmethod.latin.utils.TypefaceUtils;
-
+import android.view.KeyEvent;
+import com.android.inputmethod.keyboard.Key;
+import java.util.List;
import java.util.Locale;
import java.util.WeakHashMap;
-
+import com.android.inputmethod.latin.LatinIME;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -112,7 +114,8 @@ import javax.annotation.Nullable;
public final class MainKeyboardView extends KeyboardView implements DrawingProxy,
MoreKeysPanel.Controller {
private static final String TAG = MainKeyboardView.class.getSimpleName();
-
+ private final static boolean DEBUG = false;
+ private boolean controlByKey = false;
/** Listener for {@link KeyboardActionListener}. */
private KeyboardActionListener mKeyboardActionListener;
@@ -158,7 +161,8 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
// More keys panel (used by both more keys keyboard and more suggestions view)
// TODO: Consider extending to support multiple more keys panels
private MoreKeysPanel mMoreKeysPanel;
-
+ private Key lastFocusKey = null;
+ private int lastFocusIndex = -1;
// Gesture floating preview text
// TODO: Make this parameter customizable by user via settings.
private int mGestureFloatingPreviewTextLingerTimeout;
@@ -170,6 +174,8 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
private final int mLanguageOnSpacebarHorizontalMargin;
private MainKeyboardAccessibilityDelegate mAccessibilityDelegate;
+
+ public static boolean KeyEventProcessedFlag = false;
public MainKeyboardView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.mainKeyboardViewStyle);
@@ -695,6 +701,7 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
@Override
public boolean onTouchEvent(final MotionEvent event) {
+ setControlByKey(false);
if (getKeyboard() == null) {
return false;
}
@@ -723,6 +730,212 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
tracker.processMotionEvent(event, mKeyDetector);
return true;
}
+ public Key processFunctionKey(int keyCode) {
+ if (lastFocusKey == null || !isControlByKey()) {
+ goFirstKey();
+ return lastFocusKey;
+ }
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_DPAD_CENTER:
+ break;
+ case KeyEvent.KEYCODE_DPAD_DOWN:
+ goKeyDown(lastFocusKey);
+ break;
+ case KeyEvent.KEYCODE_DPAD_RIGHT:
+ goKeyRight(lastFocusKey);
+ break;
+ case KeyEvent.KEYCODE_DPAD_LEFT:
+ goKeyLeft(lastFocusKey);
+ break;
+ case KeyEvent.KEYCODE_DPAD_UP:
+ goKeyUp(lastFocusKey);
+ break;
+ default:
+ break;
+ }
+ return lastFocusKey;
+ }
+
+ public boolean checkLastKey() {
+ final Keyboard kb = getKeyboard();
+ List<Key> sortedKeys = kb.getSortedKeys();
+ int sz = sortedKeys.size();
+ if (lastFocusIndex >= sz)
+ return false;
+ if (lastFocusIndex < 0)
+ return false;
+ Key k = sortedKeys.get(lastFocusIndex);
+ if (k != lastFocusKey && k != null)
+ return false;
+ return true;
+ }
+
+ private boolean checkFacing(Key src, Key dst) {
+ int mid = src.getX() + src.getWidth() / 2;
+ int leftX = src.getX();
+ int rightX = src.getX() + src.getWidth();
+ if ((leftX > dst.getX() && leftX < dst.getX() + dst.getWidth()) ||
+ (rightX > dst.getX() && rightX < dst.getX() + dst.getWidth()))
+ return true;
+ return false;
+ }
+
+ public Key goFirstKey() {
+ if (DEBUG)
+ Log.d(TAG, "Trace_key, now enter goFirstKey()");
+ final Keyboard kb = getKeyboard();
+ List<Key> sortedKeys = kb.getSortedKeys();
+ Key ret = sortedKeys.get(0);
+ changeFocusState(lastFocusKey, ret);
+ lastFocusIndex = 0;
+ invalidateKey(ret);
+ this.requestFocus();
+ return ret;
+ }
+
+ private void changeFocusState(Key lastKey, Key curKey) {
+ if (lastFocusKey != null) {
+ lastKey.onUnFocus();
+ invalidateKey(lastKey);
+ }
+ if (curKey != null) {
+ curKey.onFocus();
+ invalidateKey(curKey);
+ lastFocusKey = curKey;
+ setControlByKey(true);
+ }
+ }
+
+ private Key goKeyDown(Key k) {
+ final Keyboard kb = getKeyboard();
+ Key ret = null;
+ int minDist = 0;
+ KeyEventProcessedFlag = true;
+ List<Key> sortedKeys = kb.getSortedKeys();
+ int sz = sortedKeys.size();
+ if (lastFocusIndex >= sz) {
+ lastFocusIndex = sz -1;
+ } else {
+ for (int i = lastFocusIndex + 1; i < sz; i++) {
+ Key tmp = sortedKeys.get(i);
+ if (k.getY() >= tmp.getY())
+ continue;
+ if (checkFacing(k, tmp)) {
+ ret = tmp;
+ lastFocusIndex = i;
+ changeFocusState(lastFocusKey, ret);
+ break;
+ }
+ if ((tmp.getX() + tmp.getWidth() / 2) >= (k.getX() + k.getWidth() / 2)) {
+ ret = tmp;
+ lastFocusIndex = i;
+ changeFocusState(lastFocusKey, ret);
+ break;
+ }
+ }
+ }
+ if (ret != null && DEBUG) {
+ Log.d(TAG, "Trace_key, key down ret:" + ret.getCode() + " label:" + ret.getLabel() + " string:" + ret.toString());
+ }
+ return ret;
+ }
+
+ private Key goKeyUp(Key k) {
+ final Keyboard kb = getKeyboard();
+ Key ret = null;
+ KeyEventProcessedFlag = false;
+ LatinIME.mIsFocusInKeyboard = false;
+ k.onUnFocus();
+ this.invalidateKey(k);
+ List<Key> sortedKeys = kb.getSortedKeys();
+ int sz = sortedKeys.size();
+ if (lastFocusIndex <= 0) {
+ lastFocusIndex = 0;
+ } else {
+ for (int i = lastFocusIndex - 1; i >= 0; i--) {
+ Key tmp = sortedKeys.get(i);
+ if (k.getY() <= tmp.getY())
+ continue;
+ if (checkFacing(k, tmp)) {
+ ret = tmp;
+ lastFocusIndex = i;
+ changeFocusState(lastFocusKey, ret);
+ KeyEventProcessedFlag = true;
+ LatinIME.mIsFocusInKeyboard = true;
+ break;
+ }
+ if ((tmp.getX() + tmp.getWidth() / 2) <= (k.getX() + k.getWidth() /2)) {
+ ret = tmp;
+ lastFocusIndex = i;
+ changeFocusState(lastFocusKey, ret);
+ KeyEventProcessedFlag = true;
+ LatinIME.mIsFocusInKeyboard = true;
+ break;
+ }
+ }
+ }
+ if (ret != null) {
+ if (DEBUG)
+ Log.d(TAG, "Trace_key, key down ret:" + ret.getCode() + " label:" + ret.getLabel() + " string:" + ret.toString());
+ return ret;
+ } else {
+ k.onFocus();
+ KeyEventProcessedFlag = true;
+ LatinIME.mIsFocusInKeyboard = true;
+ return k;
+ }
+ }
+
+ private Key goKeyLeft(Key k) {
+ if (lastFocusIndex == 0) {
+ return k;
+ }
+
+ final Keyboard kb = getKeyboard();
+ Key ret = null;
+ KeyEventProcessedFlag = false;
+ LatinIME.mIsFocusInKeyboard = false;
+ k.onUnFocus();
+ this.invalidateKey(k);
+ List<Key> sortedKeys = kb.getSortedKeys();
+ int sz = sortedKeys.size();
+ if (lastFocusIndex > 0 && lastFocusIndex < sz) {
+ lastFocusIndex--;
+ ret = sortedKeys.get(lastFocusIndex);
+ changeFocusState(lastFocusKey, ret);
+ KeyEventProcessedFlag = true;
+ LatinIME.mIsFocusInKeyboard = true;
+ }
+ if (ret != null && DEBUG) {
+ Log.d(TAG, "Trace_key, key down ret:" + ret.getCode() + " label:" + ret.getLabel() + " string:" + ret.toString());
+ }
+ return ret;
+ }
+
+ private Key goKeyRight(Key k) {
+ final Keyboard kb = getKeyboard();
+ Key ret = null;
+ List<Key> sortedKeys = kb.getSortedKeys();
+ KeyEventProcessedFlag = true;
+ int sz = sortedKeys.size();
+ if (lastFocusIndex >= 0 && lastFocusIndex < sz -1) {
+ lastFocusIndex++;
+ ret = sortedKeys.get(lastFocusIndex);
+ changeFocusState(lastFocusKey, ret);
+ }
+ if (ret != null && DEBUG) {
+ Log.d(TAG, "Trace_key, key down ret:" + ret.getCode() + " label:" + ret.getLabel() + " string:" + ret.toString());
+ }
+ return ret;
+ }
+
+ protected boolean isControlByKey() {
+ return controlByKey;
+ }
+
+ protected void setControlByKey(boolean b) {
+ controlByKey = b;
+ }
public void cancelAllOngoingEvents() {
mTimerHandler.cancelAllMessages();
@@ -892,4 +1105,9 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
super.deallocateMemory();
mDrawingPreviewPlacerView.deallocateMemory();
}
+
+
+ public Key getLastFocusKey(){
+ return lastFocusKey;
+ }
}
diff --git a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java
old mode 100644
new mode 100755
index a3b869d734..af4cd42323
--- a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java
+++ b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/keyboard/emoji/EmojiPalettesView.java
@@ -30,6 +30,7 @@ import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
+import android.util.Log;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -50,7 +51,10 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodSubtype;
import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.utils.ResourceUtils;
-
+import android.view.KeyEvent;
+import com.android.inputmethod.keyboard.Key;
+import android.view.FocusFinder;
+import java.util.concurrent.TimeUnit;
/**
* View class to implement Emoji palettes.
* The Emoji keyboard consists of group of views layout/emoji_palettes_view.
@@ -65,6 +69,8 @@ import com.android.inputmethod.latin.utils.ResourceUtils;
public final class EmojiPalettesView extends LinearLayout implements OnTabChangeListener,
ViewPager.OnPageChangeListener, View.OnClickListener, View.OnTouchListener,
EmojiPageKeyboardView.OnKeyEventListener {
+ private final static String TAG = "EmojiPalettesView";
+ private final static boolean DEBUG = false;
private final int mFunctionalKeyBackgroundId;
private final int mSpacebarBackgroundId;
private final boolean mCategoryIndicatorEnabled;
@@ -75,7 +81,7 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
private EmojiPalettesAdapter mEmojiPalettesAdapter;
private final EmojiLayoutParams mEmojiLayoutParams;
private final DeleteKeyOnTouchListener mDeleteKeyOnTouchListener;
-
+ private Key lastFocusKey = null;
private ImageButton mDeleteKey;
private TextView mAlphabetKeyLeft;
private TextView mAlphabetKeyRight;
@@ -356,6 +362,69 @@ public final class EmojiPalettesView extends LinearLayout implements OnTabChange
}
mKeyboardActionListener.onReleaseKey(code, false /* withSliding */);
}
+ public Key processFunctionKey(int keyCode) {
+ Key ret = null;
+ if (lastFocusKey == null) {
+ goFirstKey();
+ return lastFocusKey;
+ }
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_DPAD_CENTER:
+ break;
+ case KeyEvent.KEYCODE_DPAD_DOWN:
+ goKeyDown(lastFocusKey);
+ break;
+ case KeyEvent.KEYCODE_DPAD_RIGHT:
+ goKeyRight(lastFocusKey);
+ break;
+ case KeyEvent.KEYCODE_DPAD_LEFT:
+ goKeyLeft(lastFocusKey);
+ break;
+ case KeyEvent.KEYCODE_DPAD_UP:
+ goKeyUp(lastFocusKey);
+ break;
+ default:
+ break;
+ }
+ return lastFocusKey;
+ }
+
+ private int getTabCount() {
+ return mEmojiCategory.getShownCategories().size();
+ }
+
+ private Key goFirstKey() {
+ Key ret = null;
+ return ret;
+ }
+
+ private Key goKeyDown(Key k) {
+ Key ret = null;
+ return ret;
+ }
+
+ private Key goKeyUp(Key k) {
+ Key ret = null;
+ return ret;
+ }
+
+ private Key goKeyLeft(Key k) {
+ Key ret = null;
+ return ret;
+ }
+
+ private Key goKeyRight(Key k) {
+ Key ret = null;
+ final TabWidget tabWidget = mTabHost.getTabWidget();
+ if (DEBUG) {
+ if (FocusFinder.getInstance().findNextFocus(tabWidget, tabWidget.findFocus(), View.FOCUS_LEFT) == null) {
+ Log.d(TAG, "Trace_key, findNextFocus null");
+ } else {
+ Log.d(TAG, "Trace_key, findNextFocus not null");
+ }
+ }
+ return ret;
+ }
public void setHardwareAcceleratedDrawingEnabled(final boolean enabled) {
if (!enabled) return;
diff --git a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/LatinIME.java b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/LatinIME.java
old mode 100644
new mode 100755
index 00ed52cad5..15b644726f
--- a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -106,7 +106,9 @@ import java.util.Locale;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
-
+import android.view.KeyEvent;
+import com.android.inputmethod.keyboard.Key;
+import android.graphics.Color;
/**
* Input method implementation for Qwerty'ish keyboard.
*/
@@ -116,7 +118,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
PermissionsManager.PermissionsResultCallback {
static final String TAG = LatinIME.class.getSimpleName();
private static final boolean TRACE = false;
-
+ private static final boolean DEBUG = true;
private static final int EXTENDED_TOUCHABLE_REGION_HEIGHT = 100;
private static final int PERIOD_FOR_AUDIO_AND_HAPTIC_FEEDBACK_IN_KEY_REPEAT = 2;
private static final int PENDING_IMS_CALLBACK_DURATION_MILLIS = 800;
@@ -171,7 +173,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private final BroadcastReceiver mDictionaryDumpBroadcastReceiver =
new DictionaryDumpBroadcastReceiver(this);
-
+ public static boolean mIsFocusInKeyboard = true;
final static class HideSoftInputReceiver extends BroadcastReceiver {
private final InputMethodService mIms;
@@ -1395,6 +1397,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void onCodeInput(final int codePoint, final int x, final int y,
final boolean isKeyRepeat) {
+ if (DEBUG)
+ Log.d(TAG, "Trace_key, onCodeInput codePoint:" + codePoint + " isKeyRepeat:" + isKeyRepeat);
// TODO: this processing does not belong inside LatinIME, the caller should be doing this.
final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView();
// x and y include some padding, but everything down the line (especially native
@@ -1725,7 +1729,20 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Hooks for hardware keyboard
@Override
public boolean onKeyDown(final int keyCode, final KeyEvent keyEvent) {
- if (mEmojiAltPhysicalKeyDetector == null) {
+ if (true)
+ Log.d(TAG, "Trace_key, onKeyDown keyCode is:" + keyCode);
+ if (mIsFocusInKeyboard) {
+ if (processKey(keyEvent, 0 != keyEvent.getRepeatCount())) {
+ if (MainKeyboardView.KeyEventProcessedFlag == false)
+ mSuggestionStripView.getWordViews().get(mSuggestionStripView.mFocusIndex).setTextColor(Color.rgb(0,255,255));
+ return true;
+ }
+ }
+ else {
+ mSuggestionStripView.processFunctionKey(keyCode);
+ return true;
+ }
+ if (mEmojiAltPhysicalKeyDetector == null) {
mEmojiAltPhysicalKeyDetector = new EmojiAltPhysicalKeyDetector(
getApplicationContext().getResources());
}
@@ -1747,10 +1764,32 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
return super.onKeyDown(keyCode, keyEvent);
}
+ private boolean processKey(KeyEvent event, boolean realAction) {
+ final View visibleKeyboardView = mKeyboardSwitcher.getVisibleKeyboardView();
+ if (visibleKeyboardView == null || !hasSuggestionStripView()) {
+ return false;
+ }
+ if (!visibleKeyboardView.isShown())
+ return false;
+ int keyCode = event.getKeyCode();
+ if (DEBUG)
+ Log.d(TAG, "Trace_key, keycode: " + keyCode + ", realAction: "+ realAction);
+ return mKeyboardSwitcher.processFunctionKey(keyCode);
+ }
+
+ public void doInputSoftKey(Key k) {
+ int codeToSend = k.getCode();
+ if (Constants.CODE_SHORTCUT == codeToSend) {
+ //mSubtypeSwitcher.switchToShortcutIME(this);
+ }
+ onCodeInput(codeToSend, k.getX(), k.getY(), false);
+ }
@Override
public boolean onKeyUp(final int keyCode, final KeyEvent keyEvent) {
- if (mEmojiAltPhysicalKeyDetector == null) {
+ if (DEBUG)
+ Log.d(TAG, "Trace_key, onKeyUp keyCode is:" + keyCode);
+ if (mEmojiAltPhysicalKeyDetector == null) {
mEmojiAltPhysicalKeyDetector = new EmojiAltPhysicalKeyDetector(
getApplicationContext().getResources());
}
@@ -1945,7 +1984,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
return mRichImm.shouldOfferSwitchingToNextInputMethod(token, fallbackValue);
}
-
+ public static void ChangeFocusState() {
+ mIsFocusInKeyboard = !mIsFocusInKeyboard;
+ }
private void setNavigationBarVisibility(final boolean visible) {
if (BuildCompatUtils.EFFECTIVE_SDK_INT > Build.VERSION_CODES.M) {
// For N and later, IMEs can specify Color.TRANSPARENT to make the navigation bar
diff --git a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
old mode 100644
new mode 100755
index c1d1fad68c..8c551c1538
--- a/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
+++ b/packages/inputmethods/LatinIME/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
@@ -54,6 +54,8 @@ import com.android.inputmethod.latin.suggestions.MoreSuggestionsView.MoreSuggest
import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
import java.util.ArrayList;
+import com.android.inputmethod.latin.LatinIME;
+import android.view.KeyEvent;
public final class SuggestionStripView extends RelativeLayout implements OnClickListener,
OnLongClickListener {
@@ -78,7 +80,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private final ArrayList<TextView> mWordViews = new ArrayList<>();
private final ArrayList<TextView> mDebugInfoViews = new ArrayList<>();
private final ArrayList<View> mDividerViews = new ArrayList<>();
-
+ public int mFocusIndex = 0;
Listener mListener;
private SuggestedWords mSuggestedWords = SuggestedWords.getEmptyInstance();
private int mStartIndexOfMoreSuggestions;
@@ -485,4 +487,37 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
maybeShowImportantNoticeTitle();
}
}
+
+ public void processFunctionKey(int keyCode) {
+ if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
+ if (mFocusIndex >= 1) {
+ mFocusIndex--;
+ mWordViews.get(mFocusIndex).setTextColor(Color.rgb(0,255,255));
+ mWordViews.get(mFocusIndex+1).setTextColor(Color.rgb(128,138,135));
+ }
+ }
+ if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
+ if (mFocusIndex <= 1) {
+ mFocusIndex++;
+ mWordViews.get(mFocusIndex).setTextColor(Color.rgb(0,255,255));
+ mWordViews.get(mFocusIndex-1).setTextColor(Color.rgb(128,138,135));
+ }
+ }
+ if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
+ LatinIME.ChangeFocusState();
+ mWordViews.get(mFocusIndex).setTextColor(Color.rgb(128,138,135));
+ mMainKeyboardView.getLastFocusKey().onFocus();
+ mMainKeyboardView.invalidateKey(mMainKeyboardView.getLastFocusKey());
+ }
+ if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
+ LatinIME.ChangeFocusState();
+ onClick(mWordViews.get(mFocusIndex));
+ mMainKeyboardView.getLastFocusKey().onFocus();
+ mMainKeyboardView.invalidateKey(mMainKeyboardView.getLastFocusKey());
+ }
+ }
+
+ public ArrayList<TextView> getWordViews() {
+ return mWordViews;
+ }
}
--
2.17.1
RK3576 Android14 LatinIME 支持遥控器操作
于 2025-02-28 13:43:59 首次发布