-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add switch cmd 'ctrl+e' to enable and use ime, 'ctrl+shift+e' to disable ime * change original handler behavior: * change text_input to send all types char * when enable IME, injectKeyEvent skip Letter or Digit or Space char, InjectText to handler it * when disable IME, InjectText skip all text, injectKeyEvent to handler it
- Loading branch information
wei.liang
committed
Nov 3, 2019
1 parent
17d53be
commit f9ce19b
Showing
22 changed files
with
420 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ build/ | |
/dist/ | ||
.idea/ | ||
.gradle/ | ||
x | ||
*.iml | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
defaultConfig { | ||
applicationId "com.genymobile.scrcpy.ime" | ||
minSdkVersion 21 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
|
||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
testImplementation 'junit:junit:4.12' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.genymobile.scrcpy.ime"> | ||
<application android:label="@string/app_name"> | ||
<service android:label="@string/app_name" android:name="com.genymobile.scrcpy.ime.ScrcpyIME" android:permission="android.permission.BIND_INPUT_METHOD"> | ||
<intent-filter> | ||
<action android:name="android.view.InputMethod"/> | ||
</intent-filter> | ||
<meta-data android:name="android.view.im" android:resource="@xml/method" /> | ||
</service> | ||
</application> | ||
</manifest> |
81 changes: 81 additions & 0 deletions
81
ime/src/main/java/com/genymobile/scrcpy/ime/ScrcpyIME.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.genymobile.scrcpy.ime; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.IntentFilter; | ||
import android.inputmethodservice.InputMethodService; | ||
import android.util.Log; | ||
import android.view.KeyEvent; | ||
import android.view.inputmethod.InputConnection; | ||
|
||
public class ScrcpyIME extends InputMethodService { | ||
private static String TAG = "ScrcpyIME"; | ||
private BroadcastReceiver receiver; | ||
private static final String COMMIT_TEXT_ACTION = "com.genymobile.scrcpy.ime.COMMIT_TEXT_ACTION"; | ||
private static final String STATE_CHANGE_ACTION = "com.genymobile.scrcpy.ime.STATE_CHANGE_ACTION"; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
this.receiver = new BroadcastReceiver() { | ||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
InputConnection inputConnection = getCurrentInputConnection(); | ||
if(inputConnection == null){ | ||
return; | ||
} | ||
String text = null; | ||
KeyEvent keyEvent = null; | ||
if((text = intent.getStringExtra("text")) != null && text.length() > 0) { | ||
inputConnection.commitText(text, 0); | ||
}else if((keyEvent = intent.getParcelableExtra("keyEvent")) != null) { | ||
inputConnection.sendKeyEvent(keyEvent); | ||
} | ||
} | ||
}; | ||
IntentFilter localIntentFilter = new IntentFilter(COMMIT_TEXT_ACTION); | ||
registerReceiver(this.receiver, localIntentFilter); | ||
} | ||
|
||
@Override | ||
public void onDestroy() { | ||
unregisterReceiver(this.receiver); | ||
Log.i(TAG, "disabling self due to destroy"); | ||
super.onDestroy(); | ||
} | ||
|
||
@Override | ||
public void onBindInput() { | ||
super.onBindInput(); | ||
Log.i(TAG, "BindInput"); | ||
sendStateBroadcast("BindInput"); | ||
} | ||
|
||
@Override | ||
public void onUnbindInput() { | ||
super.onUnbindInput(); | ||
Log.i(TAG, "UnbindInput"); | ||
sendStateBroadcast("UnbindInput"); | ||
} | ||
|
||
@Override | ||
public void onWindowShown() { | ||
super.onWindowShown(); | ||
Log.i(TAG, "WindowShown"); | ||
sendStateBroadcast("WindowShown"); | ||
} | ||
|
||
@Override | ||
public void onWindowHidden() { | ||
super.onWindowHidden(); | ||
Log.i(TAG, "WindowHidden"); | ||
sendStateBroadcast("WindowHidden"); | ||
} | ||
|
||
private void sendStateBroadcast(String state) { | ||
Intent intent = new Intent(STATE_CHANGE_ACTION); | ||
intent.putExtra("state", state); | ||
sendBroadcast(intent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">Scrcpy</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<input-method xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<subtype android:label="@string/app_name" android:imeSubtypeLocale="en_US" android:imeSubtypeMode="keyboard" /> | ||
</input-method> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) 2006 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package android.content; | ||
import android.content.Intent; | ||
import android.os.Bundle; | ||
/** | ||
* System private API for dispatching intent broadcasts. This is given to the | ||
* activity manager as part of registering for an intent broadcasts, and is | ||
* called when it receives intents. | ||
* | ||
* {@hide} | ||
*/ | ||
oneway interface IIntentReceiver { | ||
void performReceive(in Intent intent, int resultCode, String data, | ||
in Bundle extras, boolean ordered, boolean sticky, int sendingUser); | ||
} |
23 changes: 23 additions & 0 deletions
23
server/src/main/aidl/com/android/internal/view/IInputMethodClient.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (C) 2008 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.android.internal.view; | ||
|
||
/** | ||
* Interface a client of the IInputMethodManager implements, to identify | ||
* itself and receive information about changes to the global manager state. | ||
*/ | ||
interface IInputMethodClient { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.