2014-11-16 23:14:06 -08:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Ahmed I. Khalil <ahmedibrahimkhali@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
* the License or (at your option) version 3 or any later version
|
|
|
|
* accepted by the membership of KDE e.V. (or its successor approved
|
|
|
|
* by the membership of KDE e.V.), which shall act as a proxy
|
|
|
|
* defined in Section 14 of version 3 of the license.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
package org.kde.kdeconnect.Plugins.MousePadPlugin;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2015-08-10 00:26:58 -07:00
|
|
|
import android.support.v4.content.ContextCompat;
|
2014-06-26 17:37:32 +00:00
|
|
|
|
|
|
|
import org.kde.kdeconnect.NetworkPackage;
|
|
|
|
import org.kde.kdeconnect.Plugins.Plugin;
|
|
|
|
import org.kde.kdeconnect_tp.R;
|
|
|
|
|
|
|
|
public class MousePadPlugin extends Plugin {
|
2014-09-17 10:36:45 +02:00
|
|
|
|
2016-06-03 00:46:18 +02:00
|
|
|
//public final static String PACKAGE_TYPE_MOUSEPAD = "kdeconnect.mousepad";
|
|
|
|
public final static String PACKAGE_TYPE_MOUSEPAD_REQUEST = "kdeconnect.mousepad.request";
|
2016-05-31 17:19:39 +02:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
@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() {
|
2015-08-10 00:26:58 -07:00
|
|
|
return ContextCompat.getDrawable(context, R.drawable.touchpad_plugin_action);
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 15:45:31 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasSettings() {
|
2014-11-09 13:27:29 -08:00
|
|
|
return true;
|
2014-09-16 15:45:31 +02:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
@Override
|
2015-04-12 00:11:30 -07:00
|
|
|
public boolean hasMainActivity() {
|
2014-06-26 17:37:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-12 00:11:30 -07:00
|
|
|
public void startMainActivity(Activity parentActivity) {
|
|
|
|
Intent intent = new Intent(parentActivity, MousePadActivity.class);
|
|
|
|
intent.putExtra("deviceId", device.getDeviceId());
|
|
|
|
parentActivity.startActivity(intent);
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|
|
|
|
|
2015-09-08 14:54:04 -07:00
|
|
|
@Override
|
|
|
|
public String[] getSupportedPackageTypes() {
|
|
|
|
return new String[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String[] getOutgoingPackageTypes() {
|
2016-06-03 00:46:18 +02:00
|
|
|
return new String[]{PACKAGE_TYPE_MOUSEPAD_REQUEST};
|
2015-09-08 14:54:04 -07:00
|
|
|
}
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
@Override
|
2015-04-12 00:11:30 -07:00
|
|
|
public String getActionName() {
|
|
|
|
return context.getString(R.string.open_mousepad);
|
2014-08-14 21:40:04 +02:00
|
|
|
}
|
|
|
|
|
2016-01-21 01:00:21 +06:00
|
|
|
public void sendMouseDelta(float dx, float dy, float sensitivity) {
|
2016-06-03 00:46:18 +02:00
|
|
|
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_REQUEST);
|
2016-01-21 01:00:21 +06:00
|
|
|
|
2016-06-04 13:45:33 +02:00
|
|
|
if (sensitivity <= 0.0001f) {
|
|
|
|
sensitivity = 1.0f;
|
|
|
|
}
|
|
|
|
|
2016-01-21 01:00:21 +06:00
|
|
|
np.set("dx", dx*sensitivity);
|
|
|
|
np.set("dy", dy*sensitivity);
|
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
device.sendPackage(np);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendSingleClick() {
|
2016-06-03 00:46:18 +02:00
|
|
|
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_REQUEST);
|
2014-06-26 17:37:32 +00:00
|
|
|
np.set("singleclick", true);
|
|
|
|
device.sendPackage(np);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendDoubleClick() {
|
2016-06-03 00:46:18 +02:00
|
|
|
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_REQUEST);
|
2014-06-26 17:37:32 +00:00
|
|
|
np.set("doubleclick", true);
|
|
|
|
device.sendPackage(np);
|
|
|
|
}
|
|
|
|
|
2014-06-29 17:58:33 +02:00
|
|
|
public void sendMiddleClick() {
|
2016-06-03 00:46:18 +02:00
|
|
|
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_REQUEST);
|
2014-06-29 17:58:33 +02:00
|
|
|
np.set("middleclick", true);
|
|
|
|
device.sendPackage(np);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sendRightClick() {
|
2016-06-03 00:46:18 +02:00
|
|
|
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_REQUEST);
|
2014-06-29 17:58:33 +02:00
|
|
|
np.set("rightclick", true);
|
|
|
|
device.sendPackage(np);
|
|
|
|
}
|
|
|
|
|
2014-12-10 23:33:13 -08:00
|
|
|
public void sendSingleHold(){
|
2016-06-03 00:46:18 +02:00
|
|
|
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_REQUEST);
|
2014-12-10 23:33:13 -08:00
|
|
|
np.set("singlehold", true);
|
|
|
|
device.sendPackage(np);
|
|
|
|
}
|
|
|
|
|
2014-06-29 17:15:00 +02:00
|
|
|
public void sendScroll(float dx, float dy) {
|
2016-06-03 00:46:18 +02:00
|
|
|
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MOUSEPAD_REQUEST);
|
2014-06-29 17:15:00 +02:00
|
|
|
np.set("scroll", true);
|
|
|
|
np.set("dx", dx);
|
|
|
|
np.set("dy", dy);
|
|
|
|
device.sendPackage(np);
|
|
|
|
}
|
|
|
|
|
2015-01-06 00:05:44 -08:00
|
|
|
public void sendKeyboardPacket(NetworkPackage np) {
|
2014-08-14 21:40:04 +02:00
|
|
|
device.sendPackage(np);
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|
2014-08-14 21:40:04 +02:00
|
|
|
|
2014-06-26 17:37:32 +00:00
|
|
|
}
|