Merge branch 'master' of https://github.com/jonatkins/ingress-intel-total-conversion
This commit is contained in:
commit
fcfb60c7e3
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.cradle.iitc_mobile"
|
package="com.cradle.iitc_mobile"
|
||||||
android:versionCode="53"
|
android:versionCode="54"
|
||||||
android:versionName="0.7.3">
|
android:versionName="0.7.4">
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="14"
|
android:minSdkVersion="14"
|
||||||
|
@ -70,6 +70,8 @@
|
|||||||
|
|
||||||
<string name="pref_ui_cat">UI</string>
|
<string name="pref_ui_cat">UI</string>
|
||||||
<string name="pref_misc_cat">Misc</string>
|
<string name="pref_misc_cat">Misc</string>
|
||||||
|
<string name="pref_developer_options_cat">Developer options</string>
|
||||||
|
<string name="pref_tweaks_cat">Tweaks</string>
|
||||||
<string name="pref_plugins">IITC Plugins</string>
|
<string name="pref_plugins">IITC Plugins</string>
|
||||||
<string name="pref_plugins_title">Available plugins</string>
|
<string name="pref_plugins_title">Available plugins</string>
|
||||||
<string name="pref_user_loc">Display user location</string>
|
<string name="pref_user_loc">Display user location</string>
|
||||||
@ -84,7 +86,7 @@
|
|||||||
<string name="pref_force_https_sum">Disabling may improve performance</string>
|
<string name="pref_force_https_sum">Disabling may improve performance</string>
|
||||||
<string name="pref_press_twice_to_exit">Press back button twice to exit</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_press_twice_to_exit_sum">Avoids accidental exits</string>
|
||||||
<string name="pref_developer_options">Developer options</string>
|
<string name="pref_advanced_options">Advanced settings</string>
|
||||||
<string name="pref_enable_dev_mode">Enable developer mode</string>
|
<string name="pref_enable_dev_mode">Enable developer mode</string>
|
||||||
<string name="pref_enable_dev_mode_sum">If enabled, all IITC sources will be loaded from external storage of the Android device.
|
<string name="pref_enable_dev_mode_sum">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/.</string>
|
Please copy all sources from $IITC_folder/build/mobile/ to /sdcard/IITC_Mobile/dev/.</string>
|
||||||
@ -92,9 +94,26 @@
|
|||||||
<string name="pref_advanced_menu_sum">In addition to the default IITC buttons the advanced menu
|
<string name="pref_advanced_menu_sum">In addition to the default IITC buttons the advanced menu
|
||||||
contains a debug pane plus an option to clear cookies</string>
|
contains a debug pane plus an option to clear cookies</string>
|
||||||
<string name="pref_disable_splash">Disable Splash Screen</string>
|
<string name="pref_disable_splash">Disable Splash Screen</string>
|
||||||
|
<string name="pref_fake_user_agent">Fake User Agent</string>
|
||||||
|
<string name="pref_fake_user_agent_sum">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</string>
|
||||||
<string name="pref_select_iitc">IITC source</string>
|
<string name="pref_select_iitc">IITC source</string>
|
||||||
<string name="pref_select_iitc_sum">Load IITC main script from url or use local script. Currently used source:</string>
|
<string name="pref_select_iitc_sum">Load IITC main script from url or use local script. Currently used source:</string>
|
||||||
|
|
||||||
|
<string name="pref_caching">Aggressive Caching</string>
|
||||||
|
<string name="pref_caching_sum">Prefer cached values even if they are expired…saves traffic but
|
||||||
|
may result in login issues</string>
|
||||||
|
<string-array name="pref_caching_array">
|
||||||
|
<item>Always</item>
|
||||||
|
<item>Mobile data only (default)</item>
|
||||||
|
<item>Never</item>
|
||||||
|
</string-array>
|
||||||
|
<string-array name="pref_caching_array_vals">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string name="menu_clear_cookies">Clear Cookies</string>
|
<string name="menu_clear_cookies">Clear Cookies</string>
|
||||||
<string name="menu_search">Search</string>
|
<string name="menu_search">Search</string>
|
||||||
<string name="choose_account_to_login">Choose account to login</string>
|
<string name="choose_account_to_login">Choose account to login</string>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
android:dialogTitle="@string/pref_about_title"/>
|
android:dialogTitle="@string/pref_about_title"/>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pref_about_cat"
|
android:key="pref_ui_cat"
|
||||||
android:title="@string/pref_ui_cat">
|
android:title="@string/pref_ui_cat">
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="pref_user_loc"
|
android:key="pref_user_loc"
|
||||||
@ -45,7 +45,8 @@
|
|||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:fragment="com.cradle.iitc_mobile.fragments.PluginsFragment"
|
android:fragment="com.cradle.iitc_mobile.fragments.PluginsFragment"
|
||||||
android:key="pref_plugins"
|
android:key="pref_plugins"
|
||||||
android:title="@string/pref_plugins" >
|
android:title="@string/pref_plugins"
|
||||||
|
android:persistent="false">
|
||||||
<intent
|
<intent
|
||||||
android:targetPackage="com.cradle.iitc_mobile"
|
android:targetPackage="com.cradle.iitc_mobile"
|
||||||
android:targetClass="com.cradle.iitc_mobile.IITC_PluginPreferenceActivity"/>
|
android:targetClass="com.cradle.iitc_mobile.IITC_PluginPreferenceActivity"/>
|
||||||
@ -64,7 +65,12 @@
|
|||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="pref_developer_options"
|
android:key="pref_developer_options"
|
||||||
android:title="@string/pref_developer_options">
|
android:title="@string/pref_developer_options_cat">
|
||||||
|
|
||||||
|
<PreferenceScreen
|
||||||
|
android:key="pref_developer_screen"
|
||||||
|
android:title="@string/pref_advanced_options"
|
||||||
|
android:persistent="false">
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="pref_dev_checkbox"
|
android:key="pref_dev_checkbox"
|
||||||
@ -72,6 +78,10 @@
|
|||||||
android:summary="@string/pref_enable_dev_mode_sum"
|
android:summary="@string/pref_enable_dev_mode_sum"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="pref_advanced_ui_cat"
|
||||||
|
android:title="@string/pref_ui_cat">
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:key="pref_advanced_menu"
|
android:key="pref_advanced_menu"
|
||||||
android:title="@string/pref_advanced_menu"
|
android:title="@string/pref_advanced_menu"
|
||||||
@ -83,17 +93,44 @@
|
|||||||
android:title="@string/pref_disable_splash"
|
android:title="@string/pref_disable_splash"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
android:key="pref_advanced_tweaks_cat"
|
||||||
|
android:title="@string/pref_tweaks_cat">
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="pref_caching"
|
||||||
|
android:title="@string/pref_caching"
|
||||||
|
android:summary="@string/pref_caching_sum"
|
||||||
|
android:defaultValue="1"
|
||||||
|
android:entries="@array/pref_caching_array"
|
||||||
|
android:entryValues="@array/pref_caching_array_vals" />
|
||||||
|
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="pref_fake_user_agent"
|
||||||
|
android:title="@string/pref_fake_user_agent"
|
||||||
|
android:summary="@string/pref_fake_user_agent_sum"
|
||||||
|
android:defaultValue="false" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
</PreferenceScreen>
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="pref_build_version"
|
android:key="pref_build_version"
|
||||||
android:title="@string/build_version"
|
android:title="@string/build_version"
|
||||||
android:enabled="false"
|
android:enabled="false"
|
||||||
android:selectable="false" />
|
android:selectable="false"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
<ListPreference
|
<ListPreference
|
||||||
android:key="pref_iitc_version"
|
android:key="pref_iitc_version"
|
||||||
android:title="@string/iitc_version"
|
android:title="@string/iitc_version"
|
||||||
android:enabled="false"
|
android:enabled="false"
|
||||||
android:selectable="false" />
|
android:selectable="false"
|
||||||
|
android:persistent="false" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
@ -112,23 +112,23 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
if (key.equals("pref_force_desktop")) {
|
if (key.equals("pref_force_desktop")) {
|
||||||
mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false);
|
mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false);
|
||||||
mNavigationHelper.onPrefChanged();
|
mNavigationHelper.onPrefChanged();
|
||||||
}
|
} else if (key.equals("pref_user_loc")) {
|
||||||
if (key.equals("pref_user_loc"))
|
|
||||||
mIsLocEnabled = sharedPreferences.getBoolean("pref_user_loc",
|
mIsLocEnabled = sharedPreferences.getBoolean("pref_user_loc",
|
||||||
false);
|
false);
|
||||||
if (key.equals("pref_fullscreen_actionbar")) {
|
} else if (key.equals("pref_fullscreen_actionbar")) {
|
||||||
mNavigationHelper.onPrefChanged();
|
mNavigationHelper.onPrefChanged();
|
||||||
return;
|
return;
|
||||||
}
|
} else if (key.equals("pref_advanced_menu")) {
|
||||||
if (key.equals("pref_advanced_menu")) {
|
|
||||||
mAdvancedMenu = sharedPreferences.getBoolean("pref_advanced_menu", false);
|
mAdvancedMenu = sharedPreferences.getBoolean("pref_advanced_menu", false);
|
||||||
mNavigationHelper.setDebugMode(mAdvancedMenu);
|
mNavigationHelper.setDebugMode(mAdvancedMenu);
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
// no reload needed
|
// no reload needed
|
||||||
return;
|
return;
|
||||||
}
|
} else if (key.equals("pref_fake_user_agent")) {
|
||||||
|
mIitcWebView.setUserAgent();
|
||||||
if (key.equals("pref_press_twice_to_exit")
|
} 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_share_selected_tab")
|
||||||
|| key.equals("pref_messages"))
|
|| key.equals("pref_messages"))
|
||||||
// no reload needed
|
// no reload needed
|
||||||
@ -271,7 +271,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
|
|
||||||
// enough idle...let's do some work
|
// enough idle...let's do some work
|
||||||
Log.d("iitcm", "resuming...reset idleTimer");
|
Log.d("iitcm", "resuming...reset idleTimer");
|
||||||
mIitcWebView.updateCaching();
|
mIitcWebView.updateCaching(false);
|
||||||
|
|
||||||
if (mIsLocEnabled) {
|
if (mIsLocEnabled) {
|
||||||
// Register the mSharedPrefChangeListener with the Location Manager to receive
|
// Register the mSharedPrefChangeListener with the Location Manager to receive
|
||||||
|
@ -15,6 +15,7 @@ public class IITC_PreferenceActivity extends Activity {
|
|||||||
MainSettings settings = new MainSettings();
|
MainSettings settings = new MainSettings();
|
||||||
|
|
||||||
getActionBar().setHomeButtonEnabled(true);
|
getActionBar().setHomeButtonEnabled(true);
|
||||||
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
// iitc version
|
// iitc version
|
||||||
Bundle bundle = getIntent().getExtras();
|
Bundle bundle = getIntent().getExtras();
|
||||||
|
@ -26,26 +26,35 @@ public class IITC_WebView extends WebView {
|
|||||||
private IITC_WebViewClient mIitcWebViewClient;
|
private IITC_WebViewClient mIitcWebViewClient;
|
||||||
private IITC_JSInterface mJsInterface;
|
private IITC_JSInterface mJsInterface;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
private SharedPreferences mSharedPrefs;
|
||||||
private boolean mDisableJs = false;
|
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
|
// init web view
|
||||||
private void iitc_init(Context c) {
|
private void iitc_init(Context c) {
|
||||||
if (this.isInEditMode()) return;
|
if (isInEditMode()) return;
|
||||||
mContext = c;
|
mContext = c;
|
||||||
mSettings = this.getSettings();
|
mSettings = getSettings();
|
||||||
mSettings.setJavaScriptEnabled(true);
|
mSettings.setJavaScriptEnabled(true);
|
||||||
mSettings.setDomStorageEnabled(true);
|
mSettings.setDomStorageEnabled(true);
|
||||||
mSettings.setAllowFileAccess(true);
|
mSettings.setAllowFileAccess(true);
|
||||||
mSettings.setGeolocationEnabled(true);
|
mSettings.setGeolocationEnabled(true);
|
||||||
mSettings.setAppCacheEnabled(true);
|
mSettings.setAppCacheEnabled(true);
|
||||||
mSettings.setDatabasePath(this.getContext().getApplicationInfo().dataDir
|
mSettings.setDatabasePath(getContext().getApplicationInfo().dataDir
|
||||||
+ "/databases/");
|
+ "/databases/");
|
||||||
mSettings.setAppCachePath(this.getContext().getCacheDir()
|
mSettings.setAppCachePath(getContext().getCacheDir()
|
||||||
.getAbsolutePath());
|
.getAbsolutePath());
|
||||||
this.mJsInterface = new IITC_JSInterface((IITC_Mobile) mContext);
|
mJsInterface = new IITC_JSInterface((IITC_Mobile) mContext);
|
||||||
this.addJavascriptInterface(mJsInterface, "android");
|
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
|
* our webchromeclient should share geolocation with the iitc script
|
||||||
*
|
*
|
||||||
@ -83,7 +92,7 @@ public class IITC_WebView extends WebView {
|
|||||||
});
|
});
|
||||||
|
|
||||||
mIitcWebViewClient = new IITC_WebViewClient(c);
|
mIitcWebViewClient = new IITC_WebViewClient(c);
|
||||||
this.setWebViewClient(mIitcWebViewClient);
|
setWebViewClient(mIitcWebViewClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructors -------------------------------------------------
|
// constructors -------------------------------------------------
|
||||||
@ -110,7 +119,7 @@ public class IITC_WebView extends WebView {
|
|||||||
@Override
|
@Override
|
||||||
public void loadUrl(String url) {
|
public void loadUrl(String url) {
|
||||||
// if in edit text mode, don't load javascript otherwise the keyboard closes.
|
// 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 &&
|
if (url.startsWith("javascript:") && testResult != null &&
|
||||||
testResult.getType() == HitTestResult.EDIT_TEXT_TYPE) {
|
testResult.getType() == HitTestResult.EDIT_TEXT_TYPE) {
|
||||||
// let window.show(...) interupt input
|
// let window.show(...) interupt input
|
||||||
@ -122,7 +131,7 @@ public class IITC_WebView extends WebView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// do nothing if script is enabled;
|
// do nothing if script is enabled;
|
||||||
if (this.mDisableJs) {
|
if (mDisableJs) {
|
||||||
Log.d("iitcm", "javascript injection disabled...return");
|
Log.d("iitcm", "javascript injection disabled...return");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -143,20 +152,27 @@ public class IITC_WebView extends WebView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public IITC_WebViewClient getWebViewClient() {
|
public IITC_WebViewClient getWebViewClient() {
|
||||||
return this.mIitcWebViewClient;
|
return mIitcWebViewClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IITC_JSInterface getJSInterface() {
|
public IITC_JSInterface getJSInterface() {
|
||||||
return this.mJsInterface;
|
return mJsInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateCaching() {
|
public void updateCaching(boolean login) {
|
||||||
boolean login = false;
|
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) {
|
if (getUrl() != null) {
|
||||||
login = getUrl().contains("accounts.google.com");
|
login = getUrl().contains("accounts.google.com");
|
||||||
}
|
}
|
||||||
// use cache if on mobile network...saves traffic
|
// use cache if on mobile network...saves traffic
|
||||||
if (!this.isConnectedToWifi() && !login) {
|
if (!isConnectedToWifi() && !login) {
|
||||||
Log.d("iitcm", "not connected to wifi...load tiles from cache");
|
Log.d("iitcm", "not connected to wifi...load tiles from cache");
|
||||||
mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
mSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
|
||||||
} else {
|
} else {
|
||||||
@ -164,6 +180,8 @@ public class IITC_WebView extends WebView {
|
|||||||
else Log.d("iitcm", "connected to wifi...load tiles from network");
|
else Log.d("iitcm", "connected to wifi...load tiles from network");
|
||||||
mSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
mSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||||
@ -184,7 +202,13 @@ public class IITC_WebView extends WebView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void disableJS(boolean val) {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -160,8 +160,8 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceivedLoginRequest(WebView view, String realm, String account, String args) {
|
public void onReceivedLoginRequest(WebView view, String realm, String account, String args) {
|
||||||
Log.d("iitcm", "Login requested: " + realm + " " + account + " " + args);
|
Log.d("iitcm", "Login requested: " + realm + " " + account + " " + args);
|
||||||
Log.d("iitcm", "logging in...set caching mode to default");
|
Log.d("iitcm", "logging in...updating caching mode");
|
||||||
view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
|
((IITC_WebView) view).updateCaching(true);
|
||||||
//((IITC_Mobile) mContext).onReceivedLoginRequest(this, view, realm, account, args);
|
//((IITC_Mobile) mContext).onReceivedLoginRequest(this, view, realm, account, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,8 +284,8 @@ public class IITC_WebViewClient extends WebViewClient {
|
|||||||
((IITC_Mobile) mContext).loadUrl(url);
|
((IITC_Mobile) mContext).loadUrl(url);
|
||||||
}
|
}
|
||||||
if (url.contains("logout")) {
|
if (url.contains("logout")) {
|
||||||
Log.d("iitcm", "logging out...set caching mode to default");
|
Log.d("iitcm", "logging out...updating caching mode");
|
||||||
view.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
|
((IITC_WebView) view).updateCaching(true);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.cradle.iitc_mobile.fragments;
|
package com.cradle.iitc_mobile.fragments;
|
||||||
|
|
||||||
|
import android.app.Dialog;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
@ -9,6 +10,13 @@ import android.preference.ListPreference;
|
|||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.Preference.OnPreferenceChangeListener;
|
import android.preference.Preference.OnPreferenceChangeListener;
|
||||||
import android.preference.PreferenceFragment;
|
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;
|
import com.cradle.iitc_mobile.R;
|
||||||
|
|
||||||
@ -60,4 +68,55 @@ public class MainSettings extends PreferenceFragment {
|
|||||||
+ " " + pref_iitc_source.getText();
|
+ " " + pref_iitc_source.getText();
|
||||||
pref_iitc_source.setSummary(pref_iitc_source_sum);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user