Refactor context menu

This commit is contained in:
Victor Shcherb 2012-08-05 14:23:06 +03:00
parent 28ed74045d
commit 34a6a245f7
11 changed files with 285 additions and 227 deletions

View file

@ -12,7 +12,6 @@ import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
@ -146,6 +145,8 @@ public class BinaryMapIndexReader {
mapIndex.length = readInt();
mapIndex.filePointer = codedIS.getTotalBytesRead();
int oldLimit = codedIS.pushLimit(mapIndex.length);
// FIXME
// codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
readMapIndex(mapIndex);
basemap = basemap || mapIndex.isBaseMap();
codedIS.popLimit(oldLimit);
@ -159,6 +160,8 @@ public class BinaryMapIndexReader {
region.filePointer = codedIS.getTotalBytesRead();
if(addressAdapter != null){
oldLimit = codedIS.pushLimit(region.length);
// FIXME
// codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
addressAdapter.readAddressIndex(region);
if(region.name != null){
addressIndexes.add(region);
@ -174,6 +177,8 @@ public class BinaryMapIndexReader {
ind.filePointer = codedIS.getTotalBytesRead();
if (transportAdapter != null) {
oldLimit = codedIS.pushLimit(ind.length);
// FIXME
// codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
transportAdapter.readTransportIndex(ind);
codedIS.popLimit(oldLimit);
transportIndexes.add(ind);
@ -187,6 +192,8 @@ public class BinaryMapIndexReader {
routeReg.filePointer = codedIS.getTotalBytesRead();
if (routeAdapter != null) {
oldLimit = codedIS.pushLimit(routeReg.length);
// FIXME
// codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
routeAdapter.readRouteIndex(routeReg);
codedIS.popLimit(oldLimit);
routingIndexes.add(routeReg);
@ -200,6 +207,8 @@ public class BinaryMapIndexReader {
poiInd.filePointer = codedIS.getTotalBytesRead();
if (poiAdapter != null) {
oldLimit = codedIS.pushLimit(poiInd.length);
// FIXME
// codedIS.skipRawBytes(codedIS.getBytesUntilLimit());
poiAdapter.readPoiIndex(poiInd);
codedIS.popLimit(oldLimit);
poiIndexes.add(poiInd);

View file

@ -1,23 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<group android:id="@+id/map_context_menu" android:menuCategory="container">
<item android:title="@string/where_am_i" android:id="@+id/map_where_am_i" android:icon="@android:drawable/ic_menu_mylocation"></item>
<item android:id="@+id/map_layers" android:title="@string/menu_layers" android:icon="@android:drawable/ic_menu_mapmode"></item>
<item android:id="@+id/map_show_settings" android:title="@string/settings_Button" android:icon="@android:drawable/ic_menu_preferences"></item>
<!-- not visible by default -->
<item android:id="@+id/map_navigate_to_point" android:title="@string/stop_navigation" android:visible="false" android:icon="@android:drawable/ic_menu_close_clear_cancel"></item>
<item android:id="@+id/map_mute" android:title="@string/menu_mute_off" android:visible="false"></item>
<item android:id="@+id/map_get_directions" android:title="@string/get_directions" android:icon="@android:drawable/ic_menu_directions"></item>
<item android:title="@string/search_button" android:id="@+id/map_specify_point" android:icon="@android:drawable/ic_menu_search"></item>
<item android:id="@+id/map_animate_route" android:title="@string/animate_route" android:visible="false"></item>
<item android:title="@string/show_gps_status" android:id="@+id/map_show_gps_status" android:icon="@android:drawable/ic_menu_compass"></item>
<item android:id="@+id/map_show_point_options" android:title="@string/show_point_options"></item>
</group>
</menu>

View file

@ -181,11 +181,9 @@ You can enable (online or cached) tile map sources, tracking settings, and many
</string>
<string name="osm_editing_plugin_description">Show settings needed for OSM feedback like collecting / modifying OSM POI objects, opening / commenting OSM bugs, and contributing recorded GPX files (requires OSM credentials).</string>
<string name="vector_maps_may_display_faster_on_some_devices">Vector maps likely display faster. May not work well on some devices.</string>
<string name="simulate_route_progression_manually">Simulate route progression manually</string>
<string name="play_commands_of_currently_selected_voice">Play commands of currently selected voice</string>
<string name="debugging_and_development">OsmAnd development</string>
<string name="native_rendering">Native rendering</string>
<string name="animate_routing">Animate navigation</string>
<string name="test_voice_prompts">Test voice prompts</string>
<string name="switch_to_raster_map_to_see">No offline vector map present for this location. You can download one in Settings (Offline data), or switch to online maps.</string>
<string name="tip_recent_changes_0_7_2_t">Changes in 0.7.2 :

View file

@ -23,17 +23,17 @@
android:summary="@string/choose_auto_follow_route_descr"></ListPreference>
<CheckBoxPreference android:title="@string/auto_zoom_map" android:summary="@string/auto_zoom_map_descr" android:key="auto_zoom_map"></CheckBoxPreference>
<CheckBoxPreference android:summary="@string/show_speed_limits_descr" android:title="@string/show_speed_limits"
<!-- <CheckBoxPreference android:summary="@string/show_speed_limits_descr" android:title="@string/show_speed_limits"
android:key="show_speed_limits"></CheckBoxPreference>
<CheckBoxPreference android:summary="@string/show_cameras_descr" android:title="@string/show_cameras"
android:key="show_cameras"></CheckBoxPreference>
<CheckBoxPreference android:title="@string/auto_zoom_map" android:summary="@string/auto_zoom_map_descr" android:key="auto_zoom_map"></CheckBoxPreference>
<CheckBoxPreference android:summary="@string/avoid_toll_roads_descr" android:title="@string/avoid_toll_roads"
android:key="avoid_toll_roads"></CheckBoxPreference>
<!--
android:key="avoid_toll_roads"></CheckBoxPreference> -->
<Preference android:title="@string/show_warnings_title" android:summary="@string/show_warnings_descr" android:key="show_routing_alarms"/>
<Preference android:title="@string/avoid_in_routing_title" android:summary="@string/avoid_in_routing_descr" android:key="avoid_in_routing"/>
-->
<CheckBoxPreference android:summary="@string/use_compass_navigation_descr" android:title="@string/use_compass_navigation"
android:key="use_compass_navigation"></CheckBoxPreference>
</PreferenceScreen>

View file

@ -1,32 +1,82 @@
package net.osmand.plus;
import gnu.trove.list.array.TIntArrayList;
import java.util.ArrayList;
import android.view.Menu;
import android.view.MenuItem;
public class OptionsMenuHelper {
private final Menu menu;
public OptionsMenuHelper(Menu menu) {
this.menu = menu;
public interface OnOptionsMenuClick {
public void prepareOptionsMenu(Menu menu, MenuItem item);
public boolean onClick(MenuItem item);
}
public void registerOptionsMenuItem(int resItemId, int resName, int resIcon, boolean visibility) {
if (resIcon != -1) {
menu.add(Menu.CATEGORY_CONTAINER, resItemId, Menu.NONE, resName).setVisible(visibility).setIcon(resIcon);
} else {
menu.add(Menu.CATEGORY_CONTAINER, resItemId, Menu.NONE, resName).setVisible(visibility);
final TIntArrayList items = new TIntArrayList();
final TIntArrayList itemNames = new TIntArrayList();
final TIntArrayList visible = new TIntArrayList();
final ArrayList<OnOptionsMenuClick> listeners = new ArrayList<OnOptionsMenuClick>();
final TIntArrayList iconList = new TIntArrayList();
public OptionsMenuHelper() {
}
public void registerOptionsMenu(Menu menu) {
for (int i = 0; i < items.size(); i++) {
int resItemId = items.get(i);
int resName = itemNames.get(i);
int resIcon = iconList.get(i);
boolean visibility = visible.get(i) > 0;
if (resIcon != -1) {
menu.add(Menu.CATEGORY_CONTAINER, resItemId, Menu.NONE, resName).setVisible(visibility).setIcon(resIcon);
} else {
menu.add(Menu.CATEGORY_CONTAINER, resItemId, Menu.NONE, resName).setVisible(visibility);
}
}
}
public void registerOptionsMenuItem(int resItemId, int resName, int resIcon) {
registerOptionsMenuItem(resItemId, resName, resIcon, true);
public boolean onClick(MenuItem mi) {
int id = mi.getItemId();
int ind = items.indexOf(id);
if(ind >= 0 && ind < listeners.size() && listeners.get(ind) != null) {
return listeners.get(ind).onClick(mi);
}
return false;
}
public void prepareOptionsMenu(Menu menu) {
for (int i = 0; i < items.size(); i++) {
int resItemId = items.get(i);
OnOptionsMenuClick l = listeners.get(i);
if (l != null) {
l.prepareOptionsMenu(menu, menu.findItem(resItemId));
}
}
}
public void registerOptionsMenuItem(int resItemId, int resName, boolean visibility) {
registerOptionsMenuItem(resItemId, resName, -1, visibility);
public void registerOptionsMenuItem(int resItemId, int resName, int resIcon, boolean visibility, OnOptionsMenuClick onClick) {
items.add(resItemId);
itemNames.add(resName);
visible.add(visibility ? 1 : 0);
listeners.add(onClick);
iconList.add(resIcon);
}
public void registerOptionsMenuItem(int resItemId, int resName) {
registerOptionsMenuItem(resItemId, resName, -1, true);
public void registerOptionsMenuItem(int resItemId, int resName, int resIcon, OnOptionsMenuClick onClick) {
registerOptionsMenuItem(resItemId, resName, resIcon, true, onClick);
}
public void registerOptionsMenuItem(int resItemId, int resName, boolean visibility, OnOptionsMenuClick onClick) {
registerOptionsMenuItem(resItemId, resName, -1, visibility, onClick);
}
public void registerOptionsMenuItem(int resItemId, int resName, OnOptionsMenuClick onClick) {
registerOptionsMenuItem(resItemId, resName, -1, true, onClick);
}
}

View file

@ -25,7 +25,6 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.preference.PreferenceScreen;
import android.view.Menu;
public abstract class OsmandPlugin {
@ -120,10 +119,6 @@ public abstract class OsmandPlugin {
public void registerOptionsMenuItems(MapActivity mapActivity, OptionsMenuHelper helper) {}
public void prepareOptionsMenuItems(MapActivity mapActivity, Menu menu) {}
public boolean onOptionsItemSelected(MapActivity mapActivity, int itemId) { return false; }
public static void refreshLayers(OsmandMapTileView mapView, MapActivity activity) {
for (OsmandPlugin plugin : activePlugins) {
plugin.updateLayers(mapView, activity);
@ -216,21 +211,6 @@ public abstract class OsmandPlugin {
}
}
public static void registerOnPrepareOptionsMenu(MapActivity mapActivity, Menu menu) {
for (OsmandPlugin plugin : activePlugins) {
plugin.prepareOptionsMenuItems(mapActivity, menu);
}
}
public static boolean registerOnOptionsMenuItemSelected(MapActivity mapActivity, int itemId) {
for (OsmandPlugin plugin : activePlugins) {
if (plugin.onOptionsItemSelected(mapActivity, itemId)) {
return true;
}
}
return false;
}
private static void installParkingPlugin(OsmandApplication app) {
Intent parkingIntent = new Intent();
parkingIntent.setComponent(new ComponentName(PARKING_PLUGIN_COMPONENT, PARKING_PLUGIN_ACTIVITY));

View file

@ -31,7 +31,6 @@ import android.content.SharedPreferences.Editor;
import android.content.pm.ActivityInfo;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.location.LocationManager;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@ -1226,10 +1225,6 @@ public class OsmandSettings {
// for background service
public final OsmandPreference<Boolean> MAP_ACTIVITY_ENABLED = new BooleanPreference("map_activity_enabled", false).makeGlobal();
// test animate routing
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> TEST_ANIMATE_ROUTING = new BooleanPreference("animate_routing", false).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<Boolean> NATIVE_RENDERING = new BooleanPreference("native_rendering", true).makeGlobal();

View file

@ -26,13 +26,13 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OptionsMenuHelper;
import net.osmand.plus.OptionsMenuHelper.OnOptionsMenuClick;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.ResourceManager;
import net.osmand.plus.activities.search.SearchActivity;
import net.osmand.plus.routing.RouteAnimation;
import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.BaseMapLayer;
@ -57,7 +57,6 @@ import android.location.Location;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings.Secure;
import android.text.ClipboardManager;
import android.text.Html;
import android.util.FloatMath;
@ -100,7 +99,8 @@ public class MapActivityActions implements DialogProvider {
private final MapActivity mapActivity;
private OsmandSettings settings;
private RoutingHelper routingHelper;
private RouteAnimation routeAnimation = new RouteAnimation();
private OptionsMenuHelper optionsMenuHelper;
public MapActivityActions(MapActivity mapActivity){
this.mapActivity = mapActivity;
@ -844,138 +844,166 @@ public class MapActivityActions implements DialogProvider {
}
public boolean onCreateOptionsMenu(Menu menu) {
// NOTE: delete not a "menu.xml" because all id-resources are generated to R-class from there
OptionsMenuHelper helper = new OptionsMenuHelper(menu);
helper.registerOptionsMenuItem(R.id.map_where_am_i, R.string.where_am_i, android.R.drawable.ic_menu_mylocation);
helper.registerOptionsMenuItem(R.id.map_layers, R.string.menu_layers, android.R.drawable.ic_menu_mapmode);
helper.registerOptionsMenuItem(R.id.map_show_settings, R.string.settings_Button, android.R.drawable.ic_menu_preferences);
helper.registerOptionsMenuItem(R.id.map_navigate_to_point, R.string.stop_navigation, android.R.drawable.ic_menu_close_clear_cancel, false);
helper.registerOptionsMenuItem(R.id.map_mute, R.string.menu_mute_off, false);
helper.registerOptionsMenuItem(R.id.map_get_directions, R.string.get_directions, android.R.drawable.ic_menu_directions);
helper.registerOptionsMenuItem(R.id.map_animate_route, R.string.animate_route, false);
helper.registerOptionsMenuItem(R.id.map_specify_point, R.string.search_button, android.R.drawable.ic_menu_search);
helper.registerOptionsMenuItem(R.id.map_show_gps_status, R.string.show_gps_status, android.R.drawable.ic_menu_compass);
helper.registerOptionsMenuItem(R.id.map_show_point_options, R.string.show_point_options);
OsmandPlugin.registerOptionsMenu(mapActivity, helper);
final OsmandMapTileView mapView = mapActivity.getMapView();
optionsMenuHelper = new OptionsMenuHelper();
optionsMenuHelper.registerOptionsMenuItem(R.string.where_am_i, R.string.where_am_i, android.R.drawable.ic_menu_mylocation,
new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem item) {
}
@Override
public boolean onClick(MenuItem item) {
if (getMyApplication().accessibilityEnabled()) {
whereAmIDialog();
} else {
mapActivity.backToLocationImpl();
}
return true;
}
});
optionsMenuHelper.registerOptionsMenuItem(R.string.menu_layers, R.string.menu_layers, android.R.drawable.ic_menu_mapmode,
new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem item) {
}
@Override
public boolean onClick(MenuItem item) {
mapActivity.getMapLayers().openLayerSelectionDialog(mapView);
return true;
}
});
optionsMenuHelper.registerOptionsMenuItem(R.string.settings_Button, R.string.settings_Button, android.R.drawable.ic_menu_preferences,
new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem item) {
}
@Override
public boolean onClick(MenuItem item) {
final Intent intentSettings = new Intent(mapActivity, OsmandIntents.getSettingsActivity());
mapActivity.startActivity(intentSettings);
return true;
}
});
optionsMenuHelper.registerOptionsMenuItem(R.string.stop_navigation, R.string.stop_navigation, android.R.drawable.ic_menu_close_clear_cancel, false,
new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem navigateToPointMenu) {
if (settings.getPointToNavigate() != null) {
navigateToPointMenu.setTitle((routingHelper.isRouteCalculated() || routingHelper.isFollowingMode() ||
routingHelper.isRouteBeingCalculated()) ? R.string.stop_routing : R.string.stop_navigation);
navigateToPointMenu.setVisible(true);
} else {
navigateToPointMenu.setVisible(false);
}
}
@Override
public boolean onClick(MenuItem item) {
if (mapActivity.getMapLayers().getNavigationLayer().getPointToNavigate() != null) {
if (routingHelper.isRouteCalculated() || routingHelper.isFollowingMode() || routingHelper.isRouteBeingCalculated()) {
routingHelper.setFinalAndCurrentLocation(null, routingHelper.getCurrentLocation(), routingHelper.getCurrentGPXRoute());
// restore default mode
boolean changed = settings.APPLICATION_MODE.set(settings.PREV_APPLICATION_MODE.get());
mapActivity.updateApplicationModeSettings();
mapView.refreshMap(changed);
} else {
mapActivity.navigateToPoint(null);
}
} else {
mapActivity.navigateToPoint(new LatLon(mapView.getLatitude(), mapView.getLongitude()));
}
mapView.refreshMap();
return true;
}
});
optionsMenuHelper.registerOptionsMenuItem(R.string.menu_mute_off, R.string.menu_mute_off, false, new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem muteMenu) {
if (routingHelper.getFinalLocation() != null && routingHelper.isFollowingMode()) {
boolean mute = routingHelper.getVoiceRouter().isMute();
muteMenu.setTitle(mute ? R.string.menu_mute_on : R.string.menu_mute_off);
muteMenu.setIcon(mute ? R.drawable.ic_menu_soundoff : R.drawable.ic_menu_soundon);
muteMenu.setVisible(true);
} else {
muteMenu.setVisible(false);
}
}
@Override
public boolean onClick(MenuItem item) {
routingHelper.getVoiceRouter().setMute(!routingHelper.getVoiceRouter().isMute());
return true;
}
});
optionsMenuHelper.registerOptionsMenuItem(R.string.get_directions, R.string.get_directions, android.R.drawable.ic_menu_directions,
new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem directions) {
if(routingHelper.isRouteCalculated()){
directions.setTitle(R.string.show_route);
} else {
directions.setTitle(R.string.get_directions);
}
}
@Override
public boolean onClick(MenuItem item) {
if (routingHelper.isRouteCalculated()) {
aboutRoute();
} else {
Location loc = mapActivity.getLastKnownLocation();
getDirections(loc, true);
}
return true;
}
});
optionsMenuHelper.registerOptionsMenuItem(R.string.search_button, R.string.search_button, android.R.drawable.ic_menu_search, new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem item) {
}
@Override
public boolean onClick(MenuItem item) {
Intent newIntent = new Intent(mapActivity, OsmandIntents.getSearchActivity());
// causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
LatLon loc = mapActivity.getMapLocation();
newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude());
newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude());
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mapActivity.startActivity(newIntent);
return true;
}
});
optionsMenuHelper.registerOptionsMenuItem(R.string.show_gps_status, R.string.show_gps_status, android.R.drawable.ic_menu_compass, new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem item) {
}
@Override
public boolean onClick(MenuItem item) {
startGpsStatusIntent();
return false;
}
});
optionsMenuHelper.registerOptionsMenuItem(R.string.show_point_options, R.string.show_point_options, new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem item) {
}
@Override
public boolean onClick(MenuItem item) {
contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
return true;
}
});
OsmandPlugin.registerOptionsMenu(mapActivity, optionsMenuHelper);
optionsMenuHelper.registerOptionsMenu(menu);
return true;
}
public void onPrepareOptionsMenu(Menu menu) {
MenuItem navigateToPointMenu = menu.findItem(R.id.map_navigate_to_point);
if (navigateToPointMenu != null) {
if (settings.getPointToNavigate() != null) {
navigateToPointMenu.setTitle((routingHelper.isRouteCalculated() || routingHelper.isFollowingMode() ||
routingHelper.isRouteBeingCalculated()) ? R.string.stop_routing : R.string.stop_navigation);
navigateToPointMenu.setVisible(true);
} else {
navigateToPointMenu.setVisible(false);
}
}
MenuItem muteMenu = menu.findItem(R.id.map_mute);
if(muteMenu != null){
if (routingHelper.getFinalLocation() != null && routingHelper.isFollowingMode()) {
boolean mute = routingHelper.getVoiceRouter().isMute();
muteMenu.setTitle(mute ? R.string.menu_mute_on : R.string.menu_mute_off);
muteMenu.setIcon(mute ? R.drawable.ic_menu_soundoff : R.drawable.ic_menu_soundon);
muteMenu.setVisible(true);
} else {
muteMenu.setVisible(false);
}
}
MenuItem directions = menu.findItem(R.id.map_get_directions);
if(routingHelper.isRouteCalculated()){
directions.setTitle(R.string.show_route);
} else {
directions.setTitle(R.string.get_directions);
}
MenuItem animateMenu = menu.findItem(R.id.map_animate_route);
if (animateMenu != null) {
if(settings.TEST_ANIMATE_ROUTING.get()){
animateMenu.setTitle(routeAnimation.isRouteAnimating() ? R.string.animate_route_off
: R.string.animate_route);
animateMenu.setVisible("1".equals(Secure.getString(
mapActivity.getContentResolver(), Secure.ALLOW_MOCK_LOCATION))
&& settings.getPointToNavigate() != null
&& routingHelper.isRouteCalculated());
animateMenu.setVisible(true);
} else {
animateMenu.setVisible(false);
}
}
OsmandPlugin.registerOnPrepareOptionsMenu(mapActivity, menu);
optionsMenuHelper.prepareOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item) {
final int itemId = item.getItemId();
OsmandMapTileView mapView = mapActivity.getMapView();
if (itemId == R.id.map_show_settings) {
final Intent intentSettings = new Intent(mapActivity, OsmandIntents.getSettingsActivity());
mapActivity.startActivity(intentSettings);
return true;
} else if (itemId == R.id.map_where_am_i) {
if (getMyApplication().accessibilityEnabled()) {
whereAmIDialog();
} else {
mapActivity.backToLocationImpl();
}
return true;
} else if (itemId == R.id.map_show_gps_status) {
startGpsStatusIntent();
return true;
} else if (itemId == R.id.map_specify_point) {
Intent newIntent = new Intent(mapActivity, OsmandIntents.getSearchActivity());
// causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
LatLon loc = mapActivity.getMapLocation();
newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude());
newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude());
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mapActivity.startActivity(newIntent);
return true;
} else {
if (itemId == R.id.map_get_directions) {
if (routingHelper.isRouteCalculated()) {
aboutRoute();
} else {
Location loc = mapActivity.getLastKnownLocation();
getDirections(loc, true);
}
return true;
} else if (itemId == R.id.map_layers) {
mapActivity.getMapLayers().openLayerSelectionDialog(mapView);
return true;
} else if (itemId == R.id.map_mute) {
routingHelper.getVoiceRouter().setMute(!routingHelper.getVoiceRouter().isMute());
return true;
} else if (itemId == R.id.map_navigate_to_point) {
if (mapActivity.getMapLayers().getNavigationLayer().getPointToNavigate() != null) {
if (routingHelper.isRouteCalculated() || routingHelper.isFollowingMode() || routingHelper.isRouteBeingCalculated()) {
routingHelper.setFinalAndCurrentLocation(null, routingHelper.getCurrentLocation(), routingHelper.getCurrentGPXRoute());
// restore default mode
boolean changed = settings.APPLICATION_MODE.set(settings.PREV_APPLICATION_MODE.get());
mapActivity.updateApplicationModeSettings();
mapView.refreshMap(changed);
} else {
mapActivity.navigateToPoint(null);
}
} else {
mapActivity.navigateToPoint(new LatLon(mapView.getLatitude(), mapView.getLongitude()));
}
mapView.refreshMap();
return true;
} else if (itemId == R.id.map_show_point_options) {
contextMenuPoint(mapView.getLatitude(), mapView.getLongitude());
return true;
} else if (itemId == R.id.map_animate_route) {
// animate moving on route
routeAnimation.startStopRouteAnimation(routingHelper, mapActivity);
return true;
} else {
return OsmandPlugin.registerOnOptionsMenuItemSelected(mapActivity, itemId);
}
}
return optionsMenuHelper.onClick(item);
}
private void startGpsStatusIntent() {

View file

@ -273,9 +273,9 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
registerBooleanPreference(osmandSettings.USE_COMPASS_IN_NAVIGATION, screen);
registerBooleanPreference(osmandSettings.LEFT_SIDE_NAVIGATION, screen);
registerBooleanPreference(osmandSettings.SHOW_CAMERAS, screen);
registerBooleanPreference(osmandSettings.SHOW_SPEED_LIMITS, screen);
registerBooleanPreference(osmandSettings.AVOID_TOLL_ROADS, screen);
// registerBooleanPreference(osmandSettings.SHOW_CAMERAS, screen);
// registerBooleanPreference(osmandSettings.SHOW_SPEED_LIMITS, screen);
// registerBooleanPreference(osmandSettings.AVOID_TOLL_ROADS, screen);
CheckBoxPreference nativeCheckbox = registerBooleanPreference(osmandSettings.NATIVE_RENDERING,screen);

View file

@ -1,11 +1,15 @@
package net.osmand.plus.development;
import net.osmand.plus.OptionsMenuHelper;
import net.osmand.plus.OptionsMenuHelper.OnOptionsMenuClick;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.routing.RouteAnimation;
import net.osmand.plus.routing.RoutingHelper;
import android.content.Intent;
import android.os.Debug;
import android.os.Debug.MemoryInfo;
@ -14,11 +18,14 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.view.Menu;
import android.view.MenuItem;
public class OsmandDevelopmentPlugin extends OsmandPlugin {
private static final String ID = "osmand.development";
private OsmandSettings settings;
private OsmandApplication app;
private RouteAnimation routeAnimation = new RouteAnimation();
public OsmandDevelopmentPlugin(OsmandApplication app) {
this.app = app;
@ -44,8 +51,29 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
}
@Override
public void registerLayers(MapActivity activity) {
}
@Override
public void registerOptionsMenuItems(final MapActivity mapActivity, OptionsMenuHelper helper) {
helper.registerOptionsMenuItem(R.string.animate_route, R.string.animate_route, false, new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem animateMenu) {
animateMenu.setTitle(routeAnimation.isRouteAnimating() ? R.string.animate_route_off : R.string.animate_route);
animateMenu.setVisible(settings.getPointToNavigate() != null);
}
@Override
public boolean onClick(MenuItem item) {
RoutingHelper routingHelper = mapActivity.getRoutingHelper();
// animate moving on route
routeAnimation.startStopRouteAnimation(routingHelper, mapActivity);
return true;
}
});
}
@Override
public void settingsActivityCreate(final SettingsActivity activity, PreferenceScreen screen) {
@ -58,9 +86,6 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
CheckBoxPreference dbg = activity.createCheckBoxPreference(settings.DEBUG_RENDERING_INFO,
R.string.trace_rendering, R.string.trace_rendering_descr);
cat.addPreference(dbg);
CheckBoxPreference animate = activity.createCheckBoxPreference(settings.TEST_ANIMATE_ROUTING,
R.string.animate_routing, R.string.simulate_route_progression_manually);
cat.addPreference(animate);
Preference pref = new Preference(app);
pref.setTitle(R.string.test_voice_prompts);

View file

@ -8,6 +8,7 @@ import net.osmand.osm.LatLon;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.OptionsMenuHelper;
import net.osmand.plus.OptionsMenuHelper.OnOptionsMenuClick;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
@ -333,31 +334,26 @@ public class ParkingPositionPlugin extends OsmandPlugin {
}
@Override
public void registerOptionsMenuItems(MapActivity mapActivity, OptionsMenuHelper helper) {
public void registerOptionsMenuItems(final MapActivity mapActivity, OptionsMenuHelper helper) {
if (parkingLayer != null) {
//NOTE: R.id.parking_lim_text - is used just as a stub
helper.registerOptionsMenuItem(R.id.parking_lim_text, R.string.osmand_parking_delete, android.R.drawable.ic_menu_mylocation);
}
}
@Override
public boolean onOptionsItemSelected(MapActivity mapActivity, int itemId) {
if (itemId == R.id.parking_lim_text) {
showDeleteDialog(mapActivity);
return true;
}
return false;
}
@Override
public void prepareOptionsMenuItems(MapActivity mapActivity, Menu menu) {
MenuItem deleteParkingItem = menu.findItem(R.id.parking_lim_text);
if (deleteParkingItem != null) {
if (settings.getParkingPosition() != null) {
deleteParkingItem.setVisible(true);
} else {
deleteParkingItem.setVisible(false);
}
helper.registerOptionsMenuItem(R.string.osmand_parking_delete, R.string.osmand_parking_delete, android.R.drawable.ic_menu_mylocation,
new OnOptionsMenuClick() {
@Override
public void prepareOptionsMenu(Menu menu, MenuItem deleteParkingItem) {
if (settings.getParkingPosition() != null) {
deleteParkingItem.setVisible(true);
} else {
deleteParkingItem.setVisible(false);
}
}
@Override
public boolean onClick(MenuItem item) {
showDeleteDialog(mapActivity);
return true;
}
});
}
}