mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-30 05:37:43 +00:00
Refactor capabilities together with Aleix
He is committing a similar patch to kdeconnect-kde
This commit is contained in:
parent
108f9e911d
commit
d253fcfd0b
@ -38,22 +38,10 @@ public class NetworkPackage {
|
||||
|
||||
public final static int ProtocolVersion = 6;
|
||||
|
||||
//TODO: Move these to their respective plugins
|
||||
public final static String PACKAGE_TYPE_IDENTITY = "kdeconnect.identity";
|
||||
public final static String PACKAGE_TYPE_PAIR = "kdeconnect.pair";
|
||||
public final static String PACKAGE_TYPE_ENCRYPTED = "kdeconnect.encrypted";
|
||||
public final static String PACKAGE_TYPE_PING = "kdeconnect.ping";
|
||||
public final static String PACKAGE_TYPE_TELEPHONY = "kdeconnect.telephony";
|
||||
public final static String PACKAGE_TYPE_BATTERY = "kdeconnect.battery";
|
||||
public final static String PACKAGE_TYPE_SFTP = "kdeconnect.sftp";
|
||||
public final static String PACKAGE_TYPE_NOTIFICATION = "kdeconnect.notification";
|
||||
public final static String PACKAGE_TYPE_CLIPBOARD = "kdeconnect.clipboard";
|
||||
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 static final String PACKAGE_TYPE_CAPABILITIES = "kdeconnect.capabilities";
|
||||
public final static String PACKAGE_TYPE_FINDMYPHONE = "kdeconnect.findmyphone" ;
|
||||
public final static String PACKAGE_TYPE_RUNCOMMAND = "kdeconnect.runcommand";
|
||||
|
||||
private long mId;
|
||||
private String mType;
|
||||
|
@ -33,6 +33,9 @@ import org.kde.kdeconnect_tp.R;
|
||||
|
||||
public class BatteryPlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_BATTERY = "kdeconnect.battery";
|
||||
public final static String PACKAGE_TYPE_BATTERY_REQUEST = "kdeconnect.battery.request";
|
||||
|
||||
// keep these fields in sync with kdeconnect-kded:BatteryPlugin.h:ThresholdBatteryEvent
|
||||
private static final int THRESHOLD_EVENT_NONE= 0;
|
||||
private static final int THRESHOLD_EVENT_BATTERY_LOW = 1;
|
||||
@ -72,7 +75,7 @@ public class BatteryPlugin extends Plugin {
|
||||
|
||||
} else {
|
||||
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_BATTERY);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_BATTERY);
|
||||
np.set("currentCharge", currentCharge);
|
||||
np.set("isCharging", isCharging);
|
||||
np.set("thresholdEvent", thresholdEvent);
|
||||
@ -99,7 +102,7 @@ public class BatteryPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_BATTERY)) return false;
|
||||
if (!np.getType().equals(PACKAGE_TYPE_BATTERY_REQUEST)) return false;
|
||||
|
||||
if (np.getBoolean("request")) {
|
||||
if (lastInfo != null) {
|
||||
@ -112,13 +115,13 @@ public class BatteryPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
String[] packetTypes = {NetworkPackage.PACKAGE_TYPE_BATTERY};
|
||||
String[] packetTypes = {PACKAGE_TYPE_BATTERY_REQUEST};
|
||||
return packetTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
String[] packetTypes = {NetworkPackage.PACKAGE_TYPE_BATTERY};
|
||||
String[] packetTypes = {PACKAGE_TYPE_BATTERY};
|
||||
return packetTypes;
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class ClipboardListener {
|
||||
String content = item.coerceToText(context).toString();
|
||||
|
||||
if (!content.equals(currentContent)) {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_CLIPBOARD);
|
||||
NetworkPackage np = new NetworkPackage(ClipboardPlugin.PACKAGE_TYPE_CLIPBOARD);
|
||||
np.set("content", content);
|
||||
device.sendPackage(np);
|
||||
currentContent = content;
|
||||
|
@ -32,6 +32,8 @@ import org.kde.kdeconnect_tp.R;
|
||||
|
||||
public class ClipboardPlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_CLIPBOARD = "kdeconnect.clipboard";
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return context.getResources().getString(R.string.pref_plugin_clipboard);
|
||||
@ -63,7 +65,7 @@ public class ClipboardPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_CLIPBOARD)) {
|
||||
if (!np.getType().equals(PACKAGE_TYPE_CLIPBOARD)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -74,13 +76,13 @@ public class ClipboardPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
String[] packetTypes = {NetworkPackage.PACKAGE_TYPE_CLIPBOARD};
|
||||
String[] packetTypes = {PACKAGE_TYPE_CLIPBOARD};
|
||||
return packetTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
String[] packetTypes = {NetworkPackage.PACKAGE_TYPE_CLIPBOARD};
|
||||
String[] packetTypes = {PACKAGE_TYPE_CLIPBOARD};
|
||||
return packetTypes;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,10 @@ import org.kde.kdeconnect_tp.R;
|
||||
* and David Edmundson 2015
|
||||
*/
|
||||
public class FindMyPhonePlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_FINDMYPHONE = "kdeconnect.findmyphone";
|
||||
public final static String PACKAGE_TYPE_FINDMYPHONE_REQUEST = "kdeconnect.findmyphone.request";
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return context.getString(R.string.findmyphone_title);
|
||||
@ -29,7 +33,7 @@ public class FindMyPhonePlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
if (np.getType().equals(NetworkPackage.PACKAGE_TYPE_FINDMYPHONE)) {
|
||||
if (np.getType().equals(PACKAGE_TYPE_FINDMYPHONE_REQUEST)) {
|
||||
//Log.e("PingPackageReceiver", "was a find my phone!");
|
||||
|
||||
Intent intent = new Intent(context,FindMyPhoneActivity.class);
|
||||
@ -43,7 +47,7 @@ public class FindMyPhonePlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_FINDMYPHONE};
|
||||
return new String[]{PACKAGE_TYPE_FINDMYPHONE_REQUEST};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -101,7 +101,7 @@ public class KeyListenerView extends View {
|
||||
}
|
||||
|
||||
public void sendChars(CharSequence chars) {
|
||||
final NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||
final NetworkPackage np = new NetworkPackage(MousePadPlugin.PACKAGE_TYPE_INPUT);
|
||||
np.set("key", chars.toString());
|
||||
sendKeyPressPackage(np);
|
||||
}
|
||||
@ -135,7 +135,7 @@ public class KeyListenerView extends View {
|
||||
//Log.e("KeyDown", "utfChar:" + (char)event.getUnicodeChar());
|
||||
//Log.e("KeyDown", "intUtfChar:" + event.getUnicodeChar());
|
||||
|
||||
final NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||
final NetworkPackage np = new NetworkPackage(MousePadPlugin.PACKAGE_TYPE_INPUT);
|
||||
|
||||
boolean modifier = false;
|
||||
if (event.isAltPressed()) {
|
||||
|
@ -31,6 +31,9 @@ import org.kde.kdeconnect_tp.R;
|
||||
|
||||
public class MousePadPlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_INPUT = "kdeconnect.input";
|
||||
public final static String PACKAGE_TYPE_INPUT_REQUEST = "kdeconnect.input.request";
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return context.getString(R.string.pref_plugin_mousepad);
|
||||
@ -70,7 +73,7 @@ public class MousePadPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_MOUSEPAD};
|
||||
return new String[]{PACKAGE_TYPE_INPUT_REQUEST};
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,7 +82,7 @@ public class MousePadPlugin extends Plugin {
|
||||
}
|
||||
|
||||
public void sendMouseDelta(float dx, float dy, float sensitivity) {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
|
||||
|
||||
np.set("dx", dx*sensitivity);
|
||||
np.set("dy", dy*sensitivity);
|
||||
@ -88,37 +91,37 @@ public class MousePadPlugin extends Plugin {
|
||||
}
|
||||
|
||||
public void sendSingleClick() {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
|
||||
np.set("singleclick", true);
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
||||
public void sendDoubleClick() {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
|
||||
np.set("doubleclick", true);
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
||||
public void sendMiddleClick() {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
|
||||
np.set("middleclick", true);
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
||||
public void sendRightClick() {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
|
||||
np.set("rightclick", true);
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
||||
public void sendSingleHold(){
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
|
||||
np.set("singlehold", true);
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
||||
public void sendScroll(float dx, float dy) {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MOUSEPAD);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_INPUT_REQUEST);
|
||||
np.set("scroll", true);
|
||||
np.set("dx", dx);
|
||||
np.set("dy", dy);
|
||||
|
@ -37,6 +37,9 @@ import java.util.HashMap;
|
||||
|
||||
public class MprisPlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_MPRIS = "kdeconnect.mpris";
|
||||
public final static String PACKAGE_TYPE_MPRIS_REQUEST = "kdeconnect.mpris.request";
|
||||
|
||||
private String player = "";
|
||||
private boolean playing = false;
|
||||
private String currentSong = "";
|
||||
@ -82,7 +85,7 @@ public class MprisPlugin extends Plugin {
|
||||
}
|
||||
|
||||
public void sendAction(String player, String action) {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("player", player);
|
||||
np.set("action", action);
|
||||
device.sendPackage(np);
|
||||
@ -92,14 +95,14 @@ public class MprisPlugin extends Plugin {
|
||||
}
|
||||
|
||||
public void setVolume(int volume) {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("player", player);
|
||||
np.set("setVolume",volume);
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("player", player);
|
||||
np.set("SetPosition", position);
|
||||
device.sendPackage(np);
|
||||
@ -108,7 +111,7 @@ public class MprisPlugin extends Plugin {
|
||||
}
|
||||
|
||||
public void Seek(int offset) {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("player", player);
|
||||
np.set("Seek", offset);
|
||||
device.sendPackage(np);
|
||||
@ -116,7 +119,7 @@ public class MprisPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_MPRIS)) return false;
|
||||
if (!np.getType().equals(PACKAGE_TYPE_MPRIS)) return false;
|
||||
|
||||
if (np.has("nowPlaying") || np.has("volume") || np.has("isPlaying") || np.has("length") || np.has("pos")) {
|
||||
if (np.getString("player").equals(player)) {
|
||||
@ -172,12 +175,12 @@ public class MprisPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
return new String[] {NetworkPackage.PACKAGE_TYPE_MPRIS};
|
||||
return new String[] {PACKAGE_TYPE_MPRIS};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
return new String[] {NetworkPackage.PACKAGE_TYPE_MPRIS};
|
||||
return new String[] {PACKAGE_TYPE_MPRIS_REQUEST};
|
||||
}
|
||||
|
||||
public void setPlayerStatusUpdatedHandler(String id, Handler h) {
|
||||
@ -251,13 +254,13 @@ public class MprisPlugin extends Plugin {
|
||||
}
|
||||
|
||||
private void requestPlayerList() {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("requestPlayerList",true);
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
||||
private void requestPlayerStatus() {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST);
|
||||
np.set("player",player);
|
||||
np.set("requestNowPlaying",true);
|
||||
np.set("requestVolume",true);
|
||||
|
@ -50,6 +50,10 @@ import java.io.InputStream;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
|
||||
public class NotificationsPlugin extends Plugin implements NotificationReceiver.NotificationListener {
|
||||
|
||||
public final static String PACKAGE_TYPE_NOTIFICATION = "kdeconnect.notification";
|
||||
public final static String PACKAGE_TYPE_NOTIFICATION_REQUEST = "kdeconnect.notification.request";
|
||||
|
||||
/*
|
||||
private boolean sendIcons = false;
|
||||
*/
|
||||
@ -109,7 +113,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
||||
}
|
||||
|
||||
// request all existing notifications
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_NOTIFICATION);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION_REQUEST);
|
||||
np.set("request", true);
|
||||
device.sendPackage(np);
|
||||
return true;
|
||||
@ -131,7 +135,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
||||
@Override
|
||||
public void onNotificationRemoved(StatusBarNotification statusBarNotification) {
|
||||
String id = getNotificationKeyCompat(statusBarNotification);
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_NOTIFICATION);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION_REQUEST);
|
||||
np.set("id", id);
|
||||
np.set("isCancel", true);
|
||||
device.sendPackage(np);
|
||||
@ -185,7 +189,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_NOTIFICATION);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_NOTIFICATION);
|
||||
|
||||
if (packageName.equals("org.kde.kdeconnect_tp"))
|
||||
{
|
||||
@ -268,7 +272,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
||||
|
||||
@Override
|
||||
public boolean onPackageReceived(final NetworkPackage np) {
|
||||
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_NOTIFICATION)) return false;
|
||||
if (!np.getType().equals(PACKAGE_TYPE_NOTIFICATION_REQUEST) && !np.getType().equals(PACKAGE_TYPE_NOTIFICATION)) return false;
|
||||
/*
|
||||
if (np.getBoolean("sendIcons")) {
|
||||
sendIcons = true;
|
||||
@ -416,12 +420,12 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_NOTIFICATION};
|
||||
return new String[]{PACKAGE_TYPE_NOTIFICATION, PACKAGE_TYPE_NOTIFICATION_REQUEST};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_NOTIFICATION};
|
||||
return new String[]{PACKAGE_TYPE_NOTIFICATION, PACKAGE_TYPE_NOTIFICATION_REQUEST};
|
||||
}
|
||||
|
||||
//For compat with API<21, because lollipop changed the way to cancel notifications
|
||||
|
@ -37,6 +37,8 @@ import org.kde.kdeconnect_tp.R;
|
||||
|
||||
public class PingPlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_PING = "kdeconnect.ping";
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return context.getResources().getString(R.string.pref_plugin_ping);
|
||||
@ -50,50 +52,50 @@ public class PingPlugin extends Plugin {
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
|
||||
//Log.e("PingPackageReceiver", "onPackageReceived");
|
||||
if (np.getType().equals(NetworkPackage.PACKAGE_TYPE_PING)) {
|
||||
//Log.e("PingPackageReceiver", "was a ping!");
|
||||
|
||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
|
||||
stackBuilder.addParentStack(MaterialActivity.class);
|
||||
stackBuilder.addNextIntent(new Intent(context, MaterialActivity.class));
|
||||
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
|
||||
0,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
);
|
||||
|
||||
int id;
|
||||
String message;
|
||||
if (np.has("message")) {
|
||||
message = np.getString("message");
|
||||
id = (int)System.currentTimeMillis();
|
||||
} else {
|
||||
message = "Ping!";
|
||||
id = 42; //A unique id to create only one notification
|
||||
}
|
||||
|
||||
Notification noti = new NotificationCompat.Builder(context)
|
||||
.setContentTitle(device.getName())
|
||||
.setContentText(message)
|
||||
.setContentIntent(resultPendingIntent)
|
||||
.setTicker(message)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setAutoCancel(true)
|
||||
.setDefaults(Notification.DEFAULT_ALL)
|
||||
.build();
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
try {
|
||||
notificationManager.notify(id, noti);
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
if (!np.getType().equals(PACKAGE_TYPE_PING)) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
//Log.e("PingPackageReceiver", "was a ping!");
|
||||
|
||||
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
|
||||
stackBuilder.addParentStack(MaterialActivity.class);
|
||||
stackBuilder.addNextIntent(new Intent(context, MaterialActivity.class));
|
||||
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(
|
||||
0,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
);
|
||||
|
||||
int id;
|
||||
String message;
|
||||
if (np.has("message")) {
|
||||
message = np.getString("message");
|
||||
id = (int)System.currentTimeMillis();
|
||||
} else {
|
||||
message = "Ping!";
|
||||
id = 42; //A unique id to create only one notification
|
||||
}
|
||||
|
||||
Notification noti = new NotificationCompat.Builder(context)
|
||||
.setContentTitle(device.getName())
|
||||
.setContentText(message)
|
||||
.setContentIntent(resultPendingIntent)
|
||||
.setTicker(message)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setAutoCancel(true)
|
||||
.setDefaults(Notification.DEFAULT_ALL)
|
||||
.build();
|
||||
|
||||
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
try {
|
||||
notificationManager.notify(id, noti);
|
||||
} catch(Exception e) {
|
||||
//4.1 will throw an exception about not having the VIBRATE permission, ignore it.
|
||||
//https://android.googlesource.com/platform/frameworks/base/+/android-4.2.1_r1.2%5E%5E!/
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,7 +106,7 @@ public class PingPlugin extends Plugin {
|
||||
@Override
|
||||
public void startMainActivity(Activity activity) {
|
||||
if (device != null) {
|
||||
device.sendPackage(new NetworkPackage(NetworkPackage.PACKAGE_TYPE_PING));
|
||||
device.sendPackage(new NetworkPackage(PACKAGE_TYPE_PING));
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,12 +122,12 @@ public class PingPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_PING};
|
||||
return new String[]{PACKAGE_TYPE_PING};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_PING};
|
||||
return new String[]{PACKAGE_TYPE_PING};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,6 +37,9 @@ import java.util.Iterator;
|
||||
|
||||
public class RunCommandPlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_RUNCOMMAND = "kdeconnect.runcommand";
|
||||
public final static String PACKAGE_TYPE_RUNCOMMAND_REQUEST = "kdeconnect.runcommand.request";
|
||||
|
||||
private ArrayList<JSONObject> commandList = new ArrayList<>();
|
||||
private ArrayList<CommandsChangedCallback> callbacks = new ArrayList<>();
|
||||
|
||||
@ -79,7 +82,7 @@ public class RunCommandPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_RUNCOMMAND)) return false;
|
||||
if (!np.getType().equals(PACKAGE_TYPE_RUNCOMMAND)) return false;
|
||||
|
||||
if (np.has("commandList")) {
|
||||
commandList.clear();
|
||||
@ -109,22 +112,22 @@ public class RunCommandPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_RUNCOMMAND};
|
||||
return new String[]{PACKAGE_TYPE_RUNCOMMAND};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_RUNCOMMAND};
|
||||
return new String[]{PACKAGE_TYPE_RUNCOMMAND_REQUEST};
|
||||
}
|
||||
|
||||
public void runCommand(String cmdKey) {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_RUNCOMMAND);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_RUNCOMMAND_REQUEST);
|
||||
np.set("key", cmdKey);
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
||||
private void requestCommandList() {
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_RUNCOMMAND);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_RUNCOMMAND_REQUEST);
|
||||
np.set("requestCommandList", true);
|
||||
device.sendPackage(np);
|
||||
}
|
||||
|
@ -33,6 +33,9 @@ import java.util.List;
|
||||
|
||||
public class SftpPlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_SFTP = "kdeconnect.sftp";
|
||||
public final static String PACKAGE_TYPE_SFTP_REQUEST = "kdeconnect.sftp.request";
|
||||
|
||||
private static final SimpleSftpServer server = new SimpleSftpServer();
|
||||
|
||||
@Override
|
||||
@ -58,12 +61,12 @@ public class SftpPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_SFTP)) return false;
|
||||
if (!np.getType().equals(PACKAGE_TYPE_SFTP_REQUEST)) return false;
|
||||
|
||||
if (np.getBoolean("startBrowsing")) {
|
||||
if (server.start()) {
|
||||
|
||||
NetworkPackage np2 = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SFTP);
|
||||
NetworkPackage np2 = new NetworkPackage(PACKAGE_TYPE_SFTP);
|
||||
|
||||
np2.set("ip", server.getLocalIpAddress());
|
||||
np2.set("port", server.port);
|
||||
@ -129,12 +132,12 @@ public class SftpPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_SFTP};
|
||||
return new String[]{PACKAGE_TYPE_SFTP_REQUEST};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_SFTP};
|
||||
return new String[]{PACKAGE_TYPE_SFTP};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ public class ShareActivity extends ActionBarActivity {
|
||||
} catch (Exception e) {
|
||||
isUrl = false;
|
||||
}
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE);
|
||||
NetworkPackage np = new NetworkPackage(SharePlugin.PACKAGE_TYPE_SHARE);
|
||||
if (isUrl) {
|
||||
np.set("url", text);
|
||||
} else {
|
||||
|
@ -58,6 +58,9 @@ import java.util.ArrayList;
|
||||
|
||||
public class SharePlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_SHARE = "kdeconnect.share";
|
||||
public final static String PACKAGE_TYPE_SHARE_REQUEST = "kdeconnect.share.request";
|
||||
|
||||
final static boolean openUrlsDirectly = true;
|
||||
|
||||
@Override
|
||||
@ -100,7 +103,7 @@ public class SharePlugin extends Plugin {
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
|
||||
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_SHARE)) {
|
||||
if (!np.getType().equals(PACKAGE_TYPE_SHARE_REQUEST)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -311,7 +314,7 @@ public class SharePlugin extends Plugin {
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
InputStream inputStream = cr.openInputStream(uri);
|
||||
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_SHARE);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_SHARE_REQUEST);
|
||||
long size = -1;
|
||||
|
||||
final NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
@ -496,12 +499,12 @@ public class SharePlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_SHARE};
|
||||
return new String[]{PACKAGE_TYPE_SHARE_REQUEST};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_SHARE};
|
||||
return new String[]{PACKAGE_TYPE_SHARE_REQUEST};
|
||||
}
|
||||
|
||||
|
||||
|
@ -36,6 +36,9 @@ import static android.provider.ContactsContract.Contacts;
|
||||
|
||||
public class TelepathyPlugin extends Plugin {
|
||||
|
||||
|
||||
public final static String PACKAGE_TYPE_SMS_REQUEST = "kdeconnect.sms";
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return context.getResources().getString(R.string.pref_plugin_telepathy);
|
||||
@ -58,7 +61,7 @@ public class TelepathyPlugin extends Plugin {
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
|
||||
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_TELEPHONY)) {
|
||||
if (!np.getType().equals(PACKAGE_TYPE_SMS_REQUEST)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -171,12 +174,12 @@ public class TelepathyPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_TELEPHONY};
|
||||
return new String[]{PACKAGE_TYPE_SMS_REQUEST};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_TELEPHONY};
|
||||
return new String[]{};
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,6 +40,9 @@ import java.util.TimerTask;
|
||||
|
||||
public class TelephonyPlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_TELEPHONY = "kdeconnect.telephony";
|
||||
public final static String PACKAGE_TYPE_TELEPHONY_REQUEST = "kdeconnect.telephony.request";
|
||||
|
||||
private int lastState = TelephonyManager.CALL_STATE_IDLE;
|
||||
private NetworkPackage lastPackage = null;
|
||||
private boolean isMuted = false;
|
||||
@ -97,7 +100,7 @@ public class TelephonyPlugin extends Plugin {
|
||||
|
||||
//Log.e("TelephonyPlugin", "callBroadcastReceived");
|
||||
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_TELEPHONY);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY);
|
||||
if (phoneNumber != null) {
|
||||
np.set("phoneNumber", phoneNumber);
|
||||
np.set("contactName", ContactsHelper.phoneNumberLookup(context, phoneNumber));
|
||||
@ -163,7 +166,7 @@ public class TelephonyPlugin extends Plugin {
|
||||
|
||||
//Log.e("SmsBroadcastReceived", message.toString());
|
||||
|
||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_TELEPHONY);
|
||||
NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_TELEPHONY);
|
||||
|
||||
np.set("event","sms");
|
||||
|
||||
@ -198,7 +201,7 @@ public class TelephonyPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public boolean onPackageReceived(NetworkPackage np) {
|
||||
if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_TELEPHONY)) {
|
||||
if (!np.getType().equals(PACKAGE_TYPE_TELEPHONY_REQUEST)) {
|
||||
return false;
|
||||
}
|
||||
if (np.getString("action").equals("mute")) {
|
||||
@ -215,12 +218,12 @@ public class TelephonyPlugin extends Plugin {
|
||||
|
||||
@Override
|
||||
public String[] getSupportedPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_TELEPHONY};
|
||||
return new String[]{PACKAGE_TYPE_TELEPHONY_REQUEST};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getOutgoingPackageTypes() {
|
||||
return new String[]{NetworkPackage.PACKAGE_TYPE_TELEPHONY};
|
||||
return new String[]{PACKAGE_TYPE_TELEPHONY};
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user