mirror of
https://github.com/yuliskov/LeanKeyboard.git
synced 2026-05-03 05:12:36 -04:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4d615bbf2 | ||
|
|
5e8e68de44 | ||
|
|
48e12a21d1 | ||
|
|
6a8b9c63e5 | ||
|
|
95ab858296 | ||
|
|
37243e4d11 | ||
|
|
0c7052be55 |
@@ -8,8 +8,8 @@ android {
|
||||
applicationId "org.liskovsoft.leankeykeyboard.pro"
|
||||
minSdkVersion project.properties.minSdkVersion
|
||||
targetSdkVersion project.properties.targetSdkVersion
|
||||
versionCode 69
|
||||
versionName "4.3.19"
|
||||
versionCode 76
|
||||
versionName "4.3.26"
|
||||
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service android:label="@string/ime_service_name" android:name="com.google.leanback.ime.LeanbackImeService" android:permission="android.permission.BIND_INPUT_METHOD">
|
||||
<service android:label="@string/ime_service_name"
|
||||
android:name="com.google.leanback.ime.LeanbackImeService"
|
||||
android:permission="android.permission.BIND_INPUT_METHOD">
|
||||
<intent-filter>
|
||||
<action android:name="android.view.InputMethod"/>
|
||||
</intent-filter>
|
||||
|
||||
@@ -320,10 +320,10 @@ public class LeanbackKeyboardContainer {
|
||||
* Init currently displayed keyboard<br/>
|
||||
* Note: all keyboard settings applied here<br/>
|
||||
* Note: this method is called constantly on new field
|
||||
* @param resources resources (not used)
|
||||
* @param res resources (not used)
|
||||
* @param info current ime attributes
|
||||
*/
|
||||
private void setImeOptions(Resources resources, EditorInfo info) {
|
||||
private void setImeOptions(Resources res, EditorInfo info) {
|
||||
// do not erase last keyboard
|
||||
if (mInitialMainKeyboard == null) {
|
||||
mInitialMainKeyboard = mAbcKeyboard;
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.graphics.Rect;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.inputmethodservice.Keyboard.Key;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.text.InputType;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@@ -30,6 +31,7 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
private static final int KEY_CHANGE_HISTORY_SIZE = 10;
|
||||
private static final long KEY_CHANGE_REVERT_TIME_MS = 100L;
|
||||
private static final String TAG = "LbKbController";
|
||||
public static final String TAG_GO = "Go";
|
||||
private boolean clickConsumed;
|
||||
private long lastClickTime;
|
||||
private LeanbackKeyboardContainer mContainer;
|
||||
@@ -51,6 +53,8 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
private LeanbackKeyboardController.TouchEventListener mTouchEventListener;
|
||||
private long prevTime;
|
||||
private boolean mShowInput;
|
||||
private int mLastEditorIdPhysicalKeyboardWasUsed;
|
||||
private boolean mHideKeyboardWhenPhysicalKeyboardUsed = true;
|
||||
|
||||
public LeanbackKeyboardController(final InputMethodService context, final LeanbackKeyboardController.InputListener listener) {
|
||||
this(context, listener, new TouchNavSpaceTracker(), new LeanbackKeyboardContainer(context));
|
||||
@@ -151,14 +155,19 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
this.commitKey(this.mContainer.getCurrFocus());
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: where all magic happens. Input from virtual kbd is processed here.
|
||||
* @param focus current key
|
||||
*/
|
||||
private void commitKey(LeanbackKeyboardContainer.KeyFocus focus) {
|
||||
if (mContainer != null && focus != null) {
|
||||
switch (focus.type) {
|
||||
case KeyFocus.TYPE_VOICE:
|
||||
mContainer.onVoiceClick();
|
||||
return;
|
||||
case KeyFocus.TYPE_ACTION:
|
||||
case KeyFocus.TYPE_ACTION: // NOTE: user presses Go, Send, Search etc
|
||||
mInputListener.onEntry(InputListener.ENTRY_TYPE_ACTION, 0, null);
|
||||
// mContext.hideWindow(); // SmartYouTubeTV fix: force hide keyboard
|
||||
return;
|
||||
case KeyFocus.TYPE_SUGGESTION:
|
||||
mInputListener.onEntry(InputListener.ENTRY_TYPE_SUGGESTION, 0, mContainer.getSuggestionText(focus.index));
|
||||
@@ -434,7 +443,8 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
private boolean handleKeyUpEvent(int keyCode, long currTime) {
|
||||
keyCode = getSimplifiedKey(keyCode);
|
||||
boolean handled;
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE) {
|
||||
handled = false;
|
||||
} else if (mContainer.isVoiceVisible()) {
|
||||
handled = true;
|
||||
@@ -604,7 +614,7 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
Button button = mContainer.getGoButton();
|
||||
button.setOnTouchListener(this);
|
||||
button.setOnHoverListener(this);
|
||||
button.setTag("Go");
|
||||
button.setTag(TAG_GO);
|
||||
return view;
|
||||
} else {
|
||||
return null;
|
||||
@@ -647,7 +657,12 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
* @param event {@link KeyEvent KeyEvent}
|
||||
* @return is event handled
|
||||
*/
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) {
|
||||
//greater than zero means it is a physical keyboard.
|
||||
//we also want to hide the view if it's a glyph (for example, not physical volume-up key)
|
||||
//if (event.getDeviceId() > 0 && event.isPrintingKey()) onPhysicalKeyboardKeyPressed();
|
||||
if (event.isPrintingKey()) onPhysicalKeyboardKeyPressed();
|
||||
|
||||
mDownFocus.set(mContainer.getCurrFocus());
|
||||
if (mSpaceTracker != null && mSpaceTracker.onKeyDown(keyCode, event)) {
|
||||
return true;
|
||||
@@ -663,6 +678,24 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
}
|
||||
}
|
||||
|
||||
private void onPhysicalKeyboardKeyPressed() {
|
||||
EditorInfo editorInfo = mContext.getCurrentInputEditorInfo();
|
||||
mLastEditorIdPhysicalKeyboardWasUsed = editorInfo == null ? 0 : editorInfo.fieldId;
|
||||
if (mHideKeyboardWhenPhysicalKeyboardUsed) {
|
||||
mContext.hideWindow();
|
||||
}
|
||||
|
||||
// For all other keys, if we want to do transformations on
|
||||
// text being entered with a hard keyboard, we need to process
|
||||
// it and do the appropriate action.
|
||||
// using physical keyboard is more annoying with candidate view in
|
||||
// the way
|
||||
// so we disable it.
|
||||
|
||||
// stopping any soft-keyboard prediction
|
||||
//abortCorrectionAndResetPredictionState(false);
|
||||
}
|
||||
|
||||
public boolean onKeyUp(int keyCode, KeyEvent keyEvent) {
|
||||
if (mSpaceTracker != null && mSpaceTracker.onKeyUp(keyCode, keyEvent)) {
|
||||
return true;
|
||||
@@ -718,31 +751,37 @@ public class LeanbackKeyboardController implements LeanbackKeyboardContainer.Voi
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
Object tag = view.getTag();
|
||||
if (tag != null && "Go".equals(tag)) {
|
||||
fakeKeyIndex(0, KeyFocus.TYPE_ACTION);
|
||||
} else {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
moveSelectorToPoint(event.getX(), event.getY());
|
||||
fakeClickDown();
|
||||
beginLongClickCountdown();
|
||||
boolean isEnterKey = TAG_GO.equals(tag);
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
if (isEnterKey) {
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (!clickConsumed) {
|
||||
clickConsumed = true;
|
||||
if (isDoubleClick()) {
|
||||
mContainer.onKeyLongPress();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fakeClickUp();
|
||||
moveSelectorToPoint(event.getX(), event.getY());
|
||||
fakeClickDown();
|
||||
beginLongClickCountdown();
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
if (isEnterKey) {
|
||||
fakeKeyIndex(0, KeyFocus.TYPE_ACTION);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!clickConsumed) {
|
||||
clickConsumed = true;
|
||||
if (isDoubleClick()) {
|
||||
mContainer.onKeyLongPress();
|
||||
break;
|
||||
}
|
||||
|
||||
fakeLongClickUp();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
fakeClickUp();
|
||||
}
|
||||
|
||||
fakeLongClickUp();
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.google.leanback.ime;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.inputmethodservice.InputMethodService;
|
||||
import android.os.Handler;
|
||||
@@ -161,8 +162,15 @@ public class LeanbackImeService extends InputMethodService {
|
||||
|
||||
connection.commitText(text, 1);
|
||||
mEnterSpaceBeforeCommitting = true;
|
||||
case InputListener.ENTRY_TYPE_ACTION:
|
||||
sendDefaultEditorAction(false);
|
||||
case InputListener.ENTRY_TYPE_ACTION: // NOTE: user presses Go, Send, Search etc
|
||||
boolean result = sendDefaultEditorAction(true);
|
||||
|
||||
if (result) {
|
||||
hideWindow(); // NOTE: SmartYouTubeTV hide kbd on search page fix
|
||||
} else {
|
||||
sendEnterKey(connection);
|
||||
}
|
||||
|
||||
updateSuggestions = false;
|
||||
break;
|
||||
case InputListener.ENTRY_TYPE_LEFT:
|
||||
@@ -210,6 +218,10 @@ public class LeanbackImeService extends InputMethodService {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendEnterKey(InputConnection connection) {
|
||||
connection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateInputView() {
|
||||
mInputView = mKeyboardController.getView();
|
||||
@@ -271,14 +283,39 @@ public class LeanbackImeService extends InputMethodService {
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
// NOTE: hide keyboard on ESC key
|
||||
// https://github.com/yuliskov/SmartYouTubeTV/issues/142
|
||||
event = mapEscToBack(event);
|
||||
keyCode = mapEscToBack(keyCode);
|
||||
|
||||
return isInputViewShown() && mKeyboardController.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||
// NOTE: hide keyboard on ESC key
|
||||
// https://github.com/yuliskov/SmartYouTubeTV/issues/142
|
||||
event = mapEscToBack(event);
|
||||
keyCode = mapEscToBack(keyCode);
|
||||
|
||||
return isInputViewShown() && mKeyboardController.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
private KeyEvent mapEscToBack(KeyEvent event) {
|
||||
if (event.getKeyCode() == KeyEvent.KEYCODE_ESCAPE) {
|
||||
// pay attention, you must pass the same action
|
||||
event = new KeyEvent(event.getAction(), KeyEvent.KEYCODE_BACK);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
private int mapEscToBack(int keyCode) {
|
||||
if (keyCode == KeyEvent.KEYCODE_ESCAPE) {
|
||||
keyCode = KeyEvent.KEYCODE_BACK;
|
||||
}
|
||||
return keyCode;
|
||||
}
|
||||
|
||||
// FireTV fix
|
||||
//@Override
|
||||
//public boolean onShowInputRequested(int flags, boolean configChange) {
|
||||
@@ -298,7 +335,7 @@ public class LeanbackImeService extends InputMethodService {
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return Service.START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -11,10 +11,10 @@
|
||||
<string name="title_movement_sensitivity">Rörelsekänslighet</string>
|
||||
<string name="btn_on">På</string>
|
||||
<string name="btn_off">Av</string>
|
||||
<string name="keyboardview_keycode_space">Space</string>
|
||||
<string name="keyboardview_keycode_delete">Delete</string>
|
||||
<string name="keyboardview_keycode_space">Blanksteg</string>
|
||||
<string name="keyboardview_keycode_delete">Ta bort</string>
|
||||
<string name="keyboardview_keycode_mode_change">Funktionsändring</string>
|
||||
<string name="keyboardview_keycode_shift">Shift</string>
|
||||
<string name="keyboardview_keycode_shift">Skift</string>
|
||||
<string name="keyboardview_keycode_caps">Caps Lock</string>
|
||||
<string name="keyboardview_keycode_left">Vänster</string>
|
||||
<string name="keyboardview_keycode_right">Höger</string>
|
||||
|
||||
7
leankeykeyboard/src/main/res/xml/accent_fa_a.xml
Normal file
7
leankeykeyboard/src/main/res/xml/accent_fa_a.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Keyboard android:keyWidth="@dimen/key_width" android:keyHeight="@dimen/key_height" android:horizontalGap="@dimen/keyboard_horizontal_gap" android:verticalGap="@dimen/keyboard_vertical_gap"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<Row>
|
||||
<Key android:keyLabel="آ" />
|
||||
</Row>
|
||||
</Keyboard>
|
||||
@@ -37,7 +37,8 @@
|
||||
<Key android:keyLabel="ی" />
|
||||
<Key android:keyLabel="ب" />
|
||||
<Key android:keyLabel="ل" />
|
||||
<Key android:keyLabel="ا" />
|
||||
<!-- fix from Shobair Mohammadi <shobairmohammadi@gmail.com> -->
|
||||
<Key android:keyLabel="ا|آ" android:popupKeyboard="@xml/accent_fa_a" />
|
||||
<Key android:keyLabel="ت" />
|
||||
<Key android:keyLabel="ن" />
|
||||
<Key android:keyLabel="م" />
|
||||
|
||||
Reference in New Issue
Block a user