Skip to content

Commit c5f3365

Browse files
committed
keyboard support
1 parent e50472a commit c5f3365

File tree

7 files changed

+131
-16
lines changed

7 files changed

+131
-16
lines changed

Make.android

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ OBJS=lib/arm64-v8a/libdrawterm.so lib/armeabi-v7a/libdrawterm.so lib/x86/libdraw
55

66
all: drawterm.apk
77

8+
clean:
9+
rm -f *.apk lib/*/*.so
10+
811
lib/arm64-v8a/libdrawterm.so:
9-
CONF=android-arm64 make;
12+
CONF=android-arm64 make -j5;
1013
CONF=android-arm64 make clean;
1114

1215
lib/armeabi-v7a/libdrawterm.so:
13-
CONF=android-arm make;
16+
CONF=android-arm make -j5;
1417
CONF=android-arm make clean;
1518

1619
lib/x86/libdrawterm.so:
17-
CONF=android-386 make;
20+
CONF=android-386 make -j5;
1821
CONF=android-386 make clean;
1922

2023
lib/x86_64/libdrawterm.so:
21-
CONF=android-amd64 make;
24+
CONF=android-amd64 make -j5;
2225
CONF=android-amd64 make clean;
2326

2427
drawterm.apk: drawterm-signed.apk

README

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@ To build on Mac OS X with Cocoa, run CONF=osx-cocoa make and "cp drawterm gui-co
2020

2121
To build for Android, make sure Make.android* files are correct for your build and target systems, then run make -f Make.android
2222

23-
On Android, there is no keyboard support in the app, the bitsy/keyboard on-screen keyboard must be used. From $home/lib/profile:
23+
USAGE
24+
-------
25+
On Android the five checkboxes at the top represent the three mouse buttons and mousewheel, determining which "buttons" are clicked. The "kb" button toggles the soft keyboard.
2426

25-
if(test -e /mnt/term/root/mnt/sdcard)
26-
rio -s -k 'bitsy/keyboard -n' -i riostart
27-
if not
28-
rio -s -i riostart
29-
30-
The five checkboxes at the top represent the three mouse buttons and mousewheel, determining which "buttons" are clicked.
3127

3228
CAVEATS
3329
--------
3430
Be aware that right now on Android the login details are saved as a plaintext string if saved, and there is no secstore support.
3531

32+
3633
BINARIES
3734
---------
3835
http://drawterm.9front.org/

gui-android/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
android:theme="@style/AppTheme">
1616
<activity
1717
android:name=".MainActivity"
18-
android:label="@string/app_name">
18+
android:label="@string/app_name"
19+
android:windowSoftInputMode="stateUnchanged|adjustNothing">
1920
<intent-filter>
2021
<action android:name="android.intent.action.MAIN" />
2122
<category android:name="android.intent.category.LAUNCHER" />

gui-android/cpp/devandroid.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ androidinit(void)
116116
output = malloc(sizeof(ACaptureSessionOutput*) * Ncameras);
117117
target = malloc(sizeof(ACameraOutputTarget*) * Ncameras);
118118

119-
sensorManager = ASensorManager_getInstanceForPackage("org.echoline.drawterm");
119+
sensorManager = ASensorManager_getInstance();
120120
}
121121

122122
static Chan*
@@ -227,7 +227,7 @@ androidopen(Chan *c, int omode)
227227
ACaptureSessionOutputContainer_add(container[s], output[s]);
228228
ACameraDevice_createCaptureSession(devices[s], container[s], &CSSCBs, &sessions[s]);
229229
ACameraOutputTarget_create(windows[s], &target[s]);
230-
ACameraDevice_createCaptureRequest(devices[s], TEMPLATE_STILL_CAPTURE, &requests[s]);
230+
ACameraDevice_createCaptureRequest(devices[s], TEMPLATE_ZERO_SHUTTER_LAG, &requests[s]);
231231
ACaptureRequest_addTarget(requests[s], target[s]);
232232
ACameraCaptureSession_capture(sessions[s], &CBs, 1, &requests[s], &i);
233233
}

gui-android/cpp/native-lib.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <libc.h>
77
#include <draw.h>
88
#include <string.h>
9+
#include <keyboard.h>
910

1011
void absmousetrack(int, int, int, ulong);
1112
ulong ticks(void);
@@ -32,6 +33,22 @@ Java_org_echoline_drawterm_MainActivity_setObject(
3233
assert(rs == JNI_OK);
3334
}
3435

36+
JNIEXPORT void JNICALL
37+
Java_org_echoline_drawterm_MainActivity_keyDown(
38+
JNIEnv *env,
39+
jobject obj,
40+
jint c) {
41+
kbdkey(c, 1);
42+
}
43+
44+
JNIEXPORT void JNICALL
45+
Java_org_echoline_drawterm_MainActivity_keyUp(
46+
JNIEnv *env,
47+
jobject obj,
48+
jint c) {
49+
kbdkey(c, 0);
50+
}
51+
3552
JNIEXPORT void JNICALL
3653
Java_org_echoline_drawterm_MainActivity_setPass(
3754
JNIEnv *env,

gui-android/java/org/echoline/drawterm/MainActivity.java

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import android.view.WindowManager;
2121
import android.view.WindowMetrics;
2222
import android.view.Surface;
23+
import android.view.inputmethod.InputMethodManager;
24+
import android.view.KeyEvent;
2325
import android.widget.ArrayAdapter;
2426
import android.widget.Button;
2527
import android.widget.EditText;
@@ -101,11 +103,20 @@ public void onClick(final View view) {
101103

102104
setContentView(R.layout.drawterm_main);
103105

106+
Button kbutton = (Button)findViewById(R.id.keyboardToggle);
107+
kbutton.setOnClickListener(new View.OnClickListener() {
108+
@Override
109+
public void onClick(final View view) {
110+
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
111+
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
112+
}
113+
});
114+
104115
int rid = res.getIdentifier("navigation_bar_height", "dimen", "android");
105116
if (rid > 0) {
106117
hp -= res.getDimensionPixelSize(rid);
107118
}
108-
LinearLayout ll = findViewById(R.id.mouseButtons);
119+
LinearLayout ll = findViewById(R.id.dtButtons);
109120
hp -= ll.getHeight();
110121

111122
int w = (int)(wp * (160.0/dm.xdpi));
@@ -156,6 +167,85 @@ public void onClick(View v) {
156167
});
157168
}
158169

170+
@Override
171+
public boolean dispatchKeyEvent(KeyEvent event)
172+
{
173+
int k = event.getUnicodeChar();
174+
if (k == 0) {
175+
k = event.getDisplayLabel();
176+
if (k != 0)
177+
k |= 0x20;
178+
}
179+
180+
switch (event.getKeyCode()) {
181+
case KeyEvent.KEYCODE_DEL:
182+
k = 0x0008;
183+
break;
184+
case KeyEvent.KEYCODE_FORWARD_DEL:
185+
k = 0x007F;
186+
break;
187+
case KeyEvent.KEYCODE_ESCAPE:
188+
k = 0x001B;
189+
break;
190+
case KeyEvent.KEYCODE_MOVE_HOME:
191+
k = 0xF00D;
192+
break;
193+
case KeyEvent.KEYCODE_MOVE_END:
194+
k = 0xF018;
195+
break;
196+
case KeyEvent.KEYCODE_PAGE_UP:
197+
k = 0xF00F;
198+
break;
199+
case KeyEvent.KEYCODE_PAGE_DOWN:
200+
k = 0xF013;
201+
break;
202+
case KeyEvent.KEYCODE_INSERT:
203+
k = 0xF014;
204+
break;
205+
case KeyEvent.KEYCODE_SYSRQ:
206+
k = 0xF010;
207+
break;
208+
case KeyEvent.KEYCODE_DPAD_UP:
209+
k = 0xF00E;
210+
break;
211+
case KeyEvent.KEYCODE_DPAD_LEFT:
212+
k = 0xF011;
213+
break;
214+
case KeyEvent.KEYCODE_DPAD_RIGHT:
215+
k = 0xF012;
216+
break;
217+
case KeyEvent.KEYCODE_DPAD_DOWN:
218+
k = 0xF800;
219+
break;
220+
}
221+
222+
if (k == 0)
223+
return true;
224+
225+
if (event.isCtrlPressed()) {
226+
keyDown(0xF017);
227+
}
228+
if (event.isAltPressed()) {
229+
keyDown(0xF015);
230+
}
231+
232+
if (event.getAction() == KeyEvent.ACTION_DOWN) {
233+
keyDown(k);
234+
}
235+
else if (event.getAction() == KeyEvent.ACTION_UP) {
236+
keyUp(k);
237+
}
238+
239+
if (event.isCtrlPressed()) {
240+
keyUp(0xF017);
241+
}
242+
if (event.isAltPressed()) {
243+
keyUp(0xF015);
244+
}
245+
246+
return true;
247+
}
248+
159249
@Override
160250
public void onBackPressed()
161251
{
@@ -188,4 +278,6 @@ public String getClipBoard() {
188278
public native void setDTSurface(Surface surface);
189279
public native void setMouse(int[] args);
190280
public native void setObject();
281+
public native void keyDown(int c);
282+
public native void keyUp(int c);
191283
}

gui-android/res/layout/drawterm_main.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
android:layout_gravity="bottom"
1414
android:gravity="center_horizontal"
1515
android:orientation="horizontal"
16-
android:id="@+id/mouseButtons">
16+
android:id="@+id/dtButtons">
1717

1818
<CheckBox
1919
android:id="@+id/mouseLeft"
@@ -35,5 +35,10 @@
3535
android:id="@+id/mouseDown"
3636
android:layout_width="wrap_content"
3737
android:layout_height="match_parent" />
38+
<Button
39+
android:id="@+id/keyboardToggle"
40+
android:text="kb"
41+
android:layout_width="wrap_content"
42+
android:layout_height="match_parent" />
3843
</LinearLayout>
3944
</LinearLayout>

0 commit comments

Comments
 (0)