overhauled button pressed backStack behaviour...use a JS callback to let it work with JS calls
This commit is contained in:
parent
cc44392d03
commit
d21fdc0176
@ -2,6 +2,9 @@
|
|||||||
//
|
//
|
||||||
window.show = function(id) {
|
window.show = function(id) {
|
||||||
window.hideall();
|
window.hideall();
|
||||||
|
if (typeof android !== 'undefined' && android && android.switchToPane) {
|
||||||
|
android.switchToPane(id);
|
||||||
|
}
|
||||||
switch(id) {
|
switch(id) {
|
||||||
case 'full':
|
case 'full':
|
||||||
window.chat.show('full');
|
window.chat.show('full');
|
||||||
|
@ -91,11 +91,7 @@ window.runOnSmartphonesAfterBoot = function() {
|
|||||||
// this is a hack, accessing Leaflet’s private _container is evil
|
// this is a hack, accessing Leaflet’s private _container is evil
|
||||||
$(this._container).on('taphold', function() {
|
$(this._container).on('taphold', function() {
|
||||||
window.renderPortalDetails(guid);
|
window.renderPortalDetails(guid);
|
||||||
if (typeof android !== 'undefined' && android && android.portalLongPressed) {
|
window.show('info');
|
||||||
android.portalLongPressed();
|
|
||||||
} else {
|
|
||||||
window.smartphone.sideButton.click();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -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="27"
|
android:versionCode="28"
|
||||||
android:versionName="0.4.6">
|
android:versionName="0.4.7">
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="14"
|
android:minSdkVersion="14"
|
||||||
|
@ -65,12 +65,52 @@ public class IITC_JSInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void portalLongPressed() {
|
public void switchToPane(String id) {
|
||||||
|
|
||||||
final IITC_Mobile iitcm = (IITC_Mobile) context;
|
final IITC_Mobile iitcm = (IITC_Mobile) context;
|
||||||
|
final int button_id;
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
if (id.equals("map")) {
|
||||||
|
button_id = android.R.id.home;
|
||||||
|
title = iitcm.getString(R.string.app_name);
|
||||||
|
}
|
||||||
|
else if (id.equals("info")) {
|
||||||
|
button_id = R.id.menu_info;
|
||||||
|
title = "Info";
|
||||||
|
}
|
||||||
|
else if (id.equals("full")) {
|
||||||
|
button_id = R.id.menu_full;
|
||||||
|
title = "Full";
|
||||||
|
}
|
||||||
|
else if (id.equals("compact")) {
|
||||||
|
button_id = R.id.menu_compact;
|
||||||
|
title = "Compact";
|
||||||
|
}
|
||||||
|
else if (id.equals("public")) {
|
||||||
|
button_id = R.id.menu_public;
|
||||||
|
title = "Public";
|
||||||
|
}
|
||||||
|
else if (id.equals("faction")) {
|
||||||
|
button_id = R.id.menu_faction;
|
||||||
|
title = "Faction";
|
||||||
|
}
|
||||||
|
else if (id.equals("debug")) {
|
||||||
|
button_id = R.id.menu_debug;
|
||||||
|
title = "Debug";
|
||||||
|
}
|
||||||
|
// default
|
||||||
|
else {
|
||||||
|
button_id = android.R.id.home;
|
||||||
|
title = iitcm.getString(R.string.app_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.d("iitcm", "switch to pane " + id);
|
||||||
iitcm.runOnUiThread(new Runnable() {
|
iitcm.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
iitcm.handleMenuItemSelected(R.id.menu_info, true);
|
iitcm.getActionBar().setTitle(title);
|
||||||
|
iitcm.backStackUpdate(button_id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
|
|
||||||
// Used for custom back stack handling
|
// Used for custom back stack handling
|
||||||
private ArrayList<Integer> backStack = new ArrayList<Integer>();
|
private ArrayList<Integer> backStack = new ArrayList<Integer>();
|
||||||
|
private boolean backStack_push = true;
|
||||||
private int currentPane = android.R.id.home;
|
private int currentPane = android.R.id.home;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -292,6 +293,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
actionBar.setDisplayHomeAsUpEnabled(enabled);
|
actionBar.setDisplayHomeAsUpEnabled(enabled);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||||
actionBar.setHomeButtonEnabled(enabled);
|
actionBar.setHomeButtonEnabled(enabled);
|
||||||
|
invalidateOptionsMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void backStackPop() {
|
public void backStackPop() {
|
||||||
@ -306,20 +308,31 @@ public class IITC_Mobile extends Activity {
|
|||||||
}
|
}
|
||||||
int index = backStack.size() - 1;
|
int index = backStack.size() - 1;
|
||||||
int itemId = backStack.remove(index);
|
int itemId = backStack.remove(index);
|
||||||
currentPane = itemId;
|
backStack_push = false;
|
||||||
handleMenuItemSelected(itemId, false);
|
handleMenuItemSelected(itemId);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void backStackUpdate(int itemId) {
|
public void backStackUpdate(int itemId) {
|
||||||
|
// ensure no double adds
|
||||||
if (itemId == currentPane) return;
|
if (itemId == currentPane) return;
|
||||||
|
if (itemId == android.R.id.home) {
|
||||||
|
backStack.clear();
|
||||||
|
backStack_push = true;
|
||||||
|
} else {
|
||||||
|
if (backStack_push)
|
||||||
backStack.add(currentPane);
|
backStack.add(currentPane);
|
||||||
|
else
|
||||||
|
backStack_push = true;
|
||||||
|
}
|
||||||
|
|
||||||
currentPane = itemId;
|
currentPane = itemId;
|
||||||
if (backStack.size() == 1) setActionBarHomeEnabledWithUp(true);
|
if (backStack.size() >= 1) {
|
||||||
|
setActionBarHomeEnabledWithUp(true);
|
||||||
|
} else {
|
||||||
|
// if we popped our last item from stack...illustrate it on home button
|
||||||
|
// Empty back stack means we should be at home (ie map) screen
|
||||||
|
setActionBarHomeEnabledWithUp(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -343,19 +356,15 @@ public class IITC_Mobile extends Activity {
|
|||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
// Handle item selection
|
// Handle item selection
|
||||||
final int itemId = item.getItemId();
|
final int itemId = item.getItemId();
|
||||||
boolean result = handleMenuItemSelected(itemId, true);
|
boolean result = handleMenuItemSelected(itemId);
|
||||||
if (!result) return super.onOptionsItemSelected(item);
|
if (!result) return super.onOptionsItemSelected(item);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean handleMenuItemSelected(int itemId, boolean addToBackStack) {
|
public boolean handleMenuItemSelected(int itemId) {
|
||||||
switch (itemId) {
|
switch (itemId) {
|
||||||
case android.R.id.home:
|
case android.R.id.home:
|
||||||
iitc_view.loadUrl("javascript: window.show('map');");
|
iitc_view.loadUrl("javascript: window.show('map');");
|
||||||
actionBar.setTitle(getString(R.string.app_name));
|
|
||||||
this.backStack.clear();
|
|
||||||
setActionBarHomeEnabledWithUp(false);
|
|
||||||
currentPane = android.R.id.home;
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.reload_button:
|
case R.id.reload_button:
|
||||||
actionBar.setTitle(getString(R.string.app_name));
|
actionBar.setTitle(getString(R.string.app_name));
|
||||||
@ -372,8 +381,6 @@ public class IITC_Mobile extends Activity {
|
|||||||
iitc_view.loadUrl("javascript: window.show('map');");
|
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:
|
||||||
@ -388,8 +395,6 @@ public class IITC_Mobile extends Activity {
|
|||||||
last_location.getLatitude() + "," +
|
last_location.getLatitude() + "," +
|
||||||
last_location.getLongitude() + "), 15);");
|
last_location.getLongitude() + "), 15);");
|
||||||
}
|
}
|
||||||
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:
|
||||||
@ -400,33 +405,21 @@ public class IITC_Mobile extends Activity {
|
|||||||
return true;
|
return true;
|
||||||
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));
|
|
||||||
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));
|
|
||||||
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));
|
|
||||||
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));
|
|
||||||
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));
|
|
||||||
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));
|
|
||||||
if (addToBackStack) backStackUpdate(itemId);
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user