Improved back handling in mobile app. Now more consistant with standard.
This commit is contained in:
@ -81,20 +81,7 @@ window.runOnSmartphonesAfterBoot = function() {
|
|||||||
var l = $('#chatcontrols a:visible');
|
var l = $('#chatcontrols a:visible');
|
||||||
l.css('width', 100/l.length + '%');
|
l.css('width', 100/l.length + '%');
|
||||||
|
|
||||||
// add event to portals that allows long press to switch to sidebar
|
// NOTE: Removed long press hook as it would break new back stack handling
|
||||||
window.addHook('portalAdded', function(data) {
|
|
||||||
data.portal.on('add', function() {
|
|
||||||
if(!this._container || this.options.addedTapHoldHandler) return;
|
|
||||||
this.options.addedTapHoldHandler = true;
|
|
||||||
var guid = this.options.guid;
|
|
||||||
|
|
||||||
// this is a hack, accessing Leaflet’s private _container is evil
|
|
||||||
$(this._container).on('taphold', function() {
|
|
||||||
window.renderPortalDetails(guid);
|
|
||||||
window.smartphone.sideButton.click();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Force lower render limits for mobile
|
// Force lower render limits for mobile
|
||||||
window.VIEWPORT_PAD_RATIO = 0.1;
|
window.VIEWPORT_PAD_RATIO = 0.1;
|
||||||
|
@ -2,15 +2,9 @@
|
|||||||
<item android:id="@+id/menu_search"
|
<item android:id="@+id/menu_search"
|
||||||
android:title="@string/menu_search"
|
android:title="@string/menu_search"
|
||||||
android:icon="@drawable/action_search"
|
android:icon="@drawable/action_search"
|
||||||
|
android:orderInCategory="10"
|
||||||
android:showAsAction="ifRoom|collapseActionView"
|
android:showAsAction="ifRoom|collapseActionView"
|
||||||
android:actionViewClass="android.widget.SearchView" />
|
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
|
<item
|
||||||
android:id="@+id/menu_info"
|
android:id="@+id/menu_info"
|
||||||
android:icon="@drawable/action_about"
|
android:icon="@drawable/action_about"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="app_name">IITC mobile</string>
|
<string name="app_name">IITC Mobile</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="reload">Reload IITC</string>
|
<string name="reload">Reload IITC</string>
|
||||||
<string name="version">Print Version</string>
|
<string name="version">Print Version</string>
|
||||||
@ -49,7 +49,6 @@
|
|||||||
<string name="pref_select_iitc">IITC source</string>
|
<string name="pref_select_iitc">IITC source</string>
|
||||||
|
|
||||||
<string name="menu_chat">Chat</string>
|
<string name="menu_chat">Chat</string>
|
||||||
<string name="menu_map">Map</string>
|
|
||||||
<string name="menu_full">Full</string>
|
<string name="menu_full">Full</string>
|
||||||
<string name="menu_compact">Compact</string>
|
<string name="menu_compact">Compact</string>
|
||||||
<string name="menu_public">Public</string>
|
<string name="menu_public">Public</string>
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package com.cradle.iitc_mobile;
|
package com.cradle.iitc_mobile;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
import android.app.ActionBar;
|
import android.app.ActionBar;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
@ -16,6 +18,7 @@ import android.location.LocationManager;
|
|||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.StrictMode;
|
import android.os.StrictMode;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
@ -44,6 +47,10 @@ public class IITC_Mobile extends Activity {
|
|||||||
private IITC_DeviceAccountLogin mLogin;
|
private IITC_DeviceAccountLogin mLogin;
|
||||||
private MenuItem searchMenuItem;
|
private MenuItem searchMenuItem;
|
||||||
|
|
||||||
|
// Used for custom back stack handling
|
||||||
|
private ArrayList<Integer> backStack = new ArrayList<Integer>();
|
||||||
|
private int currentPane = android.R.id.home;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -62,8 +69,9 @@ public class IITC_Mobile extends Activity {
|
|||||||
actionBar = this.getActionBar();
|
actionBar = this.getActionBar();
|
||||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
|
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
|
||||||
| ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
|
| ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_TITLE);
|
||||||
actionBar.setTitle(getString(R.string.menu_map));
|
actionBar.setTitle(getString(R.string.app_name));
|
||||||
actionBar.setHomeButtonEnabled(true);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||||
|
actionBar.setHomeButtonEnabled(true);
|
||||||
|
|
||||||
// do something if user changed something in the settings
|
// do something if user changed something in the settings
|
||||||
SharedPreferences sharedPref = PreferenceManager
|
SharedPreferences sharedPref = PreferenceManager
|
||||||
@ -121,6 +129,10 @@ public class IITC_Mobile extends Activity {
|
|||||||
|
|
||||||
fullscreen_actionbar = sharedPref.getBoolean("pref_fullscreen_actionbar", false);
|
fullscreen_actionbar = sharedPref.getBoolean("pref_fullscreen_actionbar", false);
|
||||||
|
|
||||||
|
// Clear the back stack
|
||||||
|
backStack.clear();
|
||||||
|
SetActionBarHomeEnabledWithUp(false);
|
||||||
|
|
||||||
handleIntent(getIntent(), true);
|
handleIntent(getIntent(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,8 +162,10 @@ public class IITC_Mobile extends Activity {
|
|||||||
(SearchView) searchMenuItem.getActionView();
|
(SearchView) searchMenuItem.getActionView();
|
||||||
searchView.setQuery(query, false);
|
searchView.setQuery(query, false);
|
||||||
searchView.clearFocus();
|
searchView.clearFocus();
|
||||||
|
actionBar.setTitle(getString(R.string.app_name));
|
||||||
|
BackStackUpdate(android.R.id.home);
|
||||||
iitc_view.loadUrl("javascript:search('" + query + "');");
|
iitc_view.loadUrl("javascript:search('" + query + "');");
|
||||||
} else if (onCreate){
|
} else if (onCreate) {
|
||||||
this.loadUrl(intel_url);
|
this.loadUrl(intel_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -229,12 +243,41 @@ public class IITC_Mobile extends Activity {
|
|||||||
// we want a self defined behavior for the back button
|
// we want a self defined behavior for the back button
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
// exit fullscreen mode if it is enabled
|
// exit fullscreen mode if it is enabled and action bar is disabled or the back stack is empty
|
||||||
if (fullscreen_mode) {
|
if (fullscreen_mode && (backStack.isEmpty() || fullscreen_actionbar)) {
|
||||||
this.toggleFullscreen();
|
this.toggleFullscreen();
|
||||||
|
} else if (!backStack.isEmpty()) {
|
||||||
|
// Pop last item from backStack and pretend the relevant menu item was clicked
|
||||||
|
BackStackPop();
|
||||||
|
} else {
|
||||||
|
super.onBackPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BackStackPop() {
|
||||||
|
int index = backStack.size() - 1;
|
||||||
|
int itemId = backStack.remove(index);
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
iitc_view.loadUrl("javascript: window.goBack();");
|
HandleMenuItemSelected(itemId, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetActionBarHomeEnabledWithUp(boolean enabled) {
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(enabled);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||||
|
actionBar.setHomeButtonEnabled(enabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BackStackUpdate(int itemId) {
|
||||||
|
if (itemId == currentPane) return;
|
||||||
|
backStack.add(currentPane);
|
||||||
|
currentPane = itemId;
|
||||||
|
if (backStack.size() == 1) SetActionBarHomeEnabledWithUp(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -255,31 +298,43 @@ public class IITC_Mobile extends Activity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
// Handle item selection
|
// Handle item selection
|
||||||
switch (item.getItemId()) {
|
final int itemId = item.getItemId();
|
||||||
|
boolean result = HandleMenuItemSelected(itemId, true);
|
||||||
|
if (!result) return super.onOptionsItemSelected(item);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean HandleMenuItemSelected(int itemId, boolean addToBackStack) {
|
||||||
|
switch (itemId) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
iitc_view.loadUrl("javascript: window.show('map');");
|
if (!backStack.isEmpty()) {
|
||||||
actionBar.setTitle(getString(R.string.menu_map));
|
BackStackPop();
|
||||||
return true;
|
}
|
||||||
case R.id.menu_map:
|
|
||||||
iitc_view.loadUrl("javascript: window.show('map');");
|
|
||||||
actionBar.setTitle(getString(R.string.menu_map));
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.reload_button:
|
case R.id.reload_button:
|
||||||
|
actionBar.setTitle(getString(R.string.app_name));
|
||||||
|
backStack.clear();
|
||||||
|
SetActionBarHomeEnabledWithUp(false);
|
||||||
this.loadUrl(intel_url);
|
this.loadUrl(intel_url);
|
||||||
actionBar.setTitle(getString(R.string.menu_map));
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.toggle_fullscreen:
|
case R.id.toggle_fullscreen:
|
||||||
toggleFullscreen();
|
toggleFullscreen();
|
||||||
return true;
|
return true;
|
||||||
case R.id.layer_chooser:
|
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
|
// the getLayers function calls the setLayers method of IITC_JSInterface
|
||||||
iitc_view.loadUrl("javascript: window.layerChooser.getLayers()");
|
iitc_view.loadUrl("javascript: window.layerChooser.getLayers()");
|
||||||
|
actionBar.setTitle(getString(R.string.app_name));
|
||||||
|
BackStackUpdate(android.R.id.home);
|
||||||
return true;
|
return true;
|
||||||
// get the users current location and focus it on map
|
// get the users current location and focus it on map
|
||||||
case R.id.locate:
|
case R.id.locate:
|
||||||
iitc_view.loadUrl("javascript: window.show('map');");
|
iitc_view.loadUrl("javascript: window.show('map');");
|
||||||
iitc_view.loadUrl("javascript: window.map.locate({setView : true, maxZoom: 15});");
|
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;
|
return true;
|
||||||
// start settings activity
|
// start settings activity
|
||||||
case R.id.action_settings:
|
case R.id.action_settings:
|
||||||
@ -291,29 +346,41 @@ public class IITC_Mobile extends Activity {
|
|||||||
case R.id.menu_info:
|
case R.id.menu_info:
|
||||||
iitc_view.loadUrl("javascript: window.show('info');");
|
iitc_view.loadUrl("javascript: window.show('info');");
|
||||||
actionBar.setTitle(getString(R.string.menu_info));
|
actionBar.setTitle(getString(R.string.menu_info));
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
if (addToBackStack) BackStackUpdate(itemId);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_full:
|
case R.id.menu_full:
|
||||||
iitc_view.loadUrl("javascript: window.show('full');");
|
iitc_view.loadUrl("javascript: window.show('full');");
|
||||||
actionBar.setTitle(getString(R.string.menu_full));
|
actionBar.setTitle(getString(R.string.menu_full));
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
if (addToBackStack) BackStackUpdate(itemId);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_compact:
|
case R.id.menu_compact:
|
||||||
iitc_view.loadUrl("javascript: window.show('compact');");
|
iitc_view.loadUrl("javascript: window.show('compact');");
|
||||||
actionBar.setTitle(getString(R.string.menu_compact));
|
actionBar.setTitle(getString(R.string.menu_compact));
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
if (addToBackStack) BackStackUpdate(itemId);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_public:
|
case R.id.menu_public:
|
||||||
iitc_view.loadUrl("javascript: window.show('public');");
|
iitc_view.loadUrl("javascript: window.show('public');");
|
||||||
actionBar.setTitle(getString(R.string.menu_public));
|
actionBar.setTitle(getString(R.string.menu_public));
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
if (addToBackStack) BackStackUpdate(itemId);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_faction:
|
case R.id.menu_faction:
|
||||||
iitc_view.loadUrl("javascript: window.show('faction');");
|
iitc_view.loadUrl("javascript: window.show('faction');");
|
||||||
actionBar.setTitle(getString(R.string.menu_faction));
|
actionBar.setTitle(getString(R.string.menu_faction));
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
if (addToBackStack) BackStackUpdate(itemId);
|
||||||
return true;
|
return true;
|
||||||
case R.id.menu_debug:
|
case R.id.menu_debug:
|
||||||
iitc_view.loadUrl("javascript: window.show('debug')");
|
iitc_view.loadUrl("javascript: window.show('debug')");
|
||||||
actionBar.setTitle(getString(R.string.menu_debug));
|
actionBar.setTitle(getString(R.string.menu_debug));
|
||||||
|
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
if (addToBackStack) BackStackUpdate(itemId);
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,17 +421,20 @@ public class IITC_Mobile extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void toggleFullscreen() {
|
public void toggleFullscreen() {
|
||||||
|
// TODO: Figure out how to handle this with new back stack?
|
||||||
|
|
||||||
if (fullscreen_mode) {
|
if (fullscreen_mode) {
|
||||||
if (fullscreen_actionbar)
|
if (fullscreen_actionbar)
|
||||||
this.getActionBar().show();
|
this.getActionBar().show();
|
||||||
this.fullscreen_mode = false;
|
this.fullscreen_mode = false;
|
||||||
} else {
|
} else {
|
||||||
if (fullscreen_actionbar)
|
if (fullscreen_actionbar) {
|
||||||
this.getActionBar().hide();
|
this.getActionBar().hide();
|
||||||
|
// 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;
|
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();
|
|
||||||
}
|
}
|
||||||
// toggle notification bar
|
// toggle notification bar
|
||||||
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
WindowManager.LayoutParams attrs = getWindow().getAttributes();
|
||||||
|
Reference in New Issue
Block a user