2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-22 18:07:55 +00:00

154 lines
4.5 KiB
Java
Raw Normal View History

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-11-16 23:14:06 -08:00
package org.kde.kdeconnect.Plugins.MousePadPlugin;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import org.kde.kdeconnect.NetworkPacket;
import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect.Plugins.PluginFactory;
import org.kde.kdeconnect_tp.R;
import androidx.core.content.ContextCompat;
@PluginFactory.LoadablePlugin
public class MousePadPlugin extends Plugin {
//public final static String PACKET_TYPE_MOUSEPAD = "kdeconnect.mousepad";
public final static String PACKET_TYPE_MOUSEPAD_REQUEST = "kdeconnect.mousepad.request";
private final static String PACKET_TYPE_MOUSEPAD_KEYBOARDSTATE = "kdeconnect.mousepad.keyboardstate";
private boolean keyboardEnabled = true;
@Override
public boolean onPacketReceived(NetworkPacket np) {
keyboardEnabled = np.getBoolean("state", true);
return true;
}
@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 ContextCompat.getDrawable(context, R.drawable.touchpad_plugin_action);
}
@Override
public boolean hasSettings() {
return true;
}
@Override
2015-04-12 00:11:30 -07:00
public boolean hasMainActivity() {
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);
}
2015-09-08 14:54:04 -07:00
@Override
public String[] getSupportedPacketTypes() {
return new String[]{PACKET_TYPE_MOUSEPAD_KEYBOARDSTATE};
2015-09-08 14:54:04 -07:00
}
@Override
public String[] getOutgoingPacketTypes() {
return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST};
2015-09-08 14:54:04 -07:00
}
@Override
2015-04-12 00:11:30 -07:00
public String getActionName() {
return context.getString(R.string.open_mousepad);
}
public void sendMouseDelta(float dx, float dy) {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
2016-01-21 01:00:21 +06:00
np.set("dx", dx);
np.set("dy", dy);
2016-01-21 01:00:21 +06:00
device.sendPacket(np);
}
public void sendSingleClick() {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
np.set("singleclick", true);
device.sendPacket(np);
}
public void sendDoubleClick() {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
np.set("doubleclick", true);
device.sendPacket(np);
}
public void sendMiddleClick() {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
np.set("middleclick", true);
device.sendPacket(np);
}
public void sendRightClick() {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
np.set("rightclick", true);
device.sendPacket(np);
}
public void sendSingleHold() {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
np.set("singlehold", true);
device.sendPacket(np);
}
public void sendScroll(float dx, float dy) {
NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
np.set("scroll", true);
np.set("dx", dx);
np.set("dy", dy);
device.sendPacket(np);
}
public void sendKeyboardPacket(NetworkPacket np) {
device.sendPacket(np);
}
boolean isKeyboardEnabled() {
return keyboardEnabled;
}
}