2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-09-04 08:05:10 +00:00

New interface for plugins

This commit is contained in:
Albert Vaca
2015-04-12 00:11:30 -07:00
parent 4d65382fa1
commit 25e1505df0
9 changed files with 99 additions and 193 deletions

View File

@@ -62,16 +62,6 @@ public class BatteryPlugin extends Plugin {
return context.getResources().getDrawable(R.drawable.icon);
}
@Override
public boolean hasSettings() {
return false;
}
@Override
public boolean isEnabledByDefault() {
return true;
}
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent batteryIntent) {
@@ -133,13 +123,4 @@ public class BatteryPlugin extends Plugin {
return true;
}
@Override
public AlertDialog getErrorDialog(Activity deviceActivity) {
return null;
}
@Override
public Button getInterfaceButton(Activity activity) {
return null;
}
}

View File

@@ -28,6 +28,7 @@ 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;
@@ -53,47 +54,26 @@ public class MousePadPlugin extends Plugin {
return context.getResources().getDrawable(R.drawable.icon);
}
@Override
public boolean isEnabledByDefault() {
return true;
}
@Override
public boolean hasSettings() {
return true;
}
@Override
public boolean onCreate() {
public boolean hasMainActivity() {
return true;
}
@Override
public void onDestroy() {
}
@Override
public boolean onPackageReceived(NetworkPackage np) {
return false;
}
@Override
public AlertDialog getErrorDialog(Activity deviceActivity) { return null; }
@Override
public Button getInterfaceButton(final Activity activity) {
Button button = new Button(activity);
button.setText(R.string.open_mousepad);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(activity, MousePadActivity.class);
public void startMainActivity(Activity parentActivity) {
Intent intent = new Intent(parentActivity, MousePadActivity.class);
intent.putExtra("deviceId", device.getDeviceId());
activity.startActivity(intent);
parentActivity.startActivity(intent);
}
});
return button;
@Override
public String getActionName() {
return context.getString(R.string.open_mousepad);
}
public void sendMouseDelta(float dx, float dy) {

View File

@@ -76,11 +76,6 @@ public class MprisPlugin extends Plugin {
return true;
}
@Override
public boolean isEnabledByDefault() {
return true;
}
@Override
public boolean onCreate() {
requestPlayerList();
@@ -267,22 +262,20 @@ public class MprisPlugin extends Plugin {
}
@Override
public AlertDialog getErrorDialog(Activity deviceActivity) {
return null;
public boolean hasMainActivity() {
return true;
}
@Override
public Button getInterfaceButton(final Activity activity) {
Button b = new Button(activity);
b.setText(R.string.open_mpris_controls);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(activity, MprisActivity.class);
public void startMainActivity(Activity parentActivity) {
Intent intent = new Intent(parentActivity, MprisActivity.class);
intent.putExtra("deviceId", device.getDeviceId());
activity.startActivity(intent);
parentActivity.startActivity(intent);
}
});
return b;
@Override
public String getActionName() {
return context.getString(R.string.open_mpris_controls);
}
}

View File

@@ -25,7 +25,6 @@ import android.app.AlertDialog;
import android.app.Notification;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
@@ -59,11 +58,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
return context.getResources().getString(R.string.pref_plugin_notifications_desc);
}
@Override
public Drawable getIcon() {
return context.getResources().getDrawable(R.drawable.icon);
}
@Override
public boolean hasSettings() {
return true;
@@ -79,11 +73,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
}
}
@Override
public boolean isEnabledByDefault() {
return true;
}
private boolean hasPermission() {
String notificationListenerList = Settings.Secure.getString(context.getContentResolver(), "enabled_notification_listeners");
return (notificationListenerList != null && notificationListenerList.contains(context.getPackageName()));
@@ -140,9 +129,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
}
}
@Override
public boolean onCreate() {
@@ -173,7 +159,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
}
@Override
public void onDestroy() {
@@ -190,9 +175,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
}
@Override
public void onNotificationRemoved(StatusBarNotification statusBarNotification) {
NotificationId id = NotificationId.fromNotification(statusBarNotification);
@@ -421,9 +403,4 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
}
}
@Override
public Button getInterfaceButton(Activity activity) {
return null;
}
}

View File

@@ -61,26 +61,6 @@ public class PingPlugin extends Plugin {
return context.getResources().getDrawable(R.drawable.icon);
}
@Override
public boolean hasSettings() {
return false;
}
@Override
public boolean isEnabledByDefault() {
return true;
}
@Override
public boolean onCreate() {
return true;
}
@Override
public void onDestroy() {
}
@Override
public boolean onPackageReceived(NetworkPackage np) {
@@ -125,21 +105,24 @@ public class PingPlugin extends Plugin {
}
@Override
public AlertDialog getErrorDialog(Activity deviceActivity) {
return null;
public String getActionName() {
return context.getString(R.string.send_ping);
}
@Override
public Button getInterfaceButton(Activity activity) {
Button b = new Button(activity);
b.setText(R.string.send_ping);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
public void startMainActivity(Activity activity) {
if (device != null) {
device.sendPackage(new NetworkPackage(NetworkPackage.PACKAGE_TYPE_PING));
}
});
return b;
}
@Override
public boolean hasMainActivity() {
return true;
}
@Override
public boolean displayInContextMenu() {
return true;
}
}

View File

@@ -25,12 +25,14 @@ import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;
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 {
@@ -61,23 +63,37 @@ public abstract class Plugin {
*/
public abstract String getDescription();
/**
* Return the action name displayed in the main activity, that
* will call startMainActivity when clicked
*/
public String getActionName() {
return getDisplayName();
}
/**
* Return an icon associated to this plugin. This function can
* access this.context to load the image from resources.
*/
public abstract Drawable getIcon();
public Drawable getIcon() {
return null;
}
/**
* Return true if this plugin should be enabled on new devices.
* This function can access this.context and perform compatibility
* checks with the Android version, but can not access this.device.
*/
public abstract boolean isEnabledByDefault();
public boolean isEnabledByDefault() {
return true;
}
/**
* Return true if this plugin needs an specific UI settings.
*/
public abstract boolean hasSettings();
public boolean hasSettings() {
return false;
}
/**
* If hasSettings returns true, this will be called when the user
@@ -92,29 +108,52 @@ public abstract class Plugin {
parentActivity.startActivity(intent);
}
/**
* Return true if the plugin should display something in the Device main view
*/
public boolean hasMainActivity() {
return false;
}
/**
* Implement here what your plugin should do when clicked
*/
public void startMainActivity(Activity parentActivity) { }
/**
* Return true if the entry for this app should appear in the context menu instead of the main view
*/
public boolean displayInContextMenu() {
return false;
}
/**
* Initialize the listeners and structures in your plugin.
* Should return true if initialization was successful.
*/
public abstract boolean onCreate();
public boolean onCreate() {
return true;
}
/**
* Finish any ongoing operations, remove listeners... so
* this object could be garbage collected.
*/
public abstract void onDestroy();
public void onDestroy() { }
/**
* If onCreate returns false, should create a dialog explaining
* the problem (and how to fix it, if possible) to the user.
*/
public abstract boolean onPackageReceived(NetworkPackage np);
public boolean onPackageReceived(NetworkPackage np) { return false; }
/**
* If onCreate returns false, should create a dialog explaining
* the problem (and how to fix it, if possible) to the user.
*/
public abstract AlertDialog getErrorDialog(Activity deviceActivity);
public AlertDialog getErrorDialog(Activity deviceActivity) {
return null;
}
/**
* Creates a button that will be displayed in the user interface
@@ -122,7 +161,18 @@ public abstract class Plugin {
* plugin would wants to expose to the user. Return null if no
* button should be displayed.
*/
public abstract Button getInterfaceButton(Activity activity);
@Deprecated
public Button getInterfaceButton(final Activity activity) {
if (!hasMainActivity()) return null;
Button b = new Button(activity);
b.setText(getActionName());
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startMainActivity(activity);
}
});
return b;
}
}

View File

@@ -56,16 +56,6 @@ public class SftpPlugin extends Plugin {
public Drawable getIcon() {
return context.getResources().getDrawable(R.drawable.icon);
}
@Override
public boolean hasSettings() {
return false;
}
@Override
public boolean isEnabledByDefault() { return true; }
@Override
public boolean onCreate() {
server.init(context, device);
return true;
@@ -147,10 +137,4 @@ public class SftpPlugin extends Plugin {
return false;
}
@Override
public AlertDialog getErrorDialog(Activity deviceActivity) { return null; }
@Override
public Button getInterfaceButton(Activity activity) { return null; }
}

View File

@@ -63,36 +63,21 @@ public class SharePlugin extends Plugin {
return context.getResources().getString(R.string.pref_plugin_sharereceiver);
}
@Override
public String getDescription() {
return context.getResources().getString(R.string.pref_plugin_sharereceiver_desc);
}
@Override
public Drawable getIcon() {
return context.getResources().getDrawable(R.drawable.icon);
}
@Override
public String getDescription() {
return context.getResources().getString(R.string.pref_plugin_sharereceiver_desc);
}
@Override
public boolean hasSettings() {
return true;
}
@Override
public boolean isEnabledByDefault() {
return true;
}
@Override
public boolean onCreate() {
return true;
}
@Override
public void onDestroy() {
}
@Override
public boolean onPackageReceived(NetworkPackage np) {
@@ -280,12 +265,4 @@ public class SharePlugin extends Plugin {
return true;
}
@Override
public AlertDialog getErrorDialog(Activity deviceActivity) {
return null;
}
@Override
public Button getInterfaceButton(Activity activity) { return null; }
}

View File

@@ -67,16 +67,6 @@ public class TelephonyPlugin extends Plugin {
return context.getResources().getDrawable(R.drawable.icon);
}
@Override
public boolean isEnabledByDefault() {
return true;
}
@Override
public boolean hasSettings() {
return false;
}
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -235,13 +225,4 @@ public class TelephonyPlugin extends Plugin {
return true;
}
@Override
public AlertDialog getErrorDialog(Activity deviceActivity) {
return null;
}
@Override
public Button getInterfaceButton(Activity activity) {
return null;
}
}