mirror of
https://github.com/yuliskov/LeanKeyboard.git
synced 2026-05-03 05:12:36 -04:00
refactoring
This commit is contained in:
@@ -1052,7 +1052,7 @@ public class LeanbackKeyboardContainer {
|
||||
|
||||
/**
|
||||
* Set touch state
|
||||
* @param state {@link LeanbackKeyboardContainer LeanbackKeyboardContainer} constant
|
||||
* @param state state e.g. {@link LeanbackKeyboardContainer#TOUCH_STATE_CLICK LeanbackKeyboardContainer.TOUCH_STATE_CLICK}
|
||||
*/
|
||||
public void setTouchState(final int state) {
|
||||
switch (state) {
|
||||
|
||||
@@ -21,8 +21,9 @@ import com.liskovsoft.leankeykeyboard.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LeanbackKeyboardController implements LeanbackKeyboardContainer.VoiceListener, LeanbackKeyboardContainer.DismissListener,
|
||||
OnTouchListener, OnHoverListener, Runnable {
|
||||
public class LeanbackKeyboardController implements LeanbackKeyboardContainer.VoiceListener,
|
||||
LeanbackKeyboardContainer.DismissListener,
|
||||
OnTouchListener, OnHoverListener, Runnable {
|
||||
public static final int CLICK_MOVEMENT_BLOCK_DURATION_MS = 500;
|
||||
private static final boolean DEBUG = false;
|
||||
private static final int KEY_CHANGE_HISTORY_SIZE = 10;
|
||||
@@ -207,75 +208,79 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
this.mContainer.setTouchState(0);
|
||||
}
|
||||
|
||||
private PointF getBestSnapPosition(PointF var1, long var2) {
|
||||
if (this.mKeyChangeHistory.size() <= 1) {
|
||||
return var1;
|
||||
private PointF getBestSnapPosition(final PointF currPoint, final long currTime) {
|
||||
if (mKeyChangeHistory.size() <= 1) {
|
||||
return currPoint;
|
||||
} else {
|
||||
int var4 = 0;
|
||||
int count = 0;
|
||||
|
||||
PointF var5;
|
||||
PointF pos;
|
||||
while (true) {
|
||||
var5 = var1;
|
||||
if (var4 >= this.mKeyChangeHistory.size() - 1) {
|
||||
pos = currPoint;
|
||||
if (count >= mKeyChangeHistory.size() - 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
LeanbackKeyboardController.KeyChange var6 = (LeanbackKeyboardController.KeyChange) this.mKeyChangeHistory.get(var4);
|
||||
if (var2 - ((LeanbackKeyboardController.KeyChange) this.mKeyChangeHistory.get(var4 + 1)).time < 100L) {
|
||||
var5 = var6.position;
|
||||
this.mKeyChangeHistory.clear();
|
||||
this.mKeyChangeHistory.add(new LeanbackKeyboardController.KeyChange(var2, var5));
|
||||
LeanbackKeyboardController.KeyChange change = mKeyChangeHistory.get(count);
|
||||
if (currTime - mKeyChangeHistory.get(count + 1).time < 100L) {
|
||||
pos = change.position;
|
||||
mKeyChangeHistory.clear();
|
||||
mKeyChangeHistory.add(new LeanbackKeyboardController.KeyChange(currTime, pos));
|
||||
break;
|
||||
}
|
||||
|
||||
++var4;
|
||||
++count;
|
||||
}
|
||||
|
||||
return var5;
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
private PointF getCurrentKeyPosition() {
|
||||
if (this.mContainer != null) {
|
||||
LeanbackKeyboardContainer.KeyFocus var1 = this.mContainer.getCurrFocus();
|
||||
return new PointF((float) var1.rect.centerX(), (float) var1.rect.centerY());
|
||||
if (mContainer != null) {
|
||||
LeanbackKeyboardContainer.KeyFocus focus = mContainer.getCurrFocus();
|
||||
return new PointF((float) focus.rect.centerX(), (float) focus.rect.centerY());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private PointF getRelativePosition(View var1, MotionEvent var2) {
|
||||
int[] var5 = new int[2];
|
||||
var1.getLocationOnScreen(var5);
|
||||
float var3 = var2.getRawX();
|
||||
float var4 = var2.getRawY();
|
||||
return new PointF(var3 - (float) var5[0], var4 - (float) var5[1]);
|
||||
private PointF getRelativePosition(View view, MotionEvent event) {
|
||||
int[] location = new int[2];
|
||||
view.getLocationOnScreen(location);
|
||||
float x = event.getRawX();
|
||||
float y = event.getRawY();
|
||||
return new PointF(x - (float) location[0], y - (float) location[1]);
|
||||
}
|
||||
|
||||
private int getSimplifiedKey(int var1) {
|
||||
int var2 = 23;
|
||||
if (var1 != 23) {
|
||||
byte var3 = 66;
|
||||
var2 = var3;
|
||||
if (var1 != 66) {
|
||||
var2 = var3;
|
||||
if (var1 != 160) {
|
||||
var2 = var1;
|
||||
if (var1 == 96) {
|
||||
var2 = var3;
|
||||
private int getSimplifiedKey(final int keyCode) {
|
||||
int defaultCode = KeyEvent.KEYCODE_DPAD_CENTER;
|
||||
if (keyCode != KeyEvent.KEYCODE_DPAD_CENTER) {
|
||||
final byte enter = KeyEvent.KEYCODE_ENTER;
|
||||
defaultCode = enter;
|
||||
if (keyCode != KeyEvent.KEYCODE_ENTER) {
|
||||
defaultCode = enter;
|
||||
if (keyCode != KeyEvent.KEYCODE_NUMPAD_ENTER) {
|
||||
defaultCode = keyCode;
|
||||
if (keyCode == KeyEvent.KEYCODE_BUTTON_A) {
|
||||
defaultCode = enter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var1 = var2;
|
||||
if (var2 == 97) {
|
||||
var1 = 4;
|
||||
|
||||
if (defaultCode == KeyEvent.KEYCODE_BUTTON_B) {
|
||||
defaultCode = KeyEvent.KEYCODE_BACK;
|
||||
}
|
||||
|
||||
return var1;
|
||||
return defaultCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle keyboard key
|
||||
* @param keyCode key code e.g {@link LeanbackKeyboardView#KEYCODE_SHIFT LeanbackKeyboardView.KEYCODE_SHIFT}
|
||||
* @param text typed content
|
||||
*/
|
||||
private void handleCommitKeyboardKey(int keyCode, CharSequence text) {
|
||||
switch (keyCode) {
|
||||
case LeanbackKeyboardView.KEYCODE_DISMISS_MINI_KEYBOARD:
|
||||
@@ -328,206 +333,205 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
}
|
||||
}
|
||||
|
||||
private boolean handleKeyDownEvent(int var1, int var2) {
|
||||
var1 = this.getSimplifiedKey(var1);
|
||||
boolean var3;
|
||||
boolean var4;
|
||||
if (var1 == 4) {
|
||||
this.mContainer.cancelVoiceRecording();
|
||||
var3 = false;
|
||||
} else if (this.mContainer.isVoiceVisible()) {
|
||||
if (var1 == 22 || var1 == 23 || var1 == 66) {
|
||||
this.mContainer.cancelVoiceRecording();
|
||||
private boolean handleKeyDownEvent(int keyCode, int eventRepeatCount) {
|
||||
keyCode = getSimplifiedKey(keyCode);
|
||||
boolean handled;
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
mContainer.cancelVoiceRecording();
|
||||
handled = false;
|
||||
} else if (mContainer.isVoiceVisible()) {
|
||||
if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
|
||||
mContainer.cancelVoiceRecording();
|
||||
}
|
||||
|
||||
var3 = true;
|
||||
handled = true;
|
||||
} else {
|
||||
var4 = true;
|
||||
var3 = var4;
|
||||
switch (var1) {
|
||||
case 19:
|
||||
var3 = this.onDirectionalMove(8);
|
||||
handled = true;
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_DPAD_UP:
|
||||
handled = onDirectionalMove(8);
|
||||
break;
|
||||
case 20:
|
||||
var3 = this.onDirectionalMove(2);
|
||||
case KeyEvent.KEYCODE_DPAD_DOWN:
|
||||
handled = onDirectionalMove(2);
|
||||
break;
|
||||
case 21:
|
||||
var3 = this.onDirectionalMove(1);
|
||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||
handled = onDirectionalMove(1);
|
||||
break;
|
||||
case 22:
|
||||
var3 = this.onDirectionalMove(4);
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||
handled = onDirectionalMove(4);
|
||||
break;
|
||||
case 23:
|
||||
case 66:
|
||||
if (var2 == 0) {
|
||||
this.mMoveCount = 0;
|
||||
this.mKeyDownKeyFocus = new LeanbackKeyboardContainer.KeyFocus();
|
||||
this.mKeyDownKeyFocus.set(this.mContainer.getCurrFocus());
|
||||
} else if (var2 == 1 && this.handleKeyLongPress(var1)) {
|
||||
this.mKeyDownKeyFocus = null;
|
||||
case KeyEvent.KEYCODE_DPAD_CENTER:
|
||||
case KeyEvent.KEYCODE_ENTER:
|
||||
if (eventRepeatCount == 0) {
|
||||
mMoveCount = 0;
|
||||
mKeyDownKeyFocus = new LeanbackKeyboardContainer.KeyFocus();
|
||||
mKeyDownKeyFocus.set(mContainer.getCurrFocus());
|
||||
} else if (eventRepeatCount == 1 && handleKeyLongPress(keyCode)) {
|
||||
mKeyDownKeyFocus = null;
|
||||
}
|
||||
|
||||
var3 = var4;
|
||||
if (this.isKeyHandledOnKeyDown(this.mContainer.getCurrKeyCode())) {
|
||||
this.commitKey();
|
||||
var3 = var4;
|
||||
handled = true;
|
||||
if (isKeyHandledOnKeyDown(mContainer.getCurrKeyCode())) {
|
||||
commitKey();
|
||||
handled = true;
|
||||
}
|
||||
break;
|
||||
case 99:
|
||||
this.handleCommitKeyboardKey(-5, (CharSequence) null);
|
||||
var3 = var4;
|
||||
case KeyEvent.KEYCODE_BUTTON_X:
|
||||
handleCommitKeyboardKey(LeanbackKeyboardView.KEYCODE_DELETE, null);
|
||||
handled = true;
|
||||
break;
|
||||
case 100:
|
||||
this.handleCommitKeyboardKey(32, (CharSequence) null);
|
||||
var3 = var4;
|
||||
case KeyEvent.KEYCODE_BUTTON_Y:
|
||||
handleCommitKeyboardKey(LeanbackKeyboardView.ASCII_SPACE, null);
|
||||
handled = true;
|
||||
break;
|
||||
case 102:
|
||||
this.handleCommitKeyboardKey(-3, (CharSequence) null);
|
||||
var3 = var4;
|
||||
case KeyEvent.KEYCODE_BUTTON_L1:
|
||||
handleCommitKeyboardKey(LeanbackKeyboardView.KEYCODE_LEFT, null);
|
||||
handled = true;
|
||||
break;
|
||||
case 103:
|
||||
this.handleCommitKeyboardKey(-4, (CharSequence) null);
|
||||
var3 = var4;
|
||||
case 106:
|
||||
case 107:
|
||||
case KeyEvent.KEYCODE_BUTTON_R1:
|
||||
handleCommitKeyboardKey(LeanbackKeyboardView.KEYCODE_RIGHT, null);
|
||||
handled = true;
|
||||
case KeyEvent.KEYCODE_BUTTON_THUMBL:
|
||||
case KeyEvent.KEYCODE_BUTTON_THUMBR:
|
||||
break;
|
||||
default:
|
||||
var3 = false;
|
||||
handled = false;
|
||||
}
|
||||
}
|
||||
|
||||
var4 = var3;
|
||||
if (!var3) {
|
||||
var4 = this.applyLETVFixesDown(var1);
|
||||
if (!handled) {
|
||||
handled = applyLETVFixesDown(keyCode);
|
||||
}
|
||||
|
||||
return var4;
|
||||
return handled;
|
||||
}
|
||||
|
||||
private boolean handleKeyLongPress(int var1) {
|
||||
boolean var2;
|
||||
if (this.isEnterKey(var1) && this.mContainer.onKeyLongPress()) {
|
||||
var2 = true;
|
||||
private boolean handleKeyLongPress(int keyCode) {
|
||||
boolean isHandled;
|
||||
if (isEnterKey(keyCode) && mContainer.onKeyLongPress()) {
|
||||
isHandled = true;
|
||||
} else {
|
||||
var2 = false;
|
||||
isHandled = false;
|
||||
}
|
||||
|
||||
this.mLongPressHandled = var2;
|
||||
if (this.mContainer.isMiniKeyboardOnScreen()) {
|
||||
mLongPressHandled = isHandled;
|
||||
if (mContainer.isMiniKeyboardOnScreen()) {
|
||||
Log.d("LbKbController", "mini keyboard shown after long press");
|
||||
}
|
||||
|
||||
return this.mLongPressHandled;
|
||||
return mLongPressHandled;
|
||||
}
|
||||
|
||||
private boolean handleKeyUpEvent(int var1, long var2) {
|
||||
var1 = this.getSimplifiedKey(var1);
|
||||
boolean var4;
|
||||
boolean var5;
|
||||
if (var1 == 4) {
|
||||
var4 = false;
|
||||
} else if (this.mContainer.isVoiceVisible()) {
|
||||
var4 = true;
|
||||
private boolean handleKeyUpEvent(int keyCode, long currTime) {
|
||||
keyCode = getSimplifiedKey(keyCode);
|
||||
boolean handled;
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
handled = false;
|
||||
} else if (mContainer.isVoiceVisible()) {
|
||||
handled = true;
|
||||
} else {
|
||||
var5 = true;
|
||||
var4 = var5;
|
||||
switch (var1) {
|
||||
case 19:
|
||||
case 20:
|
||||
case 21:
|
||||
case 22:
|
||||
this.clearKeyIfNecessary();
|
||||
var4 = var5;
|
||||
handled = true;
|
||||
switch (keyCode) {
|
||||
case KeyEvent.KEYCODE_DPAD_UP:
|
||||
case KeyEvent.KEYCODE_DPAD_DOWN:
|
||||
case KeyEvent.KEYCODE_DPAD_LEFT:
|
||||
case KeyEvent.KEYCODE_DPAD_RIGHT:
|
||||
clearKeyIfNecessary();
|
||||
handled = true;
|
||||
break;
|
||||
case 23:
|
||||
case 66:
|
||||
if (this.mContainer.getCurrKeyCode() == -1) {
|
||||
this.mDoubleClickDetector.addEvent(var2);
|
||||
var4 = var5;
|
||||
case KeyEvent.KEYCODE_DPAD_CENTER:
|
||||
case KeyEvent.KEYCODE_ENTER:
|
||||
if (mContainer.getCurrKeyCode() == LeanbackKeyboardView.KEYCODE_SHIFT) {
|
||||
mDoubleClickDetector.addEvent(currTime);
|
||||
handled = true;
|
||||
} else {
|
||||
var4 = var5;
|
||||
if (!this.isKeyHandledOnKeyDown(this.mContainer.getCurrKeyCode())) {
|
||||
this.commitKey(this.mKeyDownKeyFocus);
|
||||
var4 = var5;
|
||||
handled = true;
|
||||
if (!isKeyHandledOnKeyDown(mContainer.getCurrKeyCode())) {
|
||||
commitKey(mKeyDownKeyFocus);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
case 99:
|
||||
case 100:
|
||||
case 102:
|
||||
case 103:
|
||||
case KeyEvent.KEYCODE_BUTTON_X:
|
||||
case KeyEvent.KEYCODE_BUTTON_Y:
|
||||
case KeyEvent.KEYCODE_BUTTON_L1:
|
||||
case KeyEvent.KEYCODE_BUTTON_R1:
|
||||
break;
|
||||
case 106:
|
||||
this.handleCommitKeyboardKey(-2, (CharSequence) null);
|
||||
var4 = var5;
|
||||
case KeyEvent.KEYCODE_BUTTON_THUMBL:
|
||||
handleCommitKeyboardKey(LeanbackKeyboardView.KEYCODE_SYM_TOGGLE, null);
|
||||
handled = true;
|
||||
break;
|
||||
case 107:
|
||||
this.handleCommitKeyboardKey(-6, (CharSequence) null);
|
||||
var4 = var5;
|
||||
case KeyEvent.KEYCODE_BUTTON_THUMBR:
|
||||
handleCommitKeyboardKey(LeanbackKeyboardView.KEYCODE_CAPS_LOCK, null);
|
||||
handled = true;
|
||||
break;
|
||||
default:
|
||||
var4 = false;
|
||||
handled = false;
|
||||
}
|
||||
}
|
||||
|
||||
var5 = var4;
|
||||
if (!var4) {
|
||||
var5 = this.applyLETVFixesUp(var1);
|
||||
if (!handled) {
|
||||
handled = applyLETVFixesUp(keyCode);
|
||||
}
|
||||
|
||||
return var5;
|
||||
return handled;
|
||||
}
|
||||
|
||||
private void initInputView() {
|
||||
this.mContainer.onInitInputView();
|
||||
this.updatePositionToCurrentFocus();
|
||||
mContainer.onInitInputView();
|
||||
updatePositionToCurrentFocus();
|
||||
}
|
||||
|
||||
private boolean isCallAllowed(int var1) {
|
||||
long var2 = System.currentTimeMillis();
|
||||
if (this.prevTime != 0L && var2 - this.prevTime <= (long) (var1 * 3)) {
|
||||
if (var2 - this.prevTime > (long) var1) {
|
||||
private boolean isCallAllowed(int periodMillis) {
|
||||
long currTimeMS = System.currentTimeMillis();
|
||||
if (this.prevTime != 0L && currTimeMS - this.prevTime <= (long) (periodMillis * 3)) {
|
||||
if (currTimeMS - this.prevTime > (long) periodMillis) {
|
||||
this.prevTime = 0L;
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
this.prevTime = var2;
|
||||
this.prevTime = currTimeMS;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isDoubleClick() {
|
||||
long var1 = System.currentTimeMillis();
|
||||
long var3 = this.lastClickTime;
|
||||
if (this.lastClickTime != 0L && var1 - var3 <= (long) 300) {
|
||||
long currTimeMS = System.currentTimeMillis();
|
||||
long lastTime = this.lastClickTime;
|
||||
if (this.lastClickTime != 0L && currTimeMS - lastTime <= (long) 300) {
|
||||
return true;
|
||||
} else {
|
||||
this.lastClickTime = var1;
|
||||
this.lastClickTime = currTimeMS;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEnterKey(int var1) {
|
||||
var1 = this.getSimplifiedKey(var1);
|
||||
return var1 == 23 || var1 == 66;
|
||||
private boolean isEnterKey(int keyCode) {
|
||||
keyCode = this.getSimplifiedKey(keyCode);
|
||||
return keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER;
|
||||
}
|
||||
|
||||
private boolean isKeyHandledOnKeyDown(int var1) {
|
||||
return var1 == -5 || var1 == -3 || var1 == -4;
|
||||
/**
|
||||
* Whether key down is handled
|
||||
* @param currKeyCode key code e.g. {@link LeanbackKeyboardView#KEYCODE_DELETE LeanbackKeyboardView.KEYCODE_DELETE}
|
||||
* @return key down is handled
|
||||
*/
|
||||
private boolean isKeyHandledOnKeyDown(int currKeyCode) {
|
||||
return currKeyCode == LeanbackKeyboardView.KEYCODE_DELETE || currKeyCode == LeanbackKeyboardView.KEYCODE_LEFT || currKeyCode == LeanbackKeyboardView.KEYCODE_RIGHT;
|
||||
}
|
||||
|
||||
private void moveSelectorToPoint(float var1, float var2) {
|
||||
LeanbackKeyboardContainer var3 = this.mContainer;
|
||||
LeanbackKeyboardContainer.KeyFocus var4 = this.mTempFocus;
|
||||
var3.getBestFocus(new Float(var1), new Float(var2), var4);
|
||||
private void moveSelectorToPoint(float x, float y) {
|
||||
LeanbackKeyboardContainer container = this.mContainer;
|
||||
LeanbackKeyboardContainer.KeyFocus focus = this.mTempFocus;
|
||||
container.getBestFocus(new Float(x), new Float(y), focus);
|
||||
this.mContainer.setFocus(this.mTempFocus);
|
||||
var3 = this.mContainer;
|
||||
Rect var5 = this.mTempFocus.rect;
|
||||
var3.alignSelector((float) var5.centerX(), (float) var5.centerY(), false);
|
||||
container = this.mContainer;
|
||||
Rect rect = this.mTempFocus.rect;
|
||||
container.alignSelector((float) rect.centerX(), (float) rect.centerY(), false);
|
||||
}
|
||||
|
||||
private boolean onDirectionalMove(int var1) {
|
||||
if (this.mContainer.getNextFocusInDirection(var1, this.mDownFocus, this.mTempFocus)) {
|
||||
private boolean onDirectionalMove(int dir) {
|
||||
if (this.mContainer.getNextFocusInDirection(dir, this.mDownFocus, this.mTempFocus)) {
|
||||
this.mContainer.setFocus(this.mTempFocus);
|
||||
this.mDownFocus.set(this.mTempFocus);
|
||||
this.clearKeyIfNecessary();
|
||||
@@ -536,104 +540,117 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
return true;
|
||||
}
|
||||
|
||||
private void performBestSnap(long var1) {
|
||||
LeanbackKeyboardContainer.KeyFocus var3 = this.mContainer.getCurrFocus();
|
||||
this.mTempPoint.x = (float) var3.rect.centerX();
|
||||
this.mTempPoint.y = (float) var3.rect.centerY();
|
||||
PointF var4 = this.getBestSnapPosition(this.mTempPoint, var1);
|
||||
this.mContainer.getBestFocus(var4.x, var4.y, this.mTempFocus);
|
||||
private void performBestSnap(long time) {
|
||||
LeanbackKeyboardContainer.KeyFocus focus = this.mContainer.getCurrFocus();
|
||||
this.mTempPoint.x = (float) focus.rect.centerX();
|
||||
this.mTempPoint.y = (float) focus.rect.centerY();
|
||||
PointF pos = this.getBestSnapPosition(this.mTempPoint, time);
|
||||
this.mContainer.getBestFocus(pos.x, pos.y, this.mTempFocus);
|
||||
this.mContainer.setFocus(this.mTempFocus);
|
||||
this.updatePositionToCurrentFocus();
|
||||
}
|
||||
|
||||
private void setKeyState(int var1, boolean var2) {
|
||||
LeanbackKeyboardContainer var3 = this.mContainer;
|
||||
LeanbackKeyboardContainer.KeyFocus var4 = var3.getCurrFocus();
|
||||
var4.index = var1;
|
||||
var4.type = 0;
|
||||
byte var5;
|
||||
if (var2) {
|
||||
var5 = 3;
|
||||
/**
|
||||
* Set key state
|
||||
* @param keyIndex key index
|
||||
* @param keyState constant e.g. {@link LeanbackKeyboardContainer#TOUCH_STATE_CLICK LeanbackKeyboardContainer.TOUCH_STATE_CLICK}
|
||||
*/
|
||||
private void setKeyState(int keyIndex, boolean keyState) {
|
||||
LeanbackKeyboardContainer container = this.mContainer;
|
||||
LeanbackKeyboardContainer.KeyFocus focus = container.getCurrFocus();
|
||||
focus.index = keyIndex;
|
||||
focus.type = KeyFocus.TYPE_MAIN;
|
||||
byte state;
|
||||
if (keyState) {
|
||||
state = LeanbackKeyboardContainer.TOUCH_STATE_CLICK;
|
||||
} else {
|
||||
var5 = 0;
|
||||
state = LeanbackKeyboardContainer.TOUCH_STATE_NO_TOUCH;
|
||||
}
|
||||
|
||||
var3.setTouchState(var5);
|
||||
container.setTouchState(state);
|
||||
}
|
||||
|
||||
private void updatePositionToCurrentFocus() {
|
||||
PointF var1 = this.getCurrentKeyPosition();
|
||||
if (var1 != null && this.mSpaceTracker != null) {
|
||||
this.mSpaceTracker.setPixelPosition(var1.x, var1.y);
|
||||
PointF pos = this.getCurrentKeyPosition();
|
||||
if (pos != null && this.mSpaceTracker != null) {
|
||||
this.mSpaceTracker.setPixelPosition(pos.x, pos.y);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean areSuggestionsEnabled() {
|
||||
return this.mContainer != null ? this.mContainer.areSuggestionsEnabled() : false;
|
||||
return mContainer != null ? mContainer.areSuggestionsEnabled() : false;
|
||||
}
|
||||
|
||||
public boolean enableAutoEnterSpace() {
|
||||
return this.mContainer != null ? this.mContainer.enableAutoEnterSpace() : false;
|
||||
return mContainer != null ? mContainer.enableAutoEnterSpace() : false;
|
||||
}
|
||||
|
||||
public View getView() {
|
||||
if (this.mContainer != null) {
|
||||
RelativeLayout var1 = this.mContainer.getView();
|
||||
var1.setClickable(true);
|
||||
var1.setOnTouchListener(this);
|
||||
var1.setOnHoverListener(this);
|
||||
Button var2 = this.mContainer.getGoButton();
|
||||
var2.setOnTouchListener(this);
|
||||
var2.setOnHoverListener(this);
|
||||
var2.setTag("Go");
|
||||
return var1;
|
||||
if (mContainer != null) {
|
||||
RelativeLayout view = mContainer.getView();
|
||||
view.setClickable(true);
|
||||
view.setOnTouchListener(this);
|
||||
view.setOnHoverListener(this);
|
||||
Button button = mContainer.getGoButton();
|
||||
button.setOnTouchListener(this);
|
||||
button.setOnHoverListener(this);
|
||||
button.setTag("Go");
|
||||
return view;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void onDismiss(boolean var1) {
|
||||
if (var1) {
|
||||
this.mInputListener.onEntry(8, 0, (CharSequence) null);
|
||||
public void onDismiss(boolean fromVoice) {
|
||||
if (fromVoice) {
|
||||
mInputListener.onEntry(InputListener.ENTRY_TYPE_VOICE_DISMISS, LeanbackKeyboardView.SHIFT_OFF, null);
|
||||
} else {
|
||||
this.mInputListener.onEntry(7, 0, (CharSequence) null);
|
||||
mInputListener.onEntry(InputListener.ENTRY_TYPE_DISMISS, LeanbackKeyboardView.SHIFT_OFF, null);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean onGenericMotionEvent(MotionEvent var1) {
|
||||
return this.mSpaceTracker != null && this.mContext != null && this.mContext.isInputViewShown() && this.mSpaceTracker.onGenericMotionEvent
|
||||
(var1);
|
||||
public boolean onGenericMotionEvent(MotionEvent event) {
|
||||
return mSpaceTracker != null && mContext != null && mContext.isInputViewShown() && mSpaceTracker.onGenericMotionEvent(event);
|
||||
}
|
||||
|
||||
public boolean onHover(View var1, MotionEvent var2) {
|
||||
boolean var4 = this.isCallAllowed(300);
|
||||
boolean var3 = var4;
|
||||
if (var4) {
|
||||
if (var2.getAction() == 7) {
|
||||
PointF var5 = this.getRelativePosition(this.mContainer.getView(), var2);
|
||||
this.moveSelectorToPoint(var5.x, var5.y);
|
||||
/**
|
||||
* Try to handle on hover event
|
||||
* @param view active view
|
||||
* @param event event object
|
||||
* @return is hover handled
|
||||
*/
|
||||
public boolean onHover(View view, MotionEvent event) {
|
||||
boolean allowed = isCallAllowed(300);
|
||||
if (allowed) {
|
||||
if (event.getAction() == MotionEvent.ACTION_HOVER_MOVE) {
|
||||
PointF pos = getRelativePosition(mContainer.getView(), event);
|
||||
moveSelectorToPoint(pos.x, pos.y);
|
||||
}
|
||||
|
||||
var3 = true;
|
||||
}
|
||||
|
||||
return var3;
|
||||
return allowed;
|
||||
}
|
||||
|
||||
public boolean onKeyDown(int var1, KeyEvent event) {
|
||||
/**
|
||||
* Try to handle key down event
|
||||
* @param keyCode key code e.g. {@link KeyEvent#KEYCODE_ENTER KeyEvent.KEYCODE_ENTER}
|
||||
* @param event {@link KeyEvent KeyEvent}
|
||||
* @return is event handled
|
||||
*/
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
this.mDownFocus.set(this.mContainer.getCurrFocus());
|
||||
if (this.mSpaceTracker != null && this.mSpaceTracker.onKeyDown(var1, event)) {
|
||||
if (this.mSpaceTracker != null && this.mSpaceTracker.onKeyDown(keyCode, event)) {
|
||||
return true;
|
||||
} else {
|
||||
if (this.isEnterKey(var1)) {
|
||||
if (this.isEnterKey(keyCode)) {
|
||||
this.mKeyDownReceived = true;
|
||||
if (event.getRepeatCount() == 0) {
|
||||
this.mContainer.setTouchState(3);
|
||||
this.mContainer.setTouchState(LeanbackKeyboardContainer.TOUCH_STATE_CLICK);
|
||||
}
|
||||
}
|
||||
|
||||
return this.handleKeyDownEvent(var1, event.getRepeatCount());
|
||||
return this.handleKeyDownEvent(keyCode, event.getRepeatCount());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -778,6 +795,12 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
int ENTRY_TYPE_VOICE = 6;
|
||||
int ENTRY_TYPE_VOICE_DISMISS = 8;
|
||||
|
||||
/**
|
||||
* User has typed something
|
||||
* @param type type e.g. {@link InputListener#ENTRY_TYPE_ACTION InputListener.ENTRY_TYPE_ACTION}
|
||||
* @param keyCode key code e.g. {@link LeanbackKeyboardView#SHIFT_ON LeanbackKeyboardView.SHIFT_ON}
|
||||
* @param text text
|
||||
*/
|
||||
void onEntry(int type, int keyCode, CharSequence text);
|
||||
}
|
||||
|
||||
@@ -785,9 +808,9 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
public PointF position;
|
||||
public long time;
|
||||
|
||||
public KeyChange(long var1, PointF var3) {
|
||||
this.time = var1;
|
||||
this.position = var3;
|
||||
public KeyChange(long time, PointF position) {
|
||||
this.time = time;
|
||||
this.position = position;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -800,7 +823,7 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
LeanbackKeyboardController.this.mKeyDownReceived = true;
|
||||
if (event.getRepeatCount() == 0) {
|
||||
LeanbackKeyboardController.this.mContainer.setTouchState(3);
|
||||
LeanbackKeyboardController.this.mSpaceTracker.blockMovementUntil(event.getEventTime() + 500L);
|
||||
LeanbackKeyboardController.this.mSpaceTracker.blockMovementUntil(event.getEventTime() + CLICK_MOVEMENT_BLOCK_DURATION_MS);
|
||||
LeanbackKeyboardController.this.performBestSnap(event.getEventTime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,21 @@
|
||||
package com.google.android.leanback.ime;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.inputmethodservice.Keyboard;
|
||||
import android.inputmethodservice.Keyboard.Key;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.View.MeasureSpec;
|
||||
import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import com.liskovsoft.leankeykeyboard.R;
|
||||
@@ -137,15 +134,15 @@ public class LeanbackKeyboardView extends FrameLayout {
|
||||
paint.setColor(mKeyTextColor);
|
||||
canvas.drawARGB(0, 0, 0, 0);
|
||||
if (key.icon != null) {
|
||||
if (key.codes[0] == -1) {
|
||||
if (key.codes[0] == NOT_A_KEY) {
|
||||
switch (mShiftState) {
|
||||
case 0:
|
||||
case SHIFT_OFF:
|
||||
key.icon = getContext().getResources().getDrawable(R.drawable.ic_ime_shift_off);
|
||||
break;
|
||||
case 1:
|
||||
case SHIFT_ON:
|
||||
key.icon = getContext().getResources().getDrawable(R.drawable.ic_ime_shift_on);
|
||||
break;
|
||||
case 2:
|
||||
case SHIFT_LOCKED:
|
||||
key.icon = getContext().getResources().getDrawable(R.drawable.ic_ime_shift_lock_on);
|
||||
}
|
||||
}
|
||||
@@ -242,74 +239,81 @@ public class LeanbackKeyboardView extends FrameLayout {
|
||||
}
|
||||
|
||||
public int getBaseMiniKbIndex() {
|
||||
return this.mBaseMiniKbIndex;
|
||||
return mBaseMiniKbIndex;
|
||||
}
|
||||
|
||||
public int getColCount() {
|
||||
return this.mColCount;
|
||||
return mColCount;
|
||||
}
|
||||
|
||||
public Key getFocusedKey() {
|
||||
return this.mFocusIndex == -1 ? null : this.mKeys[this.mFocusIndex].key;
|
||||
return mFocusIndex == -1 ? null : mKeys[mFocusIndex].key;
|
||||
}
|
||||
|
||||
public Key getKey(int index) {
|
||||
return this.mKeys != null && this.mKeys.length != 0 && index >= 0 && index <= this.mKeys.length ? this.mKeys[index].key : null;
|
||||
return mKeys != null && mKeys.length != 0 && index >= 0 && index <= mKeys.length ? mKeys[index].key : null;
|
||||
}
|
||||
|
||||
public Keyboard getKeyboard() {
|
||||
return this.mKeyboard;
|
||||
return mKeyboard;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get index of the key under cursor
|
||||
* @param x x position
|
||||
* @param y y position
|
||||
* @return index of the key
|
||||
*/
|
||||
public int getNearestIndex(final float x, final float y) {
|
||||
int result;
|
||||
if (mKeys != null && mKeys.length != 0) {
|
||||
float paddingLeft = (float) getPaddingLeft();
|
||||
float paddingTop = (float) getPaddingTop();
|
||||
float height = (float) (getMeasuredHeight() - getPaddingTop() - getPaddingBottom());
|
||||
float width = (float) (getMeasuredWidth() - getPaddingLeft() - getPaddingRight());
|
||||
int rows = getRowCount();
|
||||
int cols = getColCount();
|
||||
int index = (int) ((y - paddingTop) / height * (float) rows);
|
||||
if (index < 0) {
|
||||
float kbHeight = (float) (getMeasuredHeight() - getPaddingTop() - getPaddingBottom());
|
||||
float kbWidth = (float) (getMeasuredWidth() - getPaddingLeft() - getPaddingRight());
|
||||
final int rows = getRowCount();
|
||||
final int cols = getColCount();
|
||||
final int indexVert = (int) ((y - paddingTop) / kbHeight * (float) rows);
|
||||
if (indexVert < 0) {
|
||||
result = 0;
|
||||
} else {
|
||||
result = index;
|
||||
if (index >= rows) {
|
||||
result = indexVert;
|
||||
if (indexVert >= rows) {
|
||||
result = rows - 1;
|
||||
}
|
||||
}
|
||||
|
||||
rows = (int) ((x - paddingLeft) / width * (float) cols);
|
||||
if (rows < 0) {
|
||||
index = 0;
|
||||
final int indexHoriz = (int) ((x - paddingLeft) / kbWidth * (float) cols);
|
||||
int indexFull;
|
||||
if (indexHoriz < 0) {
|
||||
indexFull = 0;
|
||||
} else {
|
||||
index = rows;
|
||||
if (rows >= cols) {
|
||||
index = cols - 1;
|
||||
indexFull = indexHoriz;
|
||||
if (indexHoriz >= cols) {
|
||||
indexFull = cols - 1;
|
||||
}
|
||||
}
|
||||
|
||||
index += mColCount * result;
|
||||
result = index;
|
||||
if (index > ASCII_PERIOD) {
|
||||
result = index;
|
||||
if (index < 53) {
|
||||
indexFull += mColCount * result;
|
||||
result = indexFull;
|
||||
if (indexFull > ASCII_PERIOD) {
|
||||
result = indexFull;
|
||||
if (indexFull < 53) {
|
||||
result = ASCII_PERIOD;
|
||||
}
|
||||
}
|
||||
|
||||
index = result;
|
||||
indexFull = result;
|
||||
if (result >= 53) {
|
||||
index = result - 6;
|
||||
indexFull = result - 6;
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
if (indexFull < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
result = index;
|
||||
if (index >= mKeys.length) {
|
||||
result = indexFull;
|
||||
if (indexFull >= mKeys.length) {
|
||||
return mKeys.length - 1;
|
||||
}
|
||||
} else {
|
||||
@@ -320,15 +324,15 @@ public class LeanbackKeyboardView extends FrameLayout {
|
||||
}
|
||||
|
||||
public int getRowCount() {
|
||||
return this.mRowCount;
|
||||
return mRowCount;
|
||||
}
|
||||
|
||||
public int getShiftState() {
|
||||
return this.mShiftState;
|
||||
return mShiftState;
|
||||
}
|
||||
|
||||
public void invalidateAllKeys() {
|
||||
this.createKeyImageViews(this.mKeys);
|
||||
createKeyImageViews(mKeys);
|
||||
}
|
||||
|
||||
public void invalidateKey(int keyIndex) {
|
||||
@@ -397,9 +401,9 @@ public class LeanbackKeyboardView extends FrameLayout {
|
||||
if (mKeyboard == null) {
|
||||
setMeasuredDimension(getPaddingLeft() + getPaddingRight(), getPaddingTop() + getPaddingBottom());
|
||||
} else {
|
||||
int calcHeight = mKeyboard.getMinWidth() + getPaddingLeft() + getPaddingRight();
|
||||
heightMeasureSpec = calcHeight;
|
||||
if (MeasureSpec.getSize(widthMeasureSpec) < calcHeight + 10) {
|
||||
int heightFull = mKeyboard.getMinWidth() + getPaddingLeft() + getPaddingRight();
|
||||
heightMeasureSpec = heightFull;
|
||||
if (MeasureSpec.getSize(widthMeasureSpec) < heightFull + 10) {
|
||||
heightMeasureSpec = MeasureSpec.getSize(widthMeasureSpec);
|
||||
}
|
||||
|
||||
@@ -424,52 +428,53 @@ public class LeanbackKeyboardView extends FrameLayout {
|
||||
public void setFocus(final int index, final boolean clicked, final boolean showFocusScale) {
|
||||
float scale = 1.0F;
|
||||
if (mKeyImageViews != null && mKeyImageViews.length != 0) {
|
||||
int calcIndex;
|
||||
int indexFull;
|
||||
|
||||
if (index >= 0 && index < mKeyImageViews.length) {
|
||||
calcIndex = index;
|
||||
indexFull = index;
|
||||
} else {
|
||||
calcIndex = -1;
|
||||
indexFull = -1;
|
||||
}
|
||||
|
||||
if (calcIndex != mFocusIndex || clicked != mFocusClicked) {
|
||||
if (calcIndex != mFocusIndex) {
|
||||
if (indexFull != mFocusIndex || clicked != mFocusClicked) {
|
||||
if (indexFull != mFocusIndex) {
|
||||
if (mFocusIndex != -1) {
|
||||
LeanbackUtils.sendAccessibilityEvent(mKeyImageViews[mFocusIndex], false);
|
||||
}
|
||||
|
||||
if (calcIndex != -1) {
|
||||
LeanbackUtils.sendAccessibilityEvent(mKeyImageViews[calcIndex], true);
|
||||
if (indexFull != -1) {
|
||||
LeanbackUtils.sendAccessibilityEvent(mKeyImageViews[indexFull], true);
|
||||
}
|
||||
}
|
||||
|
||||
if (mCurrentFocusView != null) {
|
||||
mCurrentFocusView.animate()
|
||||
.scaleX(1.0F)
|
||||
.scaleY(1.0F)
|
||||
.setInterpolator(LeanbackKeyboardContainer.sMovementInterpolator)
|
||||
.setStartDelay((long) mUnfocusStartDelay);
|
||||
.scaleX(1.0F)
|
||||
.scaleY(1.0F)
|
||||
.setInterpolator(LeanbackKeyboardContainer.sMovementInterpolator)
|
||||
.setStartDelay((long) mUnfocusStartDelay);
|
||||
|
||||
mCurrentFocusView.animate()
|
||||
.setDuration((long) mClickAnimDur)
|
||||
.setInterpolator(LeanbackKeyboardContainer.sMovementInterpolator)
|
||||
.setStartDelay((long) mUnfocusStartDelay);
|
||||
.setDuration((long) mClickAnimDur)
|
||||
.setInterpolator(LeanbackKeyboardContainer.sMovementInterpolator)
|
||||
.setStartDelay((long) mUnfocusStartDelay);
|
||||
}
|
||||
|
||||
if (calcIndex != -1) {
|
||||
if (indexFull != -1) {
|
||||
if (clicked) {
|
||||
scale = mClickedScale;
|
||||
} else if (showFocusScale) {
|
||||
scale = mFocusedScale;
|
||||
}
|
||||
|
||||
mCurrentFocusView = mKeyImageViews[calcIndex];
|
||||
mCurrentFocusView = mKeyImageViews[indexFull];
|
||||
mCurrentFocusView.animate().scaleX(scale).scaleY(scale).setInterpolator(LeanbackKeyboardContainer.sMovementInterpolator)
|
||||
.setDuration((long) mClickAnimDur).start();
|
||||
}
|
||||
|
||||
mFocusIndex = calcIndex;
|
||||
mFocusIndex = indexFull;
|
||||
mFocusClicked = clicked;
|
||||
if (-1 != calcIndex && !mKeys[calcIndex].isInMiniKb) {
|
||||
if (-1 != indexFull && !mKeys[indexFull].isInMiniKb) {
|
||||
dismissMiniKeyboard();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.google.android.leanback.ime;
|
||||
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.inputmethod.CompletionInfo;
|
||||
@@ -10,85 +11,85 @@ import com.liskovsoft.leankeykeyboard.R;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LeanbackSuggestionsFactory {
|
||||
private static final boolean DEBUG = Log.isLoggable("LbSuggestionsFactory", Log.DEBUG);
|
||||
private static final int MODE_AUTO_COMPLETE = 2;
|
||||
private static final int MODE_DEFAULT = 0;
|
||||
private static final int MODE_DOMAIN = 1;
|
||||
private static final String TAG = "LbSuggestionsFactory";
|
||||
private InputMethodService mContext;
|
||||
private int mMode;
|
||||
private int mNumSuggestions;
|
||||
private final ArrayList<String> mSuggestions = new ArrayList();
|
||||
private static final boolean DEBUG = Log.isLoggable("LbSuggestionsFactory", Log.DEBUG);
|
||||
private static final int MODE_AUTO_COMPLETE = 2;
|
||||
private static final int MODE_DEFAULT = 0;
|
||||
private static final int MODE_DOMAIN = 1;
|
||||
private static final String TAG = "LbSuggestionsFactory";
|
||||
private InputMethodService mContext;
|
||||
private int mMode;
|
||||
private int mNumSuggestions;
|
||||
private final ArrayList<String> mSuggestions = new ArrayList<>();
|
||||
|
||||
public LeanbackSuggestionsFactory(InputMethodService context, int numSuggestions) {
|
||||
this.mContext = context;
|
||||
this.mNumSuggestions = numSuggestions;
|
||||
}
|
||||
public LeanbackSuggestionsFactory(InputMethodService context, int numSuggestions) {
|
||||
mContext = context;
|
||||
mNumSuggestions = numSuggestions;
|
||||
}
|
||||
|
||||
public void clearSuggestions() {
|
||||
this.mSuggestions.clear();
|
||||
}
|
||||
public void clearSuggestions() {
|
||||
mSuggestions.clear();
|
||||
}
|
||||
|
||||
public void createSuggestions() {
|
||||
this.clearSuggestions();
|
||||
if (this.mMode == 1) {
|
||||
String[] var3 = this.mContext.getResources().getStringArray(R.array.common_domains);
|
||||
int var2 = var3.length;
|
||||
public void createSuggestions() {
|
||||
clearSuggestions();
|
||||
if (mMode == MODE_DOMAIN) {
|
||||
String[] domains = mContext.getResources().getStringArray(R.array.common_domains);
|
||||
int totalDomains = domains.length;
|
||||
|
||||
for(int var1 = 0; var1 < var2; ++var1) {
|
||||
String var4 = var3[var1];
|
||||
this.mSuggestions.add(var4);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < totalDomains; ++i) {
|
||||
String domain = domains[i];
|
||||
mSuggestions.add(domain);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<String> getSuggestions() {
|
||||
return this.mSuggestions;
|
||||
}
|
||||
public ArrayList<String> getSuggestions() {
|
||||
return mSuggestions;
|
||||
}
|
||||
|
||||
public void onDisplayCompletions(CompletionInfo[] infos) {
|
||||
this.createSuggestions();
|
||||
int len;
|
||||
if (infos == null) {
|
||||
len = 0;
|
||||
} else {
|
||||
len = infos.length;
|
||||
}
|
||||
public void onDisplayCompletions(CompletionInfo[] infos) {
|
||||
createSuggestions();
|
||||
int len;
|
||||
if (infos == null) {
|
||||
len = 0;
|
||||
} else {
|
||||
len = infos.length;
|
||||
}
|
||||
|
||||
for(int i = 0; i < len && this.mSuggestions.size() < this.mNumSuggestions && !TextUtils.isEmpty(infos[i].getText()); ++i) {
|
||||
this.mSuggestions.add(i, infos[i].getText().toString());
|
||||
}
|
||||
for (int i = 0; i < len && mSuggestions.size() < mNumSuggestions && !TextUtils.isEmpty(infos[i].getText()); ++i) {
|
||||
mSuggestions.add(i, infos[i].getText().toString());
|
||||
}
|
||||
|
||||
if (Log.isLoggable("LbSuggestionsFactory", Log.DEBUG)) {
|
||||
for(len = 0; len < this.mSuggestions.size(); ++len) {
|
||||
Log.d("LbSuggestionsFactory", "completion " + len + ": " + (String)this.mSuggestions.get(len));
|
||||
}
|
||||
}
|
||||
if (Log.isLoggable("LbSuggestionsFactory", Log.DEBUG)) {
|
||||
for (len = 0; len < mSuggestions.size(); ++len) {
|
||||
Log.d("LbSuggestionsFactory", "completion " + len + ": " + mSuggestions.get(len));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void onStartInput(EditorInfo info) {
|
||||
this.mMode = 0;
|
||||
if ((info.inputType & 65536) != 0) {
|
||||
this.mMode = 2;
|
||||
}
|
||||
public void onStartInput(EditorInfo info) {
|
||||
mMode = MODE_DEFAULT;
|
||||
if ((info.inputType & 65536) != 0) {
|
||||
mMode = MODE_AUTO_COMPLETE;
|
||||
}
|
||||
|
||||
switch(LeanbackUtils.getInputTypeClass(info)) {
|
||||
case 1:
|
||||
switch(LeanbackUtils.getInputTypeVariation(info)) {
|
||||
case 32:
|
||||
case 208:
|
||||
this.mMode = 1;
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
switch (LeanbackUtils.getInputTypeClass(info)) {
|
||||
case InputType.TYPE_CLASS_TEXT:
|
||||
switch (LeanbackUtils.getInputTypeVariation(info)) {
|
||||
case InputType.TYPE_DATETIME_VARIATION_TIME:
|
||||
case InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS:
|
||||
mMode = MODE_DOMAIN;
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldSuggestionsAmend() {
|
||||
return this.mMode == 1;
|
||||
}
|
||||
public boolean shouldSuggestionsAmend() {
|
||||
return mMode == MODE_DOMAIN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,20 @@ public class LeanbackUtils {
|
||||
return info.imeOptions & (EditorInfo.IME_FLAG_NO_ENTER_ACTION | EditorInfo.IME_MASK_ACTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class of the input
|
||||
* @param info attrs
|
||||
* @return constant e.g. {@link InputType#TYPE_CLASS_TEXT InputType.TYPE_CLASS_TEXT}
|
||||
*/
|
||||
public static int getInputTypeClass(EditorInfo info) {
|
||||
return info.inputType & InputType.TYPE_MASK_CLASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variation of the input
|
||||
* @param info attrs
|
||||
* @return constant e.g. {@link InputType#TYPE_DATETIME_VARIATION_DATE InputType.TYPE_DATETIME_VARIATION_DATE}
|
||||
*/
|
||||
public static int getInputTypeVariation(EditorInfo info) {
|
||||
return info.inputType & InputType.TYPE_MASK_VARIATION;
|
||||
}
|
||||
|
||||
@@ -204,18 +204,18 @@ public class LeanbackImeService extends InputMethodService {
|
||||
|
||||
@Override
|
||||
public View onCreateInputView() {
|
||||
this.mInputView = this.mKeyboardController.getView();
|
||||
this.mInputView.requestFocus();
|
||||
return this.mInputView;
|
||||
mInputView = mKeyboardController.getView();
|
||||
mInputView.requestFocus();
|
||||
return mInputView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayCompletions(CompletionInfo[] var1) {
|
||||
if (this.mKeyboardController.areSuggestionsEnabled()) {
|
||||
this.mShouldClearSuggestions = false;
|
||||
this.mHandler.removeMessages(123);
|
||||
this.mSuggestionsFactory.onDisplayCompletions(var1);
|
||||
this.mKeyboardController.updateSuggestions(this.mSuggestionsFactory.getSuggestions());
|
||||
public void onDisplayCompletions(CompletionInfo[] infos) {
|
||||
if (mKeyboardController.areSuggestionsEnabled()) {
|
||||
mShouldClearSuggestions = false;
|
||||
mHandler.removeMessages(123);
|
||||
mSuggestionsFactory.onDisplayCompletions(infos);
|
||||
mKeyboardController.updateSuggestions(this.mSuggestionsFactory.getSuggestions());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.liskovsoft.keyboardaddons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.inputmethodservice.Keyboard;
|
||||
import com.anysoftkeyboard.keyboards.KeyboardAddOnAndBuilder;
|
||||
import com.anysoftkeyboard.keyboards.ApkResourceKeyboardFactory;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.keyboards.KeyboardAddOnAndBuilder;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.keyboards.ApkLangKeyboardFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -13,7 +13,7 @@ public class KeyboardManager {
|
||||
private final Context mContext;
|
||||
private final List<KeyboardAddOnAndBuilder> mKeyboardBuilders;
|
||||
private final List<Keyboard> mAllKeyboards;
|
||||
private final ApkResourceKeyboardFactory mKeyboardFactory;
|
||||
private final ApkLangKeyboardFactory mKeyboardFactory;
|
||||
private int mKeyboardIndex = 0;
|
||||
|
||||
public KeyboardManager(Context ctx, int keyboardResId) {
|
||||
@@ -23,7 +23,7 @@ public class KeyboardManager {
|
||||
public KeyboardManager(Context ctx, Keyboard englishKeyboard) {
|
||||
mContext = ctx;
|
||||
mEnglishKeyboard = englishKeyboard;
|
||||
mKeyboardFactory = new ApkResourceKeyboardFactory();
|
||||
mKeyboardFactory = new ApkLangKeyboardFactory();
|
||||
|
||||
mKeyboardBuilders = mKeyboardFactory.getAllAvailableKeyboards(mContext);
|
||||
mAllKeyboards = buildAllKeyboards();
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.anysoftkeyboard.addons;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.addons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.anysoftkeyboard.addons;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.addons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
@@ -23,7 +23,7 @@ import android.support.annotation.Nullable;
|
||||
import android.support.v4.util.SparseArrayCompat;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.anysoftkeyboard.utils.Logger;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.utils.Logger;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.anysoftkeyboard.addons;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.addons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -26,8 +26,8 @@ import android.content.pm.ResolveInfo;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Xml;
|
||||
|
||||
//import com.anysoftkeyboard.AnySoftKeyboard;
|
||||
import com.anysoftkeyboard.utils.Logger;
|
||||
//import com.liskovsoft.keyboardaddons.apklangfactory.AnySoftKeyboard;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.utils.Logger;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.anysoftkeyboard.addons;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.addons;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.anysoftkeyboard.utils.Logger;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.utils.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.anysoftkeyboard.keyboards;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.keyboards;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -23,15 +23,15 @@ import android.preference.PreferenceManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.anysoftkeyboard.addons.AddOn;
|
||||
import com.anysoftkeyboard.addons.AddOnsFactory;
|
||||
import com.anysoftkeyboard.utils.Logger;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.addons.AddOn;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.addons.AddOnsFactory;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.utils.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class ApkResourceKeyboardFactory extends AddOnsFactory<KeyboardAddOnAndBuilder> {
|
||||
public class ApkLangKeyboardFactory extends AddOnsFactory<KeyboardAddOnAndBuilder> {
|
||||
private static final String TAG = "ASK_KF";
|
||||
|
||||
private static final String XML_LAYOUT_RES_ID_ATTRIBUTE = "layoutResId";
|
||||
@@ -44,7 +44,7 @@ public class ApkResourceKeyboardFactory extends AddOnsFactory<KeyboardAddOnAndBu
|
||||
private static final String XML_PHYSICAL_TRANSLATION_RES_ID_ATTRIBUTE = "physicalKeyboardMappingResId";
|
||||
private static final String XML_DEFAULT_ATTRIBUTE = "defaultEnabled";
|
||||
|
||||
public ApkResourceKeyboardFactory() {
|
||||
public ApkLangKeyboardFactory() {
|
||||
super(TAG, "com.liskovsoft.leankey.langpack.KEYBOARD", "com.liskovsoft.leankey.langpack.keyboards",
|
||||
"Keyboards", "Keyboard",
|
||||
0, true);
|
||||
@@ -14,13 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.anysoftkeyboard.keyboards;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.keyboards;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.anysoftkeyboard.addons.AddOn;
|
||||
import com.anysoftkeyboard.addons.AddOnImpl;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.addons.AddOn;
|
||||
import com.liskovsoft.keyboardaddons.apklangfactory.addons.AddOnImpl;
|
||||
|
||||
public class KeyboardAddOnAndBuilder extends AddOnImpl {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.anysoftkeyboard.utils;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
|
||||
public class BuildConfig {
|
||||
public final static boolean TESTING_BUILD = true;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.anysoftkeyboard.utils;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.anysoftkeyboard.utils;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
|
||||
public interface LogProvider {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.anysoftkeyboard.utils;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.anysoftkeyboard.utils;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
|
||||
/**
|
||||
* Doesn't do anything. For release.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.anysoftkeyboard.utils;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
|
||||
import android.util.Xml;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.anysoftkeyboard.utils;
|
||||
package com.liskovsoft.keyboardaddons.apklangfactory.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
Reference in New Issue
Block a user