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 00000000..d866d616
Binary files /dev/null and b/mobile/res/drawable-hdpi/ic_action_new.png differ
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 00000000..f17e7980
Binary files /dev/null and b/mobile/res/drawable-mdpi/ic_action_new.png differ
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 00000000..5508b5c0
Binary files /dev/null and b/mobile/res/drawable-xhdpi/ic_action_new.png differ
diff --git a/mobile/res/drawable-xxhdpi/ic_action_new.png b/mobile/res/drawable-xxhdpi/ic_action_new.png
new file mode 100644
index 00000000..c42c2bfb
Binary files /dev/null and b/mobile/res/drawable-xxhdpi/ic_action_new.png differ
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
),