Commit e2b2e91f authored by Albert Vaca Cintora's avatar Albert Vaca Cintora
Browse files

Improvements to plugins settings.

Added a startPreferencesActivity method to Plugin so we don't need to do a
hack to launch a custom activity for the notifications plugin.

CCMAIL: grg.vineet@gmail.com
parent 5e905ddd
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<activity <activity
android:name="org.kde.kdeconnect.UserInterface.SettingsActivity" android:name="org.kde.kdeconnect.UserInterface.SettingsActivity"
android:label="@string/settings" android:label="@string/device_menu_plugins"
android:parentActivityName="org.kde.kdeconnect.UserInterface.DeviceActivity" android:parentActivityName="org.kde.kdeconnect.UserInterface.DeviceActivity"
> >
<meta-data android:name="android.support.PARENT_ACTIVITY" <meta-data android:name="android.support.PARENT_ACTIVITY"
...@@ -101,7 +101,7 @@ ...@@ -101,7 +101,7 @@
<activity <activity
android:name="org.kde.kdeconnect.UserInterface.PluginSettingsActivity" android:name="org.kde.kdeconnect.UserInterface.PluginSettingsActivity"
android:label="@string/mpris_settings" android:label="@string/device_menu_plugins"
android:parentActivityName="org.kde.kdeconnect.UserInterface.SettingsActivity" android:parentActivityName="org.kde.kdeconnect.UserInterface.SettingsActivity"
> >
<meta-data android:name="android.support.PARENT_ACTIVITY" <meta-data android:name="android.support.PARENT_ACTIVITY"
...@@ -194,6 +194,7 @@ ...@@ -194,6 +194,7 @@
android:name="android.support.PARENT_ACTIVITY" android:name="android.support.PARENT_ACTIVITY"
android:value="org.kde.kdeconnect.UserInterface.PluginSettingsActivity" /> android:value="org.kde.kdeconnect.UserInterface.PluginSettingsActivity" />
</activity> </activity>
</application> </application>
</manifest> </manifest>
...@@ -29,21 +29,25 @@ ...@@ -29,21 +29,25 @@
<string name="open_mpris_controls">Open remote control</string> <string name="open_mpris_controls">Open remote control</string>
<string name="open_mousepad">Open touchpad control</string> <string name="open_mousepad">Open touchpad control</string>
<string name="mousepad_info">Move a finger on the screen to move the mouse cursor</string> <string name="mousepad_info">Move a finger on the screen to move the mouse cursor</string>
<string name="mousepad_double_tap_settings_title">Set two finger tap action</string>
<string name="mousepad_triple_tap_settings_title">Set three finger tap action</string>
<string name="mousepad_double_tap_key" translatable="false">mousepad_double_tap_key</string> <string name="mousepad_double_tap_key" translatable="false">mousepad_double_tap_key</string>
<string name="mousepad_triple_tap_key" translatable="false">mousepad_triple_tap_key</string> <string name="mousepad_triple_tap_key" translatable="false">mousepad_triple_tap_key</string>
<string name="mousepad_right_value" translatable="false">right</string> <string-array name="mousepad_tap_entries">
<string name="mousepad_middle_value" translatable="false">middle</string> <item>Right click</item>
<string name="mousepad_double_tap_settings_title">Set Two Finger Tap Action</string> <item>Middle click</item>
<string name="mousepad_double_default" translatable="false">@string/mousepad_right_value</string> </string-array>
<string name="mousepad_triple_default" translatable="false">@string/mousepad_middle_value</string> <string name="mousepad_double_default">right</string>
<string name="mousepad_triple_tap_settings_title">Set Three Finger Tap Action</string> <string name="mousepad_triple_default">middle</string>
<string name="mousepad_right_click">Right click</string> <string-array name="mousepad_tap_values" translatable="false">
<string name="mousepad_middle_click">Middle click</string> <item>right</item>
<item>middle</item>
</string-array>
<string name="category_connected_devices">Connected devices</string> <string name="category_connected_devices">Connected devices</string>
<string name="category_not_paired_devices">Available devices</string> <string name="category_not_paired_devices">Available devices</string>
<string name="category_remembered_devices">Remembered devices</string> <string name="category_remembered_devices">Remembered devices</string>
<string name="plugins_failed_to_load">Plugins failed to load (tap for more info):</string> <string name="plugins_failed_to_load">Plugins failed to load (tap for more info):</string>
<string name="device_menu_plugins">Select plugins</string> <string name="device_menu_plugins">Plugin settings</string>
<string name="device_menu_unpair">Unpair</string> <string name="device_menu_unpair">Unpair</string>
<string name="device_not_reachable">Paired device not reachable</string> <string name="device_not_reachable">Paired device not reachable</string>
<string name="unknown_device">Unknown device</string> <string name="unknown_device">Unknown device</string>
...@@ -83,17 +87,30 @@ ...@@ -83,17 +87,30 @@
<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_settings">Multimedia Settings</string>
<string name="mpris_time_settings_title">Interval Time</string> <string name="mpris_time_settings_title">Forward/rewind buttons</string>
<string name="mpris_time_settings_summary">Adjust the time to fast forward or rewind a multimedia file.</string> <string name="mpris_time_settings_summary">Adjust the time to fast forward/rewind when pressed.</string>
<string name="mpris_time_key" translatable="false">mpris_interval_time</string> <string name="mpris_time_key" translatable="false">mpris_interval_time</string>
<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 name="mpris_time_default" translatable="false">10000000</string> <string name="mpris_time_default" translatable="false">10000000</string>
<string-array name="mpris_time_entries_values" translatable="false">
<item>10000000</item>
<item>20000000</item>
<item>30000000</item>
<item>60000000</item>
<item>120000000</item>
</string-array>
<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">Settings</string>
<string name="plugin_settings_with_name">%s settings</string> <string name="plugin_settings_with_name">%s 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>
...@@ -103,7 +120,7 @@ ...@@ -103,7 +120,7 @@
<string name="share_notification_preference">Noisy notifications</string> <string name="share_notification_preference">Noisy notifications</string>
<string name="share_notification_preference_summary">Vibrate and play a sound when receiving a file</string> <string name="share_notification_preference_summary">Vibrate and play a sound when receiving a file</string>
<string name="title_activity_notification_filter">Notification filter</string> <string name="title_activity_notification_filter">Notification filter</string>
<string name="filter_apps_info">Notifications will be synchronized for selected applications</string> <string name="filter_apps_info">Notifications will be synchronized for the selected apps.</string>
<string name="sftp_internal_storage">Internal storage</string> <string name="sftp_internal_storage">Internal storage</string>
<string name="sftp_all_files">All files</string> <string name="sftp_all_files">All files</string>
<string name="sftp_sdcard_num">SD card %d</string> <string name="sftp_sdcard_num">SD card %d</string>
...@@ -115,29 +132,4 @@ ...@@ -115,29 +132,4 @@
<string name="custom_dev_list_help">Use this option only if your device is not automatically detected. Enter IP address or hostname below and touch the button to add it to the list. Touch an existing item to remove it from the list.</string> <string name="custom_dev_list_help">Use this option only if your device is not automatically detected. Enter IP address or hostname below and touch the button to add it to the list. Touch an existing item to remove it from the list.</string>
<string name="mpris_player_on_device">%1$s on %2$s</string> <string name="mpris_player_on_device">%1$s on %2$s</string>
<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" translatable="false">
<item>10000000</item>
<item>20000000</item>
<item>30000000</item>
<item>60000000</item>
<item>120000000</item>
</string-array>
<string-array name="mousepad_tap_entries" translatable="false">
<item>@string/mousepad_right_click</item>
<item>@string/mousepad_middle_click</item>
</string-array>
<string-array name="mousepad_tap_values" translatable="false">
<item>@string/mousepad_right_value</item>
<item>@string/mousepad_middle_value</item>
</string-array>
</resources> </resources>
...@@ -558,7 +558,15 @@ public class Device implements BaseLink.PackageReceiver { ...@@ -558,7 +558,15 @@ public class Device implements BaseLink.PackageReceiver {
// //
public Plugin getPlugin(String name) { public Plugin getPlugin(String name) {
return plugins.get(name); return getPlugin(name, false);
}
public Plugin getPlugin(String name, boolean includeFailed) {
Plugin plugin = plugins.get(name);
if (includeFailed && plugin == null) {
plugin = failedPlugins.get(name);
}
return plugin;
} }
private synchronized void addPlugin(final String name) { private synchronized void addPlugin(final String name) {
......
...@@ -38,6 +38,7 @@ import org.kde.kdeconnect.Helpers.AppsHelper; ...@@ -38,6 +38,7 @@ import org.kde.kdeconnect.Helpers.AppsHelper;
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.UserInterface.DeviceActivity; import org.kde.kdeconnect.UserInterface.DeviceActivity;
import org.kde.kdeconnect.UserInterface.SettingsActivity;
import org.kde.kdeconnect_tp.R; import org.kde.kdeconnect_tp.R;
public class NotificationsPlugin extends Plugin implements NotificationReceiver.NotificationListener { public class NotificationsPlugin extends Plugin implements NotificationReceiver.NotificationListener {
...@@ -67,13 +68,42 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. ...@@ -67,13 +68,42 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
return true; return true;
} }
@Override
public void startPreferencesActivity(final SettingsActivity parentActivity) {
if (hasPermission()) {
Intent intent = new Intent(parentActivity, NotificationFilterActivity.class);
parentActivity.startActivity(intent);
} else {
new AlertDialog.Builder(parentActivity)
.setTitle(R.string.pref_plugin_notifications)
.setMessage(R.string.no_permissions)
.setPositiveButton(R.string.open_settings, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
parentActivity.startActivityForResult(intent, DeviceActivity.RESULT_NEEDS_RELOAD);
}
})
.setNegativeButton(R.string.cancel,new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//Do nothing
}
})
.create().show();
}
}
@Override @Override
public boolean isEnabledByDefault() { public boolean isEnabledByDefault() {
return true; return true;
} }
private boolean hasPermission() {
String notificationListenerList = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners");
return (notificationListenerList != null && notificationListenerList.contains(context.getPackageName()));
}
static class NotificationId { static class NotificationId {
String packageName; String packageName;
...@@ -136,9 +166,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver. ...@@ -136,9 +166,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
return false; return false;
} }
//Check for permissions if (hasPermission()) {
String notificationListenerList = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners");
if (notificationListenerList != null && notificationListenerList.contains(context.getPackageName())) {
NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() { NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() {
@Override @Override
public void onServiceStart(NotificationReceiver service) { public void onServiceStart(NotificationReceiver service) {
......
...@@ -23,18 +23,22 @@ package org.kde.kdeconnect.Plugins; ...@@ -23,18 +23,22 @@ package org.kde.kdeconnect.Plugins;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.preference.PreferenceActivity;
import android.widget.Button; import android.widget.Button;
import org.kde.kdeconnect.Device; 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.SettingsActivity;
public abstract class Plugin { public abstract class Plugin {
protected Device device; protected Device device;
protected Context context; protected Context context;
public void setContext(Context context, Device device) { public final void setContext(Context context, Device device) {
this.device = device; this.device = device;
this.context = context; this.context = context;
} }
...@@ -71,12 +75,24 @@ public abstract class Plugin { ...@@ -71,12 +75,24 @@ public abstract class Plugin {
*/ */
public abstract boolean isEnabledByDefault(); public abstract boolean isEnabledByDefault();
/** /**
* Return true if this plugin needs an specific UI settings. * Return true if this plugin needs an specific UI settings.
*/ */
public abstract boolean hasSettings(); public abstract boolean hasSettings();
/**
* If hasSettings returns true, this will be called when the user
* wants to access this plugin preferences and should launch some
* kind of interface. The default implementation will launch a
* SettingsActivity with content from "yourplugin"_preferences.xml.
*/
public void startPreferencesActivity(SettingsActivity parentActivity) {
Intent intent = new Intent(parentActivity, PluginSettingsActivity.class);
intent.putExtra("plugin_display_name", getDisplayName());
intent.putExtra("plugin_name", getPluginName());
parentActivity.startActivity(intent);
}
/** /**
* 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.
......
...@@ -20,12 +20,10 @@ ...@@ -20,12 +20,10 @@
package org.kde.kdeconnect.UserInterface; package org.kde.kdeconnect.UserInterface;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.util.Log;
import org.kde.kdeconnect.Plugins.NotificationsPlugin.NotificationFilterActivity; import org.kde.kdeconnect_tp.R;
public class PluginSettingsActivity extends PreferenceActivity { public class PluginSettingsActivity extends PreferenceActivity {
...@@ -33,14 +31,12 @@ public class PluginSettingsActivity extends PreferenceActivity { ...@@ -33,14 +31,12 @@ public class PluginSettingsActivity extends PreferenceActivity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
String resource_name = getIntent().getStringExtra(Intent.EXTRA_INTENT); String pluginDisplayName = getIntent().getStringExtra("plugin_display_name");
if (resource_name.equals("plugin_notifications_preferences")){ setTitle(getString(R.string.plugin_settings_with_name, pluginDisplayName));
Intent intent = new Intent(PluginSettingsActivity.this,NotificationFilterActivity.class);
startActivity(intent); String pluginName = getIntent().getStringExtra("plugin_name");
finish(); int resFile = getResources().getIdentifier(pluginName + "_preferences", "xml", getPackageName());
}else { addPreferencesFromResource(resFile);
int resource_file = getResources().getIdentifier(resource_name, "xml", getPackageName());
addPreferencesFromResource(resource_file);
}
} }
} }
...@@ -26,11 +26,13 @@ import android.preference.CheckBoxPreference; ...@@ -26,11 +26,13 @@ import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.util.Log;
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.Plugin;
import org.kde.kdeconnect.Plugins.PluginFactory; import org.kde.kdeconnect.Plugins.PluginFactory;
import org.kde.kdeconnect_tp.R; import org.kde.kdeconnect_tp.R;
...@@ -72,7 +74,7 @@ public class SettingsActivity extends PreferenceActivity { ...@@ -72,7 +74,7 @@ public class SettingsActivity extends PreferenceActivity {
if (info.hasSettings()) { if (info.hasSettings()) {
final Preference pluginPreference = new Preference(getBaseContext()); final Preference pluginPreference = new Preference(getBaseContext());
pluginPreference.setKey(pluginName + getString(R.string.plugin_settings_key)); pluginPreference.setKey(pluginName + "_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);
...@@ -84,16 +86,16 @@ public class SettingsActivity extends PreferenceActivity { ...@@ -84,16 +86,16 @@ public class SettingsActivity extends PreferenceActivity {
@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 pref = preferences.get(i); Preference pref = preferences.get(i);
if (pref.getDependency() == null) { //Is a plugin check if (pref.getDependency() == null) { //Is a check to enable/disable a plugin
CheckBoxPreference check = (CheckBoxPreference)pref; CheckBoxPreference check = (CheckBoxPreference)pref;
boolean enabled = device.isPluginEnabled(pref.getKey()); boolean enabled = device.isPluginEnabled(pref.getKey());
device.setPluginEnabled(pref.getKey(), !enabled); device.setPluginEnabled(pref.getKey(), !enabled);
check.setChecked(!enabled); check.setChecked(!enabled);
} else { //Is a plugin suboption } else { //Is a plugin suboption
if (pref.isEnabled()) { if (pref.isEnabled()) {
Intent intent = new Intent(SettingsActivity.this, PluginSettingsActivity.class); String pluginName = pref.getDependency(); //The parent pref will be named like the plugin
intent.putExtra(Intent.EXTRA_INTENT, pref.getKey()); Plugin plugin = device.getPlugin(pluginName, true);
startActivity(intent); plugin.startPreferencesActivity(SettingsActivity.this);
} }
} }
} }
...@@ -102,6 +104,5 @@ public class SettingsActivity extends PreferenceActivity { ...@@ -102,6 +104,5 @@ public class SettingsActivity extends PreferenceActivity {
}); });
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment