added preferences activity to iitcm...adds possibility to force desktop mode
This commit is contained in:
parent
4dbe4cc06b
commit
30f1f0e4ec
@ -2,7 +2,7 @@
|
|||||||
<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="1"
|
android:versionCode="1"
|
||||||
android:versionName="0.2.3" >
|
android:versionName="0.2.4" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="14"
|
android:minSdkVersion="14"
|
||||||
@ -33,6 +33,12 @@
|
|||||||
<data android:host="www.ingress.com" android:scheme="http" android:pathPrefix="/intel"></data>
|
<data android:host="www.ingress.com" android:scheme="http" android:pathPrefix="/intel"></data>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name="com.cradle.iitc_mobile.IITC_Settings"
|
||||||
|
android:theme="@style/AppBaseTheme"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:configChanges="orientation|keyboard|keyboardHidden|screenSize" >
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
android:showAsAction="ifRoom"
|
android:showAsAction="ifRoom"
|
||||||
android:title="@string/reload"></item>
|
android:title="@string/reload"></item>
|
||||||
|
|
||||||
<item android:id="@+id/version_num"
|
<item android:id="@+id/settings"
|
||||||
android:orderInCategory="100"
|
android:orderInCategory="120"
|
||||||
android:showAsAction="never"
|
android:showAsAction="never"
|
||||||
android:title="@string/version"></item>
|
android:title="@string/action_settings"></item>
|
||||||
|
|
||||||
<item android:id="@+id/cache_clear"
|
<item android:id="@+id/cache_clear"
|
||||||
android:orderInCategory="100"
|
android:orderInCategory="100"
|
||||||
|
@ -7,5 +7,8 @@
|
|||||||
<string name="version">Print Version</string>
|
<string name="version">Print Version</string>
|
||||||
<string name="cache_clear">Clear Cache</string>
|
<string name="cache_clear">Clear Cache</string>
|
||||||
<string name="locate">Get Location</string>
|
<string name="locate">Get Location</string>
|
||||||
|
<string name="build_version">Build Version</string>
|
||||||
|
|
||||||
|
<string name="pref_force_desktop">Force desktop mode</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
12
mobile/res/xml/preferences.xml
Normal file
12
mobile/res/xml/preferences.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="pref_force_desktop"
|
||||||
|
android:title="@string/pref_force_desktop"
|
||||||
|
android:defaultValue="true" />
|
||||||
|
<ListPreference
|
||||||
|
android:key="pref_build_version"
|
||||||
|
android:title="@string/build_version"
|
||||||
|
android:enabled="false"
|
||||||
|
android:selectable="false" />
|
||||||
|
</PreferenceScreen>
|
@ -7,10 +7,10 @@ import com.cradle.iitc_mobile.R;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
@ -20,7 +20,8 @@ public class IITC_Mobile extends Activity {
|
|||||||
|
|
||||||
private IITC_WebView iitc_view;
|
private IITC_WebView iitc_view;
|
||||||
private boolean back_button_pressed = false;
|
private boolean back_button_pressed = false;
|
||||||
|
private boolean desktop = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -45,16 +46,30 @@ public class IITC_Mobile extends Activity {
|
|||||||
Log.d("Intent received", "url: " + url);
|
Log.d("Intent received", "url: " + url);
|
||||||
if (url.contains("ingress.com")) {
|
if (url.contains("ingress.com")) {
|
||||||
Log.d("Intent received", "loading url...");
|
Log.d("Intent received", "loading url...");
|
||||||
iitc_view.loadUrl(url);
|
iitc_view.loadUrl(addUrlParam(url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Log.d("No Intent call", "loading https://www.ingress.com/intel");
|
Log.d("No Intent call", "loading https://www.ingress.com/intel");
|
||||||
iitc_view.loadUrl("https://www.ingress.com/intel");
|
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
// reload page if, the desktop/mobile pref has changed
|
||||||
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
if (desktop != sharedPref.getBoolean("pref_force_desktop", false)) {
|
||||||
|
Log.d("pref changed", "force Desktop/Mobile changed...reloading");
|
||||||
|
desktop = sharedPref.getBoolean("pref_force_desktop", false);
|
||||||
|
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
||||||
|
injectJS();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// save instance state to avoid reloading on orientation change
|
// save instance state to avoid reloading on orientation change
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
@ -94,24 +109,8 @@ public class IITC_Mobile extends Activity {
|
|||||||
// Handle item selection
|
// Handle item selection
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.reload_button:
|
case R.id.reload_button:
|
||||||
iitc_view.loadUrl("https://www.ingress.com/intel");
|
iitc_view.loadUrl(addUrlParam("https://www.ingress.com/intel"));
|
||||||
try {
|
injectJS();
|
||||||
iitc_view.getWebViewClient().loadIITC_JS(this);
|
|
||||||
} catch (IOException e1) {
|
|
||||||
e1.printStackTrace();
|
|
||||||
} catch (NullPointerException e2) {
|
|
||||||
e2.printStackTrace();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
// print version number
|
|
||||||
case R.id.version_num:
|
|
||||||
PackageInfo pinfo;
|
|
||||||
try {
|
|
||||||
pinfo = getPackageManager().getPackageInfo(getPackageName(), 0);
|
|
||||||
Toast.makeText(this, "Build version: " + pinfo.versionName, Toast.LENGTH_SHORT).show();
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
// clear cache
|
// clear cache
|
||||||
case R.id.cache_clear:
|
case R.id.cache_clear:
|
||||||
@ -123,8 +122,31 @@ public class IITC_Mobile extends Activity {
|
|||||||
case R.id.locate:
|
case R.id.locate:
|
||||||
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});");
|
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 13});");
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.settings:
|
||||||
|
startActivity(new Intent(this, IITC_Settings.class));
|
||||||
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void injectJS() {
|
||||||
|
try {
|
||||||
|
iitc_view.getWebViewClient().loadIITC_JS(this);
|
||||||
|
} catch (IOException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
} catch (NullPointerException e2) {
|
||||||
|
e2.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String addUrlParam(String url) {
|
||||||
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
this.desktop = sharedPref.getBoolean("pref_force_desktop", false);
|
||||||
|
|
||||||
|
if (desktop)
|
||||||
|
return (url + "?vp=f");
|
||||||
|
else
|
||||||
|
return (url + "?vp=m");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
16
mobile/src/com/cradle/iitc_mobile/IITC_Settings.java
Normal file
16
mobile/src/com/cradle/iitc_mobile/IITC_Settings.java
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package com.cradle.iitc_mobile;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
public class IITC_Settings extends Activity {
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
// Display the fragment as the main content.
|
||||||
|
getFragmentManager().beginTransaction()
|
||||||
|
.replace(android.R.id.content, new IITC_SettingsFragment())
|
||||||
|
.commit();
|
||||||
|
}
|
||||||
|
}
|
31
mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java
Normal file
31
mobile/src/com/cradle/iitc_mobile/IITC_SettingsFragment.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.cradle.iitc_mobile;
|
||||||
|
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.ListPreference;
|
||||||
|
import android.preference.PreferenceFragment;
|
||||||
|
|
||||||
|
public class IITC_SettingsFragment extends PreferenceFragment {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
addPreferencesFromResource(R.xml.preferences);
|
||||||
|
|
||||||
|
// set build version
|
||||||
|
ListPreference pref_build_version = (ListPreference) findPreference("pref_build_version");
|
||||||
|
PackageManager pm = getActivity().getPackageManager();
|
||||||
|
String version = "unknown";
|
||||||
|
try {
|
||||||
|
PackageInfo info = pm.getPackageInfo(getActivity().getPackageName(), 0);
|
||||||
|
version = info.versionName;
|
||||||
|
}
|
||||||
|
catch (NameNotFoundException e) {
|
||||||
|
}
|
||||||
|
pref_build_version.setSummary(version);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user