overhauled button pressed backStack behaviour...use a JS callback to let it work with JS calls

This commit is contained in:
Philipp Schaefer 2013-06-14 16:49:54 +02:00
parent cc44392d03
commit d21fdc0176
5 changed files with 72 additions and 40 deletions

View File

@ -2,6 +2,9 @@
//
window.show = function(id) {
window.hideall();
if (typeof android !== 'undefined' && android && android.switchToPane) {
android.switchToPane(id);
}
switch(id) {
case 'full':
window.chat.show('full');

View File

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

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="27"
android:versionName="0.4.6">
android:versionCode="28"
android:versionName="0.4.7">
<uses-sdk
android:minSdkVersion="14"

View File

@ -65,12 +65,52 @@ public class IITC_JSInterface {
}
@JavascriptInterface
public void portalLongPressed() {
public void switchToPane(String id) {
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() {
@Override
public void run() {
iitcm.handleMenuItemSelected(R.id.menu_info, true);
iitcm.getActionBar().setTitle(title);
iitcm.backStackUpdate(button_id);
}
});
}

View File

@ -52,6 +52,7 @@ public class IITC_Mobile extends Activity {
// Used for custom back stack handling
private ArrayList<Integer> backStack = new ArrayList<Integer>();
private boolean backStack_push = true;
private int currentPane = android.R.id.home;
@Override
@ -292,6 +293,7 @@ public class IITC_Mobile extends Activity {
actionBar.setDisplayHomeAsUpEnabled(enabled);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)
actionBar.setHomeButtonEnabled(enabled);
invalidateOptionsMenu();
}
public void backStackPop() {
@ -306,20 +308,31 @@ public class IITC_Mobile extends Activity {
}
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);
}
backStack_push = false;
handleMenuItemSelected(itemId);
}
public void backStackUpdate(int itemId) {
// ensure no double adds
if (itemId == currentPane) return;
backStack.add(currentPane);
if (itemId == android.R.id.home) {
backStack.clear();
backStack_push = true;
} else {
if (backStack_push)
backStack.add(currentPane);
else
backStack_push = true;
}
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
@ -343,19 +356,15 @@ public class IITC_Mobile extends Activity {
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
final int itemId = item.getItemId();
boolean result = handleMenuItemSelected(itemId, true);
boolean result = handleMenuItemSelected(itemId);
if (!result) return super.onOptionsItemSelected(item);
return true;
}
public boolean handleMenuItemSelected(int itemId, boolean addToBackStack) {
public boolean handleMenuItemSelected(int itemId) {
switch (itemId) {
case android.R.id.home:
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;
case R.id.reload_button:
actionBar.setTitle(getString(R.string.app_name));
@ -372,8 +381,6 @@ public class IITC_Mobile extends Activity {
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:
@ -388,8 +395,6 @@ public class IITC_Mobile extends Activity {
last_location.getLatitude() + "," +
last_location.getLongitude() + "), 15);");
}
actionBar.setTitle(getString(R.string.app_name));
backStackUpdate(android.R.id.home);
return true;
// start settings activity
case R.id.action_settings:
@ -400,33 +405,21 @@ public class IITC_Mobile extends Activity {
return true;
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 false;