2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-28 20:57:42 +00:00

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
This commit is contained in:
Ronny Yabar Aizcorbe 2014-09-16 15:45:31 +02:00 committed by Albert Vaca
parent b9a0b3d2f0
commit b2fa8ab506
18 changed files with 166 additions and 15 deletions

View File

@ -88,6 +88,15 @@
android:value="org.kde.kdeconnect.UserInterface.DeviceActivity" /> android:value="org.kde.kdeconnect.UserInterface.DeviceActivity" />
</activity> </activity>
<activity
android:name="org.kde.kdeconnect.UserInterface.PluginSettingsActivity"
android:label="@string/mpris_settings"
android:parentActivityName="org.kde.kdeconnect.UserInterface.SettingsActivity"
>
<meta-data android:name="android.support.PARENT_ACTIVITY"
android:value="org.kde.kdeconnect.UserInterface.SettingsActivity" />
</activity>
<receiver android:name="org.kde.kdeconnect.KdeConnectBroadcastReceiver"> <receiver android:name="org.kde.kdeconnect.KdeConnectBroadcastReceiver">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED" /> <action android:name="android.intent.action.PACKAGE_REPLACED" />

View File

@ -46,6 +46,11 @@ public class BatteryPlugin extends Plugin {
return context.getResources().getDrawable(R.drawable.icon); return context.getResources().getDrawable(R.drawable.icon);
} }
@Override
public boolean hasSettings() {
return false;
}
@Override @Override
public boolean isEnabledByDefault() { public boolean isEnabledByDefault() {
return true; return true;

View File

@ -35,6 +35,11 @@ public class ClipboardPlugin extends Plugin {
return context.getResources().getDrawable(R.drawable.icon); return context.getResources().getDrawable(R.drawable.icon);
} }
@Override
public boolean hasSettings() {
return false;
}
@Override @Override
public boolean isEnabledByDefault() { public boolean isEnabledByDefault() {
//Disabled by default due to just one direction sync(incoming clipboard change) in early version of android. //Disabled by default due to just one direction sync(incoming clipboard change) in early version of android.

View File

@ -38,6 +38,11 @@ public class MousePadPlugin extends Plugin {
return true; return true;
} }
@Override
public boolean hasSettings() {
return false;
}
@Override @Override
public boolean onCreate() { public boolean onCreate() {
return true; return true;

View File

@ -1,9 +1,11 @@
package org.kde.kdeconnect.Plugins.MprisPlugin; package org.kde.kdeconnect.Plugins.MprisPlugin;
import android.app.Activity; import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
@ -216,6 +218,11 @@ public class MprisActivity extends Activity {
deviceId = getIntent().getStringExtra("deviceId"); 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() { BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
@Override @Override
public void onServiceStart(BackgroundService service) { public void onServiceStart(BackgroundService service) {
@ -263,7 +270,7 @@ public class MprisActivity extends Activity {
Device device = service.getDevice(deviceId); Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris"); MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
if (mpris == null) return; 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); Device device = service.getDevice(deviceId);
MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris"); MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris");
if (mpris == null) return; if (mpris == null) return;
mpris.Seek(10000000); // 10 seconds. TODO: plugin settings UI? mpris.Seek(interval_time);
} }
}); });
} }

View File

@ -54,6 +54,11 @@ public class MprisPlugin extends Plugin {
return context.getResources().getDrawable(R.drawable.icon); return context.getResources().getDrawable(R.drawable.icon);
} }
@Override
public boolean hasSettings() {
return true;
}
@Override @Override
public boolean isEnabledByDefault() { public boolean isEnabledByDefault() {
return true; return true;

View File

@ -45,6 +45,11 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
return context.getResources().getDrawable(R.drawable.icon); return context.getResources().getDrawable(R.drawable.icon);
} }
@Override
public boolean hasSettings() {
return false;
}
@Override @Override
public boolean isEnabledByDefault() { public boolean isEnabledByDefault() {
return true; return true;

View File

@ -45,6 +45,11 @@ public class PingPlugin extends Plugin {
return context.getResources().getDrawable(R.drawable.icon); return context.getResources().getDrawable(R.drawable.icon);
} }
@Override
public boolean hasSettings() {
return false;
}
@Override @Override
public boolean isEnabledByDefault() { public boolean isEnabledByDefault() {
return true; return true;

View File

@ -51,6 +51,12 @@ public abstract class Plugin {
*/ */
public abstract boolean isEnabledByDefault(); 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. * Initialize the listeners and structures in your plugin.
* Should return true if initialization was successful. * Should return true if initialization was successful.

View File

@ -24,12 +24,14 @@ public class PluginFactory {
public static class PluginInfo { 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.pluginName = pluginName;
this.displayName = displayName; this.displayName = displayName;
this.description = description; this.description = description;
this.icon = icon; this.icon = icon;
this.enabledByDefault = enabledByDefault; this.enabledByDefault = enabledByDefault;
this.hasSettings = hasSettings;
} }
public String getPluginName() { public String getPluginName() {
@ -48,6 +50,8 @@ public class PluginFactory {
return icon; return icon;
} }
public boolean hasSettings() { return hasSettings; }
public boolean isEnabledByDefault() { public boolean isEnabledByDefault() {
return enabledByDefault; return enabledByDefault;
} }
@ -57,6 +61,7 @@ public class PluginFactory {
private final String description; private final String description;
private final Drawable icon; private final Drawable icon;
private final boolean enabledByDefault; private final boolean enabledByDefault;
private final boolean hasSettings;
} }
@ -82,7 +87,8 @@ public class PluginFactory {
try { try {
Plugin p = ((Plugin)availablePlugins.get(pluginName).newInstance()); Plugin p = ((Plugin)availablePlugins.get(pluginName).newInstance());
p.setContext(context, null); 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 availablePluginsInfo.put(pluginName, info); //Cache it
return info; return info;
} catch(Exception e) { } catch(Exception e) {

View File

@ -37,6 +37,11 @@ public class SftpPlugin extends Plugin {
return context.getResources().getDrawable(R.drawable.icon); return context.getResources().getDrawable(R.drawable.icon);
} }
@Override
public boolean hasSettings() {
return false;
}
@Override @Override
public boolean isEnabledByDefault() {return true;} public boolean isEnabledByDefault() {return true;}

View File

@ -55,6 +55,11 @@ public class SharePlugin extends Plugin {
return context.getResources().getDrawable(R.drawable.icon); return context.getResources().getDrawable(R.drawable.icon);
} }
@Override
public boolean hasSettings() {
return false;
}
@Override @Override
public boolean isEnabledByDefault() { public boolean isEnabledByDefault() {
return true; return true;

View File

@ -48,6 +48,11 @@ public class TelephonyPlugin extends Plugin {
return true; return true;
} }
@Override
public boolean hasSettings() {
return false;
}
private final BroadcastReceiver receiver = new BroadcastReceiver() { private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {

View File

@ -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);
}
}

View File

@ -1,24 +1,29 @@
package org.kde.kdeconnect.UserInterface; package org.kde.kdeconnect.UserInterface;
import android.app.ListActivity; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen;
import android.view.View; import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import org.kde.kdeconnect.BackgroundService; import org.kde.kdeconnect.BackgroundService;
import org.kde.kdeconnect.Device; import org.kde.kdeconnect.Device;
import org.kde.kdeconnect.Plugins.PluginFactory; import org.kde.kdeconnect.Plugins.PluginFactory;
import org.kde.kdeconnect_tp.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Set; import java.util.Set;
public class SettingsActivity extends ListActivity { public class SettingsActivity extends PreferenceActivity {
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
final PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(this);
setPreferenceScreen(preferenceScreen);
final String deviceId = getIntent().getStringExtra("deviceId"); final String deviceId = getIntent().getStringExtra("deviceId");
BackgroundService.RunCommand(getApplicationContext(), new BackgroundService.InstanceCallback() { BackgroundService.RunCommand(getApplicationContext(), new BackgroundService.InstanceCallback() {
@ -30,26 +35,45 @@ public class SettingsActivity extends ListActivity {
final ArrayList<Preference> preferences = new ArrayList<Preference>(); final ArrayList<Preference> preferences = new ArrayList<Preference>();
for (final String pluginName : plugins) { for (final String pluginName : plugins) {
CheckBoxPreference pref = new CheckBoxPreference(getBaseContext()); final CheckBoxPreference pref = new CheckBoxPreference(getBaseContext());
PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(getBaseContext(), pluginName); PluginFactory.PluginInfo info = PluginFactory.getPluginInfo(getBaseContext(), pluginName);
pref.setKey(pluginName); pref.setKey(pluginName);
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(pluginName));
preferences.add(pref); 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)); setListAdapter(new PreferenceListAdapter(SettingsActivity.this, preferences));
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { 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()); pref.setChecked(!enabled);
device.setPluginEnabled(pref.getKey(), !enabled); } else {
Intent intent = new Intent(SettingsActivity.this, PluginSettingsActivity.class);
pref.setChecked(!enabled); 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) 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 {
} }
} }

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="mpris_time_entries">
<item>10 seconds</item>
<item>20 seconds</item>
<item>30 seconds</item>
<item>1 minute</item>
<item>2 minutes</item>
</string-array>
<string-array name="mpris_time_entries_values">
<item>10000000</item>
<item>20000000</item>
<item>30000000</item>
<item>60000000</item>
<item>120000000</item>
</string-array>
</resources>

View File

@ -72,13 +72,19 @@
<string name="mpris_ff">Fast-forward</string> <string name="mpris_ff">Fast-forward</string>
<string name="mpris_next">Next</string> <string name="mpris_next">Next</string>
<string name="mpris_volume">Volume</string> <string name="mpris_volume">Volume</string>
<string name="mpris_settings">Multimedia Settings</string>
<string name="mpris_time_settings_title">Interval Time</string>
<string name="mpris_time_settings_summary">Adjust the time to fast forward or rewind a multimedia file.</string>
<string name="mpris_time_key" translatable="false">mpris_interval_time</string>
<string name="mpris_time_default" translatable="false">10000000</string>
<string name="share_to">Share To...</string> <string name="share_to">Share To...</string>
<string name="protocol_version_older">This device uses an old protocol version</string> <string name="protocol_version_older">This device uses an old protocol version</string>
<string name="protocol_version_newer">This device uses a newer protocol version</string> <string name="protocol_version_newer">This device uses a newer protocol version</string>
<string name="general_settings">General Settings</string> <string name="general_settings">General Settings</string>
<string name="plugin_settings">Settings</string>
<string name="plugin_settings_key" translatable="false">_preferences</string>
<string name="device_name">Device name</string> <string name="device_name">Device name</string>
<string name="device_name_preference_summary">%s</string> <string name="device_name_preference_summary">%s</string>
<string name="invalid_device_name">Invalid device name</string> <string name="invalid_device_name">Invalid device name</string>
<string name="shareplugin_text_saved">Received text, saved to clipboard</string> <string name="shareplugin_text_saved">Received text, saved to clipboard</string>
</resources> </resources>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListPreference
android:id="@+id/mpris_time_preference"
android:key="@string/mpris_time_key"
android:title="@string/mpris_time_settings_title"
android:summary="@string/mpris_time_settings_summary"
android:entries="@array/mpris_time_entries"
android:entryValues="@array/mpris_time_entries_values"
android:defaultValue="@string/mpris_time_default" />
</PreferenceScreen>