2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +00:00

Add support for using the keyboard.

This patch adds a menu entry to display the keyboard in the mousepad plugin
and allow the user to send keystrokes. Dead keys are not yet supported, and
behavior is unknown if entered.

REVIEW: 119255
This commit is contained in:
Saikrishna Arcot
2014-08-01 12:28:12 +02:00
committed by Albert Vaca
parent 80ed8a58d5
commit d02684c714
4 changed files with 74 additions and 1 deletions

View File

@@ -1,8 +1,11 @@
package org.kde.kdeconnect.Plugins.MousePadPlugin;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.inputmethod.InputMethodManager;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -56,6 +59,9 @@ public class MousePadActivity extends Activity implements GestureDetector.OnGest
case R.id.menu_middle_click:
sendMiddleClick();
return true;
case R.id.menu_show_keyboard:
showKeyboard();
return true;
default:
return super.onOptionsItemSelected(item);
}
@@ -205,6 +211,56 @@ public class MousePadActivity extends Activity implements GestureDetector.OnGest
return true;
}
@Override
public boolean onKeyDown(int keyCode, final KeyEvent event) {
String character = new String(new char[] {(char) event.getUnicodeChar(0)});
int modifier = 0;
if (keyCode == KeyEvent.KEYCODE_DEL) {
modifier = 1;
} else if (keyCode == KeyEvent.KEYCODE_ENTER) {
modifier = 1 << 1;
} else if (keyCode == KeyEvent.KEYCODE_TAB) {
modifier = 1 << 1 | 1;
}
// Add space for Home, End, Page Up, and Page Down
if (event.isShiftPressed()) {
modifier |= 1 << 3;
}
if (android.os.Build.VERSION.SDK_INT >= 11) {
if (event.isCtrlPressed()) {
modifier |= 1 << 4;
}
}
if (character.charAt(0) == 0 && modifier == 0) {
return super.onKeyDown(keyCode, event);
}
final String characterToSend;
if (character.charAt(0) == 0) {
characterToSend = "";
} else {
characterToSend = character;
}
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
if (mousePadPlugin == null) return;
mousePadPlugin.sendKey(characterToSend, 0);
}
});
return true;
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (event.getUnicodeChar() == 0) {
return super.onKeyDown(keyCode, event);
}
return true;
}
private void sendMiddleClick() {
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
@Override
@@ -228,4 +284,9 @@ public class MousePadActivity extends Activity implements GestureDetector.OnGest
}
});
}
private void showKeyboard() {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
}
}

View File

@@ -95,6 +95,13 @@ public class MousePadPlugin extends Plugin {
device.sendPackage(np);
}
public void sendKey(String key, int modifier) {
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
np.set("key", key);
np.set("modifier", modifier);
device.sendPackage(np);
}
@Override
public Button getInterfaceButton(final Activity activity) {
Button button = new Button(activity);

View File

@@ -9,4 +9,8 @@ xmlns:kdeconnect="http://schemas.android.com/apk/res-auto/android">
<item android:id="@+id/menu_middle_click"
android:title="@string/middle_click"
kdeconnect:showAsAction="never" />
</menu>
<item android:id="@+id/menu_show_keyboard"
android:title="@string/show_keyboard"
kdeconnect:showAsAction="never" />
</menu>

View File

@@ -57,6 +57,7 @@
<string name="reconnect">Reconnect</string>
<string name="right_click">Send Right Click</string>
<string name="middle_click">Send Middle Click</string>
<string name="show_keyboard">Show Keyboard</string>
<string name="device_not_paired">Device not paired</string>
<string name="request_pairing">Request pairing</string>
<string name="pairing_accept">Accept</string>