This commit is contained in:
Jon Atkins 2013-05-26 19:30:34 +01:00
commit e609c64775
8 changed files with 158 additions and 85 deletions

View File

@ -6,27 +6,6 @@
// Used to disable on multitouch devices
window.showZoom = true;
window.setupBackButton = function() {
var c = window.isSmartphone()
? window.smartphone.mapButton
: $('#chatcontrols a.active');
window.setupBackButton._actions = [c.get(0)];
$('#chatcontrols a').click(function() {
// ignore shrink button
if($(this).hasClass('toggle')) return;
window.setupBackButton._actions.push(this);
window.setupBackButton._actions = window.setupBackButton._actions.slice(-2);
});
window.goBack = function() {
var a = window.setupBackButton._actions[0];
if(!a) return;
$(a).click();
window.setupBackButton._actions = [a];
}
}
window.setupLargeImagePreview = function() {
$('#portaldetails').on('click', '.imgpreview', function() {
var img = $(this).find('img')[0];
@ -408,7 +387,6 @@ function boot() {
window.setupQRLoadLib();
window.setupLayerChooserSelectOne();
window.setupLayerChooserStatusRecorder();
window.setupBackButton();
// read here ONCE, so the URL is only evaluated one time after the
// necessary data has been loaded.
urlPortalLL = getURLParam('pll');

View File

@ -90,8 +90,12 @@ window.runOnSmartphonesAfterBoot = function() {
// this is a hack, accessing Leaflets private _container is evil
$(this._container).on('taphold', function() {
if (typeof android !== 'undefined' && android && android.portalLongPressed) {
android.portalLongPressed();
} else {
window.renderPortalDetails(guid);
window.smartphone.sideButton.click();
}
});
});
});

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cradle.iitc_mobile"
android:versionCode="22"
android:versionName="0.4.1">
android:versionCode="23"
android:versionName="0.4.2">
<uses-sdk
android:minSdkVersion="14"

View File

@ -2,15 +2,9 @@
<item android:id="@+id/menu_search"
android:title="@string/menu_search"
android:icon="@drawable/action_search"
android:orderInCategory="10"
android:showAsAction="ifRoom|collapseActionView"
android:actionViewClass="android.widget.SearchView" />
<item
android:id="@+id/menu_map"
android:icon="@drawable/location_map"
android:orderInCategory="20"
android:showAsAction="ifRoom"
android:title="@string/menu_map">
</item>
<item
android:id="@+id/menu_info"
android:icon="@drawable/action_about"

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">IITC mobile</string>
<string name="app_name">IITC Mobile</string>
<string name="action_settings">Settings</string>
<string name="reload">Reload IITC</string>
<string name="version">Print Version</string>
@ -40,6 +40,8 @@
<string name="pref_user_zoom_sum">Shows +/- buttons even on multitouch capable devices.</string>
<string name="pref_fullscreen_actionbar">Hide Action Bar in fullscreen mode</string>
<string name="pref_fullscreen_actionbar_sum">Nice for screenshots. Note: IITCM cannot be controlled without Action Bar.</string>
<string name="pref_force_desktop">Force desktop mode</string>
<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_developer_options">Developer options</string>
@ -49,7 +51,6 @@
<string name="pref_select_iitc">IITC source</string>
<string name="menu_chat">Chat</string>
<string name="menu_map">Map</string>
<string name="menu_full">Full</string>
<string name="menu_compact">Compact</string>
<string name="menu_public">Public</string>

View File

@ -27,6 +27,11 @@
android:title="@string/pref_fullscreen_actionbar"
android:summary="@string/pref_fullscreen_actionbar_sum"
android:defaultValue="false" />
<CheckBoxPreference
android:key="pref_force_desktop"
android:title="@string/pref_force_desktop"
android:summary="@string/pref_force_desktop_sum"
android:defaultValue="false" />
</PreferenceCategory>
<PreferenceCategory

View File

@ -64,6 +64,16 @@ public class IITC_JSInterface {
.show();
}
@JavascriptInterface
public void portalLongPressed() {
final IITC_Mobile iitcm = (IITC_Mobile) context;
iitcm.runOnUiThread(new Runnable() {
@Override
public void run() {
iitcm.handleMenuItemSelected(R.id.menu_info, true);
}
});
}
// get layers and list them in a dialog
@JavascriptInterface
public void setLayers(String base_layer, String overlay_layer) {

View File

@ -1,6 +1,7 @@
package com.cradle.iitc_mobile;
import java.io.IOException;
import java.util.ArrayList;
import android.app.ActionBar;
import android.app.Activity;
@ -16,8 +17,8 @@ import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.preference.PreferenceManager;
import android.util.Log;
@ -34,7 +35,6 @@ public class IITC_Mobile extends Activity {
private static final int REQUEST_LOGIN = 1;
private IITC_WebView iitc_view;
private boolean back_button_pressed = false;
private OnSharedPreferenceChangeListener listener;
private String intel_url = "https://www.ingress.com/intel";
private boolean user_loc = false;
@ -45,6 +45,11 @@ public class IITC_Mobile extends Activity {
private ActionBar actionBar;
private IITC_DeviceAccountLogin mLogin;
private MenuItem searchMenuItem;
private boolean desktop = false;
// Used for custom back stack handling
private ArrayList<Integer> backStack = new ArrayList<Integer>();
private int currentPane = android.R.id.home;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -64,7 +69,8 @@ public class IITC_Mobile extends Activity {
actionBar = this.getActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
| ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setTitle(getString(R.string.menu_map));
actionBar.setTitle(getString(R.string.app_name));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
actionBar.setHomeButtonEnabled(true);
// do something if user changed something in the settings
@ -74,6 +80,10 @@ public class IITC_Mobile extends Activity {
@Override
public void onSharedPreferenceChanged(
SharedPreferences sharedPreferences, String key) {
if (key.equals("pref_force_desktop")) {
desktop = sharedPreferences.getBoolean("pref_force_desktop", false);
invalidateOptionsMenu();
}
if (key.equals("pref_user_loc"))
user_loc = sharedPreferences.getBoolean("pref_user_loc",
false);
@ -88,6 +98,9 @@ public class IITC_Mobile extends Activity {
};
sharedPref.registerOnSharedPreferenceChangeListener(listener);
// enable/disable desktop mode on menu create and url load
desktop = sharedPref.getBoolean("pref_force_desktop", false);
// Acquire a reference to the system Location Manager
loc_mngr = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
@ -123,6 +136,10 @@ public class IITC_Mobile extends Activity {
fullscreen_actionbar = sharedPref.getBoolean("pref_fullscreen_actionbar", false);
// Clear the back stack
backStack.clear();
setActionBarHomeEnabledWithUp(false);
handleIntent(getIntent(), true);
}
@ -152,6 +169,8 @@ public class IITC_Mobile extends Activity {
(SearchView) searchMenuItem.getActionView();
searchView.setQuery(query, false);
searchView.clearFocus();
actionBar.setTitle(getString(R.string.app_name));
backStackUpdate(android.R.id.home);
iitc_view.loadUrl("javascript:search('" + query + "');");
} else if (onCreate) {
this.loadUrl(intel_url);
@ -231,27 +250,49 @@ public class IITC_Mobile extends Activity {
// we want a self defined behavior for the back button
@Override
public void onBackPressed() {
// exit fullscreen mode if it is enabled
if (fullscreen_mode) {
// exit fullscreen mode if it is enabled and action bar is disabled or the back stack is empty
if (fullscreen_mode && (backStack.isEmpty() || fullscreen_actionbar)) {
this.toggleFullscreen();
return;
}
if (this.back_button_pressed) {
} else if (!backStack.isEmpty()) {
// Pop last item from backStack and pretend the relevant menu item was clicked
backStackPop();
} else {
super.onBackPressed();
}
}
private void setActionBarHomeEnabledWithUp(boolean enabled) {
actionBar.setDisplayHomeAsUpEnabled(enabled);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
actionBar.setHomeButtonEnabled(enabled);
}
public void backStackPop() {
// shouldn't be called when back stack is empty
// catch wrong usage
if (backStack.isEmpty()) {
// Empty back stack means we should be at home (ie map) screen
setActionBarHomeEnabledWithUp(false);
actionBar.setTitle(getString(R.string.app_name));
iitc_view.loadUrl("javascript: window.show('map');");
return;
}
iitc_view.loadUrl("javascript: window.goBack();");
this.back_button_pressed = true;
Toast.makeText(this, "Press twice to exit", Toast.LENGTH_SHORT).show();
// reset back button after 0.5 seconds
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
back_button_pressed = false;
int index = backStack.size() - 1;
int itemId = backStack.remove(index);
currentPane = itemId;
handleMenuItemSelected(itemId, false);
// if we popped our last item from stack...illustrate it on home button
if (backStack.isEmpty()) {
// Empty back stack means we should be at home (ie map) screen
setActionBarHomeEnabledWithUp(false);
}
}, 500);
}
public void backStackUpdate(int itemId) {
if (itemId == currentPane) return;
backStack.add(currentPane);
currentPane = itemId;
if (backStack.size() == 1) setActionBarHomeEnabledWithUp(true);
}
@Override
@ -266,37 +307,53 @@ public class IITC_Mobile extends Activity {
// Assumes current activity is the searchable activity
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
// enable/disable desktop menu
enableDesktopUI(menu, desktop);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
final int itemId = item.getItemId();
boolean result = handleMenuItemSelected(itemId, true);
if (!result) return super.onOptionsItemSelected(item);
return true;
}
public boolean handleMenuItemSelected(int itemId, boolean addToBackStack) {
switch (itemId) {
case android.R.id.home:
iitc_view.loadUrl("javascript: window.show('map');");
actionBar.setTitle(getString(R.string.menu_map));
return true;
case R.id.menu_map:
iitc_view.loadUrl("javascript: window.show('map');");
actionBar.setTitle(getString(R.string.menu_map));
actionBar.setTitle(getString(R.string.app_name));
this.backStack.clear();
setActionBarHomeEnabledWithUp(false);
currentPane = android.R.id.home;
return true;
case R.id.reload_button:
actionBar.setTitle(getString(R.string.app_name));
backStack.clear();
setActionBarHomeEnabledWithUp(false);
this.loadUrl(intel_url);
actionBar.setTitle(getString(R.string.menu_map));
return true;
case R.id.toggle_fullscreen:
toggleFullscreen();
return true;
case R.id.layer_chooser:
// Force map view to handle potential issue with back stack
if (!backStack.isEmpty() && currentPane != android.R.id.home)
iitc_view.loadUrl("javascript: window.show('map');");
// the getLayers function calls the setLayers method of IITC_JSInterface
iitc_view.loadUrl("javascript: window.layerChooser.getLayers()");
actionBar.setTitle(getString(R.string.app_name));
backStackUpdate(android.R.id.home);
return true;
// get the users current location and focus it on map
case R.id.locate:
iitc_view.loadUrl("javascript: window.show('map');");
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 15});");
actionBar.setTitle(getString(R.string.menu_map));
actionBar.setTitle(getString(R.string.app_name));
backStackUpdate(android.R.id.home);
return true;
// start settings activity
case R.id.action_settings:
@ -308,29 +365,35 @@ public class IITC_Mobile extends Activity {
case R.id.menu_info:
iitc_view.loadUrl("javascript: window.show('info');");
actionBar.setTitle(getString(R.string.menu_info));
if (addToBackStack) backStackUpdate(itemId);
return true;
case R.id.menu_full:
iitc_view.loadUrl("javascript: window.show('full');");
actionBar.setTitle(getString(R.string.menu_full));
if (addToBackStack) backStackUpdate(itemId);
return true;
case R.id.menu_compact:
iitc_view.loadUrl("javascript: window.show('compact');");
actionBar.setTitle(getString(R.string.menu_compact));
if (addToBackStack) backStackUpdate(itemId);
return true;
case R.id.menu_public:
iitc_view.loadUrl("javascript: window.show('public');");
actionBar.setTitle(getString(R.string.menu_public));
if (addToBackStack) backStackUpdate(itemId);
return true;
case R.id.menu_faction:
iitc_view.loadUrl("javascript: window.show('faction');");
actionBar.setTitle(getString(R.string.menu_faction));
if (addToBackStack) backStackUpdate(itemId);
return true;
case R.id.menu_debug:
iitc_view.loadUrl("javascript: window.show('debug')");
actionBar.setTitle(getString(R.string.menu_debug));
if (addToBackStack) backStackUpdate(itemId);
return true;
default:
return super.onOptionsItemSelected(item);
return false;
}
}
@ -344,9 +407,11 @@ public class IITC_Mobile extends Activity {
}
}
// Force mobile view.
// New actions are not compatible with desktop mode
// vp=f enables desktop mode...vp=m is the defaul mobile view
private String addUrlParam(String url) {
if (desktop)
return (url + "?vp=f");
else
return (url + "?vp=m");
}
@ -371,18 +436,21 @@ public class IITC_Mobile extends Activity {
}
public void toggleFullscreen() {
// TODO: Figure out how to handle this with new back stack?
if (fullscreen_mode) {
if (fullscreen_actionbar)
this.getActionBar().show();
this.fullscreen_mode = false;
} else {
if (fullscreen_actionbar)
if (fullscreen_actionbar) {
this.getActionBar().hide();
this.fullscreen_mode = true;
// show a toast with instructions to exit the fc mode again
Toast.makeText(this, "Press back button to exit fullscreen",
Toast.LENGTH_SHORT).show();
}
this.fullscreen_mode = true;
}
// toggle notification bar
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags ^= WindowManager.LayoutParams.FLAG_FULLSCREEN;
@ -430,4 +498,17 @@ public class IITC_Mobile extends Activity {
// garbage collection
mLogin = null;
}
// disable/enable some menu buttons...
public void enableDesktopUI(Menu menu, boolean desktop) {
MenuItem item;
item = menu.findItem(R.id.menu_chat);
item.setVisible(!desktop);
item = menu.findItem(R.id.menu_info);
item.setVisible(!desktop);
item = menu.findItem(R.id.menu_debug);
item.setVisible(!desktop);
item = menu.findItem(R.id.layer_chooser);
item.setVisible(!desktop);
}
}