added option: move cache to external storage

This commit is contained in:
Philipp Schaefer 2013-10-22 12:12:17 +02:00
parent 9248fe6221
commit 437a33f1d5
6 changed files with 36 additions and 5 deletions

View File

@ -14,8 +14,10 @@
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:name=".IITC_Application"
android:allowBackup="true"
android:icon="@drawable/ic_iitcm"
android:label="@string/app_name"

View File

@ -84,6 +84,8 @@
<string name="pref_force_desktop_sum">Nice for tablets, looks awful on smartphones</string>
<string name="pref_force_https">Force https</string>
<string name="pref_force_https_sum">Disabling may improve performance</string>
<string name="pref_external_storage">Move cache to external storage</string>
<string name="pref_external_storage_sum">Restart required! Write cache to sdCard. Saves internal storage. External storage has to be mounted.</string>
<string name="pref_press_twice_to_exit">Press back button twice to exit</string>
<string name="pref_press_twice_to_exit_sum">Avoids accidental exits</string>
<string name="pref_advanced_options">Advanced settings</string>

View File

@ -56,6 +56,11 @@
android:title="@string/pref_force_https"
android:summary="@string/pref_force_https_sum"
android:defaultValue="true" />
<CheckBoxPreference
android:key="pref_external_storage"
android:title="@string/pref_external_storage"
android:summary="@string/pref_external_storage_sum"
android:defaultValue="false" />
<CheckBoxPreference
android:key="pref_press_twice_to_exit"
android:title="@string/pref_press_twice_to_exit"

View File

@ -0,0 +1,17 @@
package com.cradle.iitc_mobile;
import android.app.Application;
import android.preference.PreferenceManager;
import java.io.File;
public class IITC_Application extends Application {
@Override
public File getCacheDir() {
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_external_storage", false)) {
return (getExternalCacheDir() != null) ? getExternalCacheDir() : super.getCacheDir();
} else {
return super.getCacheDir();
}
}
}

View File

@ -30,6 +30,7 @@ import android.widget.Toast;
import com.cradle.iitc_mobile.IITC_NavigationHelper.Pane;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Locale;
@ -130,7 +131,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
mIitcWebView.updateCaching(false);
} else if (key.equals("pref_press_twice_to_exit")
|| key.equals("pref_share_selected_tab")
|| key.equals("pref_messages"))
|| key.equals("pref_messages")
|| key.equals("pref_external_storage"))
// no reload needed
return;
@ -481,6 +483,11 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
}
}
@Override
public File getCacheDir() {
return getApplicationContext().getCacheDir();
}
public void reloadIITC() {
mNavigationHelper.reset();
mMapSettings.reset();

View File

@ -44,10 +44,8 @@ public class IITC_WebView extends WebView {
mSettings.setAllowFileAccess(true);
mSettings.setGeolocationEnabled(true);
mSettings.setAppCacheEnabled(true);
mSettings.setDatabasePath(getContext().getApplicationInfo().dataDir
+ "/databases/");
mSettings.setAppCachePath(getContext().getCacheDir()
.getAbsolutePath());
mSettings.setDatabasePath(getContext().getApplicationInfo().dataDir + "/databases/");
mSettings.setAppCachePath(getContext().getCacheDir().getAbsolutePath());
mJsInterface = new IITC_JSInterface((IITC_Mobile) mContext);
addJavascriptInterface(mJsInterface, "android");
mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);