Merge branch 'master' of https://github.com/jonatkins/ingress-intel-total-conversion
This commit is contained in:
commit
2c2f89edf8
@ -115,11 +115,11 @@
|
|||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="com.cradle.iitc_mobile.IITC_PreferenceActivity"
|
android:name="com.cradle.iitc_mobile.prefs.PreferenceActivity"
|
||||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
|
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
|
||||||
android:label="@string/activity_settings"/>
|
android:label="@string/activity_settings"/>
|
||||||
<activity
|
<activity
|
||||||
android:name="com.cradle.iitc_mobile.IITC_PluginPreferenceActivity"
|
android:name="com.cradle.iitc_mobile.prefs.PluginPreferenceActivity"
|
||||||
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
|
android:configChanges="orientation|keyboard|keyboardHidden|screenSize"
|
||||||
android:label="@string/activity_plugins"/>
|
android:label="@string/activity_plugins"/>
|
||||||
<activity
|
<activity
|
||||||
|
@ -7,7 +7,7 @@ The Android App behaves like the desktop version, but uses the mobile view, whic
|
|||||||
|
|
||||||
- supports all official IITC plugins
|
- supports all official IITC plugins
|
||||||
|
|
||||||
- easy installation of unofficial plugins (installation via plugin preference, click on *.user.js file or URL, email attachement etc.)
|
- easy installation and update of unofficial plugins (installation via plugin preference, click on *.user.js file or URL, email attachement etc.)
|
||||||
|
|
||||||
- show users current location
|
- show users current location
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ The Android App behaves like the desktop version, but uses the mobile view, whic
|
|||||||
|
|
||||||
- configurable fullscreen modes (includes immersive mode on Android 4.4+)
|
- configurable fullscreen modes (includes immersive mode on Android 4.4+)
|
||||||
|
|
||||||
- navigation drawers for IITC views, layer chooser and highlighters
|
- navigation drawers for IITC panes, layer chooser and highlighters
|
||||||
|
|
||||||
- in-app screenshots
|
- in-app screenshots
|
||||||
|
|
||||||
|
@ -130,6 +130,11 @@
|
|||||||
Note: If just want to use the desktop mode use the \'force desktop mode\' setting</string>
|
Note: If just want to use the desktop mode use the \'force desktop mode\' setting</string>
|
||||||
<string name="pref_android_menu">Configure IITCm menu</string>
|
<string name="pref_android_menu">Configure IITCm menu</string>
|
||||||
<string name="pref_android_menu_sum">Toggle visibility of IITCm menu entries</string>
|
<string name="pref_android_menu_sum">Toggle visibility of IITCm menu entries</string>
|
||||||
|
<string name="pref_update_plugins_cat">User plugin updates</string>
|
||||||
|
<string name="pref_update_plugins_interval">Configure plugin update interval</string>
|
||||||
|
<string name="pref_update_plugins_interval_sum">How often IITCm should search for new plugin versions</string>
|
||||||
|
<string name="pref_force_plugin_update">Force plugin update</string>
|
||||||
|
<string name="pref_force_plugin_update_sum">Update all enabled user plugins</string>
|
||||||
|
|
||||||
<string-array name="pref_hide_fullscreen">
|
<string-array name="pref_hide_fullscreen">
|
||||||
<item>System Bar</item>
|
<item>System Bar</item>
|
||||||
@ -178,6 +183,22 @@
|
|||||||
<item>2</item>
|
<item>2</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_update_plugins_interval_titles">
|
||||||
|
<item>Disable</item>
|
||||||
|
<item>1 day</item>
|
||||||
|
<item>2 days</item>
|
||||||
|
<item>1 week</item>
|
||||||
|
<item>2 weeks</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="pref_update_plugins_interval_values">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
<item>7</item>
|
||||||
|
<item>14</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string name="menu_reload">Reload IITC</string>
|
<string name="menu_reload">Reload IITC</string>
|
||||||
<string name="menu_toggle_fullscreen">Toggle fullscreen</string>
|
<string name="menu_toggle_fullscreen">Toggle fullscreen</string>
|
||||||
<string name="menu_layer_chooser">Layer Chooser</string>
|
<string name="menu_layer_chooser">Layer Chooser</string>
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
android:summary="@string/pref_plugins_sum"
|
android:summary="@string/pref_plugins_sum"
|
||||||
android:title="@string/pref_plugins">
|
android:title="@string/pref_plugins">
|
||||||
<intent
|
<intent
|
||||||
android:targetClass="com.cradle.iitc_mobile.IITC_PluginPreferenceActivity"
|
android:targetClass="com.cradle.iitc_mobile.prefs.PluginPreferenceActivity"
|
||||||
android:targetPackage="com.cradle.iitc_mobile"/>
|
android:targetPackage="com.cradle.iitc_mobile"/>
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|
||||||
@ -92,6 +92,21 @@
|
|||||||
android:key="pref_disable_splash"
|
android:key="pref_disable_splash"
|
||||||
android:title="@string/pref_disable_splash"/>
|
android:title="@string/pref_disable_splash"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="pref_update_plugins"
|
||||||
|
android:title="@string/pref_update_plugins_cat">
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="7"
|
||||||
|
android:entries="@array/pref_update_plugins_interval_titles"
|
||||||
|
android:entryValues="@array/pref_update_plugins_interval_values"
|
||||||
|
android:key="pref_update_plugins_interval"
|
||||||
|
android:title="@string/pref_update_plugins_interval"
|
||||||
|
android:summary="@string/pref_update_plugins_interval_sum"/>
|
||||||
|
<com.cradle.iitc_mobile.prefs.ForceUpdatePreference
|
||||||
|
android:key="pref_force_plugin_update"
|
||||||
|
android:title="@string/pref_force_plugin_update"
|
||||||
|
android:summary="@string/pref_force_plugin_update_sum"/>
|
||||||
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pref_advanced_tweaks_cat"
|
android:key="pref_advanced_tweaks_cat"
|
||||||
android:title="@string/pref_tweaks_cat">
|
android:title="@string/pref_tweaks_cat">
|
||||||
@ -106,7 +121,7 @@
|
|||||||
android:key="pref_about_screen"
|
android:key="pref_about_screen"
|
||||||
android:persistent="false"
|
android:persistent="false"
|
||||||
android:title="@string/pref_about_title">
|
android:title="@string/pref_about_title">
|
||||||
<com.cradle.iitc_mobile.IITC_AboutDialogPreference
|
<com.cradle.iitc_mobile.prefs.AboutDialogPreference
|
||||||
android:dialogIcon="@android:drawable/ic_dialog_info"
|
android:dialogIcon="@android:drawable/ic_dialog_info"
|
||||||
android:key="pref_about"
|
android:key="pref_about"
|
||||||
android:title="@string/pref_about_title"/>
|
android:title="@string/pref_about_title"/>
|
||||||
|
@ -19,6 +19,8 @@ import android.webkit.WebResourceResponse;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.cradle.iitc_mobile.IITC_Mobile.ResponseHandler;
|
import com.cradle.iitc_mobile.IITC_Mobile.ResponseHandler;
|
||||||
|
import com.cradle.iitc_mobile.async.UpdateScript;
|
||||||
|
import com.cradle.iitc_mobile.prefs.PluginPreferenceActivity;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -39,6 +41,8 @@ import java.net.URL;
|
|||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class IITC_FileManager {
|
public class IITC_FileManager {
|
||||||
private static final WebResourceResponse EMPTY =
|
private static final WebResourceResponse EMPTY =
|
||||||
@ -48,7 +52,10 @@ public class IITC_FileManager {
|
|||||||
"script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));\n"
|
"script.appendChild(document.createTextNode('('+ wrapper +')('+JSON.stringify(info)+');'));\n"
|
||||||
+ "(document.body || document.head || document.documentElement).appendChild(script);";
|
+ "(document.body || document.head || document.documentElement).appendChild(script);";
|
||||||
|
|
||||||
|
private long mUpdateInterval = 1000*60*60*24*7;
|
||||||
|
|
||||||
public static final String DOMAIN = ".iitcm.localhost";
|
public static final String DOMAIN = ".iitcm.localhost";
|
||||||
|
// update interval is 2 days by default
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* copies the contents of a stream into another stream and (optionally) closes the output stream afterwards
|
* copies the contents of a stream into another stream and (optionally) closes the output stream afterwards
|
||||||
@ -306,13 +313,44 @@ public class IITC_FileManager {
|
|||||||
if (invalidateHeaders) {
|
if (invalidateHeaders) {
|
||||||
try {
|
try {
|
||||||
thread.join();
|
thread.join();
|
||||||
((IITC_PluginPreferenceActivity) mActivity).invalidateHeaders();
|
((PluginPreferenceActivity) mActivity).invalidateHeaders();
|
||||||
} catch (final InterruptedException e) {
|
} catch (final InterruptedException e) {
|
||||||
Log.w(e);
|
Log.w(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updatePlugins(boolean force) {
|
||||||
|
// do nothing if updates are disabled
|
||||||
|
if (mUpdateInterval == 0 && !force) return;
|
||||||
|
// check last script update
|
||||||
|
final long lastUpdated = mPrefs.getLong("pref_last_plugin_update", 0);
|
||||||
|
final long now = System.currentTimeMillis();
|
||||||
|
|
||||||
|
// return if no update wanted
|
||||||
|
if ((now - lastUpdated < mUpdateInterval) && !force) return;
|
||||||
|
// get the plugin preferences
|
||||||
|
final TreeMap<String, ?> all_prefs = new TreeMap<String, Object>(mPrefs.getAll());
|
||||||
|
|
||||||
|
// iterate through all plugins
|
||||||
|
for (final Map.Entry<String, ?> entry : all_prefs.entrySet()) {
|
||||||
|
final String plugin = entry.getKey();
|
||||||
|
if (plugin.endsWith(".user.js") && entry.getValue().toString().equals("true")) {
|
||||||
|
if (plugin.startsWith(PLUGINS_PATH)) {
|
||||||
|
new UpdateScript(mActivity).execute(plugin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mPrefs
|
||||||
|
.edit()
|
||||||
|
.putLong("pref_last_plugin_update", now)
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUpdateInterval(int interval) {
|
||||||
|
mUpdateInterval = 1000*60*60*24 * interval;
|
||||||
|
}
|
||||||
|
|
||||||
private class FileRequest extends WebResourceResponse implements ResponseHandler, Runnable {
|
private class FileRequest extends WebResourceResponse implements ResponseHandler, Runnable {
|
||||||
private Intent mData;
|
private Intent mData;
|
||||||
private final String mFunctionName;
|
private final String mFunctionName;
|
||||||
|
@ -40,6 +40,8 @@ import android.widget.TextView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
|
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
|
||||||
|
import com.cradle.iitc_mobile.prefs.PluginPreferenceActivity;
|
||||||
|
import com.cradle.iitc_mobile.prefs.PreferenceActivity;
|
||||||
import com.cradle.iitc_mobile.share.ShareActivity;
|
import com.cradle.iitc_mobile.share.ShareActivity;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -145,6 +147,7 @@ public class IITC_Mobile extends Activity
|
|||||||
mIitcWebView.updateFullscreenStatus();
|
mIitcWebView.updateFullscreenStatus();
|
||||||
|
|
||||||
mFileManager = new IITC_FileManager(this);
|
mFileManager = new IITC_FileManager(this);
|
||||||
|
mFileManager.setUpdateInterval(Integer.parseInt(mSharedPrefs.getString("pref_update_plugins_interval", "7")));
|
||||||
|
|
||||||
mUserLocation = new IITC_UserLocation(this);
|
mUserLocation = new IITC_UserLocation(this);
|
||||||
mUserLocation.setLocationMode(Integer.parseInt(mSharedPrefs.getString("pref_user_location_mode", "0")));
|
mUserLocation.setLocationMode(Integer.parseInt(mSharedPrefs.getString("pref_user_location_mode", "0")));
|
||||||
@ -191,6 +194,14 @@ public class IITC_Mobile extends Activity
|
|||||||
return;
|
return;
|
||||||
} else if (key.equals("pref_fake_user_agent")) {
|
} else if (key.equals("pref_fake_user_agent")) {
|
||||||
mIitcWebView.setUserAgent();
|
mIitcWebView.setUserAgent();
|
||||||
|
} else if (key.equals("pref_last_plugin_update")) {
|
||||||
|
Long forceUpdate = sharedPreferences.getLong("pref_last_plugin_update", 0);
|
||||||
|
if (forceUpdate == 0) mFileManager.updatePlugins(true);
|
||||||
|
return;
|
||||||
|
} else if (key.equals("pref_update_plugins_interval")) {
|
||||||
|
final int interval = Integer.parseInt(mSharedPrefs.getString("pref_update_plugins_interval", "7"));
|
||||||
|
mFileManager.setUpdateInterval(interval);
|
||||||
|
return;
|
||||||
} else if (key.equals("pref_press_twice_to_exit")
|
} else if (key.equals("pref_press_twice_to_exit")
|
||||||
|| key.equals("pref_share_selected_tab")
|
|| key.equals("pref_share_selected_tab")
|
||||||
|| key.equals("pref_messages")
|
|| key.equals("pref_messages")
|
||||||
@ -248,7 +259,7 @@ public class IITC_Mobile extends Activity
|
|||||||
final String type = intent.getType() == null ? "" : intent.getType();
|
final String type = intent.getType() == null ? "" : intent.getType();
|
||||||
final String path = uri.getPath() == null ? "" : uri.getPath();
|
final String path = uri.getPath() == null ? "" : uri.getPath();
|
||||||
if (path.endsWith(".user.js") || type.contains("javascript")) {
|
if (path.endsWith(".user.js") || type.contains("javascript")) {
|
||||||
final Intent prefIntent = new Intent(this, IITC_PluginPreferenceActivity.class);
|
final Intent prefIntent = new Intent(this, PluginPreferenceActivity.class);
|
||||||
prefIntent.setDataAndType(uri, intent.getType());
|
prefIntent.setDataAndType(uri, intent.getType());
|
||||||
startActivity(prefIntent);
|
startActivity(prefIntent);
|
||||||
}
|
}
|
||||||
@ -565,7 +576,7 @@ public class IITC_Mobile extends Activity
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_settings: // start settings activity
|
case R.id.action_settings: // start settings activity
|
||||||
final Intent intent = new Intent(this, IITC_PreferenceActivity.class);
|
final Intent intent = new Intent(this, PreferenceActivity.class);
|
||||||
try {
|
try {
|
||||||
intent.putExtra("iitc_version", mFileManager.getIITCVersion());
|
intent.putExtra("iitc_version", mFileManager.getIITCVersion());
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
@ -704,6 +715,7 @@ public class IITC_Mobile extends Activity
|
|||||||
mNavigationHelper.onLoadingStateChanged();
|
mNavigationHelper.onLoadingStateChanged();
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
updateViews();
|
updateViews();
|
||||||
|
if (!isLoading) mFileManager.updatePlugins(false);
|
||||||
|
|
||||||
if (mSearchTerm != null && !isLoading) {
|
if (mSearchTerm != null && !isLoading) {
|
||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(new Runnable() {
|
||||||
|
84
mobile/src/com/cradle/iitc_mobile/async/UpdateScript.java
Normal file
84
mobile/src/com/cradle/iitc_mobile/async/UpdateScript.java
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
package com.cradle.iitc_mobile.async;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import com.cradle.iitc_mobile.IITC_FileManager;
|
||||||
|
import com.cradle.iitc_mobile.IITC_Mobile;
|
||||||
|
import com.cradle.iitc_mobile.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class UpdateScript extends AsyncTask<String, Void, Boolean> {
|
||||||
|
|
||||||
|
private final Activity mActivity;
|
||||||
|
private String mFilePath;
|
||||||
|
private String mScript;
|
||||||
|
|
||||||
|
public UpdateScript(final Activity activity) {
|
||||||
|
mActivity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Boolean doInBackground(final String... urls) {
|
||||||
|
try {
|
||||||
|
mFilePath = urls[0];
|
||||||
|
// get local script meta information
|
||||||
|
mScript = IITC_FileManager.readStream(new FileInputStream(new File(mFilePath)));
|
||||||
|
final String updateURL = IITC_FileManager.getScriptInfo(mScript).get("updateURL");
|
||||||
|
final String downloadURL = IITC_FileManager.getScriptInfo(mScript).get("downloadURL");
|
||||||
|
|
||||||
|
// get remote script meta information
|
||||||
|
final File file_old = new File(mFilePath);
|
||||||
|
final InputStream is = new URL(updateURL).openStream();
|
||||||
|
final String old_version = IITC_FileManager.getScriptInfo(mScript).get("version");
|
||||||
|
final String new_version = IITC_FileManager.getScriptInfo(IITC_FileManager.readStream(is)).get("version");
|
||||||
|
|
||||||
|
// update script if neccessary
|
||||||
|
if (old_version.compareTo(new_version) < 0) {
|
||||||
|
Log.d("plugin " + mFilePath + " outdated\n" + old_version + " vs " + new_version);
|
||||||
|
Log.d("updating file....");
|
||||||
|
IITC_FileManager.copyStream(new URL(downloadURL).openStream(), new FileOutputStream(file_old), true);
|
||||||
|
Log.d("...done");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (final IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void onPostExecute(Boolean updated) {
|
||||||
|
if (updated) {
|
||||||
|
final String name = IITC_FileManager.getScriptInfo(mScript).get("name");
|
||||||
|
new AlertDialog.Builder(mActivity)
|
||||||
|
.setTitle("Plugin updated")
|
||||||
|
.setMessage(name)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton("Reload", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.cancel();
|
||||||
|
((IITC_Mobile) mActivity).reloadIITC();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -16,9 +16,9 @@ import android.view.ViewParent;
|
|||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import com.cradle.iitc_mobile.IITC_AboutDialogPreference;
|
|
||||||
import com.cradle.iitc_mobile.Log;
|
import com.cradle.iitc_mobile.Log;
|
||||||
import com.cradle.iitc_mobile.R;
|
import com.cradle.iitc_mobile.R;
|
||||||
|
import com.cradle.iitc_mobile.prefs.AboutDialogPreference;
|
||||||
|
|
||||||
public class MainSettings extends PreferenceFragment {
|
public class MainSettings extends PreferenceFragment {
|
||||||
@Override
|
@Override
|
||||||
@ -40,7 +40,7 @@ public class MainSettings extends PreferenceFragment {
|
|||||||
Log.w(e);
|
Log.w(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
final IITC_AboutDialogPreference pref_about = (IITC_AboutDialogPreference) findPreference("pref_about");
|
final AboutDialogPreference pref_about = (AboutDialogPreference) findPreference("pref_about");
|
||||||
pref_about.setVersions(iitcVersion, buildVersion);
|
pref_about.setVersions(iitcVersion, buildVersion);
|
||||||
|
|
||||||
final ListPreference pref_user_location_mode = (ListPreference) findPreference("pref_user_location_mode");
|
final ListPreference pref_user_location_mode = (ListPreference) findPreference("pref_user_location_mode");
|
||||||
|
@ -4,9 +4,9 @@ import android.app.ActionBar;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceFragment;
|
import android.preference.PreferenceFragment;
|
||||||
|
|
||||||
import com.cradle.iitc_mobile.IITC_PluginPreference;
|
|
||||||
import com.cradle.iitc_mobile.IITC_PluginPreferenceActivity;
|
|
||||||
import com.cradle.iitc_mobile.R;
|
import com.cradle.iitc_mobile.R;
|
||||||
|
import com.cradle.iitc_mobile.prefs.PluginPreference;
|
||||||
|
import com.cradle.iitc_mobile.prefs.PluginPreferenceActivity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@ -26,11 +26,11 @@ public class PluginsFragment extends PreferenceFragment {
|
|||||||
// get plugins category for this fragments and plugins list
|
// get plugins category for this fragments and plugins list
|
||||||
String category = getArguments().getString("category");
|
String category = getArguments().getString("category");
|
||||||
boolean userPlugin = getArguments().getBoolean("userPlugin");
|
boolean userPlugin = getArguments().getBoolean("userPlugin");
|
||||||
ArrayList<IITC_PluginPreference> prefs =
|
ArrayList<PluginPreference> prefs =
|
||||||
IITC_PluginPreferenceActivity.getPluginPreference(category, userPlugin);
|
PluginPreferenceActivity.getPluginPreference(category, userPlugin);
|
||||||
|
|
||||||
// add plugin checkbox preferences
|
// add plugin checkbox preferences
|
||||||
for (IITC_PluginPreference pref : prefs) {
|
for (PluginPreference pref : prefs) {
|
||||||
getPreferenceScreen().addPreference(pref);
|
getPreferenceScreen().addPreference(pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile.prefs;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
@ -9,11 +9,13 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class IITC_AboutDialogPreference extends Preference {
|
import com.cradle.iitc_mobile.R;
|
||||||
|
|
||||||
|
public class AboutDialogPreference extends Preference {
|
||||||
private String mBuildVersion = "";
|
private String mBuildVersion = "";
|
||||||
private String mIitcVersion = "";
|
private String mIitcVersion = "";
|
||||||
|
|
||||||
public IITC_AboutDialogPreference(Context context, AttributeSet attrs) {
|
public AboutDialogPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.cradle.iitc_mobile.prefs;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.preference.Preference;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
|
||||||
|
import com.cradle.iitc_mobile.R;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The OptionDialogPreference will display a dialog, and will persist the
|
||||||
|
* <code>true</code> when pressing the positive button and <code>false</code>
|
||||||
|
* otherwise. It will persist to the android:key specified in xml-preference.
|
||||||
|
*/
|
||||||
|
public class ForceUpdatePreference extends Preference {
|
||||||
|
|
||||||
|
public ForceUpdatePreference(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onClick() {
|
||||||
|
super.onClick();
|
||||||
|
new AlertDialog.Builder(getContext())
|
||||||
|
.setTitle(R.string.pref_force_plugin_update)
|
||||||
|
.setMessage(R.string.pref_force_plugin_update_sum)
|
||||||
|
.setCancelable(true)
|
||||||
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(getContext())
|
||||||
|
.edit()
|
||||||
|
.putLong("pref_last_plugin_update", 0)
|
||||||
|
.commit();
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create()
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile.prefs;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
@ -7,9 +7,9 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
// multiline checkbox preference
|
// multiline checkbox preference
|
||||||
public class IITC_PluginPreference extends CheckBoxPreference {
|
public class PluginPreference extends CheckBoxPreference {
|
||||||
|
|
||||||
public IITC_PluginPreference(Context context) {
|
public PluginPreference(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile.prefs;
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -18,6 +18,10 @@ import android.widget.ListAdapter;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.cradle.iitc_mobile.IITC_FileManager;
|
||||||
|
import com.cradle.iitc_mobile.IITC_NotificationHelper;
|
||||||
|
import com.cradle.iitc_mobile.Log;
|
||||||
|
import com.cradle.iitc_mobile.R;
|
||||||
import com.cradle.iitc_mobile.fragments.PluginsFragment;
|
import com.cradle.iitc_mobile.fragments.PluginsFragment;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -31,7 +35,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
public class PluginPreferenceActivity extends PreferenceActivity {
|
||||||
|
|
||||||
private final static int COPY_PLUGIN_REQUEST = 1;
|
private final static int COPY_PLUGIN_REQUEST = 1;
|
||||||
|
|
||||||
@ -39,10 +43,10 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
|||||||
// we use a tree map to have a map with alphabetical order
|
// 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
|
// don't initialize the asset plugin map, because it tells us if the settings are started the first time
|
||||||
// and we have to parse plugins to build the preference screen
|
// and we have to parse plugins to build the preference screen
|
||||||
private static TreeMap<String, ArrayList<IITC_PluginPreference>> sAssetPlugins = null;
|
private static TreeMap<String, ArrayList<PluginPreference>> sAssetPlugins = null;
|
||||||
// user plugins can be initialized.
|
// user plugins can be initialized.
|
||||||
private static final TreeMap<String, ArrayList<IITC_PluginPreference>> sUserPlugins =
|
private static final TreeMap<String, ArrayList<PluginPreference>> sUserPlugins =
|
||||||
new TreeMap<String, ArrayList<IITC_PluginPreference>>();
|
new TreeMap<String, ArrayList<PluginPreference>>();
|
||||||
private static int mDeletedPlugins = 0;
|
private static int mDeletedPlugins = 0;
|
||||||
|
|
||||||
private IITC_FileManager mFileManager;
|
private IITC_FileManager mFileManager;
|
||||||
@ -69,7 +73,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
|||||||
// it is enough to parse the plugin only on first start.
|
// it is enough to parse the plugin only on first start.
|
||||||
if (sAssetPlugins == null) {
|
if (sAssetPlugins == null) {
|
||||||
Log.d("opened plugin prefs the first time since app start -> parse plugins");
|
Log.d("opened plugin prefs the first time since app start -> parse plugins");
|
||||||
sAssetPlugins = new TreeMap<String, ArrayList<IITC_PluginPreference>>();
|
sAssetPlugins = new TreeMap<String, ArrayList<PluginPreference>>();
|
||||||
setUpPluginPreferenceScreen();
|
setUpPluginPreferenceScreen();
|
||||||
} else {
|
} else {
|
||||||
checkForNewPlugins();
|
checkForNewPlugins();
|
||||||
@ -170,7 +174,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// called by Plugins Fragment
|
// called by Plugins Fragment
|
||||||
public static ArrayList<IITC_PluginPreference> getPluginPreference(final String key, final boolean userPlugin) {
|
public static ArrayList<PluginPreference> getPluginPreference(final String key, final boolean userPlugin) {
|
||||||
if (userPlugin) return sUserPlugins.get(key);
|
if (userPlugin) return sUserPlugins.get(key);
|
||||||
|
|
||||||
return sAssetPlugins.get(key);
|
return sAssetPlugins.get(key);
|
||||||
@ -203,10 +207,10 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
|||||||
final File[] userPlugins = getUserPlugins();
|
final File[] userPlugins = getUserPlugins();
|
||||||
final String[] officialPlugins = getAssetPlugins();
|
final String[] officialPlugins = getAssetPlugins();
|
||||||
int numPlugins = 0;
|
int numPlugins = 0;
|
||||||
for (final Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sUserPlugins.entrySet()) {
|
for (final Map.Entry<String, ArrayList<PluginPreference>> entry : sUserPlugins.entrySet()) {
|
||||||
numPlugins += entry.getValue().size();
|
numPlugins += entry.getValue().size();
|
||||||
}
|
}
|
||||||
for (final Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sAssetPlugins.entrySet()) {
|
for (final Map.Entry<String, ArrayList<PluginPreference>> entry : sAssetPlugins.entrySet()) {
|
||||||
numPlugins += entry.getValue().size();
|
numPlugins += entry.getValue().size();
|
||||||
}
|
}
|
||||||
if ((userPlugins.length + officialPlugins.length) != (numPlugins + mDeletedPlugins)) {
|
if ((userPlugins.length + officialPlugins.length) != (numPlugins + mDeletedPlugins)) {
|
||||||
@ -267,24 +271,24 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
|||||||
// first check if we need a new category
|
// first check if we need a new category
|
||||||
if (userPlugin) {
|
if (userPlugin) {
|
||||||
if (!sUserPlugins.containsKey(plugin_cat)) {
|
if (!sUserPlugins.containsKey(plugin_cat)) {
|
||||||
sUserPlugins.put(plugin_cat, new ArrayList<IITC_PluginPreference>());
|
sUserPlugins.put(plugin_cat, new ArrayList<PluginPreference>());
|
||||||
Log.d("create " + plugin_cat + " and add " + plugin_name);
|
Log.d("create " + plugin_cat + " and add " + plugin_name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!sAssetPlugins.containsKey(plugin_cat)) {
|
if (!sAssetPlugins.containsKey(plugin_cat)) {
|
||||||
sAssetPlugins.put(plugin_cat, new ArrayList<IITC_PluginPreference>());
|
sAssetPlugins.put(plugin_cat, new ArrayList<PluginPreference>());
|
||||||
Log.d("create " + plugin_cat + " and add " + plugin_name);
|
Log.d("create " + plugin_cat + " and add " + plugin_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now build a new checkable preference for the plugin
|
// now build a new checkable preference for the plugin
|
||||||
final IITC_PluginPreference plugin_pref = new IITC_PluginPreference(this);
|
final PluginPreference plugin_pref = new PluginPreference(this);
|
||||||
plugin_pref.setKey(plugin_key);
|
plugin_pref.setKey(plugin_key);
|
||||||
plugin_pref.setTitle(plugin_name);
|
plugin_pref.setTitle(plugin_name);
|
||||||
plugin_pref.setSummary(plugin_desc);
|
plugin_pref.setSummary(plugin_desc);
|
||||||
plugin_pref.setDefaultValue(false);
|
plugin_pref.setDefaultValue(false);
|
||||||
plugin_pref.setPersistent(true);
|
plugin_pref.setPersistent(true);
|
||||||
final ArrayList<IITC_PluginPreference> list =
|
final ArrayList<PluginPreference> list =
|
||||||
userPlugin ? sUserPlugins.get(plugin_cat) : sAssetPlugins.get(plugin_cat);
|
userPlugin ? sUserPlugins.get(plugin_cat) : sAssetPlugins.get(plugin_cat);
|
||||||
list.add(plugin_pref);
|
list.add(plugin_pref);
|
||||||
}
|
}
|
||||||
@ -294,7 +298,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
|||||||
final Header category = new Header();
|
final Header category = new Header();
|
||||||
category.title = "User Plugins";
|
category.title = "User Plugins";
|
||||||
mHeaders.add(category);
|
mHeaders.add(category);
|
||||||
for (final Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sUserPlugins.entrySet()) {
|
for (final Map.Entry<String, ArrayList<PluginPreference>> entry : sUserPlugins.entrySet()) {
|
||||||
addHeader(entry.getKey(), true);
|
addHeader(entry.getKey(), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -302,7 +306,7 @@ public class IITC_PluginPreferenceActivity extends PreferenceActivity {
|
|||||||
final Header category = new Header();
|
final Header category = new Header();
|
||||||
category.title = "Official Plugins";
|
category.title = "Official Plugins";
|
||||||
mHeaders.add(category);
|
mHeaders.add(category);
|
||||||
for (final Map.Entry<String, ArrayList<IITC_PluginPreference>> entry : sAssetPlugins.entrySet()) {
|
for (final Map.Entry<String, ArrayList<PluginPreference>> entry : sAssetPlugins.entrySet()) {
|
||||||
addHeader(entry.getKey(), false);
|
addHeader(entry.getKey(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile.prefs;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -6,7 +6,7 @@ import android.view.MenuItem;
|
|||||||
|
|
||||||
import com.cradle.iitc_mobile.fragments.MainSettings;
|
import com.cradle.iitc_mobile.fragments.MainSettings;
|
||||||
|
|
||||||
public class IITC_PreferenceActivity extends Activity {
|
public class PreferenceActivity extends Activity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
Loading…
x
Reference in New Issue
Block a user