Skip to content

Commit d7a4505

Browse files
authored
Merge pull request #77 from dqtz5vpvj9-create/master
Add IME action shortcuts and Update Gradle
2 parents 9466caa + 480be4f commit d7a4505

File tree

5 files changed

+80
-19
lines changed

5 files changed

+80
-19
lines changed

build.gradle

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
buildscript {
22
repositories {
3-
jcenter()
3+
maven { url 'https://maven.aliyun.com/repository/google' }
4+
maven { url 'https://maven.aliyun.com/repository/central' }
45
google()
6+
mavenCentral()
57
}
68
dependencies {
7-
classpath 'com.android.tools.build:gradle:4.0.0'
9+
classpath 'com.android.tools.build:gradle:8.1.0'
810
}
11+
}
912

10-
allprojects {
11-
repositories {
12-
google()
13-
jcenter()
14-
}
13+
allprojects {
14+
repositories {
15+
maven { url 'https://maven.aliyun.com/repository/google' }
16+
maven { url 'https://maven.aliyun.com/repository/central' }
17+
google()
18+
mavenCentral()
1519
}
1620
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Sep 05 14:14:30 HKT 2020
1+
#Wed Dec 03 11:08:02 CST 2025
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

keyboardservice/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 33
5-
buildToolsVersion '28.0.3'
4+
namespace 'com.android.adbkeyboard'
5+
compileSdk 33
66

77
defaultConfig {
88
applicationId 'com.android.adbkeyboard'
9-
minSdkVersion 15
10-
targetSdkVersion 33
9+
minSdk 21
10+
targetSdk 33
1111
versionCode 2
1212
versionName "2.0"
1313
}

keyboardservice/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.android.adbkeyboard"
32
android:versionCode="1"
43
android:versionName="1.0" >
54

keyboardservice/src/main/java/com/android/adbkeyboard/AdbIME.java

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.view.InputDevice;
1111
import android.view.KeyEvent;
1212
import android.view.View;
13+
import android.view.inputmethod.EditorInfo;
1314
import android.view.inputmethod.ExtractedTextRequest;
1415
import android.view.inputmethod.InputConnection;
1516

@@ -21,6 +22,11 @@ public class AdbIME extends InputMethodService {
2122
private String IME_EDITORCODE = "ADB_EDITOR_CODE";
2223
private String IME_MESSAGE_B64 = "ADB_INPUT_B64";
2324
private String IME_CLEAR_TEXT = "ADB_CLEAR_TEXT";
25+
private String IME_ACTION_SEARCH = "ADB_ACTION_SEARCH";
26+
private String IME_ACTION_GO = "ADB_ACTION_GO";
27+
private String IME_ACTION_DONE = "ADB_ACTION_DONE";
28+
private String IME_ACTION_NEXT = "ADB_ACTION_NEXT";
29+
private String IME_ACTION_SEND = "ADB_ACTION_SEND";
2430
private BroadcastReceiver mReceiver = null;
2531

2632
@Override
@@ -35,6 +41,11 @@ public View onCreateInputView() {
3541
filter.addAction(IME_EDITORCODE);
3642
filter.addAction(IME_MESSAGE_B64);
3743
filter.addAction(IME_CLEAR_TEXT);
44+
filter.addAction(IME_ACTION_SEARCH);
45+
filter.addAction(IME_ACTION_GO);
46+
filter.addAction(IME_ACTION_DONE);
47+
filter.addAction(IME_ACTION_NEXT);
48+
filter.addAction(IME_ACTION_SEND);
3849
mReceiver = new AdbReceiver();
3950
registerReceiver(mReceiver, filter);
4051
}
@@ -153,11 +164,58 @@ public void onReceive(Context context, Intent intent) {
153164
if (intent.getAction().equals(IME_CLEAR_TEXT)) {
154165
InputConnection ic = getCurrentInputConnection();
155166
if (ic != null) {
156-
//REF: stackoverflow/33082004 author: Maxime Epain
157-
CharSequence curPos = ic.getExtractedText(new ExtractedTextRequest(), 0).text;
158-
CharSequence beforePos = ic.getTextBeforeCursor(curPos.length(), 0);
159-
CharSequence afterPos = ic.getTextAfterCursor(curPos.length(), 0);
160-
ic.deleteSurroundingText(beforePos.length(), afterPos.length());
167+
// Try to get extracted text first
168+
ExtractedTextRequest req = new ExtractedTextRequest();
169+
req.hintMaxChars = 100000;
170+
req.hintMaxLines = 10000;
171+
android.view.inputmethod.ExtractedText et = ic.getExtractedText(req, 0);
172+
if (et != null && et.text != null) {
173+
CharSequence beforePos = ic.getTextBeforeCursor(et.text.length(), 0);
174+
CharSequence afterPos = ic.getTextAfterCursor(et.text.length(), 0);
175+
if (beforePos != null && afterPos != null) {
176+
ic.deleteSurroundingText(beforePos.length(), afterPos.length());
177+
}
178+
} else {
179+
// Fallback: select all and delete
180+
ic.performContextMenuAction(android.R.id.selectAll);
181+
ic.commitText("", 1);
182+
}
183+
}
184+
}
185+
186+
// IME Actions - convenient shortcuts
187+
if (intent.getAction().equals(IME_ACTION_SEARCH)) {
188+
InputConnection ic = getCurrentInputConnection();
189+
if (ic != null) {
190+
ic.performEditorAction(EditorInfo.IME_ACTION_SEARCH);
191+
}
192+
}
193+
194+
if (intent.getAction().equals(IME_ACTION_GO)) {
195+
InputConnection ic = getCurrentInputConnection();
196+
if (ic != null) {
197+
ic.performEditorAction(EditorInfo.IME_ACTION_GO);
198+
}
199+
}
200+
201+
if (intent.getAction().equals(IME_ACTION_DONE)) {
202+
InputConnection ic = getCurrentInputConnection();
203+
if (ic != null) {
204+
ic.performEditorAction(EditorInfo.IME_ACTION_DONE);
205+
}
206+
}
207+
208+
if (intent.getAction().equals(IME_ACTION_NEXT)) {
209+
InputConnection ic = getCurrentInputConnection();
210+
if (ic != null) {
211+
ic.performEditorAction(EditorInfo.IME_ACTION_NEXT);
212+
}
213+
}
214+
215+
if (intent.getAction().equals(IME_ACTION_SEND)) {
216+
InputConnection ic = getCurrentInputConnection();
217+
if (ic != null) {
218+
ic.performEditorAction(EditorInfo.IME_ACTION_SEND);
161219
}
162220
}
163221
}

0 commit comments

Comments
 (0)