mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-09-01 06:35:09 +00:00
New interface for plugins
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user