2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 06:05:12 +00:00

Plugin key is now the plugin class instead of being defined by each plugin

This commit is contained in:
Albert Vaca
2015-06-06 00:38:51 -07:00
parent a5e9b29e20
commit 3b0a3e265d
20 changed files with 95 additions and 154 deletions

View File

@@ -614,29 +614,37 @@ public class Device implements BaseLink.PackageReceiver {
// Plugin-related functions
//
public Plugin getPlugin(String name) {
return getPlugin(name, false);
public <T extends Plugin> T getPlugin(Class<T> pluginClass) {
return (T)getPlugin(Plugin.getPluginKey(pluginClass));
}
public Plugin getPlugin(String name, boolean includeFailed) {
Plugin plugin = plugins.get(name);
public <T extends Plugin> T getPlugin(Class<T> pluginClass, boolean includeFailed) {
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) {
plugin = failedPlugins.get(name);
plugin = failedPlugins.get(pluginKey);
}
return plugin;
}
private synchronized void addPlugin(final String name) {
Plugin existing = plugins.get(name);
private synchronized void addPlugin(final String pluginKey) {
Plugin existing = plugins.get(pluginKey);
if (existing != null) {
Log.w("KDE/addPlugin","plugin already present:" + name);
Log.w("KDE/addPlugin","plugin already present:" + pluginKey);
return;
}
final Plugin plugin = PluginFactory.instantiatePluginForDevice(context, name, this);
final Plugin plugin = PluginFactory.instantiatePluginForDevice(context, pluginKey, this);
if (plugin == null) {
Log.e("KDE/addPlugin","could not instantiate plugin: "+name);
failedPlugins.put(name, plugin);
Log.e("KDE/addPlugin","could not instantiate plugin: "+pluginKey);
failedPlugins.put(pluginKey, plugin);
return;
}
@@ -650,17 +658,17 @@ public class Device implements BaseLink.PackageReceiver {
} catch (Exception e) {
success = false;
e.printStackTrace();
Log.e("KDE/addPlugin", "Exception loading plugin " + name);
Log.e("KDE/addPlugin", "Exception loading plugin " + pluginKey);
}
if (success) {
//Log.e("addPlugin","added " + name);
failedPlugins.remove(name);
plugins.put(name, plugin);
//Log.e("addPlugin","added " + pluginKey);
failedPlugins.remove(pluginKey);
plugins.put(pluginKey, plugin);
} else {
Log.e("KDE/addPlugin", "plugin failed to load " + name);
plugins.remove(name);
failedPlugins.put(name, plugin);
Log.e("KDE/addPlugin", "plugin failed to load " + pluginKey);
plugins.remove(pluginKey);
failedPlugins.put(pluginKey, plugin);
}
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 failedPlugin = failedPlugins.remove(name);
Plugin plugin = plugins.remove(pluginKey);
Plugin failedPlugin = failedPlugins.remove(pluginKey);
if (plugin == null) {
if (failedPlugin == null) {
@@ -687,10 +695,10 @@ public class Device implements BaseLink.PackageReceiver {
try {
plugin.onDestroy();
//Log.e("removePlugin","removed " + name);
//Log.e("removePlugin","removed " + pluginKey);
} catch (Exception e) {
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) {
@@ -700,15 +708,15 @@ public class Device implements BaseLink.PackageReceiver {
return true;
}
public void setPluginEnabled(String pluginName, boolean value) {
settings.edit().putBoolean(pluginName,value).apply();
if (value && isPaired() && isReachable()) addPlugin(pluginName);
else removePlugin(pluginName);
public void setPluginEnabled(String pluginKey, boolean value) {
settings.edit().putBoolean(pluginKey,value).apply();
if (value && isPaired() && isReachable()) addPlugin(pluginKey);
else removePlugin(pluginKey);
}
public boolean isPluginEnabled(String pluginName) {
boolean enabledByDefault = PluginFactory.getPluginInfo(context, pluginName).isEnabledByDefault();
boolean enabled = settings.getBoolean(pluginName, enabledByDefault);
public boolean isPluginEnabled(String pluginKey) {
boolean enabledByDefault = PluginFactory.getPluginInfo(context, pluginKey).isEnabledByDefault();
boolean enabled = settings.getBoolean(pluginKey, enabledByDefault);
return enabled;
}
@@ -722,15 +730,15 @@ public class Device implements BaseLink.PackageReceiver {
Set<String> availablePlugins = PluginFactory.getAvailablePlugins();
for(String pluginName : availablePlugins) {
for(String pluginKey : availablePlugins) {
boolean enabled = false;
if (isPaired() && isReachable()) {
enabled = isPluginEnabled(pluginName);
enabled = isPluginEnabled(pluginKey);
}
if (enabled) {
addPlugin(pluginName);
addPlugin(pluginKey);
} else {
removePlugin(pluginName);
removePlugin(pluginKey);
}
}

View File

@@ -20,20 +20,17 @@
package org.kde.kdeconnect.Plugins.BatteryPlugin;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.os.BatteryManager;
import android.widget.Button;
import org.kde.kdeconnect.NetworkPackage;
import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect_tp.R;
public class BatteryPlugin extends Plugin {
// keep these fields in sync with kdeconnect-kded:BatteryPlugin.h:ThresholdBatteryEvent
@@ -42,11 +39,6 @@ public class BatteryPlugin extends Plugin {
private NetworkPackage lastInfo = null;
@Override
public String getPluginName() {
return "plugin_battery";
}
@Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_battery);

View File

@@ -31,10 +31,6 @@ import org.kde.kdeconnect_tp.R;
public class ClipboardPlugin extends Plugin {
@Override
public String getPluginName() {
return "plugin_clipboard";
}
@Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_clipboard);

View File

@@ -176,7 +176,7 @@ public class KeyListenerView extends View {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = (MousePadPlugin) device.getPlugin("plugin_mousepad");
MousePadPlugin mousePadPlugin = (MousePadPlugin) device.getPlugin(MousePadPlugin.class);
if (mousePadPlugin == null) return;
mousePadPlugin.sendKeyboardPacket(np);
}

View File

@@ -182,7 +182,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
if (mousePadPlugin == null) return;
mousePadPlugin.sendMouseDelta(mCurrentX - mPrevX, mCurrentY - mPrevY);
mPrevX = mCurrentX;
@@ -227,7 +227,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
if (mousePadPlugin == null) return;
mousePadPlugin.sendScroll(0, scrollToSendY);
}
@@ -248,7 +248,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
if (mousePadPlugin == null) return;
mousePadPlugin.sendSingleHold();
}
@@ -266,7 +266,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
if (mousePadPlugin == null) return;
mousePadPlugin.sendSingleClick();
}
@@ -280,7 +280,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
if (mousePadPlugin == null) return;
mousePadPlugin.sendDoubleClick();
}
@@ -327,7 +327,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = (MousePadPlugin)device.getPlugin("plugin_mousepad");
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
if (mousePadPlugin == null) return;
mousePadPlugin.sendMiddleClick();
}
@@ -339,7 +339,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = (MousePadPlugin) device.getPlugin("plugin_mousepad");
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
if (mousePadPlugin == null) return;
mousePadPlugin.sendRightClick();
}
@@ -350,7 +350,7 @@ public class MousePadActivity extends ActionBarActivity implements GestureDetect
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = (MousePadPlugin) device.getPlugin("plugin_mousepad");
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
if (mousePadPlugin == null) return;
mousePadPlugin.sendSingleHold();
}

View File

@@ -21,24 +21,15 @@
package org.kde.kdeconnect.Plugins.MousePadPlugin;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;
import org.kde.kdeconnect.NetworkPackage;
import org.kde.kdeconnect.Plugins.MprisPlugin.MprisActivity;
import org.kde.kdeconnect.Plugins.Plugin;
import org.kde.kdeconnect_tp.R;
public class MousePadPlugin extends Plugin {
@Override
public String getPluginName() {
return "plugin_mousepad";
}
@Override
public String getDisplayName() {
return context.getString(R.string.pref_plugin_mousepad);

View File

@@ -75,7 +75,7 @@ public class MprisActivity extends ActionBarActivity {
public void onServiceStart(BackgroundService service) {
final Device device = service.getDevice(deviceId);
final MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
final MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris == null) {
Log.e("MprisActivity", "device has no mpris plugin!");
return;
@@ -246,7 +246,7 @@ public class MprisActivity extends ActionBarActivity {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris == null) return;
updateVolume(mpris, 5);
}
@@ -257,7 +257,7 @@ public class MprisActivity extends ActionBarActivity {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris == null) return;
updateVolume(mpris, -5);
}
@@ -309,7 +309,7 @@ public class MprisActivity extends ActionBarActivity {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris == null) return;
mpris.sendAction("PlayPause");
}
@@ -324,7 +324,7 @@ public class MprisActivity extends ActionBarActivity {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris == null) return;
mpris.sendAction("Previous");
}
@@ -339,7 +339,7 @@ public class MprisActivity extends ActionBarActivity {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris == null) return;
mpris.Seek(interval_time * -1);
}
@@ -354,7 +354,7 @@ public class MprisActivity extends ActionBarActivity {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris == null) return;
mpris.Seek(interval_time);
}
@@ -369,7 +369,7 @@ public class MprisActivity extends ActionBarActivity {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris == null) return;
mpris.sendAction("Next");
}
@@ -392,7 +392,7 @@ public class MprisActivity extends ActionBarActivity {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris == null) return;
mpris.setVolume(seekBar.getProgress());
}
@@ -409,7 +409,7 @@ public class MprisActivity extends ActionBarActivity {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris != null) {
positionSeek.setProgress((int) (mpris.getPosition()));
}
@@ -438,7 +438,7 @@ public class MprisActivity extends ActionBarActivity {
@Override
public void onServiceStart(BackgroundService service) {
Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin) device.getPlugin("plugin_mpris");
MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
if (mpris != null) {
mpris.setPosition(seekBar.getProgress());
}

View File

@@ -21,14 +21,11 @@
package org.kde.kdeconnect.Plugins.MprisPlugin;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import org.kde.kdeconnect.NetworkPackage;
import org.kde.kdeconnect.Plugins.Plugin;
@@ -51,11 +48,6 @@ public class MprisPlugin extends Plugin {
private ArrayList<String> playerList = new ArrayList<String>();
private HashMap<String,Handler> playerListUpdated = new HashMap<String,Handler>();
@Override
public String getPluginName() {
return "plugin_mpris";
}
@Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_mpris);

View File

@@ -30,7 +30,6 @@ import android.os.Bundle;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.widget.Button;
import org.kde.kdeconnect.Helpers.AppsHelper;
import org.kde.kdeconnect.NetworkPackage;
@@ -43,10 +42,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
/*
private boolean sendIcons = false;
*/
@Override
public String getPluginName() {
return "plugin_notifications";
}
@Override
public String getDisplayName() {

View File

@@ -21,17 +21,13 @@
package org.kde.kdeconnect.Plugins.PingPlugin;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.view.View;
import android.widget.Button;
import org.kde.kdeconnect.NetworkPackage;
import org.kde.kdeconnect.Plugins.Plugin;
@@ -41,11 +37,6 @@ import org.kde.kdeconnect_tp.R;
public class PingPlugin extends Plugin {
@Override
public String getPluginName() {
return "plugin_ping";
}
@Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_ping);

View File

@@ -32,7 +32,6 @@ import org.kde.kdeconnect.Device;
import org.kde.kdeconnect.NetworkPackage;
import org.kde.kdeconnect.UserInterface.PluginSettingsActivity;
import org.kde.kdeconnect.UserInterface.SettingsActivity;
import org.kde.kdeconnect_tp.R;
public abstract class Plugin {
@@ -46,10 +45,14 @@ public abstract class Plugin {
/**
* Return the internal plugin name, that will be used as a
* unique key to distinguish it. This function can not access
* this.context nor this.device.
* unique key to distinguish it. Use the class name as key.
*/
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
@@ -104,7 +107,7 @@ public abstract class Plugin {
public void startPreferencesActivity(SettingsActivity parentActivity) {
Intent intent = new Intent(parentActivity, PluginSettingsActivity.class);
intent.putExtra("plugin_display_name", getDisplayName());
intent.putExtra("plugin_name", getPluginName());
intent.putExtra("plugin_key", getPluginKey());
parentActivity.startActivity(intent);
}

View File

@@ -44,9 +44,8 @@ public class PluginFactory {
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) {
this.pluginName = pluginName;
this.displayName = displayName;
this.description = description;
this.icon = icon;
@@ -54,10 +53,6 @@ public class PluginFactory {
this.hasSettings = hasSettings;
}
public String getPluginName() {
return pluginName;
}
public String getDisplayName() {
return displayName;
}
@@ -76,7 +71,6 @@ public class PluginFactory {
return enabledByDefault;
}
private final String pluginName;
private final String displayName;
private final String description;
private final Drawable icon;
@@ -101,15 +95,15 @@ public class PluginFactory {
PluginFactory.registerPlugin(SharePlugin.class);
}
public static PluginInfo getPluginInfo(Context context, String pluginName) {
PluginInfo info = availablePluginsInfo.get(pluginName); //Is it cached?
public static PluginInfo getPluginInfo(Context context, String pluginKey) {
PluginInfo info = availablePluginsInfo.get(pluginKey); //Is it cached?
if (info != null) return info;
try {
Plugin p = ((Plugin)availablePlugins.get(pluginName).newInstance());
Plugin p = ((Plugin)availablePlugins.get(pluginKey).newInstance());
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());
availablePluginsInfo.put(pluginName, info); //Cache it
availablePluginsInfo.put(pluginKey, info); //Cache it
return info;
} catch(Exception e) {
Log.e("PluginFactory","getPluginInfo exception");
@@ -122,10 +116,10 @@ public class PluginFactory {
return availablePlugins.keySet();
}
public static Plugin instantiatePluginForDevice(Context context, String pluginName, Device device) {
Class c = availablePlugins.get(pluginName);
public static Plugin instantiatePluginForDevice(Context context, String pluginKey, Device device) {
Class c = availablePlugins.get(pluginKey);
if (c == null) {
Log.e("PluginFactory", "Plugin not found: "+pluginName);
Log.e("PluginFactory", "Plugin not found: "+pluginKey);
return null;
}
@@ -134,7 +128,7 @@ public class PluginFactory {
plugin.setContext(context, device);
return plugin;
} catch(Exception e) {
Log.e("PluginFactory", "Could not instantiate plugin: "+pluginName);
Log.e("PluginFactory", "Could not instantiate plugin: "+pluginKey);
e.printStackTrace();
return null;
}
@@ -144,8 +138,8 @@ public class PluginFactory {
public static void registerPlugin(Class<? extends Plugin> pluginClass) {
try {
//I hate this but I need to create an instance because abstract static functions can't be declared
String pluginName = (pluginClass.newInstance()).getPluginName();
availablePlugins.put(pluginName, pluginClass);
String pluginKey = Plugin.getPluginKey(pluginClass);
availablePlugins.put(pluginKey, pluginClass);
} catch(Exception e) {
Log.e("PluginFactory","addPlugin exception");
e.printStackTrace();

View File

@@ -20,11 +20,7 @@
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.widget.Button;
import org.kde.kdeconnect.Helpers.StorageHelper;
import org.kde.kdeconnect.NetworkPackage;
@@ -39,9 +35,6 @@ public class SftpPlugin extends Plugin {
private static final SimpleSftpServer server = new SimpleSftpServer();
@Override
public String getPluginName() {return "plugin_sftp";}
@Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_sftp);

View File

@@ -21,7 +21,6 @@
package org.kde.kdeconnect.Plugins.SharePlugin;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
@@ -37,7 +36,6 @@ import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;
import org.kde.kdeconnect.Helpers.FilesHelper;
@@ -50,14 +48,8 @@ import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
public class SharePlugin extends Plugin {
@Override
public String getPluginName() {
return "plugin_share";
}
@Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_sharereceiver);

View File

@@ -20,18 +20,14 @@
package org.kde.kdeconnect.Plugins.TelephonyPlugin;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.widget.Button;
import org.kde.kdeconnect.Helpers.ContactsHelper;
import org.kde.kdeconnect.NetworkPackage;
@@ -47,11 +43,6 @@ public class TelephonyPlugin extends Plugin {
private NetworkPackage lastPackage = null;
private boolean isMuted = false;
@Override
public String getPluginName() {
return "plugin_telephony";
}
@Override
public String getDisplayName() {
return context.getResources().getString(R.string.pref_plugin_telephony);

View File

@@ -25,6 +25,8 @@ import android.preference.PreferenceActivity;
import org.kde.kdeconnect_tp.R;
import java.util.Locale;
public class PluginSettingsActivity extends PreferenceActivity {
@Override
@@ -34,8 +36,8 @@ public class PluginSettingsActivity extends PreferenceActivity {
String pluginDisplayName = getIntent().getStringExtra("plugin_display_name");
setTitle(getString(R.string.plugin_settings_with_name, pluginDisplayName));
String pluginName = getIntent().getStringExtra("plugin_name");
int resFile = getResources().getIdentifier(pluginName + "_preferences", "xml", getPackageName());
String pluginKey = getIntent().getStringExtra("plugin_key");
int resFile = getResources().getIdentifier(pluginKey.toLowerCase(Locale.ENGLISH) + "_preferences", "xml", getPackageName());
addPreferencesFromResource(resFile);
}

View File

@@ -35,6 +35,7 @@ import org.kde.kdeconnect.Plugins.PluginFactory;
import org.kde.kdeconnect_tp.R;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Set;
public class SettingsActivity extends PreferenceActivity {
@@ -59,20 +60,20 @@ public class SettingsActivity extends PreferenceActivity {
Set<String> plugins = PluginFactory.getAvailablePlugins();
final ArrayList<Preference> preferences = new ArrayList<Preference>();
for (final String pluginName : plugins) {
for (final String pluginKey : plugins) {
final CheckBoxPreference pref = new CheckBoxPreference(getBaseContext());
PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(getBaseContext(), pluginName);
pref.setKey(pluginName);
PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(getBaseContext(), pluginKey);
pref.setKey(pluginKey);
pref.setTitle(info.getDisplayName());
pref.setSummary(info.getDescription());
pref.setChecked(device.isPluginEnabled(pluginName));
pref.setChecked(device.isPluginEnabled(pluginKey));
preferences.add(pref);
preferenceScreen.addPreference(pref);
if (info.hasSettings()) {
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()));
preferences.add(pluginPreference);
preferenceScreen.addPreference(pluginPreference);
@@ -91,8 +92,8 @@ public class SettingsActivity extends PreferenceActivity {
check.setChecked(!enabled);
} else { //Is a plugin suboption
if (pref.isEnabled()) {
String pluginName = pref.getDependency(); //The parent pref will be named like the plugin
Plugin plugin = device.getPlugin(pluginName, true);
String pluginKey = pref.getDependency(); //The parent pref will be named like the plugin
Plugin plugin = device.getPlugin(pluginKey, true);
if (plugin != null) {
plugin.startPreferencesActivity(SettingsActivity.this);
} else { //Could happen if the device is not connected anymore