mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-01 06:35:09 +00:00
Plugin key is now the plugin class instead of being defined by each plugin
This commit is contained in:
@@ -614,29 +614,37 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
// Plugin-related functions
|
// Plugin-related functions
|
||||||
//
|
//
|
||||||
|
|
||||||
public Plugin getPlugin(String name) {
|
public <T extends Plugin> T getPlugin(Class<T> pluginClass) {
|
||||||
return getPlugin(name, false);
|
return (T)getPlugin(Plugin.getPluginKey(pluginClass));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Plugin getPlugin(String name, boolean includeFailed) {
|
public <T extends Plugin> T getPlugin(Class<T> pluginClass, boolean includeFailed) {
|
||||||
Plugin plugin = plugins.get(name);
|
return (T)getPlugin(Plugin.getPluginKey(pluginClass), includeFailed);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plugin getPlugin(String pluginKey) {
|
||||||
|
return getPlugin(pluginKey, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Plugin getPlugin(String pluginKey, boolean includeFailed) {
|
||||||
|
Plugin plugin = plugins.get(pluginKey);
|
||||||
if (includeFailed && plugin == null) {
|
if (includeFailed && plugin == null) {
|
||||||
plugin = failedPlugins.get(name);
|
plugin = failedPlugins.get(pluginKey);
|
||||||
}
|
}
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void addPlugin(final String name) {
|
private synchronized void addPlugin(final String pluginKey) {
|
||||||
Plugin existing = plugins.get(name);
|
Plugin existing = plugins.get(pluginKey);
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
Log.w("KDE/addPlugin","plugin already present:" + name);
|
Log.w("KDE/addPlugin","plugin already present:" + pluginKey);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Plugin plugin = PluginFactory.instantiatePluginForDevice(context, name, this);
|
final Plugin plugin = PluginFactory.instantiatePluginForDevice(context, pluginKey, this);
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
Log.e("KDE/addPlugin","could not instantiate plugin: "+name);
|
Log.e("KDE/addPlugin","could not instantiate plugin: "+pluginKey);
|
||||||
failedPlugins.put(name, plugin);
|
failedPlugins.put(pluginKey, plugin);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,17 +658,17 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
success = false;
|
success = false;
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.e("KDE/addPlugin", "Exception loading plugin " + name);
|
Log.e("KDE/addPlugin", "Exception loading plugin " + pluginKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
//Log.e("addPlugin","added " + name);
|
//Log.e("addPlugin","added " + pluginKey);
|
||||||
failedPlugins.remove(name);
|
failedPlugins.remove(pluginKey);
|
||||||
plugins.put(name, plugin);
|
plugins.put(pluginKey, plugin);
|
||||||
} else {
|
} else {
|
||||||
Log.e("KDE/addPlugin", "plugin failed to load " + name);
|
Log.e("KDE/addPlugin", "plugin failed to load " + pluginKey);
|
||||||
plugins.remove(name);
|
plugins.remove(pluginKey);
|
||||||
failedPlugins.put(name, plugin);
|
failedPlugins.put(pluginKey, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PluginsChangedListener listener : pluginsChangedListeners) {
|
for (PluginsChangedListener listener : pluginsChangedListeners) {
|
||||||
@@ -672,10 +680,10 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized boolean removePlugin(String name) {
|
private synchronized boolean removePlugin(String pluginKey) {
|
||||||
|
|
||||||
Plugin plugin = plugins.remove(name);
|
Plugin plugin = plugins.remove(pluginKey);
|
||||||
Plugin failedPlugin = failedPlugins.remove(name);
|
Plugin failedPlugin = failedPlugins.remove(pluginKey);
|
||||||
|
|
||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
if (failedPlugin == null) {
|
if (failedPlugin == null) {
|
||||||
@@ -687,10 +695,10 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
plugin.onDestroy();
|
plugin.onDestroy();
|
||||||
//Log.e("removePlugin","removed " + name);
|
//Log.e("removePlugin","removed " + pluginKey);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.e("KDE/removePlugin","Exception calling onDestroy for plugin "+name);
|
Log.e("KDE/removePlugin","Exception calling onDestroy for plugin "+pluginKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (PluginsChangedListener listener : pluginsChangedListeners) {
|
for (PluginsChangedListener listener : pluginsChangedListeners) {
|
||||||
@@ -700,15 +708,15 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPluginEnabled(String pluginName, boolean value) {
|
public void setPluginEnabled(String pluginKey, boolean value) {
|
||||||
settings.edit().putBoolean(pluginName,value).apply();
|
settings.edit().putBoolean(pluginKey,value).apply();
|
||||||
if (value && isPaired() && isReachable()) addPlugin(pluginName);
|
if (value && isPaired() && isReachable()) addPlugin(pluginKey);
|
||||||
else removePlugin(pluginName);
|
else removePlugin(pluginKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPluginEnabled(String pluginName) {
|
public boolean isPluginEnabled(String pluginKey) {
|
||||||
boolean enabledByDefault = PluginFactory.getPluginInfo(context, pluginName).isEnabledByDefault();
|
boolean enabledByDefault = PluginFactory.getPluginInfo(context, pluginKey).isEnabledByDefault();
|
||||||
boolean enabled = settings.getBoolean(pluginName, enabledByDefault);
|
boolean enabled = settings.getBoolean(pluginKey, enabledByDefault);
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -722,15 +730,15 @@ public class Device implements BaseLink.PackageReceiver {
|
|||||||
|
|
||||||
Set<String> availablePlugins = PluginFactory.getAvailablePlugins();
|
Set<String> availablePlugins = PluginFactory.getAvailablePlugins();
|
||||||
|
|
||||||
for(String pluginName : availablePlugins) {
|
for(String pluginKey : availablePlugins) {
|
||||||
boolean enabled = false;
|
boolean enabled = false;
|
||||||
if (isPaired() && isReachable()) {
|
if (isPaired() && isReachable()) {
|
||||||
enabled = isPluginEnabled(pluginName);
|
enabled = isPluginEnabled(pluginKey);
|
||||||
}
|
}
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
addPlugin(pluginName);
|
addPlugin(pluginKey);
|
||||||
} else {
|
} else {
|
||||||
removePlugin(pluginName);
|
removePlugin(pluginKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,20 +20,17 @@
|
|||||||
|
|
||||||
package org.kde.kdeconnect.Plugins.BatteryPlugin;
|
package org.kde.kdeconnect.Plugins.BatteryPlugin;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.BatteryManager;
|
import android.os.BatteryManager;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
import org.kde.kdeconnect.Plugins.Plugin;
|
import org.kde.kdeconnect.Plugins.Plugin;
|
||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
|
|
||||||
public class BatteryPlugin extends Plugin {
|
public class BatteryPlugin extends Plugin {
|
||||||
|
|
||||||
// keep these fields in sync with kdeconnect-kded:BatteryPlugin.h:ThresholdBatteryEvent
|
// keep these fields in sync with kdeconnect-kded:BatteryPlugin.h:ThresholdBatteryEvent
|
||||||
@@ -42,11 +39,6 @@ public class BatteryPlugin extends Plugin {
|
|||||||
|
|
||||||
private NetworkPackage lastInfo = null;
|
private NetworkPackage lastInfo = null;
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPluginName() {
|
|
||||||
return "plugin_battery";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return context.getResources().getString(R.string.pref_plugin_battery);
|
return context.getResources().getString(R.string.pref_plugin_battery);
|
||||||
|
@@ -31,10 +31,6 @@ import org.kde.kdeconnect_tp.R;
|
|||||||
|
|
||||||
public class ClipboardPlugin extends Plugin {
|
public class ClipboardPlugin extends Plugin {
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPluginName() {
|
|
||||||
return "plugin_clipboard";
|
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return context.getResources().getString(R.string.pref_plugin_clipboard);
|
return context.getResources().getString(R.string.pref_plugin_clipboard);
|
||||||
|
@@ -176,7 +176,7 @@ public class KeyListenerView extends View {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin) device.getPlugin("plugin_mousepad");
|
MousePadPlugin mousePadPlugin = (MousePadPlugin) device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendKeyboardPacket(np);
|
mousePadPlugin.sendKeyboardPacket(np);
|
||||||
}
|
}
|
||||||
|
@@ -182,7 +182,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendMouseDelta(mCurrentX - mPrevX, mCurrentY - mPrevY);
|
mousePadPlugin.sendMouseDelta(mCurrentX - mPrevX, mCurrentY - mPrevY);
|
||||||
mPrevX = mCurrentX;
|
mPrevX = mCurrentX;
|
||||||
@@ -227,7 +227,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendScroll(0, scrollToSendY);
|
mousePadPlugin.sendScroll(0, scrollToSendY);
|
||||||
}
|
}
|
||||||
@@ -248,7 +248,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendSingleHold();
|
mousePadPlugin.sendSingleHold();
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendSingleClick();
|
mousePadPlugin.sendSingleClick();
|
||||||
}
|
}
|
||||||
@@ -280,7 +280,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendDoubleClick();
|
mousePadPlugin.sendDoubleClick();
|
||||||
}
|
}
|
||||||
@@ -327,7 +327,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendMiddleClick();
|
mousePadPlugin.sendMiddleClick();
|
||||||
}
|
}
|
||||||
@@ -339,7 +339,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin) device.getPlugin("plugin_mousepad");
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendRightClick();
|
mousePadPlugin.sendRightClick();
|
||||||
}
|
}
|
||||||
@@ -350,7 +350,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = (MousePadPlugin) device.getPlugin("plugin_mousepad");
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendSingleHold();
|
mousePadPlugin.sendSingleHold();
|
||||||
}
|
}
|
||||||
|
@@ -21,24 +21,15 @@
|
|||||||
package org.kde.kdeconnect.Plugins.MousePadPlugin;
|
package org.kde.kdeconnect.Plugins.MousePadPlugin;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
import org.kde.kdeconnect.Plugins.MprisPlugin.MprisActivity;
|
|
||||||
import org.kde.kdeconnect.Plugins.Plugin;
|
import org.kde.kdeconnect.Plugins.Plugin;
|
||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
public class MousePadPlugin extends Plugin {
|
public class MousePadPlugin extends Plugin {
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPluginName() {
|
|
||||||
return "plugin_mousepad";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return context.getString(R.string.pref_plugin_mousepad);
|
return context.getString(R.string.pref_plugin_mousepad);
|
||||||
|
@@ -75,7 +75,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
|
|
||||||
final Device device = service.getDevice(deviceId);
|
final Device device = service.getDevice(deviceId);
|
||||||
final MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
|
final MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris == null) {
|
if (mpris == null) {
|
||||||
Log.e("MprisActivity", "device has no mpris plugin!");
|
Log.e("MprisActivity", "device has no mpris plugin!");
|
||||||
return;
|
return;
|
||||||
@@ -246,7 +246,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
|
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris == null) return;
|
if (mpris == null) return;
|
||||||
updateVolume(mpris, 5);
|
updateVolume(mpris, 5);
|
||||||
}
|
}
|
||||||
@@ -257,7 +257,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
|
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris == null) return;
|
if (mpris == null) return;
|
||||||
updateVolume(mpris, -5);
|
updateVolume(mpris, -5);
|
||||||
}
|
}
|
||||||
@@ -309,7 +309,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
|
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris == null) return;
|
if (mpris == null) return;
|
||||||
mpris.sendAction("PlayPause");
|
mpris.sendAction("PlayPause");
|
||||||
}
|
}
|
||||||
@@ -324,7 +324,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
|
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris == null) return;
|
if (mpris == null) return;
|
||||||
mpris.sendAction("Previous");
|
mpris.sendAction("Previous");
|
||||||
}
|
}
|
||||||
@@ -339,7 +339,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
|
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris == null) return;
|
if (mpris == null) return;
|
||||||
mpris.Seek(interval_time * -1);
|
mpris.Seek(interval_time * -1);
|
||||||
}
|
}
|
||||||
@@ -354,7 +354,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
|
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris == null) return;
|
if (mpris == null) return;
|
||||||
mpris.Seek(interval_time);
|
mpris.Seek(interval_time);
|
||||||
}
|
}
|
||||||
@@ -369,7 +369,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
|
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris == null) return;
|
if (mpris == null) return;
|
||||||
mpris.sendAction("Next");
|
mpris.sendAction("Next");
|
||||||
}
|
}
|
||||||
@@ -392,7 +392,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
|
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris == null) return;
|
if (mpris == null) return;
|
||||||
mpris.setVolume(seekBar.getProgress());
|
mpris.setVolume(seekBar.getProgress());
|
||||||
}
|
}
|
||||||
@@ -409,7 +409,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
|
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris != null) {
|
if (mpris != null) {
|
||||||
positionSeek.setProgress((int) (mpris.getPosition()));
|
positionSeek.setProgress((int) (mpris.getPosition()));
|
||||||
}
|
}
|
||||||
@@ -438,7 +438,7 @@ public class MprisActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onServiceStart(BackgroundService service) {
|
public void onServiceStart(BackgroundService service) {
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
|
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
if (mpris != null) {
|
if (mpris != null) {
|
||||||
mpris.setPosition(seekBar.getProgress());
|
mpris.setPosition(seekBar.getProgress());
|
||||||
}
|
}
|
||||||
|
@@ -21,14 +21,11 @@
|
|||||||
package org.kde.kdeconnect.Plugins.MprisPlugin;
|
package org.kde.kdeconnect.Plugins.MprisPlugin;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
import org.kde.kdeconnect.Plugins.Plugin;
|
import org.kde.kdeconnect.Plugins.Plugin;
|
||||||
@@ -51,11 +48,6 @@ public class MprisPlugin extends Plugin {
|
|||||||
private ArrayList<String> playerList = new ArrayList<String>();
|
private ArrayList<String> playerList = new ArrayList<String>();
|
||||||
private HashMap<String,Handler> playerListUpdated = new HashMap<String,Handler>();
|
private HashMap<String,Handler> playerListUpdated = new HashMap<String,Handler>();
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPluginName() {
|
|
||||||
return "plugin_mpris";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return context.getResources().getString(R.string.pref_plugin_mpris);
|
return context.getResources().getString(R.string.pref_plugin_mpris);
|
||||||
|
@@ -30,7 +30,6 @@ import android.os.Bundle;
|
|||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import org.kde.kdeconnect.Helpers.AppsHelper;
|
import org.kde.kdeconnect.Helpers.AppsHelper;
|
||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
@@ -43,10 +42,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
/*
|
/*
|
||||||
private boolean sendIcons = false;
|
private boolean sendIcons = false;
|
||||||
*/
|
*/
|
||||||
@Override
|
|
||||||
public String getPluginName() {
|
|
||||||
return "plugin_notifications";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
|
@@ -21,17 +21,13 @@
|
|||||||
package org.kde.kdeconnect.Plugins.PingPlugin;
|
package org.kde.kdeconnect.Plugins.PingPlugin;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
import org.kde.kdeconnect.Plugins.Plugin;
|
import org.kde.kdeconnect.Plugins.Plugin;
|
||||||
@@ -41,11 +37,6 @@ import org.kde.kdeconnect_tp.R;
|
|||||||
|
|
||||||
public class PingPlugin extends Plugin {
|
public class PingPlugin extends Plugin {
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPluginName() {
|
|
||||||
return "plugin_ping";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return context.getResources().getString(R.string.pref_plugin_ping);
|
return context.getResources().getString(R.string.pref_plugin_ping);
|
||||||
|
@@ -32,7 +32,6 @@ import org.kde.kdeconnect.Device;
|
|||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
import org.kde.kdeconnect.UserInterface.PluginSettingsActivity;
|
import org.kde.kdeconnect.UserInterface.PluginSettingsActivity;
|
||||||
import org.kde.kdeconnect.UserInterface.SettingsActivity;
|
import org.kde.kdeconnect.UserInterface.SettingsActivity;
|
||||||
import org.kde.kdeconnect_tp.R;
|
|
||||||
|
|
||||||
public abstract class Plugin {
|
public abstract class Plugin {
|
||||||
|
|
||||||
@@ -46,10 +45,14 @@ public abstract class Plugin {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the internal plugin name, that will be used as a
|
* Return the internal plugin name, that will be used as a
|
||||||
* unique key to distinguish it. This function can not access
|
* unique key to distinguish it. Use the class name as key.
|
||||||
* this.context nor this.device.
|
|
||||||
*/
|
*/
|
||||||
public abstract String getPluginName();
|
public String getPluginKey() {
|
||||||
|
return getPluginKey(this.getClass());
|
||||||
|
}
|
||||||
|
public static String getPluginKey(Class<? extends Plugin> p) {
|
||||||
|
return p.getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the human-readable plugin name. This function can
|
* Return the human-readable plugin name. This function can
|
||||||
@@ -104,7 +107,7 @@ public abstract class Plugin {
|
|||||||
public void startPreferencesActivity(SettingsActivity parentActivity) {
|
public void startPreferencesActivity(SettingsActivity parentActivity) {
|
||||||
Intent intent = new Intent(parentActivity, PluginSettingsActivity.class);
|
Intent intent = new Intent(parentActivity, PluginSettingsActivity.class);
|
||||||
intent.putExtra("plugin_display_name", getDisplayName());
|
intent.putExtra("plugin_display_name", getDisplayName());
|
||||||
intent.putExtra("plugin_name", getPluginName());
|
intent.putExtra("plugin_key", getPluginKey());
|
||||||
parentActivity.startActivity(intent);
|
parentActivity.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -44,9 +44,8 @@ public class PluginFactory {
|
|||||||
|
|
||||||
public static class PluginInfo {
|
public static class PluginInfo {
|
||||||
|
|
||||||
public PluginInfo(String pluginName, String displayName, String description, Drawable icon,
|
public PluginInfo(String displayName, String description, Drawable icon,
|
||||||
boolean enabledByDefault, boolean hasSettings) {
|
boolean enabledByDefault, boolean hasSettings) {
|
||||||
this.pluginName = pluginName;
|
|
||||||
this.displayName = displayName;
|
this.displayName = displayName;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
@@ -54,10 +53,6 @@ public class PluginFactory {
|
|||||||
this.hasSettings = hasSettings;
|
this.hasSettings = hasSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPluginName() {
|
|
||||||
return pluginName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return displayName;
|
return displayName;
|
||||||
}
|
}
|
||||||
@@ -76,7 +71,6 @@ public class PluginFactory {
|
|||||||
return enabledByDefault;
|
return enabledByDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String pluginName;
|
|
||||||
private final String displayName;
|
private final String displayName;
|
||||||
private final String description;
|
private final String description;
|
||||||
private final Drawable icon;
|
private final Drawable icon;
|
||||||
@@ -101,15 +95,15 @@ public class PluginFactory {
|
|||||||
PluginFactory.registerPlugin(SharePlugin.class);
|
PluginFactory.registerPlugin(SharePlugin.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PluginInfo getPluginInfo(Context context, String pluginName) {
|
public static PluginInfo getPluginInfo(Context context, String pluginKey) {
|
||||||
PluginInfo info = availablePluginsInfo.get(pluginName); //Is it cached?
|
PluginInfo info = availablePluginsInfo.get(pluginKey); //Is it cached?
|
||||||
if (info != null) return info;
|
if (info != null) return info;
|
||||||
try {
|
try {
|
||||||
Plugin p = ((Plugin)availablePlugins.get(pluginName).newInstance());
|
Plugin p = ((Plugin)availablePlugins.get(pluginKey).newInstance());
|
||||||
p.setContext(context, null);
|
p.setContext(context, null);
|
||||||
info = new PluginInfo(pluginName, p.getDisplayName(), p.getDescription(), p.getIcon(),
|
info = new PluginInfo(p.getDisplayName(), p.getDescription(), p.getIcon(),
|
||||||
p.isEnabledByDefault(), p.hasSettings());
|
p.isEnabledByDefault(), p.hasSettings());
|
||||||
availablePluginsInfo.put(pluginName, info); //Cache it
|
availablePluginsInfo.put(pluginKey, info); //Cache it
|
||||||
return info;
|
return info;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Log.e("PluginFactory","getPluginInfo exception");
|
Log.e("PluginFactory","getPluginInfo exception");
|
||||||
@@ -122,10 +116,10 @@ public class PluginFactory {
|
|||||||
return availablePlugins.keySet();
|
return availablePlugins.keySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Plugin instantiatePluginForDevice(Context context, String pluginName, Device device) {
|
public static Plugin instantiatePluginForDevice(Context context, String pluginKey, Device device) {
|
||||||
Class c = availablePlugins.get(pluginName);
|
Class c = availablePlugins.get(pluginKey);
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
Log.e("PluginFactory", "Plugin not found: "+pluginName);
|
Log.e("PluginFactory", "Plugin not found: "+pluginKey);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +128,7 @@ public class PluginFactory {
|
|||||||
plugin.setContext(context, device);
|
plugin.setContext(context, device);
|
||||||
return plugin;
|
return plugin;
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Log.e("PluginFactory", "Could not instantiate plugin: "+pluginName);
|
Log.e("PluginFactory", "Could not instantiate plugin: "+pluginKey);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -144,8 +138,8 @@ public class PluginFactory {
|
|||||||
public static void registerPlugin(Class<? extends Plugin> 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 = (pluginClass.newInstance()).getPluginName();
|
String pluginKey = Plugin.getPluginKey(pluginClass);
|
||||||
availablePlugins.put(pluginName, pluginClass);
|
availablePlugins.put(pluginKey, pluginClass);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
Log.e("PluginFactory","addPlugin exception");
|
Log.e("PluginFactory","addPlugin exception");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@@ -20,11 +20,7 @@
|
|||||||
|
|
||||||
package org.kde.kdeconnect.Plugins.SftpPlugin;
|
package org.kde.kdeconnect.Plugins.SftpPlugin;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import org.kde.kdeconnect.Helpers.StorageHelper;
|
import org.kde.kdeconnect.Helpers.StorageHelper;
|
||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
@@ -39,9 +35,6 @@ public class SftpPlugin extends Plugin {
|
|||||||
|
|
||||||
private static final SimpleSftpServer server = new SimpleSftpServer();
|
private static final SimpleSftpServer server = new SimpleSftpServer();
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPluginName() {return "plugin_sftp";}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return context.getResources().getString(R.string.pref_plugin_sftp);
|
return context.getResources().getString(R.string.pref_plugin_sftp);
|
||||||
|
@@ -21,7 +21,6 @@
|
|||||||
package org.kde.kdeconnect.Plugins.SharePlugin;
|
package org.kde.kdeconnect.Plugins.SharePlugin;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
@@ -37,7 +36,6 @@ import android.preference.PreferenceManager;
|
|||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.kde.kdeconnect.Helpers.FilesHelper;
|
import org.kde.kdeconnect.Helpers.FilesHelper;
|
||||||
@@ -50,14 +48,8 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
|
||||||
public class SharePlugin extends Plugin {
|
public class SharePlugin extends Plugin {
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPluginName() {
|
|
||||||
return "plugin_share";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return context.getResources().getString(R.string.pref_plugin_sharereceiver);
|
return context.getResources().getString(R.string.pref_plugin_sharereceiver);
|
||||||
|
@@ -20,18 +20,14 @@
|
|||||||
|
|
||||||
package org.kde.kdeconnect.Plugins.TelephonyPlugin;
|
package org.kde.kdeconnect.Plugins.TelephonyPlugin;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.telephony.SmsMessage;
|
import android.telephony.SmsMessage;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.widget.Button;
|
|
||||||
|
|
||||||
import org.kde.kdeconnect.Helpers.ContactsHelper;
|
import org.kde.kdeconnect.Helpers.ContactsHelper;
|
||||||
import org.kde.kdeconnect.NetworkPackage;
|
import org.kde.kdeconnect.NetworkPackage;
|
||||||
@@ -47,11 +43,6 @@ public class TelephonyPlugin extends Plugin {
|
|||||||
private NetworkPackage lastPackage = null;
|
private NetworkPackage lastPackage = null;
|
||||||
private boolean isMuted = false;
|
private boolean isMuted = false;
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getPluginName() {
|
|
||||||
return "plugin_telephony";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDisplayName() {
|
public String getDisplayName() {
|
||||||
return context.getResources().getString(R.string.pref_plugin_telephony);
|
return context.getResources().getString(R.string.pref_plugin_telephony);
|
||||||
|
@@ -25,6 +25,8 @@ import android.preference.PreferenceActivity;
|
|||||||
|
|
||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public class PluginSettingsActivity extends PreferenceActivity {
|
public class PluginSettingsActivity extends PreferenceActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -34,8 +36,8 @@ public class PluginSettingsActivity extends PreferenceActivity {
|
|||||||
String pluginDisplayName = getIntent().getStringExtra("plugin_display_name");
|
String pluginDisplayName = getIntent().getStringExtra("plugin_display_name");
|
||||||
setTitle(getString(R.string.plugin_settings_with_name, pluginDisplayName));
|
setTitle(getString(R.string.plugin_settings_with_name, pluginDisplayName));
|
||||||
|
|
||||||
String pluginName = getIntent().getStringExtra("plugin_name");
|
String pluginKey = getIntent().getStringExtra("plugin_key");
|
||||||
int resFile = getResources().getIdentifier(pluginName + "_preferences", "xml", getPackageName());
|
int resFile = getResources().getIdentifier(pluginKey.toLowerCase(Locale.ENGLISH) + "_preferences", "xml", getPackageName());
|
||||||
addPreferencesFromResource(resFile);
|
addPreferencesFromResource(resFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,6 +35,7 @@ import org.kde.kdeconnect.Plugins.PluginFactory;
|
|||||||
import org.kde.kdeconnect_tp.R;
|
import org.kde.kdeconnect_tp.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class SettingsActivity extends PreferenceActivity {
|
public class SettingsActivity extends PreferenceActivity {
|
||||||
@@ -59,20 +60,20 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
Set<String> plugins = PluginFactory.getAvailablePlugins();
|
Set<String> plugins = PluginFactory.getAvailablePlugins();
|
||||||
|
|
||||||
final ArrayList<Preference> preferences = new ArrayList<Preference>();
|
final ArrayList<Preference> preferences = new ArrayList<Preference>();
|
||||||
for (final String pluginName : plugins) {
|
for (final String pluginKey : plugins) {
|
||||||
final CheckBoxPreference pref = new CheckBoxPreference(getBaseContext());
|
final CheckBoxPreference pref = new CheckBoxPreference(getBaseContext());
|
||||||
|
|
||||||
PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(getBaseContext(), pluginName);
|
PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(getBaseContext(), pluginKey);
|
||||||
pref.setKey(pluginName);
|
pref.setKey(pluginKey);
|
||||||
pref.setTitle(info.getDisplayName());
|
pref.setTitle(info.getDisplayName());
|
||||||
pref.setSummary(info.getDescription());
|
pref.setSummary(info.getDescription());
|
||||||
pref.setChecked(device.isPluginEnabled(pluginName));
|
pref.setChecked(device.isPluginEnabled(pluginKey));
|
||||||
preferences.add(pref);
|
preferences.add(pref);
|
||||||
preferenceScreen.addPreference(pref);
|
preferenceScreen.addPreference(pref);
|
||||||
|
|
||||||
if (info.hasSettings()) {
|
if (info.hasSettings()) {
|
||||||
final Preference pluginPreference = new Preference(getBaseContext());
|
final Preference pluginPreference = new Preference(getBaseContext());
|
||||||
pluginPreference.setKey(pluginName + "_preferences");
|
pluginPreference.setKey(pluginKey.toLowerCase(Locale.ENGLISH) + "_preferences");
|
||||||
pluginPreference.setSummary(getString(R.string.plugin_settings_with_name, info.getDisplayName()));
|
pluginPreference.setSummary(getString(R.string.plugin_settings_with_name, info.getDisplayName()));
|
||||||
preferences.add(pluginPreference);
|
preferences.add(pluginPreference);
|
||||||
preferenceScreen.addPreference(pluginPreference);
|
preferenceScreen.addPreference(pluginPreference);
|
||||||
@@ -91,8 +92,8 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
check.setChecked(!enabled);
|
check.setChecked(!enabled);
|
||||||
} else { //Is a plugin suboption
|
} else { //Is a plugin suboption
|
||||||
if (pref.isEnabled()) {
|
if (pref.isEnabled()) {
|
||||||
String pluginName = pref.getDependency(); //The parent pref will be named like the plugin
|
String pluginKey = pref.getDependency(); //The parent pref will be named like the plugin
|
||||||
Plugin plugin = device.getPlugin(pluginName, true);
|
Plugin plugin = device.getPlugin(pluginKey, true);
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
plugin.startPreferencesActivity(SettingsActivity.this);
|
plugin.startPreferencesActivity(SettingsActivity.this);
|
||||||
} else { //Could happen if the device is not connected anymore
|
} else { //Could happen if the device is not connected anymore
|
||||||
|
Reference in New Issue
Block a user