Fix crashes
This commit is contained in:
parent
005bae6db9
commit
ef031d7ec9
13 changed files with 115 additions and 79 deletions
|
@ -536,7 +536,7 @@ public class BinaryMapIndexReader {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new IllegalArgumentException(name);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<City> getCities(String region, SearchRequest<City> resultMatcher,
|
public List<City> getCities(String region, SearchRequest<City> resultMatcher,
|
||||||
|
@ -547,6 +547,9 @@ public class BinaryMapIndexReader {
|
||||||
int cityType) throws IOException {
|
int cityType) throws IOException {
|
||||||
List<City> cities = new ArrayList<City>();
|
List<City> cities = new ArrayList<City>();
|
||||||
AddressRegion r = getRegionByName(region);
|
AddressRegion r = getRegionByName(region);
|
||||||
|
if(r == null) {
|
||||||
|
return cities;
|
||||||
|
}
|
||||||
for(CitiesBlock block : r.cities) {
|
for(CitiesBlock block : r.cities) {
|
||||||
if(block.type == cityType) {
|
if(block.type == cityType) {
|
||||||
codedIS.seek(block.filePointer);
|
codedIS.seek(block.filePointer);
|
||||||
|
|
|
@ -117,7 +117,13 @@ public class PointDescription {
|
||||||
return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.northing) + " "
|
return pnt.zone_number + "" + pnt.zone_letter + " " + ((long) pnt.northing) + " "
|
||||||
+ ((long) pnt.easting);
|
+ ((long) pnt.easting);
|
||||||
} else {
|
} else {
|
||||||
return ctx.getString( sh? R.string.short_location_on_map : R.string.location_on_map, convert(lat, f), convert(lon, f));
|
try {
|
||||||
|
return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, convert(lat, f),
|
||||||
|
convert(lon, f));
|
||||||
|
} catch(RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ctx.getString(sh ? R.string.short_location_on_map : R.string.location_on_map, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -433,7 +433,7 @@ public class OsmandSettings {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean setValue(Object prefs, Integer val) {
|
protected boolean setValue(Object prefs, Integer val) {
|
||||||
return settingsAPI.edit( prefs).putInt(getId(), val).commit();
|
return settingsAPI.edit(prefs).putInt(getId(), val).commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ import net.osmand.plus.views.PointNavigationLayer;
|
||||||
import net.osmand.plus.views.RouteLayer;
|
import net.osmand.plus.views.RouteLayer;
|
||||||
import net.osmand.plus.views.TransportInfoLayer;
|
import net.osmand.plus.views.TransportInfoLayer;
|
||||||
import net.osmand.plus.views.TransportStopsLayer;
|
import net.osmand.plus.views.TransportStopsLayer;
|
||||||
|
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -76,9 +77,15 @@ public class MapActivityLayers {
|
||||||
private ContextMenuLayer contextMenuLayer;
|
private ContextMenuLayer contextMenuLayer;
|
||||||
private MapControlsLayer mapControlsLayer;
|
private MapControlsLayer mapControlsLayer;
|
||||||
private DownloadedRegionsLayer downloadedRegionsLayer;
|
private DownloadedRegionsLayer downloadedRegionsLayer;
|
||||||
|
private MapWidgetRegistry mapWidgetRegistry;
|
||||||
|
|
||||||
public MapActivityLayers(MapActivity activity) {
|
public MapActivityLayers(MapActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
|
this.mapWidgetRegistry = new MapWidgetRegistry(activity.getMyApplication().getSettings());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MapWidgetRegistry getMapWidgetRegistry() {
|
||||||
|
return mapWidgetRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OsmandApplication getApplication(){
|
public OsmandApplication getApplication(){
|
||||||
|
|
|
@ -72,7 +72,6 @@ public class TrackActivity extends TabActivity {
|
||||||
|
|
||||||
setViewPagerAdapter(mViewPager, new ArrayList<TabActivity.TabItem>());
|
setViewPagerAdapter(mViewPager, new ArrayList<TabActivity.TabItem>());
|
||||||
mSlidingTabLayout.setViewPager(mViewPager);
|
mSlidingTabLayout.setViewPager(mViewPager);
|
||||||
|
|
||||||
new AsyncTask<Void, Void, GPXFile>() {
|
new AsyncTask<Void, Void, GPXFile>() {
|
||||||
|
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
|
@ -114,6 +113,9 @@ public class TrackActivity extends TabActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<GpxSelectionHelper.GpxDisplayGroup> getResult() {
|
public List<GpxSelectionHelper.GpxDisplayGroup> getResult() {
|
||||||
|
if(result == null) {
|
||||||
|
return new ArrayList<GpxSelectionHelper.GpxDisplayGroup>();
|
||||||
|
}
|
||||||
if (result.modifiedTime != modifiedTime) {
|
if (result.modifiedTime != modifiedTime) {
|
||||||
modifiedTime = result.modifiedTime;
|
modifiedTime = result.modifiedTime;
|
||||||
GpxSelectionHelper selectedGpxHelper = ((OsmandApplication) getApplication()).getSelectedGpxHelper();
|
GpxSelectionHelper selectedGpxHelper = ((OsmandApplication) getApplication()).getSelectedGpxHelper();
|
||||||
|
@ -171,11 +173,11 @@ public class TrackActivity extends TabActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isHavingWayPoints(){
|
boolean isHavingWayPoints(){
|
||||||
return getGpx().hasWptPt();
|
return getGpx() != null && getGpx().hasWptPt();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isHavingRoutePoints(){
|
boolean isHavingRoutePoints(){
|
||||||
return getGpx().hasRtePt();
|
return getGpx() != null && getGpx().hasRtePt();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GPXFile getGpx() {
|
public GPXFile getGpx() {
|
||||||
|
|
|
@ -44,6 +44,7 @@ public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<Reg
|
||||||
protected LatLon getLocation(RegionAddressRepository item) {
|
protected LatLon getLocation(RegionAddressRepository item) {
|
||||||
return item.getEstimatedRegionCenter();
|
return item.getEstimatedRegionCenter();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
|
@ -31,6 +31,7 @@ import net.osmand.plus.osmo.DashOsMoFragment;
|
||||||
import net.osmand.plus.parkingpoint.DashParkingFragment;
|
import net.osmand.plus.parkingpoint.DashParkingFragment;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.views.DownloadedRegionsLayer;
|
import net.osmand.plus.views.DownloadedRegionsLayer;
|
||||||
|
import net.osmand.plus.views.MapInfoLayer;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
@ -422,8 +423,8 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
} else {
|
} else {
|
||||||
scrollView.setVisibility(View.GONE);
|
scrollView.setVisibility(View.GONE);
|
||||||
listViewLayout.setVisibility(View.VISIBLE);
|
listViewLayout.setVisibility(View.VISIBLE);
|
||||||
if(listView instanceof ObservableListView) {
|
if (listView instanceof ObservableListView) {
|
||||||
onScrollChanged(((ObservableListView)listView).getScrollY(), false, false);
|
onScrollChanged(((ObservableListView) listView).getScrollY(), false, false);
|
||||||
}
|
}
|
||||||
if(refresh) {
|
if(refresh) {
|
||||||
refreshContent(false);
|
refreshContent(false);
|
||||||
|
@ -471,7 +472,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (DashboardType.CONFIGURE_SCREEN == visibleType) {
|
if (DashboardType.CONFIGURE_SCREEN == visibleType) {
|
||||||
cm = mapActivity.getMapLayers().getMapInfoLayer().getViewConfigureMenuAdapter();
|
cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity);
|
||||||
} else if(DashboardType.CONFIGURE_MAP == visibleType) {
|
} else if(DashboardType.CONFIGURE_MAP == visibleType) {
|
||||||
cm = new ConfigureMapMenu().createListAdapter(mapActivity);
|
cm = new ConfigureMapMenu().createListAdapter(mapActivity);
|
||||||
} else if(DashboardType.LIST_MENU == visibleType) {
|
} else if(DashboardType.LIST_MENU == visibleType) {
|
||||||
|
@ -779,8 +780,10 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
|
public void onScrollChanged(int scrollY, boolean firstScroll, boolean dragging) {
|
||||||
// Translate list background
|
// Translate list background
|
||||||
if (portrait) {
|
if (portrait) {
|
||||||
|
if(listBackgroundView != null) {
|
||||||
setTranslationY(listBackgroundView, Math.max(0, -scrollY + mFlexibleSpaceImageHeight));
|
setTranslationY(listBackgroundView, Math.max(0, -scrollY + mFlexibleSpaceImageHeight));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (portrait) {
|
if (portrait) {
|
||||||
setTranslationY(toolbar, Math.min(0, -scrollY + mFlexibleSpaceImageHeight - mFlexibleBlurSpaceHeight));
|
setTranslationY(toolbar, Math.min(0, -scrollY + mFlexibleSpaceImageHeight - mFlexibleBlurSpaceHeight));
|
||||||
}
|
}
|
||||||
|
@ -839,7 +842,7 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
||||||
private void updateListAdapter(ArrayAdapter<?> listAdapter, OnItemClickListener listener) {
|
private void updateListAdapter(ArrayAdapter<?> listAdapter, OnItemClickListener listener) {
|
||||||
this.listAdapter = listAdapter;
|
this.listAdapter = listAdapter;
|
||||||
this.listAdapterOnClickListener = listener;
|
this.listAdapterOnClickListener = listener;
|
||||||
if(this.listView != null) {
|
if (this.listView != null) {
|
||||||
listView.setAdapter(listAdapter);
|
listView.setAdapter(listAdapter);
|
||||||
if(!portrait) {
|
if(!portrait) {
|
||||||
listView.setOnItemClickListener(this.listAdapterOnClickListener);
|
listView.setOnItemClickListener(this.listAdapterOnClickListener);
|
||||||
|
|
|
@ -106,7 +106,7 @@ public class SelectedGPXFragment extends ListFragment {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
updateContent();
|
updateContent();
|
||||||
updateEnable = true;
|
updateEnable = true;
|
||||||
if(getGpx().showCurrentTrack && filterType() == GpxDisplayItemType.TRACK_POINTS) {
|
if(getGpx() != null && getGpx().showCurrentTrack && filterType() == GpxDisplayItemType.TRACK_POINTS) {
|
||||||
startHandler();
|
startHandler();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ public class SelectedGPXFragment extends ListFragment {
|
||||||
|
|
||||||
|
|
||||||
protected List<GpxDisplayGroup> filterGroups(GpxDisplayItemType type) {
|
protected List<GpxDisplayGroup> filterGroups(GpxDisplayItemType type) {
|
||||||
List<GpxDisplayGroup> result = ((TrackActivity)getActivity()).getResult();
|
List<GpxDisplayGroup> result = ((TrackActivity) getActivity()).getResult();
|
||||||
List<GpxDisplayGroup> groups = new ArrayList<GpxSelectionHelper.GpxDisplayGroup>();
|
List<GpxDisplayGroup> groups = new ArrayList<GpxSelectionHelper.GpxDisplayGroup>();
|
||||||
for (GpxDisplayGroup group : result) {
|
for (GpxDisplayGroup group : result) {
|
||||||
boolean add = group.getType() == type || type == null;
|
boolean add = group.getType() == type || type == null;
|
||||||
|
@ -238,7 +238,7 @@ public class SelectedGPXFragment extends ListFragment {
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
menu.clear();
|
menu.clear();
|
||||||
((TrackActivity) getActivity()).getClearToolbar(false);
|
((TrackActivity) getActivity()).getClearToolbar(false);
|
||||||
if (getGpx().path != null && !getGpx().showCurrentTrack) {
|
if (getGpx() != null && getGpx().path != null && !getGpx().showCurrentTrack) {
|
||||||
MenuItem item = menu.add(R.string.shared_string_share).setIcon(R.drawable.ic_action_gshare_dark)
|
MenuItem item = menu.add(R.string.shared_string_share).setIcon(R.drawable.ic_action_gshare_dark)
|
||||||
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.osmo;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
|
@ -201,13 +202,16 @@ public class DashOsMoFragment extends DashLocationFragment implements OsMoGroups
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove all inactive devices
|
//remove all inactive devices
|
||||||
for (OsMoGroupsStorage.OsMoDevice device : devices) {
|
Iterator<OsMoDevice> it = devices.iterator();
|
||||||
if (!device.isActive() && !device.isEnabled() && devices.size() > 2) {
|
while (it.hasNext()) {
|
||||||
devices.remove(device);
|
|
||||||
}
|
|
||||||
if (devices.size() < 4) {
|
if (devices.size() < 4) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
OsMoGroupsStorage.OsMoDevice device = it.next();
|
||||||
|
if (!device.isActive() && !device.isEnabled() && devices.size() > 2) {
|
||||||
|
it.remove();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sortDevices(devices);
|
sortDevices(devices);
|
||||||
|
|
|
@ -126,8 +126,10 @@ public class PoiFiltersHelper {
|
||||||
AbstractPoiType tp = application.getPoiTypes().getAnyPoiTypeByKey(typeId);
|
AbstractPoiType tp = application.getPoiTypes().getAnyPoiTypeByKey(typeId);
|
||||||
if(tp != null) {
|
if(tp != null) {
|
||||||
PoiLegacyFilter lf = new PoiLegacyFilter(tp, application);
|
PoiLegacyFilter lf = new PoiLegacyFilter(tp, application);
|
||||||
cacheTopStandardFilters.add(lf);
|
ArrayList<PoiLegacyFilter> copy = new ArrayList<PoiLegacyFilter>(cacheTopStandardFilters);
|
||||||
sortListOfFilters(cacheTopStandardFilters);
|
copy.add(lf);
|
||||||
|
sortListOfFilters(copy);
|
||||||
|
cacheTopStandardFilters = copy;
|
||||||
return lf;
|
return lf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,9 +138,9 @@ public class PoiFiltersHelper {
|
||||||
|
|
||||||
|
|
||||||
public void reloadAllPoiFilters() {
|
public void reloadAllPoiFilters() {
|
||||||
cacheTopStandardFilters = null;
|
|
||||||
showAllPOIFilter = null;
|
showAllPOIFilter = null;
|
||||||
getShowAllPOIFilter();
|
getShowAllPOIFilter();
|
||||||
|
cacheTopStandardFilters = null;
|
||||||
getTopDefinedPoiFilters();
|
getTopDefinedPoiFilters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,15 +170,16 @@ public class PoiFiltersHelper {
|
||||||
|
|
||||||
public List<PoiLegacyFilter> getTopDefinedPoiFilters() {
|
public List<PoiLegacyFilter> getTopDefinedPoiFilters() {
|
||||||
if (cacheTopStandardFilters == null) {
|
if (cacheTopStandardFilters == null) {
|
||||||
cacheTopStandardFilters = new ArrayList<PoiLegacyFilter>();
|
List<PoiLegacyFilter> top = new ArrayList<PoiLegacyFilter>();
|
||||||
// user defined
|
// user defined
|
||||||
cacheTopStandardFilters.addAll(getUserDefinedPoiFilters());
|
top.addAll(getUserDefinedPoiFilters());
|
||||||
// default
|
// default
|
||||||
MapPoiTypes poiTypes = application.getPoiTypes();
|
MapPoiTypes poiTypes = application.getPoiTypes();
|
||||||
for (PoiFilter t : poiTypes.getTopVisibleFilters()) {
|
for (PoiFilter t : poiTypes.getTopVisibleFilters()) {
|
||||||
cacheTopStandardFilters.add(new PoiLegacyFilter(t, application));
|
top.add(new PoiLegacyFilter(t, application));
|
||||||
}
|
}
|
||||||
sortListOfFilters(cacheTopStandardFilters);
|
sortListOfFilters(top);
|
||||||
|
cacheTopStandardFilters = top;
|
||||||
}
|
}
|
||||||
List<PoiLegacyFilter> result = new ArrayList<PoiLegacyFilter>();
|
List<PoiLegacyFilter> result = new ArrayList<PoiLegacyFilter>();
|
||||||
if(OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) != null) {
|
if(OsmandPlugin.getEnabledPlugin(AccessibilityPlugin.class) != null) {
|
||||||
|
@ -205,7 +208,9 @@ public class PoiFiltersHelper {
|
||||||
}
|
}
|
||||||
boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter);
|
boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter);
|
||||||
if(res){
|
if(res){
|
||||||
cacheTopStandardFilters.remove(filter);
|
ArrayList<PoiLegacyFilter> copy = new ArrayList<>(cacheTopStandardFilters);
|
||||||
|
copy.remove(filter);
|
||||||
|
cacheTopStandardFilters = copy;
|
||||||
}
|
}
|
||||||
helper.close();
|
helper.close();
|
||||||
return res;
|
return res;
|
||||||
|
@ -225,8 +230,10 @@ public class PoiFiltersHelper {
|
||||||
}
|
}
|
||||||
res = helper.addFilter(filter, helper.getWritableDatabase(), false);
|
res = helper.addFilter(filter, helper.getWritableDatabase(), false);
|
||||||
if(res){
|
if(res){
|
||||||
cacheTopStandardFilters.add(filter);
|
ArrayList<PoiLegacyFilter> copy = new ArrayList<>(cacheTopStandardFilters);
|
||||||
sortListOfFilters(cacheTopStandardFilters);
|
copy.add(filter);
|
||||||
|
sortListOfFilters(copy);
|
||||||
|
cacheTopStandardFilters = copy;
|
||||||
}
|
}
|
||||||
helper.close();
|
helper.close();
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -216,9 +216,9 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
|
||||||
};
|
};
|
||||||
adapter.item(R.string.layer_map).iconColor(R.drawable.ic_world_globe_dark)
|
adapter.item(R.string.layer_map).iconColor(R.drawable.ic_world_globe_dark)
|
||||||
.listen(listener).position(3).reg();
|
.listen(listener).position(3).reg();
|
||||||
adapter.item(R.string.layer_overlay).selected(overlayLayer.getMap() != null ? 1 : 0).
|
adapter.item(R.string.layer_overlay).selected(overlayLayer != null && overlayLayer.getMap() != null ? 1 : 0).
|
||||||
iconColor(R.drawable.ic_layer_top_dark).listen(listener).position(14).reg();
|
iconColor(R.drawable.ic_layer_top_dark).listen(listener).position(14).reg();
|
||||||
adapter.item(R.string.layer_underlay).selected(underlayLayer.getMap() != null ? 1 : 0)
|
adapter.item(R.string.layer_underlay).selected(underlayLayer != null && underlayLayer.getMap() != null ? 1 : 0)
|
||||||
.iconColor(R.drawable.ic_layer_bottom_dark).listen(listener).position(15).reg();
|
.iconColor(R.drawable.ic_layer_bottom_dark).listen(listener).position(15).reg();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,14 +4,10 @@ package net.osmand.plus.views;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.ApplicationMode;
|
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
|
||||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView;
|
||||||
|
@ -28,7 +24,6 @@ import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
|
@ -71,8 +66,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
@Override
|
@Override
|
||||||
public void initLayer(final OsmandMapTileView view) {
|
public void initLayer(final OsmandMapTileView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
mapInfoControls = new MapWidgetRegistry(map.getMyApplication().getSettings());
|
mapInfoControls = map.getMapLayers().getMapWidgetRegistry() ;
|
||||||
|
|
||||||
leftStack = (LinearLayout) map.findViewById(R.id.map_left_widgets_panel);
|
leftStack = (LinearLayout) map.findViewById(R.id.map_left_widgets_panel);
|
||||||
rightStack = (LinearLayout) map.findViewById(R.id.map_right_widgets_panel);
|
rightStack = (LinearLayout) map.findViewById(R.id.map_right_widgets_panel);
|
||||||
expand = (ImageButton) map.findViewById(R.id.map_collapse_button);
|
expand = (ImageButton) map.findViewById(R.id.map_collapse_button);
|
||||||
|
@ -307,32 +301,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public ContextMenuAdapter getViewConfigureMenuAdapter() {
|
|
||||||
ContextMenuAdapter cm = new ContextMenuAdapter(view.getContext());
|
|
||||||
cm.setDefaultLayoutId(R.layout.drawer_list_item);
|
|
||||||
cm.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg();
|
|
||||||
cm.setChangeAppModeListener(new ConfigureMapMenu.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(boolean allModes) {
|
|
||||||
map.getDashboard().updateListAdapter(getViewConfigureMenuAdapter());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
cm.item(R.string.map_widget_reset)
|
|
||||||
.iconColor(R.drawable.ic_action_reset_to_default_dark).listen(new OnContextMenuClick() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
|
||||||
mapInfoControls.resetToDefault();
|
|
||||||
recreateControls();
|
|
||||||
adapter.notifyDataSetInvalidated();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}).reg();
|
|
||||||
final ApplicationMode mode = settings.getApplicationMode();
|
|
||||||
mapInfoControls.addControls(this, cm, mode);
|
|
||||||
return cm;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
|
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||||
import net.osmand.plus.views.MapInfoLayer;
|
import net.osmand.plus.views.MapInfoLayer;
|
||||||
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -214,21 +215,21 @@ public class MapWidgetRegistry {
|
||||||
settings.CENTER_POSITION_ON_MAP.resetToDefault();
|
settings.CENTER_POSITION_ON_MAP.resetToDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addControlsAppearance(final MapInfoLayer mil, ContextMenuAdapter cm, ApplicationMode mode) {
|
public void addControlsAppearance(final MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) {
|
||||||
// addControlId(mil, cm, R.string.map_widget_show_ruler, settings.SHOW_RULER);
|
// addControlId(mil, cm, R.string.map_widget_show_ruler, settings.SHOW_RULER);
|
||||||
addControlId(mil, cm, R.string.map_widget_show_destination_arrow, settings.SHOW_DESTINATION_ARROW);
|
addControlId(map, cm, R.string.map_widget_show_destination_arrow, settings.SHOW_DESTINATION_ARROW);
|
||||||
addControlId(mil, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME);
|
addControlId(map, cm, R.string.map_widget_transparent, settings.TRANSPARENT_MAP_THEME);
|
||||||
addControlId(mil, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP);
|
addControlId(map, cm, R.string.always_center_position_on_map, settings.CENTER_POSITION_ON_MAP);
|
||||||
if(mode != ApplicationMode.DEFAULT) {
|
if(mode != ApplicationMode.DEFAULT) {
|
||||||
addControlId(mil, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME);
|
addControlId(map, cm, R.string.map_widget_top_text, settings.SHOW_STREET_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addControlId(final MapInfoLayer mil, ContextMenuAdapter cm, int stringId, OsmandPreference<Boolean> pref) {
|
private void addControlId(final MapActivity map, ContextMenuAdapter cm, int stringId, OsmandPreference<Boolean> pref) {
|
||||||
cm.item(stringId).selected( pref.get() ? 1 : 0)
|
cm.item(stringId).selected( pref.get() ? 1 : 0)
|
||||||
// .icons(r.drawableDark, r.drawableLight)
|
// .icons(r.drawableDark, r.drawableLight)
|
||||||
.listen(new ApearanceOnContextMenuClick(pref, mil.getMapActivity())).reg();
|
.listen(new ApearanceOnContextMenuClick(pref, map)).reg();
|
||||||
}
|
}
|
||||||
|
|
||||||
class ApearanceOnContextMenuClick implements OnContextMenuClick {
|
class ApearanceOnContextMenuClick implements OnContextMenuClick {
|
||||||
|
@ -259,15 +260,15 @@ public class MapWidgetRegistry {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void addControls(MapInfoLayer mil, ContextMenuAdapter cm, ApplicationMode mode) {
|
public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) {
|
||||||
cm.item(R.string.map_widget_right).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
|
cm.item(R.string.map_widget_right).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
|
||||||
addControls(mil, cm, right, mode);
|
addControls(map, cm, right, mode);
|
||||||
if(mode != ApplicationMode.DEFAULT) {
|
if(mode != ApplicationMode.DEFAULT) {
|
||||||
cm.item(R.string.map_widget_left).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
|
cm.item(R.string.map_widget_left).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
|
||||||
addControls(mil, cm, left, mode);
|
addControls(map, cm, left, mode);
|
||||||
}
|
}
|
||||||
cm.item(R.string.map_widget_appearance_rem).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
|
cm.item(R.string.map_widget_appearance_rem).setCategory(true).layout(R.layout.drawer_list_sub_header).reg();
|
||||||
addControlsAppearance(mil, cm, mode);
|
addControlsAppearance(map, cm, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getText(Context ctx, final ApplicationMode mode, final MapWidgetRegInfo r) {
|
public String getText(Context ctx, final ApplicationMode mode, final MapWidgetRegInfo r) {
|
||||||
|
@ -282,7 +283,7 @@ public class MapWidgetRegistry {
|
||||||
return left;
|
return left;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addControls(final MapInfoLayer mil, final ContextMenuAdapter adapter, Set<MapWidgetRegInfo> top, final ApplicationMode mode) {
|
private void addControls(final MapActivity map, final ContextMenuAdapter adapter, Set<MapWidgetRegInfo> top, final ApplicationMode mode) {
|
||||||
for(final MapWidgetRegInfo r : top){
|
for(final MapWidgetRegInfo r : top){
|
||||||
adapter.item(r.messageId).selected(r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0)
|
adapter.item(r.messageId).selected(r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0)
|
||||||
.iconColor(r.drawableMenu).listen(new OnContextMenuClick() {
|
.iconColor(r.drawableMenu).listen(new OnContextMenuClick() {
|
||||||
|
@ -290,14 +291,17 @@ public class MapWidgetRegistry {
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
|
public boolean onContextMenuClick(ArrayAdapter<?> a, int itemId, int pos, boolean isChecked) {
|
||||||
changeVisibility(r);
|
changeVisibility(r);
|
||||||
|
MapInfoLayer mil = map.getMapLayers().getMapInfoLayer();
|
||||||
|
if (mil != null) {
|
||||||
mil.recreateControls();
|
mil.recreateControls();
|
||||||
|
}
|
||||||
adapter.setItemName(pos, getText(mil.getMapActivity(), mode, r));
|
adapter.setItemName(pos, getText(mil.getMapActivity(), mode, r));
|
||||||
adapter.setSelection(pos, r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0);
|
adapter.setSelection(pos, r.visibleCollapsed(mode) || r.visible(mode) ? 1 : 0);
|
||||||
a.notifyDataSetInvalidated();
|
a.notifyDataSetInvalidated();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}).reg();
|
}).reg();
|
||||||
adapter.setItemName(adapter.length() - 1, getText(mil.getMapActivity(), mode, r));
|
adapter.setItemName(adapter.length() - 1, getText(map, mode, r));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,4 +377,34 @@ public class MapWidgetRegistry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ContextMenuAdapter getViewConfigureMenuAdapter(final MapActivity map) {
|
||||||
|
ContextMenuAdapter cm = new ContextMenuAdapter(map);
|
||||||
|
cm.setDefaultLayoutId(R.layout.drawer_list_item);
|
||||||
|
cm.item(R.string.app_modes_choose).layout(R.layout.mode_toggles).reg();
|
||||||
|
cm.setChangeAppModeListener(new ConfigureMapMenu.OnClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(boolean allModes) {
|
||||||
|
map.getDashboard().updateListAdapter(getViewConfigureMenuAdapter(map));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
cm.item(R.string.map_widget_reset).iconColor(R.drawable.ic_action_reset_to_default_dark)
|
||||||
|
.listen(new OnContextMenuClick() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||||
|
resetToDefault();
|
||||||
|
MapInfoLayer mil = map.getMapLayers().getMapInfoLayer();
|
||||||
|
if (mil != null) {
|
||||||
|
mil.recreateControls();
|
||||||
|
}
|
||||||
|
adapter.notifyDataSetInvalidated();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}).reg();
|
||||||
|
final ApplicationMode mode = settings.getApplicationMode();
|
||||||
|
addControls(map, cm, mode);
|
||||||
|
return cm;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue