got back long press on portal functionality

This commit is contained in:
Philipp Schaefer 2013-05-25 13:39:58 +02:00
parent 5cc27b70d9
commit d3461b0451
3 changed files with 51 additions and 24 deletions

View File

@ -81,7 +81,24 @@ 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 + '%');
// NOTE: Removed long press hook as it would break new back stack handling // add event to portals that allows long press to switch to sidebar
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 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();
}
});
});
});
// Force lower render limits for mobile // Force lower render limits for mobile
window.VIEWPORT_PAD_RATIO = 0.1; window.VIEWPORT_PAD_RATIO = 0.1;

View File

@ -64,6 +64,16 @@ public class IITC_JSInterface {
.show(); .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 // get layers and list them in a dialog
@JavascriptInterface @JavascriptInterface
public void setLayers(String base_layer, String overlay_layer) { public void setLayers(String base_layer, String overlay_layer) {

View File

@ -162,7 +162,7 @@ public class IITC_Mobile extends Activity {
searchView.setQuery(query, false); searchView.setQuery(query, false);
searchView.clearFocus(); searchView.clearFocus();
actionBar.setTitle(getString(R.string.app_name)); actionBar.setTitle(getString(R.string.app_name));
BackStackUpdate(android.R.id.home); 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);
@ -247,13 +247,19 @@ public class IITC_Mobile extends Activity {
this.toggleFullscreen(); this.toggleFullscreen();
} else if (!backStack.isEmpty()) { } else if (!backStack.isEmpty()) {
// Pop last item from backStack and pretend the relevant menu item was clicked // Pop last item from backStack and pretend the relevant menu item was clicked
BackStackPop(); backStackPop();
} else { } else {
super.onBackPressed(); super.onBackPressed();
} }
} }
private void BackStackPop() { 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() {
if (backStack.isEmpty()) { if (backStack.isEmpty()) {
// Empty back stack means we should be at home (ie map) screen // Empty back stack means we should be at home (ie map) screen
SetActionBarHomeEnabledWithUp(false); SetActionBarHomeEnabledWithUp(false);
@ -264,16 +270,10 @@ 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; currentPane = itemId;
HandleMenuItemSelected(itemId, false); handleMenuItemSelected(itemId, false);
} }
private void SetActionBarHomeEnabledWithUp(boolean enabled) { public void backStackUpdate(int itemId) {
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; if (itemId == currentPane) return;
backStack.add(currentPane); backStack.add(currentPane);
currentPane = itemId; currentPane = itemId;
@ -299,16 +299,16 @@ 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, true);
if (!result) return super.onOptionsItemSelected(item); if (!result) return super.onOptionsItemSelected(item);
return true; return true;
} }
private boolean HandleMenuItemSelected(int itemId, boolean addToBackStack) { public boolean handleMenuItemSelected(int itemId, boolean addToBackStack) {
switch (itemId) { switch (itemId) {
case android.R.id.home: case android.R.id.home:
if (!backStack.isEmpty()) { if (!backStack.isEmpty()) {
BackStackPop(); backStackPop();
} }
iitc_view.loadUrl("javascript: window.show('map');"); iitc_view.loadUrl("javascript: window.show('map');");
actionBar.setTitle(getString(R.string.app_name)); actionBar.setTitle(getString(R.string.app_name));
@ -329,14 +329,14 @@ public class IITC_Mobile extends Activity {
// 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)); actionBar.setTitle(getString(R.string.app_name));
BackStackUpdate(android.R.id.home); 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.app_name)); actionBar.setTitle(getString(R.string.app_name));
BackStackUpdate(android.R.id.home); 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:
@ -347,33 +347,33 @@ 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)); actionBar.setTitle((R.string.menu_info));
if (addToBackStack) BackStackUpdate(itemId); 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));
if (addToBackStack) BackStackUpdate(itemId); 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));
if (addToBackStack) BackStackUpdate(itemId); 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));
if (addToBackStack) BackStackUpdate(itemId); 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));
if (addToBackStack) BackStackUpdate(itemId); 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));
if (addToBackStack) BackStackUpdate(itemId); if (addToBackStack) backStackUpdate(itemId);
return true; return true;
default: default:
return false; return false;