mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-22 18:07:55 +00:00
Added preferences and the ability to enable and disable plugins from there
This commit is contained in:
parent
cc947902f3
commit
4930a019d4
@ -10,13 +10,13 @@
|
|||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:icon="@drawable/ic_launcher"
|
android:icon="@drawable/ic_launcher"
|
||||||
android:label="@string/app_name"
|
android:label="KdeConnect "
|
||||||
android:theme="@style/AppTheme" >
|
android:theme="@style/AppTheme" >
|
||||||
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.kde.connect.MainActivity"
|
android:name="org.kde.connect.MainActivity"
|
||||||
android:label="@string/app_name" >
|
android:label="KdeConnect " >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
@ -26,9 +26,13 @@
|
|||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.kde.connect.MprisActivity"
|
android:name="org.kde.connect.MprisActivity"
|
||||||
android:label="KdeConnect - Mpris controls"
|
android:label="KdeConnect Mpris controls"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name="org.kde.connect.SettingsActivity"
|
||||||
|
android:label="KdeConnect Settings"
|
||||||
|
/>
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
|
@ -6,6 +6,7 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.kde.connect.ComputerLinks.BaseComputerLink;
|
import org.kde.connect.ComputerLinks.BaseComputerLink;
|
||||||
@ -17,42 +18,64 @@ import org.kde.connect.PackageInterfaces.CallPackageInterface;
|
|||||||
import org.kde.connect.PackageInterfaces.ClipboardPackageInterface;
|
import org.kde.connect.PackageInterfaces.ClipboardPackageInterface;
|
||||||
import org.kde.connect.PackageInterfaces.MprisControlPackageInterface;
|
import org.kde.connect.PackageInterfaces.MprisControlPackageInterface;
|
||||||
import org.kde.connect.PackageInterfaces.PingPackageInterface;
|
import org.kde.connect.PackageInterfaces.PingPackageInterface;
|
||||||
|
import org.kde.kdeconnect.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class BackgroundService extends Service {
|
public class BackgroundService extends Service {
|
||||||
|
|
||||||
SharedPreferences settings;
|
|
||||||
|
|
||||||
ArrayList<BaseLinkProvider> linkProviders = new ArrayList<BaseLinkProvider>();
|
ArrayList<BaseLinkProvider> linkProviders = new ArrayList<BaseLinkProvider>();
|
||||||
|
|
||||||
ArrayList<BasePackageInterface> packageInterfaces = new ArrayList<BasePackageInterface>();
|
ArrayList<BasePackageInterface> packageInterfaces = new ArrayList<BasePackageInterface>();
|
||||||
|
|
||||||
HashMap<String, Device> devices = new HashMap<String, Device>();
|
HashMap<String, Device> devices = new HashMap<String, Device>();
|
||||||
|
|
||||||
private void registerPackageInterfaces() {
|
public void registerLinkProviders() {
|
||||||
|
|
||||||
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
if (settings.getBoolean("avahitcp_link", true)) {
|
||||||
|
linkProviders.add(new AvahiTcpLinkProvider(this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerPackageInterfacesFromSettings() {
|
||||||
|
|
||||||
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
Log.e("registerPackageInterfacesFromSettings","registerPackageInterfacesFromSettings");
|
||||||
|
|
||||||
if (settings.getBoolean("call_interface", true)) {
|
if (settings.getBoolean("call_interface", true)) {
|
||||||
packageInterfaces.add(new CallPackageInterface(getApplicationContext()));
|
addPackageInterface(CallPackageInterface.class);
|
||||||
|
} else {
|
||||||
|
removePackageInterface(CallPackageInterface.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.getBoolean("ping_interface", true)) {
|
if (settings.getBoolean("ping_interface", true)) {
|
||||||
packageInterfaces.add(new PingPackageInterface(getApplicationContext()));
|
addPackageInterface(PingPackageInterface.class);
|
||||||
|
} else {
|
||||||
|
removePackageInterface(PingPackageInterface.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.getBoolean("clipboard_interface", true)) {
|
if (settings.getBoolean("clipboard_interface", true)) {
|
||||||
packageInterfaces.add(new ClipboardPackageInterface(getApplicationContext()));
|
addPackageInterface(ClipboardPackageInterface.class);
|
||||||
|
} else {
|
||||||
|
removePackageInterface(ClipboardPackageInterface.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.getBoolean("battery_interface", true)) {
|
if (settings.getBoolean("battery_interface", true)) {
|
||||||
packageInterfaces.add(new BatteryMonitorPackageInterface(getApplicationContext()));
|
addPackageInterface(BatteryMonitorPackageInterface.class);
|
||||||
|
} else {
|
||||||
|
removePackageInterface(BatteryMonitorPackageInterface.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.getBoolean("mpris_interface", true)) {
|
if (settings.getBoolean("mpris_interface", true)) {
|
||||||
packageInterfaces.add(new MprisControlPackageInterface(getApplicationContext()));
|
addPackageInterface(MprisControlPackageInterface.class);
|
||||||
|
} else {
|
||||||
|
removePackageInterface(MprisControlPackageInterface.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BasePackageInterface getPackageInterface(Class c) {
|
public BasePackageInterface getPackageInterface(Class c) {
|
||||||
@ -62,35 +85,49 @@ public class BackgroundService extends Service {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerLinkProviders() {
|
public BasePackageInterface addPackageInterface(Class c) {
|
||||||
if (settings.getBoolean("avahitcp_link", true)) {
|
BasePackageInterface pi = getPackageInterface(c);
|
||||||
linkProviders.add(new AvahiTcpLinkProvider(this));
|
if (pi != null) {
|
||||||
|
Log.e("addPackageInterface","package interface already existent");
|
||||||
|
return pi;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
pi = (BasePackageInterface)c.newInstance();
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Log.e("addPackageInterface","Error instantiating packageinterface");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
packageInterfaces.add(pi);
|
||||||
|
pi.onCreate(getApplicationContext());
|
||||||
|
for (Device dev : devices.values()) {
|
||||||
|
dev.addPackageReceiver(pi);
|
||||||
|
pi.addDevice(dev);
|
||||||
|
}
|
||||||
|
return pi;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ArrayList<String> getVisibleDevices() {
|
public boolean removePackageInterface(Class c) {
|
||||||
ArrayList<String> list = new ArrayList<String>();
|
for (BasePackageInterface pi : packageInterfaces) {
|
||||||
for(Device d : devices.values()) {
|
if (c.isInstance(pi)) {
|
||||||
list.add(d.getName());
|
packageInterfaces.remove(pi);
|
||||||
|
for (Device dev : devices.values()) {
|
||||||
|
dev.removePackageReceiver(pi);
|
||||||
|
pi.removeDevice(dev);
|
||||||
}
|
}
|
||||||
return list;
|
pi.onDestroy();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Log.e("removePackageInterface","Unexistent preference");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//This will be called for each intent launch, even if the service is already started and is reused
|
public Device getDevice(String id) {
|
||||||
@Override
|
return devices.get(id);
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
||||||
Log.i("BackgroundService","onStartCommand");
|
|
||||||
for (InstanceCallback c : callbacks) {
|
|
||||||
c.onServiceStart(this);
|
|
||||||
}
|
|
||||||
callbacks.clear();
|
|
||||||
return Service.START_STICKY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startDiscovery() {
|
private BaseLinkProvider.ConnectionReceiver deviceListener = new BaseLinkProvider.ConnectionReceiver() {
|
||||||
Log.i("StartDiscovery","Registering connection receivers");
|
|
||||||
for (BaseLinkProvider a : linkProviders) {
|
|
||||||
a.reachComputers(new BaseLinkProvider.ConnectionReceiver() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionAccepted(String deviceId, String name, BaseComputerLink link) {
|
public void onConnectionAccepted(String deviceId, String name, BaseComputerLink link) {
|
||||||
Log.i("BackgroundService", "Connection accepted!");
|
Log.i("BackgroundService", "Connection accepted!");
|
||||||
@ -119,7 +156,31 @@ public class BackgroundService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
public ArrayList<String> getVisibleDevices() {
|
||||||
|
ArrayList<String> list = new ArrayList<String>();
|
||||||
|
for(Device d : devices.values()) {
|
||||||
|
list.add(d.getName());
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
//This will be called for each intent launch, even if the service is already started and is reused
|
||||||
|
@Override
|
||||||
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
Log.i("BackgroundService","onStartCommand");
|
||||||
|
for (InstanceCallback c : callbacks) {
|
||||||
|
c.onServiceStart(this);
|
||||||
|
}
|
||||||
|
callbacks.clear();
|
||||||
|
return Service.START_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startDiscovery() {
|
||||||
|
Log.i("StartDiscovery","Registering connection receivers");
|
||||||
|
for (BaseLinkProvider a : linkProviders) {
|
||||||
|
a.reachComputers(deviceListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,9 +191,7 @@ public class BackgroundService extends Service {
|
|||||||
|
|
||||||
Log.i("BackgroundService","Service not started yet, initializing...");
|
Log.i("BackgroundService","Service not started yet, initializing...");
|
||||||
|
|
||||||
settings = getSharedPreferences("KdeConnect", 0);
|
registerPackageInterfacesFromSettings();
|
||||||
|
|
||||||
registerPackageInterfaces();
|
|
||||||
registerLinkProviders();
|
registerLinkProviders();
|
||||||
startDiscovery();
|
startDiscovery();
|
||||||
|
|
||||||
|
@ -67,6 +67,10 @@ public class Device {
|
|||||||
receivers.add(receiver);
|
receivers.add(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removePackageReceiver(BasePackageInterface receiver) {
|
||||||
|
receivers.remove(receiver);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean sendPackage(final NetworkPackage np) {
|
public boolean sendPackage(final NetworkPackage np) {
|
||||||
Log.e("Device", "sendPackage");
|
Log.e("Device", "sendPackage");
|
||||||
|
|
||||||
@ -86,7 +90,7 @@ public class Device {
|
|||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
|
|
||||||
return true; //FIXME
|
return true; //FIXME: Detect when unable to send a package and try again somehow
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
@ -94,4 +95,15 @@ public class MainActivity extends Activity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||||
|
switch(item.getItemId()){
|
||||||
|
case R.id.action_settings:
|
||||||
|
Intent intent = new Intent(this,SettingsActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return super.onMenuItemSelected(featureId, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ public class MprisActivity extends Activity {
|
|||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
|
||||||
final MprisControlPackageInterface mpris = (MprisControlPackageInterface)service.getPackageInterface(MprisControlPackageInterface.class);
|
final MprisControlPackageInterface mpris = (MprisControlPackageInterface)service.getPackageInterface(MprisControlPackageInterface.class);
|
||||||
|
if (mpris == null) return;
|
||||||
|
|
||||||
mpris.setNowPlayingUpdatedHandler(new Handler() {
|
mpris.setNowPlayingUpdatedHandler(new Handler() {
|
||||||
@Override
|
@Override
|
||||||
@ -84,6 +85,7 @@ public class MprisActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
MprisControlPackageInterface mpris = (MprisControlPackageInterface)service.getPackageInterface(MprisControlPackageInterface.class);
|
MprisControlPackageInterface mpris = (MprisControlPackageInterface)service.getPackageInterface(MprisControlPackageInterface.class);
|
||||||
|
if (mpris == null) return;
|
||||||
mpris.sendAction("PlayPause");
|
mpris.sendAction("PlayPause");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -97,6 +99,7 @@ public class MprisActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
MprisControlPackageInterface mpris = (MprisControlPackageInterface)service.getPackageInterface(MprisControlPackageInterface.class);
|
MprisControlPackageInterface mpris = (MprisControlPackageInterface)service.getPackageInterface(MprisControlPackageInterface.class);
|
||||||
|
if (mpris == null) return;
|
||||||
mpris.sendAction("Previous");
|
mpris.sendAction("Previous");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -110,6 +113,7 @@ public class MprisActivity extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
MprisControlPackageInterface mpris = (MprisControlPackageInterface)service.getPackageInterface(MprisControlPackageInterface.class);
|
MprisControlPackageInterface mpris = (MprisControlPackageInterface)service.getPackageInterface(MprisControlPackageInterface.class);
|
||||||
|
if (mpris == null) return;
|
||||||
mpris.sendAction("Next");
|
mpris.sendAction("Next");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.kde.connect.PackageInterfaces;
|
package org.kde.connect.PackageInterfaces;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import org.kde.connect.Device;
|
import org.kde.connect.Device;
|
||||||
import org.kde.connect.NetworkPackage;
|
import org.kde.connect.NetworkPackage;
|
||||||
|
|
||||||
@ -35,8 +37,9 @@ public abstract class BasePackageInterface {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//To override, returns true if package was handled
|
//To override
|
||||||
|
public abstract boolean onCreate(Context context);
|
||||||
|
public abstract void onDestroy();
|
||||||
public abstract boolean onPackageReceived(Device d, NetworkPackage np);
|
public abstract boolean onPackageReceived(Device d, NetworkPackage np);
|
||||||
|
|
||||||
public abstract boolean onDeviceConnected(Device d);
|
public abstract boolean onDeviceConnected(Device d);
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,9 @@ public class BatteryMonitorPackageInterface extends BasePackageInterface {
|
|||||||
|
|
||||||
NetworkPackage lastPackage = null;
|
NetworkPackage lastPackage = null;
|
||||||
|
|
||||||
public BatteryMonitorPackageInterface(final Context context) {
|
Context context;
|
||||||
final IntentFilter ifilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
|
||||||
context.registerReceiver(new BroadcastReceiver() {
|
BroadcastReceiver receiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public class BatteryMonitorPackageInterface extends BasePackageInterface {
|
|||||||
int currentCharge = 100;
|
int currentCharge = 100;
|
||||||
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
|
int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
|
||||||
if (status != BatteryManager.BATTERY_STATUS_FULL) {
|
if (status != BatteryManager.BATTERY_STATUS_FULL) {
|
||||||
Intent batteryStatus = context.registerReceiver(null, ifilter);
|
Intent batteryStatus = context.registerReceiver(null, filter);
|
||||||
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
|
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
|
||||||
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
|
||||||
currentCharge = level*100 / scale;
|
currentCharge = level*100 / scale;
|
||||||
@ -45,8 +45,20 @@ public class BatteryMonitorPackageInterface extends BasePackageInterface {
|
|||||||
sendPackage(np);
|
sendPackage(np);
|
||||||
lastPackage = np;
|
lastPackage = np;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}, ifilter);
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreate(final Context context) {
|
||||||
|
this.context = context;
|
||||||
|
context.registerReceiver(receiver, filter);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
context.unregisterReceiver(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,11 +11,9 @@ import org.kde.connect.NetworkPackage;
|
|||||||
|
|
||||||
public class CallPackageInterface extends BasePackageInterface {
|
public class CallPackageInterface extends BasePackageInterface {
|
||||||
|
|
||||||
public CallPackageInterface(final Context ctx) {
|
private Context context;
|
||||||
|
|
||||||
//Log.i("CallPackageInterface", "Registered");
|
private PhoneStateListener callStateListener = new PhoneStateListener() {
|
||||||
|
|
||||||
PhoneStateListener callStateListener = new PhoneStateListener() {
|
|
||||||
|
|
||||||
int lastState = TelephonyManager.CALL_STATE_IDLE;
|
int lastState = TelephonyManager.CALL_STATE_IDLE;
|
||||||
NetworkPackage lastPackage = null;
|
NetworkPackage lastPackage = null;
|
||||||
@ -95,9 +93,22 @@ public class CallPackageInterface extends BasePackageInterface {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
|
@Override
|
||||||
|
public boolean onCreate(final Context context) {
|
||||||
|
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
|
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
|
tm.listen(callStateListener, PhoneStateListener.LISTEN_CALL_STATE);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
tm.listen(callStateListener, PhoneStateListener.LISTEN_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -9,14 +9,11 @@ import org.kde.connect.NetworkPackage;
|
|||||||
|
|
||||||
public class ClipboardPackageInterface extends BasePackageInterface {
|
public class ClipboardPackageInterface extends BasePackageInterface {
|
||||||
|
|
||||||
ClipboardManager cm;
|
|
||||||
boolean ignore_next_clipboard_change = false;
|
boolean ignore_next_clipboard_change = false;
|
||||||
|
|
||||||
public ClipboardPackageInterface(final Context ctx) {
|
Context context;
|
||||||
|
ClipboardManager cm;
|
||||||
cm = (ClipboardManager)ctx.getSystemService(Context.CLIPBOARD_SERVICE);
|
ClipboardManager.OnPrimaryClipChangedListener listener = new ClipboardManager.OnPrimaryClipChangedListener() {
|
||||||
|
|
||||||
cm.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrimaryClipChanged() {
|
public void onPrimaryClipChanged() {
|
||||||
try {
|
try {
|
||||||
@ -26,14 +23,29 @@ public class ClipboardPackageInterface extends BasePackageInterface {
|
|||||||
}
|
}
|
||||||
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_CLIPBOARD);
|
NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_CLIPBOARD);
|
||||||
ClipData.Item item = cm.getPrimaryClip().getItemAt(0);
|
ClipData.Item item = cm.getPrimaryClip().getItemAt(0);
|
||||||
np.set("content",item.coerceToText(ctx).toString());
|
np.set("content",item.coerceToText(context).toString());
|
||||||
sendPackage(np);
|
sendPackage(np);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
//Probably clipboard was not text
|
//Probably clipboard was not text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCreate(Context context) {
|
||||||
|
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
|
cm = (ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
cm.addPrimaryClipChangedListener(listener);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
cm.removePrimaryClipChangedListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,8 +26,15 @@ public class MprisControlPackageInterface extends BasePackageInterface {
|
|||||||
|
|
||||||
String player = "";
|
String player = "";
|
||||||
|
|
||||||
public MprisControlPackageInterface(Context ctx) {
|
@Override
|
||||||
|
public boolean onCreate(Context ctx) {
|
||||||
context = ctx;
|
context = ctx;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
playerList.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendAction(String s) {
|
public void sendAction(String s) {
|
||||||
|
@ -14,8 +14,15 @@ public class PingPackageInterface extends BasePackageInterface {
|
|||||||
|
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
public PingPackageInterface(Context ctx) {
|
@Override
|
||||||
|
public boolean onCreate(Context ctx) {
|
||||||
context = ctx;
|
context = ctx;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDestroy() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPing() {
|
public void sendPing() {
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package org.kde.connect;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
|
||||||
|
public class SettingsActivity extends Activity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Display the fragment as the main content.
|
||||||
|
getFragmentManager().beginTransaction()
|
||||||
|
.replace(android.R.id.content, new SettingsFragment())
|
||||||
|
.commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package org.kde.connect;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.kde.kdeconnect.R;
|
||||||
|
|
||||||
|
public class SettingsFragment extends PreferenceFragment {
|
||||||
|
|
||||||
|
SharedPreferences.OnSharedPreferenceChangeListener preferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
|
|
||||||
|
Log.e("onSharedPreferenceChanged",key+"->"+sharedPreferences.getBoolean(key,true));
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity == null) return;
|
||||||
|
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
||||||
|
@Override
|
||||||
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
service.registerPackageInterfacesFromSettings();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
addPreferencesFromResource(R.xml.settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
getPreferenceManager().getSharedPreferences()
|
||||||
|
.registerOnSharedPreferenceChangeListener(preferenceChangeListener);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
getPreferenceManager().getSharedPreferences()
|
||||||
|
.unregisterOnSharedPreferenceChangeListener(preferenceChangeListener);
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,11 +1,16 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="app_name" >KdeConnect
|
<string name="action_settings" >Settings</string>
|
||||||
</string>
|
<string name="pref_enable_call_interface">Call notifications</string>
|
||||||
<string name="action_settings" >Settings
|
<string name="pref_enable_call_interface_desc">Send incoming and missed call notifications</string>
|
||||||
</string>
|
<string name="pref_enable_clipboard_interface">Clipboard sync</string>
|
||||||
<string name="hello_world" >Hello world!
|
<string name="pref_enable_clipboard_interface_desc">Share the clipboard content</string>
|
||||||
</string>
|
<string name="pref_enable_battery_interface">Battery report</string>
|
||||||
|
<string name="pref_enable_battery_interface_desc">Periodically report battery status</string>
|
||||||
|
<string name="pref_enable_mpris_interface">MPRIS controls</string>
|
||||||
|
<string name="pref_enable_mpris_interface_desc">Control audio/video from your phone</string>
|
||||||
|
<string name="pref_enable_ping_interface">Pings</string>
|
||||||
|
<string name="pref_enable_ping_interface_desc">Enable sending and receiving ping notifications</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
36
KdeConnect/src/main/res/xml/settings.xml
Normal file
36
KdeConnect/src/main/res/xml/settings.xml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<PreferenceScreen
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="call_interface"
|
||||||
|
android:title="@string/pref_enable_call_interface"
|
||||||
|
android:summary="@string/pref_enable_call_interface_desc"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="ping_interface"
|
||||||
|
android:title="@string/pref_enable_ping_interface"
|
||||||
|
android:summary="@string/pref_enable_ping_interface_desc"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="clipboard_interface"
|
||||||
|
android:title="@string/pref_enable_clipboard_interface"
|
||||||
|
android:summary="@string/pref_enable_clipboard_interface_desc"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="battery_interface"
|
||||||
|
android:title="@string/pref_enable_battery_interface"
|
||||||
|
android:summary="@string/pref_enable_battery_interface_desc"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="mpris_interface"
|
||||||
|
android:title="@string/pref_enable_mpris_interface"
|
||||||
|
android:summary="@string/pref_enable_mpris_interface_desc"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user