Compare commits

..

1 Commits

Author SHA1 Message Date
Yuriy Liskov
37243e4d11 hide soft kbd on physical key 2018-08-03 19:00:34 +03:00
3 changed files with 31 additions and 4 deletions

View File

@@ -8,8 +8,8 @@ android {
applicationId "org.liskovsoft.leankeykeyboard.pro"
minSdkVersion project.properties.minSdkVersion
targetSdkVersion project.properties.targetSdkVersion
versionCode 70
versionName "4.3.20"
versionCode 71
versionName "4.3.21"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

View File

@@ -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>

View File

@@ -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;
@@ -51,6 +52,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));
@@ -647,7 +650,11 @@ 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();
mDownFocus.set(mContainer.getCurrFocus());
if (mSpaceTracker != null && mSpaceTracker.onKeyDown(keyCode, event)) {
return true;
@@ -663,6 +670,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;