diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml index 0b7c9866..9416f52f 100644 --- a/mobile/AndroidManifest.xml +++ b/mobile/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="54" + android:versionName="0.7.4"> UI Misc + Developer options + Tweaks IITC Plugins Available plugins Display user location @@ -84,7 +86,7 @@ Disabling may improve performance Press back button twice to exit Avoids accidental exits - Developer options + Advanced settings Enable developer mode If enabled, all IITC sources will be loaded from external storage of the Android device. Please copy all sources from $IITC_folder/build/mobile/ to /sdcard/IITC_Mobile/dev/. @@ -92,9 +94,26 @@ In addition to the default IITC buttons the advanced menu contains a debug pane plus an option to clear cookies Disable Splash Screen + Fake User Agent + Let IITCm appear as a desktop browser for the intel site. + Note: If just want to use the desktop mode use the \'force desktop mode\' setting IITC source Load IITC main script from url or use local script. Currently used source: + Aggressive Caching + Prefer cached values even if they are expired…saves traffic but + may result in login issues + + Always + Mobile data only (default) + Never + + + 0 + 1 + 2 + + Clear Cookies Search Choose account to login diff --git a/mobile/res/xml/preferences.xml b/mobile/res/xml/preferences.xml index 7fc502d4..4e743e35 100644 --- a/mobile/res/xml/preferences.xml +++ b/mobile/res/xml/preferences.xml @@ -10,7 +10,7 @@ android:dialogTitle="@string/pref_about_title"/> + android:title="@string/pref_plugins" + android:persistent="false"> @@ -64,36 +65,72 @@ + android:title="@string/pref_developer_options_cat"> - + - - - + + + + + + + + + + + + + + + + + + + android:selectable="false" + android:persistent="false" /> + android:selectable="false" + android:persistent="false" /> + \ No newline at end of file diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java index 25c4cb9c..ec2ea46d 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_Mobile.java @@ -112,23 +112,23 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis if (key.equals("pref_force_desktop")) { mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false); mNavigationHelper.onPrefChanged(); - } - if (key.equals("pref_user_loc")) + } else if (key.equals("pref_user_loc")) { mIsLocEnabled = sharedPreferences.getBoolean("pref_user_loc", false); - if (key.equals("pref_fullscreen_actionbar")) { + } else if (key.equals("pref_fullscreen_actionbar")) { mNavigationHelper.onPrefChanged(); return; - } - if (key.equals("pref_advanced_menu")) { + } else if (key.equals("pref_advanced_menu")) { mAdvancedMenu = sharedPreferences.getBoolean("pref_advanced_menu", false); mNavigationHelper.setDebugMode(mAdvancedMenu); invalidateOptionsMenu(); // no reload needed return; - } - - if (key.equals("pref_press_twice_to_exit") + } else if (key.equals("pref_fake_user_agent")) { + mIitcWebView.setUserAgent(); + } else if (key.equals("pref_caching")) { + mIitcWebView.updateCaching(false); + } else if (key.equals("pref_press_twice_to_exit") || key.equals("pref_share_selected_tab") || key.equals("pref_messages")) // no reload needed @@ -271,7 +271,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis // enough idle...let's do some work Log.d("iitcm", "resuming...reset idleTimer"); - mIitcWebView.updateCaching(); + mIitcWebView.updateCaching(false); if (mIsLocEnabled) { // Register the mSharedPrefChangeListener with the Location Manager to receive diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_PreferenceActivity.java b/mobile/src/com/cradle/iitc_mobile/IITC_PreferenceActivity.java index 2595d41b..a5521541 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_PreferenceActivity.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_PreferenceActivity.java @@ -15,6 +15,7 @@ public class IITC_PreferenceActivity extends Activity { MainSettings settings = new MainSettings(); getActionBar().setHomeButtonEnabled(true); + getActionBar().setDisplayHomeAsUpEnabled(true); // iitc version Bundle bundle = getIntent().getExtras(); diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java index affa80c1..1941a116 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java @@ -26,26 +26,35 @@ public class IITC_WebView extends WebView { private IITC_WebViewClient mIitcWebViewClient; private IITC_JSInterface mJsInterface; private Context mContext; + private SharedPreferences mSharedPrefs; private boolean mDisableJs = false; + private String mDefaultUserAgent; + private final String mDesktopUserAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:17.0)" + + " Gecko/20130810 Firefox/17.0 Iceweasel/17.0.8"; + + // init web view private void iitc_init(Context c) { - if (this.isInEditMode()) return; + if (isInEditMode()) return; mContext = c; - mSettings = this.getSettings(); + mSettings = getSettings(); mSettings.setJavaScriptEnabled(true); mSettings.setDomStorageEnabled(true); mSettings.setAllowFileAccess(true); mSettings.setGeolocationEnabled(true); mSettings.setAppCacheEnabled(true); - mSettings.setDatabasePath(this.getContext().getApplicationInfo().dataDir + mSettings.setDatabasePath(getContext().getApplicationInfo().dataDir + "/databases/"); - mSettings.setAppCachePath(this.getContext().getCacheDir() + mSettings.setAppCachePath(getContext().getCacheDir() .getAbsolutePath()); - this.mJsInterface = new IITC_JSInterface((IITC_Mobile) mContext); - this.addJavascriptInterface(mJsInterface, "android"); + mJsInterface = new IITC_JSInterface((IITC_Mobile) mContext); + addJavascriptInterface(mJsInterface, "android"); + mSharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); + mDefaultUserAgent = mSettings.getUserAgentString(); + setUserAgent(); - this.setWebChromeClient(new WebChromeClient() { + setWebChromeClient(new WebChromeClient() { /** * our webchromeclient should share geolocation with the iitc script * @@ -83,7 +92,7 @@ public class IITC_WebView extends WebView { }); mIitcWebViewClient = new IITC_WebViewClient(c); - this.setWebViewClient(mIitcWebViewClient); + setWebViewClient(mIitcWebViewClient); } // constructors ------------------------------------------------- @@ -110,7 +119,7 @@ public class IITC_WebView extends WebView { @Override public void loadUrl(String url) { // if in edit text mode, don't load javascript otherwise the keyboard closes. - HitTestResult testResult = this.getHitTestResult(); + HitTestResult testResult = getHitTestResult(); if (url.startsWith("javascript:") && testResult != null && testResult.getType() == HitTestResult.EDIT_TEXT_TYPE) { // let window.show(...) interupt input @@ -122,7 +131,7 @@ public class IITC_WebView extends WebView { } } // do nothing if script is enabled; - if (this.mDisableJs) { + if (mDisableJs) { Log.d("iitcm", "javascript injection disabled...return"); return; } @@ -143,26 +152,35 @@ public class IITC_WebView extends WebView { } public IITC_WebViewClient getWebViewClient() { - return this.mIitcWebViewClient; + return mIitcWebViewClient; } public IITC_JSInterface getJSInterface() { - return this.mJsInterface; + return mJsInterface; } - public void updateCaching() { - boolean login = false; - if (getUrl() != null) { - login = getUrl().contains("accounts.google.com"); - } - // use cache if on mobile network...saves traffic - if (!this.isConnectedToWifi() && !login) { - Log.d("iitcm", "not connected to wifi...load tiles from cache"); - mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); - } else { - if (login) Log.d("iitcm", "login...load tiles from network"); - else Log.d("iitcm", "connected to wifi...load tiles from network"); - mSettings.setCacheMode(WebSettings.LOAD_DEFAULT); + public void updateCaching(boolean login) { + switch(Integer.parseInt(mSharedPrefs.getString("pref_caching", "1"))) { + case 0: + mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); + break; + case 2: + mSettings.setCacheMode(WebSettings.LOAD_DEFAULT); + break; + default: + if (getUrl() != null) { + login = getUrl().contains("accounts.google.com"); + } + // use cache if on mobile network...saves traffic + if (!isConnectedToWifi() && !login) { + Log.d("iitcm", "not connected to wifi...load tiles from cache"); + mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); + } else { + if (login) Log.d("iitcm", "login...load tiles from network"); + else Log.d("iitcm", "connected to wifi...load tiles from network"); + mSettings.setCacheMode(WebSettings.LOAD_DEFAULT); + } + break; } } @@ -184,7 +202,13 @@ public class IITC_WebView extends WebView { } public void disableJS(boolean val) { - this.mDisableJs = val; + mDisableJs = val; + } + + public void setUserAgent() { + String ua = mSharedPrefs.getBoolean("pref_fake_user_agent", false) ? mDesktopUserAgent : mDefaultUserAgent; + Log.d("iitcm", "setting user agent to: " + ua); + mSettings.setUserAgentString(ua); } } diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index 83947756..a41835ae 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -160,8 +160,8 @@ public class IITC_WebViewClient extends WebViewClient { @Override public void onReceivedLoginRequest(WebView view, String realm, String account, String args) { Log.d("iitcm", "Login requested: " + realm + " " + account + " " + args); - Log.d("iitcm", "logging in...set caching mode to default"); - view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); + Log.d("iitcm", "logging in...updating caching mode"); + ((IITC_WebView) view).updateCaching(true); //((IITC_Mobile) mContext).onReceivedLoginRequest(this, view, realm, account, args); } @@ -284,8 +284,8 @@ public class IITC_WebViewClient extends WebViewClient { ((IITC_Mobile) mContext).loadUrl(url); } if (url.contains("logout")) { - Log.d("iitcm", "logging out...set caching mode to default"); - view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT); + Log.d("iitcm", "logging out...updating caching mode"); + ((IITC_WebView) view).updateCaching(true); } return false; } else { diff --git a/mobile/src/com/cradle/iitc_mobile/fragments/MainSettings.java b/mobile/src/com/cradle/iitc_mobile/fragments/MainSettings.java index f26c18cc..49af96ea 100644 --- a/mobile/src/com/cradle/iitc_mobile/fragments/MainSettings.java +++ b/mobile/src/com/cradle/iitc_mobile/fragments/MainSettings.java @@ -1,5 +1,6 @@ package com.cradle.iitc_mobile.fragments; +import android.app.Dialog; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; @@ -9,6 +10,13 @@ import android.preference.ListPreference; import android.preference.Preference; import android.preference.Preference.OnPreferenceChangeListener; import android.preference.PreferenceFragment; +import android.preference.PreferenceScreen; +import android.util.Log; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewParent; +import android.widget.FrameLayout; +import android.widget.LinearLayout; import com.cradle.iitc_mobile.R; @@ -60,4 +68,55 @@ public class MainSettings extends PreferenceFragment { + " " + pref_iitc_source.getText(); pref_iitc_source.setSummary(pref_iitc_source_sum); } + + // we want a home button + HomeAsUpEnabled in nested preferences + // for some odd reasons android is not able to do this by default + // so we need some additional hacks... + // thx to http://stackoverflow.com/a/16800527/2638486 !! + @Override + public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) { + if (preference.getTitle().toString().equals(getString(R.string.pref_advanced_options))) + initializeActionBar((PreferenceScreen) preference); + return super.onPreferenceTreeClick(preferenceScreen, preference); + } + + // Apply custom home button area click listener to close the PreferenceScreen + // because PreferenceScreens are dialogs which swallow + // events instead of passing to the activity + // Related Issue: https://code.google.com/p/android/issues/detail?id=4611 + public static void initializeActionBar(PreferenceScreen preferenceScreen) { + final Dialog dialog = preferenceScreen.getDialog(); + + if (dialog != null) { + dialog.getActionBar().setDisplayHomeAsUpEnabled(true); + + View homeBtn = dialog.findViewById(android.R.id.home); + + if (homeBtn != null) { + View.OnClickListener dismissDialogClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + dialog.dismiss(); + } + }; + + ViewParent homeBtnContainer = homeBtn.getParent(); + + // The home button is an ImageView inside a FrameLayout + if (homeBtnContainer instanceof FrameLayout) { + ViewGroup containerParent = (ViewGroup) homeBtnContainer.getParent(); + + if (containerParent instanceof LinearLayout) { + // This view also contains the title text, set the whole view as clickable + ((LinearLayout) containerParent).setOnClickListener(dismissDialogClickListener); + } else { + // Just set it on the home button + ((FrameLayout) homeBtnContainer).setOnClickListener(dismissDialogClickListener); + } + } else { + homeBtn.setOnClickListener(dismissDialogClickListener); + } + } + } + } }