For those that want to modify this for another device, here's some useful points:
- The class PluginManager in AnkiDroid detects/enables/disables plugins and builds the relevant entries in the Preferences based on which plugins are installed.
- The PluginManager detects as plugins anything that listens to intent "com.ichi2.anki.plugin.action.USE_PLUGIN". It then tries to identify what kind of plugin it is, so that the right interface/protocol can be used.
Obviously right now there's only one type called controller and is identified by the category of the intent which must be "com.ichi2.anki.plugin.controller" for controllers.
- All controller plugins are supposed to be handled by class Controller manager. It does a lot of things:
1) It asks the plugin manager if there is any controller plugin enabled (and installed).
2) If found, it tries to enable and goes through an initialization phase that is captured by modes:
- isBound, meaning the plugin service has started and it can send and receive messages to AnkiDroid.
- isConnecting, the service is waiting for connection to the controller to be established.
- isConnected, controller is connected.
- isListening, ankidroid is listening for controller actions, meaning the plugin service should send them to ControllerManager and ControllerManager should propagate them to listening activity.
3) Keep track of which activity is listening for controller actions.
4) Shutdown the plugin on exit.
- The ControllerManager itself is controlled by activities (or FragmentActivities) that inherit from AnkiControllableActivity (or AnkiControllableFragmentedActivity) and that implement IAnkiControllable interface. Most of these should just implement the handleControllerMessage method that tells the activity how to interpret the controller actions and the getSupportedControllerActions, the latter not ready yet.
- The entry activity of AnkiDroid (DeckPicker) also overrides the canStartController and canStopController so that they return true. This is the only activity that asks the ControllerManager to enable/disable of the plugin. The other activities can listen for actions, but can't start/stop the plugin.
- The mapping of actions that Activities support and Actions that Controller supports should happen on the ControllerManager level, so that the activities don't have to know anything specific to the controller-type. Basically the activities provide the manager with what actions they can do and the controller plugin provides the manager with all available actions it can do and a preference screen should let the user decide to map this to that.
The controller plugin should also provide a default mapping, in case the user hasn't defined one.
Let me know if you have any suggestions for the ControllerManager workflow as it should cater for all different types of devices we want to support. I'll try to write up a more comprehensive description of the initialization process.
Kostas
On Friday, 12 October 2012 08:26:39 UTC+1, Ruz wrote: