mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 18:07:55 +00:00
Android Implementation of MousePad feature
CCMAIL: ahmedibrahimkhali@gmail.com
This commit is contained in:
parent
7ae687ae11
commit
ce597f2e51
@ -125,6 +125,17 @@
|
|||||||
android:value="org.kde.kdeconnect.UserInterface.DeviceActivity" />
|
android:value="org.kde.kdeconnect.UserInterface.DeviceActivity" />
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:theme="@style/Theme.AppCompat"
|
||||||
|
android:name="org.kde.kdeconnect.Plugins.MousePadPlugin.MousePadActivity"
|
||||||
|
android:label="@string/remote_control"
|
||||||
|
android:screenOrientation="fullSensor"
|
||||||
|
android:parentActivityName="org.kde.kdeconnect.UserInterface.DeviceActivity"
|
||||||
|
>
|
||||||
|
<meta-data android:name="android.support.PARENT_ACTIVITY"
|
||||||
|
android:value="org.kde.kdeconnect.UserInterface.DeviceActivity" />
|
||||||
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:theme="@style/Theme.AppCompat"
|
android:theme="@style/Theme.AppCompat"
|
||||||
android:name="org.kde.kdeconnect.UserInterface.ShareToReceiver"
|
android:name="org.kde.kdeconnect.UserInterface.ShareToReceiver"
|
||||||
|
@ -36,6 +36,7 @@ public class NetworkPackage {
|
|||||||
public final static String PACKAGE_TYPE_NOTIFICATION = "kdeconnect.notification";
|
public final static String PACKAGE_TYPE_NOTIFICATION = "kdeconnect.notification";
|
||||||
public final static String PACKAGE_TYPE_CLIPBOARD = "kdeconnect.clipboard";
|
public final static String PACKAGE_TYPE_CLIPBOARD = "kdeconnect.clipboard";
|
||||||
public final static String PACKAGE_TYPE_MPRIS = "kdeconnect.mpris";
|
public final static String PACKAGE_TYPE_MPRIS = "kdeconnect.mpris";
|
||||||
|
public final static String PACKAGE_TYPE_MOUSEPAD = "kdeconnect.mousepad";
|
||||||
public final static String PACKAGE_TYPE_SHARE = "kdeconnect.share";
|
public final static String PACKAGE_TYPE_SHARE = "kdeconnect.share";
|
||||||
|
|
||||||
private long mId;
|
private long mId;
|
||||||
|
@ -0,0 +1,124 @@
|
|||||||
|
package org.kde.kdeconnect.Plugins.MousePadPlugin;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.GestureDetector;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import org.kde.kdeconnect.BackgroundService;
|
||||||
|
import org.kde.kdeconnect.Device;
|
||||||
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
|
public class MousePadActivity extends Activity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
|
||||||
|
private float mPrevX;
|
||||||
|
private float mPrevY;
|
||||||
|
private float mCurrentX;
|
||||||
|
private float mCurrentY;
|
||||||
|
|
||||||
|
private String deviceId;
|
||||||
|
|
||||||
|
private GestureDetector mDetector;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_mousepad);
|
||||||
|
deviceId = getIntent().getStringExtra("deviceId");
|
||||||
|
mDetector = new GestureDetector(this, this);
|
||||||
|
mDetector.setOnDoubleTapListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
|
mDetector.onTouchEvent(event);
|
||||||
|
int actionType = event.getAction();
|
||||||
|
final float x = event.getX();
|
||||||
|
final float y = event.getY();
|
||||||
|
switch (actionType) {
|
||||||
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
mPrevX = x;
|
||||||
|
mPrevY = y;
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_MOVE:
|
||||||
|
mCurrentX = x;
|
||||||
|
mCurrentY = y;
|
||||||
|
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.sendPoints(mCurrentX - mPrevX, mCurrentY - mPrevY);
|
||||||
|
mPrevX = mCurrentX;
|
||||||
|
mPrevY = mCurrentY;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onDown(MotionEvent e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onShowPress(MotionEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onSingleTapUp(MotionEvent e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLongPress(MotionEvent e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||||
|
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.sendSingleClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onDoubleTap(MotionEvent e) {
|
||||||
|
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.sendDoubleClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onDoubleTapEvent(MotionEvent e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,105 @@
|
|||||||
|
package org.kde.kdeconnect.Plugins.MousePadPlugin;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
|
import org.kde.kdeconnect.Plugins.Plugin;
|
||||||
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
|
public class MousePadPlugin extends Plugin {
|
||||||
|
@Override
|
||||||
|
public String getPluginName() {
|
||||||
|
return "plugin_mousepad";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDisplayName() {
|
||||||
|
return context.getString(R.string.pref_plugin_mousepad);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDescription() {
|
||||||
|
return context.getString(R.string.pref_plugin_mousepad_desc);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Drawable getIcon() {
|
||||||
|
return context.getResources().getDrawable(R.drawable.icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabledByDefault() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreate() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onPackageReceived(NetworkPackage np) {
|
||||||
|
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_MOUSEPAD)) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AlertDialog getErrorDialog(Context baseContext) {
|
||||||
|
return new AlertDialog.Builder(baseContext)
|
||||||
|
.setTitle(R.string.pref_plugin_mousepad)
|
||||||
|
.setMessage(R.string.plugin_not_available)
|
||||||
|
.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialogInterface, int i) {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPoints(float dx, float dy) {
|
||||||
|
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||||
|
np.set("dx", dx);
|
||||||
|
np.set("dy", dy);
|
||||||
|
device.sendPackage(np);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendSingleClick() {
|
||||||
|
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||||
|
np.set("singleclick", true);
|
||||||
|
device.sendPackage(np);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendDoubleClick() {
|
||||||
|
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||||
|
np.set("doubleclick", true);
|
||||||
|
device.sendPackage(np);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Button getInterfaceButton(final Activity activity) {
|
||||||
|
Button button = new Button(activity);
|
||||||
|
button.setText(R.string.open_mousepad);
|
||||||
|
button.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Intent intent = new Intent(activity, MousePadActivity.class);
|
||||||
|
intent.putExtra("deviceId", device.getDeviceId());
|
||||||
|
activity.startActivity(intent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,8 @@ import android.util.Log;
|
|||||||
|
|
||||||
import org.kde.kdeconnect.Device;
|
import org.kde.kdeconnect.Device;
|
||||||
import org.kde.kdeconnect.Plugins.BatteryPlugin.BatteryPlugin;
|
import org.kde.kdeconnect.Plugins.BatteryPlugin.BatteryPlugin;
|
||||||
|
import org.kde.kdeconnect.Plugins.MousePadPlugin.MousePadActivity;
|
||||||
|
import org.kde.kdeconnect.Plugins.MousePadPlugin.MousePadPlugin;
|
||||||
import org.kde.kdeconnect.Plugins.SftpPlugin.SftpPlugin;
|
import org.kde.kdeconnect.Plugins.SftpPlugin.SftpPlugin;
|
||||||
import org.kde.kdeconnect.Plugins.ClibpoardPlugin.ClipboardPlugin;
|
import org.kde.kdeconnect.Plugins.ClibpoardPlugin.ClipboardPlugin;
|
||||||
import org.kde.kdeconnect.Plugins.MprisPlugin.MprisPlugin;
|
import org.kde.kdeconnect.Plugins.MprisPlugin.MprisPlugin;
|
||||||
@ -70,6 +72,7 @@ public class PluginFactory {
|
|||||||
PluginFactory.registerPlugin(BatteryPlugin.class);
|
PluginFactory.registerPlugin(BatteryPlugin.class);
|
||||||
PluginFactory.registerPlugin(SftpPlugin.class);
|
PluginFactory.registerPlugin(SftpPlugin.class);
|
||||||
PluginFactory.registerPlugin(NotificationsPlugin.class);
|
PluginFactory.registerPlugin(NotificationsPlugin.class);
|
||||||
|
PluginFactory.registerPlugin(MousePadPlugin.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PluginInfo getPluginInfo(Context context, String pluginName) {
|
public static PluginInfo getPluginInfo(Context context, String pluginName) {
|
||||||
@ -111,10 +114,10 @@ public class PluginFactory {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerPlugin(Class pluginClass) {
|
public static void registerPlugin(Class<? extends Plugin> pluginClass) {
|
||||||
try {
|
try {
|
||||||
//I hate this but I need to create an instance because abstract static functions can't be declared
|
//I hate this but I need to create an instance because abstract static functions can't be declared
|
||||||
String pluginName = ((Plugin)pluginClass.newInstance()).getPluginName();
|
String pluginName = (pluginClass.newInstance()).getPluginName();
|
||||||
availablePlugins.put(pluginName, pluginClass);
|
availablePlugins.put(pluginName, pluginClass);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Log.e("PluginFactory","addPlugin exception");
|
Log.e("PluginFactory","addPlugin exception");
|
||||||
|
14
src/main/res/layout/activity_mousepad.xml
Normal file
14
src/main/res/layout/activity_mousepad.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="vertical" android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/mousepad_info"
|
||||||
|
android:gravity="center"
|
||||||
|
style="@android:style/TextAppearance.Medium"
|
||||||
|
android:layout_centerInParent="true"/>
|
||||||
|
</RelativeLayout>
|
@ -9,6 +9,8 @@
|
|||||||
<string name="pref_plugin_sftp_desc">Allows to browse the phone\'s filesystem remotely</string>
|
<string name="pref_plugin_sftp_desc">Allows to browse the phone\'s filesystem remotely</string>
|
||||||
<string name="pref_plugin_clipboard">Clipboard sync</string>
|
<string name="pref_plugin_clipboard">Clipboard sync</string>
|
||||||
<string name="pref_plugin_clipboard_desc">Share the clipboard content</string>
|
<string name="pref_plugin_clipboard_desc">Share the clipboard content</string>
|
||||||
|
<string name="pref_plugin_mousepad">Mouse Remote Control</string>
|
||||||
|
<string name="pref_plugin_mousepad_desc">Control your mouse remotely</string>
|
||||||
<string name="pref_plugin_mpris">Multimedia remote controls</string>
|
<string name="pref_plugin_mpris">Multimedia remote controls</string>
|
||||||
<string name="pref_plugin_mpris_desc">Control audio/video from your phone</string>
|
<string name="pref_plugin_mpris_desc">Control audio/video from your phone</string>
|
||||||
<string name="pref_plugin_ping">Ping</string>
|
<string name="pref_plugin_ping">Ping</string>
|
||||||
@ -23,6 +25,8 @@
|
|||||||
<string name="no_permissions">You need to grant permission to access notifications</string>
|
<string name="no_permissions">You need to grant permission to access notifications</string>
|
||||||
<string name="send_ping">Send ping</string>
|
<string name="send_ping">Send ping</string>
|
||||||
<string name="open_mpris_controls">Open remote control</string>
|
<string name="open_mpris_controls">Open remote control</string>
|
||||||
|
<string name="open_mousepad">Open mousepad control</string>
|
||||||
|
<string name="mousepad_info">Move your thumb on the screen to move the mouse cursor</string>
|
||||||
<string name="category_connected_devices">Connected devices</string>
|
<string name="category_connected_devices">Connected devices</string>
|
||||||
<string name="category_not_paired_devices">Not paired devices</string>
|
<string name="category_not_paired_devices">Not paired devices</string>
|
||||||
<string name="category_remembered_devices">Remembered devices</string>
|
<string name="category_remembered_devices">Remembered devices</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user