From 2054b5f7902d780a826e4145cef3531e7e5d6861 Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Wed, 12 Feb 2014 14:53:31 +0100 Subject: [PATCH] added 'add external plugin' button to IITC plugins preference. ensures that the scripts are always copied to the correct folder. --- mobile/res/drawable-hdpi/ic_action_new.png | Bin 0 -> 262 bytes mobile/res/drawable-mdpi/ic_action_new.png | Bin 0 -> 185 bytes mobile/res/drawable-xhdpi/ic_action_new.png | Bin 0 -> 250 bytes mobile/res/drawable-xxhdpi/ic_action_new.png | Bin 0 -> 288 bytes mobile/res/menu/plugins.xml | 12 +++ mobile/res/values/strings.xml | 6 +- .../IITC_PluginPreferenceActivity.java | 75 +++++++++++++++++- website/page/faq.php | 10 +-- 8 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 mobile/res/drawable-hdpi/ic_action_new.png create mode 100644 mobile/res/drawable-mdpi/ic_action_new.png create mode 100644 mobile/res/drawable-xhdpi/ic_action_new.png create mode 100644 mobile/res/drawable-xxhdpi/ic_action_new.png create mode 100644 mobile/res/menu/plugins.xml diff --git a/mobile/res/drawable-hdpi/ic_action_new.png b/mobile/res/drawable-hdpi/ic_action_new.png new file mode 100644 index 0000000000000000000000000000000000000000..d866d6160db2dade92436e92401864bf79ab37f9 GIT binary patch literal 262 zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTC$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1GD?D8sLn>~)nSPMBK|z4!;0>128*SSfO(WZG({C@e<@zQ{J^CA$J^9^h-4+HW z4uu9V;m}>FaPIT6gtre({HFI@`KRUogk{zopr05h*# A?EnA( literal 0 HcmV?d00001 diff --git a/mobile/res/drawable-mdpi/ic_action_new.png b/mobile/res/drawable-mdpi/ic_action_new.png new file mode 100644 index 0000000000000000000000000000000000000000..f17e7980ee9aee545cb23bf93e9b21613278514c GIT binary patch literal 185 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz$r9IylHmNblJdl&R0hYC{G?O` z&)mfH)S%SFl*+=BsWw1G(Vi}jAr-gYOn2mC5a3}6{c~dRo|E${f{)I<>^0$x%HC5M zDbb1y96PG#E}b*crF~7D(!F;|OdJXg4Qn5Lbvcy#A}ws*s|Kr{TRL)zK;aKt8+M77 g+o>-wVv%4tbz9`!VZkj~Kx-I0UHx3vIVCg!07CUbG5`Po literal 0 HcmV?d00001 diff --git a/mobile/res/drawable-xhdpi/ic_action_new.png b/mobile/res/drawable-xhdpi/ic_action_new.png new file mode 100644 index 0000000000000000000000000000000000000000..5508b5c0c80873705bd4a87b5b3f322682b8ecc6 GIT binary patch literal 250 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I1|(Ny7TyC=k|nMYCBgY=CFO}lsSJ)O`AMk? zp1FzXsX?iUDV2pMQ*D5X=6Jd|hE&{ob8{o_0Rq5^R4#zoa!TTmI4pvG3cp7q|nHQyOG-t(>I#F z#D3}eTWRVH4?g^mC}cuY2XL>W2A$!YSA2~)w76%4K0S5*a0S5fcdD8Rv zceE*+xnB=)Yj?TB;6H(ZLxCZ%&M`j0O9;PKB(w9LEqJYWi4o`^fwP(i7(N^q{1!7k Q^CifIp00i_>zopr0M9i`&Hw-a literal 0 HcmV?d00001 diff --git a/mobile/res/menu/plugins.xml b/mobile/res/menu/plugins.xml new file mode 100644 index 00000000..3ea61645 --- /dev/null +++ b/mobile/res/menu/plugins.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/mobile/res/values/strings.xml b/mobile/res/values/strings.xml index 68552943..710a3140 100644 --- a/mobile/res/values/strings.xml +++ b/mobile/res/values/strings.xml @@ -86,9 +86,8 @@
IITC Mobile is able to load external plugins too!

- • create %1$s
- • move *.user.js files there
- • plugins should be listed above the official plugins]]> + Add them by clicking the (+) icon at the top right. + The plugin files have to end with \'.user.js\' and are copied to %1$s
]]>
Share portal you can:
@@ -162,6 +161,7 @@ Clear Cookies Search Debug + Add external plugins Choose account to login Login failed. Search Locations diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java b/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java index 8c63b348..b3157a01 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_PluginPreferenceActivity.java @@ -1,26 +1,32 @@ package com.cradle.iitc_mobile; +import android.content.ActivityNotFoundException; import android.content.Context; +import android.content.Intent; import android.content.res.AssetManager; import android.os.Bundle; import android.os.Environment; import android.preference.PreferenceActivity; import android.text.TextUtils; import android.view.LayoutInflater; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ListAdapter; import android.widget.TextView; +import android.widget.Toast; import com.cradle.iitc_mobile.fragments.PluginsFragment; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -29,6 +35,8 @@ import java.util.TreeMap; public class IITC_PluginPreferenceActivity extends PreferenceActivity { + private final static int COPY_PLUGIN_REQUEST = 1; + private List
mHeaders; // we use a tree map to have a map with alphabetical order // don't initialize the asset plugin map, because it tells us if the settings are started the first time @@ -103,17 +111,75 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { } } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.plugins, menu); + return super.onCreateOptionsMenu(menu); + } + @Override public boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // exit settings when home button (iitc icon) is pressed onBackPressed(); return true; + case R.id.menu_plugins_add: + // create the chooser Intent + final Intent target = new Intent(Intent.ACTION_GET_CONTENT); + // iitcm only parses *.user.js scripts + target.setType("file/*"); + target.addCategory(Intent.CATEGORY_OPENABLE); + + try { + startActivityForResult(Intent.createChooser(target, "Choose file"), COPY_PLUGIN_REQUEST); + } catch (final ActivityNotFoundException e) { + Toast.makeText(this, "No activity to select a file found." + + "Please install a file browser of your choice!", Toast.LENGTH_LONG).show(); + } default: return super.onOptionsItemSelected(item); } } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + switch(requestCode) { + case COPY_PLUGIN_REQUEST: + if (data != null && data.getData() != null) { + String filePath = data.getData().getPath(); + copyPlugin(filePath); + return; + } + break; + default: + super.onActivityResult(requestCode, resultCode, data); + break; + + } + } + + private void copyPlugin(String pluginPath) { + try { + File inFile = new File(pluginPath); + // create IITCm external plugins directory if it doesn't already exist + File pluginsDirectory = getUserPluginsDirectory(); + pluginsDirectory.mkdirs(); + + // create in and out streams and copy plugin + File outFile = new File(pluginsDirectory.getPath() + "/" + inFile.getName()); + InputStream is = new FileInputStream(inFile); + OutputStream os = new FileOutputStream(outFile); + IITC_FileManager.copyStream(is, os, true); + + // invalidate headers to build a fresh preference screen with the new plugin listed + invalidateHeaders(); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + @Override protected boolean isValidFragment(final String s) { return true; @@ -140,10 +206,15 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { return asset_array; } - private File[] getUserPlugins() { + private File getUserPluginsDirectory() { final String iitc_path = Environment.getExternalStorageDirectory().getPath() + "/IITC_Mobile/"; final File directory = new File(iitc_path + "plugins/"); + return directory; + } + + private File[] getUserPlugins() { + final File directory = getUserPluginsDirectory(); File[] files = directory.listFiles(); if (files == null) { files = new File[0]; @@ -164,6 +235,8 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity { if ((userPlugins.length + officialPlugins.length) != (numPlugins + mDeletedPlugins)) { Log.d("new or less plugins found since last start, rebuild preferences"); sAssetPlugins.clear(); + sUserPlugins.clear(); + mDeletedPlugins = 0; setUpPluginPreferenceScreen(); } } diff --git a/website/page/faq.php b/website/page/faq.php index cf706b6b..3c4f1e93 100644 --- a/website/page/faq.php +++ b/website/page/faq.php @@ -158,19 +158,17 @@ From here you can remove/disable individual plugins or IITC itself. END ), -'mobile-plugins' => Array ( "IITC Mobile: Is it possible to add other plugins to IITC Mobile?", +'mobile-plugins' => Array ( "IITC Mobile: Is it possible to add external plugins to IITC Mobile?", <<<'END' Yes it is!
    -
  • Create a folder named "IITC_Mobile" in your home directory.
  • -
  • Inside this folder, create a new folder named "plugins".
  • -
  • Copy all your additional plugins to this folder.
  • -
  • You should see your plugins listed above the official plugins.
  • +
  • Navigate to the IITC Plugins preference screen and click the (+) icon at the top right. You can select the script using a file explorer of your choice.
  • +
  • IITCm creates a new folder in your home directory, named "IITC_Mobile". Inside this folder you'll find a "plugins" folder where all external plugins are copied to.
Note:
  • The filename has to end with *.user.js.
  • -
  • If you don't know where to find your home directory: Enable dev-mode in the settings and follow the hint.
  • +
  • You need a file explorer app installed to add external plugins
END ),