From b2fa8ab5065b56c82b962343e02b9f439c9405b4 Mon Sep 17 00:00:00 2001 From: Ronny Yabar Aizcorbe Date: Tue, 16 Sep 2014 15:45:31 +0200 Subject: [PATCH] Plugin-specific settings Added support for specific plugin settings. Added interval time preference to fast forward or rewind a multimedia file instead of hardcording the time. REVIEW: 120005 --- src/main/AndroidManifest.xml | 9 ++++ .../Plugins/BatteryPlugin/BatteryPlugin.java | 5 +++ .../ClibpoardPlugin/ClipboardPlugin.java | 5 +++ .../MousePadPlugin/MousePadPlugin.java | 5 +++ .../Plugins/MprisPlugin/MprisActivity.java | 11 ++++- .../Plugins/MprisPlugin/MprisPlugin.java | 5 +++ .../NotificationsPlugin.java | 5 +++ .../Plugins/PingPlugin/PingPlugin.java | 5 +++ .../org/kde/kdeconnect/Plugins/Plugin.java | 6 +++ .../kde/kdeconnect/Plugins/PluginFactory.java | 10 ++++- .../Plugins/SftpPlugin/SftpPlugin.java | 5 +++ .../Plugins/SharePlugin/SharePlugin.java | 5 +++ .../TelephonyPlugin/TelephonyPlugin.java | 5 +++ .../UserInterface/PluginSettingsActivity.java | 17 ++++++++ .../UserInterface/SettingsActivity.java | 42 ++++++++++++++----- src/main/res/values/arrays.xml | 18 ++++++++ src/main/res/values/strings.xml | 8 +++- src/main/res/xml/plugin_mpris_preferences.xml | 15 +++++++ 18 files changed, 166 insertions(+), 15 deletions(-) create mode 100644 src/main/java/org/kde/kdeconnect/UserInterface/PluginSettingsActivity.java create mode 100644 src/main/res/values/arrays.xml create mode 100644 src/main/res/xml/plugin_mpris_preferences.xml diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 499e92e8..53c9e4c3 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -88,6 +88,15 @@ android:value="org.kde.kdeconnect.UserInterface.DeviceActivity" /> + + + + diff --git a/src/main/java/org/kde/kdeconnect/Plugins/BatteryPlugin/BatteryPlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/BatteryPlugin/BatteryPlugin.java index 7761c213..5e09393a 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/BatteryPlugin/BatteryPlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/BatteryPlugin/BatteryPlugin.java @@ -46,6 +46,11 @@ public class BatteryPlugin extends Plugin { return context.getResources().getDrawable(R.drawable.icon); } + @Override + public boolean hasSettings() { + return false; + } + @Override public boolean isEnabledByDefault() { return true; diff --git a/src/main/java/org/kde/kdeconnect/Plugins/ClibpoardPlugin/ClipboardPlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/ClibpoardPlugin/ClipboardPlugin.java index 68315ff1..772b6d4b 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/ClibpoardPlugin/ClipboardPlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/ClibpoardPlugin/ClipboardPlugin.java @@ -35,6 +35,11 @@ public class ClipboardPlugin extends Plugin { return context.getResources().getDrawable(R.drawable.icon); } + @Override + public boolean hasSettings() { + return false; + } + @Override public boolean isEnabledByDefault() { //Disabled by default due to just one direction sync(incoming clipboard change) in early version of android. diff --git a/src/main/java/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadPlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadPlugin.java index 491e694b..0189c24d 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadPlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/MousePadPlugin/MousePadPlugin.java @@ -38,6 +38,11 @@ public class MousePadPlugin extends Plugin { return true; } + @Override + public boolean hasSettings() { + return false; + } + @Override public boolean onCreate() { return true; diff --git a/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java b/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java index b219e072..2956412f 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java @@ -1,9 +1,11 @@ package org.kde.kdeconnect.Plugins.MprisPlugin; import android.app.Activity; +import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.preference.PreferenceManager; import android.util.Log; import android.view.KeyEvent; import android.view.View; @@ -216,6 +218,11 @@ public class MprisActivity extends Activity { deviceId = getIntent().getStringExtra("deviceId"); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + String interval_time_str = prefs.getString(getString(R.string.mpris_time_key), + getString(R.string.mpris_time_default)); + final int interval_time = Integer.parseInt(interval_time_str); + BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { @Override public void onServiceStart(BackgroundService service) { @@ -263,7 +270,7 @@ public class MprisActivity extends Activity { Device device = service.getDevice(deviceId); MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris"); if (mpris == null) return; - mpris.Seek(-10000000); // -10 seconds. TODO: plugin settings UI? + mpris.Seek(interval_time * -1); } }); } @@ -278,7 +285,7 @@ public class MprisActivity extends Activity { Device device = service.getDevice(deviceId); MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris"); if (mpris == null) return; - mpris.Seek(10000000); // 10 seconds. TODO: plugin settings UI? + mpris.Seek(interval_time); } }); } diff --git a/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java index 38843925..6aa12c77 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java @@ -54,6 +54,11 @@ public class MprisPlugin extends Plugin { return context.getResources().getDrawable(R.drawable.icon); } + @Override + public boolean hasSettings() { + return true; + } + @Override public boolean isEnabledByDefault() { return true; diff --git a/src/main/java/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java index adc48253..948053d2 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/NotificationsPlugin/NotificationsPlugin.java @@ -45,6 +45,11 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. return context.getResources().getDrawable(R.drawable.icon); } + @Override + public boolean hasSettings() { + return false; + } + @Override public boolean isEnabledByDefault() { return true; diff --git a/src/main/java/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java index 51d20280..a24284c1 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/PingPlugin/PingPlugin.java @@ -45,6 +45,11 @@ public class PingPlugin extends Plugin { return context.getResources().getDrawable(R.drawable.icon); } + @Override + public boolean hasSettings() { + return false; + } + @Override public boolean isEnabledByDefault() { return true; diff --git a/src/main/java/org/kde/kdeconnect/Plugins/Plugin.java b/src/main/java/org/kde/kdeconnect/Plugins/Plugin.java index a91016ac..b8b1d17d 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/Plugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/Plugin.java @@ -51,6 +51,12 @@ public abstract class Plugin { */ public abstract boolean isEnabledByDefault(); + + /** + * Return true if this plugin needs an specific UI settings. + */ + public abstract boolean hasSettings(); + /** * Initialize the listeners and structures in your plugin. * Should return true if initialization was successful. diff --git a/src/main/java/org/kde/kdeconnect/Plugins/PluginFactory.java b/src/main/java/org/kde/kdeconnect/Plugins/PluginFactory.java index 8d046ccc..430cd123 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/PluginFactory.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/PluginFactory.java @@ -24,12 +24,14 @@ public class PluginFactory { public static class PluginInfo { - public PluginInfo(String pluginName, String displayName, String description, Drawable icon, boolean enabledByDefault) { + public PluginInfo(String pluginName, String displayName, String description, Drawable icon, + boolean enabledByDefault, boolean hasSettings) { this.pluginName = pluginName; this.displayName = displayName; this.description = description; this.icon = icon; this.enabledByDefault = enabledByDefault; + this.hasSettings = hasSettings; } public String getPluginName() { @@ -48,6 +50,8 @@ public class PluginFactory { return icon; } + public boolean hasSettings() { return hasSettings; } + public boolean isEnabledByDefault() { return enabledByDefault; } @@ -57,6 +61,7 @@ public class PluginFactory { private final String description; private final Drawable icon; private final boolean enabledByDefault; + private final boolean hasSettings; } @@ -82,7 +87,8 @@ public class PluginFactory { try { Plugin p = ((Plugin)availablePlugins.get(pluginName).newInstance()); p.setContext(context, null); - info = new PluginInfo(pluginName, p.getDisplayName(), p.getDescription(), p.getIcon(), p.isEnabledByDefault()); + info = new PluginInfo(pluginName, p.getDisplayName(), p.getDescription(), p.getIcon(), + p.isEnabledByDefault(), p.hasSettings()); availablePluginsInfo.put(pluginName, info); //Cache it return info; } catch(Exception e) { diff --git a/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java index eee7bf9a..0e62808f 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java @@ -37,6 +37,11 @@ public class SftpPlugin extends Plugin { return context.getResources().getDrawable(R.drawable.icon); } + @Override + public boolean hasSettings() { + return false; + } + @Override public boolean isEnabledByDefault() {return true;} diff --git a/src/main/java/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java index b0c28cb0..01ed552b 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/SharePlugin/SharePlugin.java @@ -55,6 +55,11 @@ public class SharePlugin extends Plugin { return context.getResources().getDrawable(R.drawable.icon); } + @Override + public boolean hasSettings() { + return false; + } + @Override public boolean isEnabledByDefault() { return true; diff --git a/src/main/java/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java index d26409ad..a6c8adad 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/TelephonyPlugin/TelephonyPlugin.java @@ -48,6 +48,11 @@ public class TelephonyPlugin extends Plugin { return true; } + @Override + public boolean hasSettings() { + return false; + } + private final BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { diff --git a/src/main/java/org/kde/kdeconnect/UserInterface/PluginSettingsActivity.java b/src/main/java/org/kde/kdeconnect/UserInterface/PluginSettingsActivity.java new file mode 100644 index 00000000..25c33410 --- /dev/null +++ b/src/main/java/org/kde/kdeconnect/UserInterface/PluginSettingsActivity.java @@ -0,0 +1,17 @@ +package org.kde.kdeconnect.UserInterface; + +import android.content.Intent; +import android.os.Bundle; +import android.preference.PreferenceActivity; + +public class PluginSettingsActivity extends PreferenceActivity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + String resource_name = getIntent().getStringExtra(Intent.EXTRA_INTENT); + int resource_file = getResources().getIdentifier(resource_name, "xml", getPackageName()); + addPreferencesFromResource(resource_file); + } +} \ No newline at end of file diff --git a/src/main/java/org/kde/kdeconnect/UserInterface/SettingsActivity.java b/src/main/java/org/kde/kdeconnect/UserInterface/SettingsActivity.java index e1599c5f..fb126ae2 100644 --- a/src/main/java/org/kde/kdeconnect/UserInterface/SettingsActivity.java +++ b/src/main/java/org/kde/kdeconnect/UserInterface/SettingsActivity.java @@ -1,24 +1,29 @@ package org.kde.kdeconnect.UserInterface; -import android.app.ListActivity; +import android.content.Intent; import android.os.Bundle; import android.preference.CheckBoxPreference; import android.preference.Preference; +import android.preference.PreferenceActivity; +import android.preference.PreferenceScreen; import android.view.View; import android.widget.AdapterView; import org.kde.kdeconnect.BackgroundService; import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Plugins.PluginFactory; +import org.kde.kdeconnect_tp.R; import java.util.ArrayList; import java.util.Set; -public class SettingsActivity extends ListActivity { +public class SettingsActivity extends PreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + final PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(this); + setPreferenceScreen(preferenceScreen); final String deviceId = getIntent().getStringExtra("deviceId"); BackgroundService.RunCommand(getApplicationContext(), new BackgroundService.InstanceCallback() { @@ -30,26 +35,45 @@ public class SettingsActivity extends ListActivity { final ArrayList preferences = new ArrayList(); for (final String pluginName : plugins) { - CheckBoxPreference pref = new CheckBoxPreference(getBaseContext()); + final CheckBoxPreference pref = new CheckBoxPreference(getBaseContext()); + PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(getBaseContext(), pluginName); pref.setKey(pluginName); pref.setTitle(info.getDisplayName()); pref.setSummary(info.getDescription()); pref.setChecked(device.isPluginEnabled(pluginName)); preferences.add(pref); + preferenceScreen.addPreference(pref); + + if (info.hasSettings()) { + final Preference pluginPreference = new Preference(getBaseContext()); + pluginPreference.setKey(info.getPluginName() + getString(R.string.plugin_settings_key)); + pluginPreference.setTitle(info.getDisplayName()); + pluginPreference.setSummary(R.string.plugin_settings); + pluginPreference.setSelectable(false); + preferences.add(pluginPreference); + preferenceScreen.addPreference(pluginPreference); + pluginPreference.setDependency(pref.getKey()); + } } setListAdapter(new PreferenceListAdapter(SettingsActivity.this, preferences)); getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { + Preference current_preference = preferences.get(i); - CheckBoxPreference pref = (CheckBoxPreference)preferences.get(i); + if (current_preference.isSelectable()) { + CheckBoxPreference pref = (CheckBoxPreference) current_preference; + boolean enabled = device.isPluginEnabled(pref.getKey()); + device.setPluginEnabled(pref.getKey(), !enabled); - boolean enabled = device.isPluginEnabled(pref.getKey()); - device.setPluginEnabled(pref.getKey(), !enabled); - - pref.setChecked(!enabled); + pref.setChecked(!enabled); + } else { + Intent intent = new Intent(SettingsActivity.this, PluginSettingsActivity.class); + intent.putExtra(Intent.EXTRA_INTENT, current_preference.getKey()); + startActivity(intent); + } getListAdapter().getView(i, view, null); //This will refresh the view (yes, this is the way to do it) @@ -64,6 +88,4 @@ public class SettingsActivity extends ListActivity { } - - } \ No newline at end of file diff --git a/src/main/res/values/arrays.xml b/src/main/res/values/arrays.xml new file mode 100644 index 00000000..2ed02b6d --- /dev/null +++ b/src/main/res/values/arrays.xml @@ -0,0 +1,18 @@ + + + + 10 seconds + 20 seconds + 30 seconds + 1 minute + 2 minutes + + + + 10000000 + 20000000 + 30000000 + 60000000 + 120000000 + + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index bec4a221..55394654 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -72,13 +72,19 @@ Fast-forward Next Volume + Multimedia Settings + Interval Time + Adjust the time to fast forward or rewind a multimedia file. + mpris_interval_time + 10000000 Share To... This device uses an old protocol version This device uses a newer protocol version General Settings + Settings + _preferences Device name %s Invalid device name Received text, saved to clipboard - diff --git a/src/main/res/xml/plugin_mpris_preferences.xml b/src/main/res/xml/plugin_mpris_preferences.xml new file mode 100644 index 00000000..c565a357 --- /dev/null +++ b/src/main/res/xml/plugin_mpris_preferences.xml @@ -0,0 +1,15 @@ + + + + + + \ No newline at end of file