====== Differences ====== This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
import_a_script_directly_into_ll [2015/02/02 21:12] lm13 |
import_a_script_directly_into_ll [2016/01/23 21:46] (current) lm13 |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | **//This is only a preview. The Repository Importer is not yet avialable.//** | + | ==== External API: Manage Scripts ==== |
| + | Add this to build.gradle of your apps module: | ||
| + | <sxh java> | ||
| + | dependencies { | ||
| + | compile 'com.faendir.lightninglauncher:scriptlib:versioncode' | ||
| + | //other dependencies... | ||
| + | }</sxh> | ||
| + | and replace //versioncode// with the latest version available. | ||
| + | (You can check for the latest version [[https://bintray.com/f43nd1r/maven/scriptlib/view|here]]) | ||
| - | In the Activity which wants to import a script add: | + | Now you can import the class ''com.faendir.lightning_launcher.scriptlib.ScriptManager'' in any of your modules files. |
| - | <sxh java;> | + | The ''ScriptManager'' provides several static methods: |
| - | @Override | + | |
| - | protected void onNewIntent(Intent intent) { | + | |
| - | super.onNewIntent(intent); | + | |
| - | if(intent.hasExtra("loadedScriptId")){ | + | |
| - | int id = (int)intent.getDoubleExtra("loadedScriptId",-1); | + | |
| - | //do something with id | + | |
| - | } | + | |
| - | // ... | + | |
| - | } | + | |
| - | } | + | |
| - | + | ||
| - | void loadScript(String code,String name,int flags){ | + | |
| - | Intent intent = new Intent("net.pierrox.lightning_launcher.script.IMPORT"); | + | |
| - | ResolveInfo info = getPackageManager().resolveService(intent,0); | + | |
| - | if(info == null) { | + | |
| - | new AlertDialog.Builder(this) | + | |
| - | .setTitle("Repository Importer missing") | + | |
| - | .setMessage("This action requires the Repository Importer to be installed. Do you wish to install it?") | + | |
| - | .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { | + | |
| - | @Override | + | |
| - | public void onClick(DialogInterface dialogInterface, int i) { | + | |
| - | dialogInterface.dismiss(); | + | |
| - | } | + | |
| - | }) | + | |
| - | .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { | + | |
| - | @Override | + | |
| - | public void onClick(DialogInterface dialogInterface, int i) { | + | |
| - | dialogInterface.dismiss(); | + | |
| - | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.trianguloy.llscript.repository"))); | + | |
| - | } | + | |
| - | }) | + | |
| - | .show(); | + | |
| - | } | + | |
| - | else { | + | |
| - | intent.setClassName(info.serviceInfo.packageName,info.serviceInfo.name); | + | |
| - | intent.putExtra("code",code); | + | |
| - | intent.putExtra("name",name); | + | |
| - | intent.putExtra("flags",flags); | + | |
| - | intent.putExtra("receiver",getComponentName().flattenToString()); | + | |
| - | intent.putExtra("forceUpdate",true); | + | |
| - | startService(intent); | + | |
| - | } | + | |
| - | } | + | |
| - | void runScript(int id, String data){ | + | Method signatures: (v1.6.7 for Repository Importer 1.10, possibly compatible with older versions) |
| - | Intent i = new Intent(Intent.ACTION_VIEW); | + | <sxh java;>loadScript(Context context, String code / int codeResourceId, String name, int flags, boolean forceUpdate, final Listener listener)</sxh> |
| - | i.setClassName("net.pierrox.lightning_launcher_extreme","net.pierrox.lightning_launcher.activities.Dashboard"); | + | * ''context'' can be any context |
| - | i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | + | * ''code'' the code the script should have / ''codeResourceId'' the raw resource id containing the script code |
| - | i.putExtra("a", 35); | + | * ''name'' name for the new script. Be sure to use as unique names for scripts as possible, because if a script with the same name already exists, it may be overwritten. It may be a good idea to start your script name with your projects name (e.g. "layoutmanager_save"). |
| - | i.putExtra("d", id + "/" + data); | + | * ''flags'' sum of flags for the script |
| - | startActivity(i); | + | * 2: App menu |
| - | } | + | * 4: Item menu |
| - | </sxh> | + | * 8: Custom Menu |
| + | * ''forceUpdate'' (optional, default is true) Whether to directly overwrite a script with the same name or not. **If this is set to false, you have to implement the confirmUpdate method in your listener.** | ||
| + | * ''listener'' a ''ScriptManager.listener'' which will retrieve the ID once the script is loaded | ||
| - | In your AndroidManifest.xml: | + | <sxh java;>runScript(Context context, int id, String data, boolean background) </sxh> |
| - | <sxh XML;> | + | * ''context'' can be any context |
| - | <uses-permission android:name="net.pierrox.lightning_launcher.IMPORT_SCRIPTS"/> | + | * ''id'' the id of the script which should be run, usually as returned by a ''ScriptManager.listener'' |
| - | </sxh> | + | * ''data'' an optional string containing additional data. Can be retrieved in the script with ''LL.getEvent().getData()'' |
| + | * ''background'' (optional, default is false) whether this script should run in the background or not | ||
| - | Then you can simply call loadScript in your Activity with valid data to install the script and with the retrieved ID you can call runScript to run that script. | + | <sxh java;>enableDebug()</sxh> |
| + | * Call this method to see extensive Log output from the library | ||
| - | This requires the Repository Importer to be installed on the device. | + | <sxh java;>askForRepositoryImporterInstallationIfMissing(boolean value)</sxh> |
| + | * By Default the library shows a dialog when the Repository Importer is missing. With this method you can disable/enable that at will. | ||
| + | |||
| + | <sxh java;>sendIntentToLauncher(Context context, Intent intent)</sxh> | ||
| + | * ''context'' can be any context | ||
| + | * ''intent'' is the intent which should be sent | ||
| + | |||
| + | <sxh java;>replaceLogger(Logger logger)</sxh> | ||
| + | * ''logger'' a logger. Use this if you want to log to an alternative place (subclass Logger) | ||
| + | |||
| + | Listener methods: | ||
| + | <sxh java;>onLoadFinished(int id);</sxh> | ||
| + | * This method is called when the load succeeded with the ID of the imported script | ||
| + | |||
| + | <sxh java;>onError()</sxh> | ||
| + | * Implement this method if you want to receive a callback when an error occurs (recommended). Do not call super.onError(). | ||
| + | |||
| + | <sxh java;>confirmUpdate(UpdateCallback callback)</sxh> | ||
| + | * Implement this method if you've set the forceUpdate flag to false. You can e.g. show a Dialog here asking the user what to do. You have to call callback.callback with a result (boolean) afterwards. | ||
| + | |||
| + | |||
| + | **//Hint: This requires the Repository Importer to be installed on the android device.//** | ||