mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-28 12:47:43 +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:
parent
b9a0b3d2f0
commit
b2fa8ab506
@ -88,6 +88,15 @@
|
||||
android:value="org.kde.kdeconnect.UserInterface.DeviceActivity" />
|
||||
</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">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.PACKAGE_REPLACED" />
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -38,6 +38,11 @@ public class MousePadPlugin extends Plugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSettings() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
return true;
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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) {
|
||||
|
@ -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;}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<Preference> preferences = new ArrayList<Preference>();
|
||||
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 {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
18
src/main/res/values/arrays.xml
Normal file
18
src/main/res/values/arrays.xml
Normal 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>
|
@ -72,13 +72,19 @@
|
||||
<string name="mpris_ff">Fast-forward</string>
|
||||
<string name="mpris_next">Next</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="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="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_preference_summary">%s</string>
|
||||
<string name="invalid_device_name">Invalid device name</string>
|
||||
<string name="shareplugin_text_saved">Received text, saved to clipboard</string>
|
||||
|
||||
</resources>
|
||||
|
15
src/main/res/xml/plugin_mpris_preferences.xml
Normal file
15
src/main/res/xml/plugin_mpris_preferences.xml
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user