Changed compass UI behaviour
This commit is contained in:
parent
00f1b7852b
commit
2e64b42727
15 changed files with 254 additions and 132 deletions
|
@ -438,6 +438,7 @@
|
|||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layers_compass_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
|
7
OsmAnd/res/layout/map_compass_button.xml
Normal file
7
OsmAnd/res/layout/map_compass_button.xml
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ImageButton android:id="@+id/map_compass_button"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="@dimen/map_small_button_size"
|
||||
android:layout_height="@dimen/map_small_button_size"
|
||||
android:background="@drawable/btn_inset_circle_trans"
|
||||
android:contentDescription="@string/map_widget_compass"/>
|
|
@ -450,6 +450,7 @@
|
|||
android:orientation="horizontal">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layers_compass_layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
|
|
@ -14,9 +14,10 @@ import java.util.Set;
|
|||
|
||||
|
||||
public class ApplicationMode {
|
||||
private static Map<String, Set<ApplicationMode>> widgets = new LinkedHashMap<String, Set<ApplicationMode>>();
|
||||
private static List<ApplicationMode> values = new ArrayList<ApplicationMode>();
|
||||
private static List<ApplicationMode> cachedFilteredValues = new ArrayList<ApplicationMode>();
|
||||
private static Map<String, Set<ApplicationMode>> widgetsVisibilityMap = new LinkedHashMap<>();
|
||||
private static Map<String, Set<ApplicationMode>> widgetsAvailabilityMap = new LinkedHashMap<>();
|
||||
private static List<ApplicationMode> values = new ArrayList<>();
|
||||
private static List<ApplicationMode> cachedFilteredValues = new ArrayList<>();
|
||||
/*
|
||||
* DEFAULT("Browse map"), CAR("Car"), BICYCLE("Bicycle"), PEDESTRIAN("Pedestrian");
|
||||
*/
|
||||
|
@ -67,27 +68,35 @@ public class ApplicationMode {
|
|||
ApplicationMode[] none = new ApplicationMode[]{};
|
||||
|
||||
// left
|
||||
regWidget("next_turn", exceptPedestrianAndDefault);
|
||||
regWidget("next_turn_small", pedestrian);
|
||||
regWidget("next_next_turn", exceptPedestrianAndDefault);
|
||||
regWidgetVisibility("next_turn", exceptPedestrianAndDefault);
|
||||
regWidgetVisibility("next_turn_small", pedestrian);
|
||||
regWidgetVisibility("next_next_turn", exceptPedestrianAndDefault);
|
||||
regWidgetAvailability("next_turn", exceptDefault);
|
||||
regWidgetAvailability("next_turn_small", exceptDefault);
|
||||
regWidgetAvailability("next_next_turn", exceptDefault);
|
||||
|
||||
// right
|
||||
regWidget("intermediate_distance", exceptDefault);
|
||||
regWidget("distance", exceptDefault);
|
||||
regWidget("time", exceptDefault);
|
||||
regWidget("speed", exceptPedestrianAndDefault);
|
||||
regWidget("max_speed", CAR);
|
||||
regWidget("altitude", pedestrianBicycle);
|
||||
regWidget("gps_info", none);
|
||||
regWidgetVisibility("intermediate_distance", exceptDefault);
|
||||
regWidgetVisibility("distance", exceptDefault);
|
||||
regWidgetVisibility("time", exceptDefault);
|
||||
regWidgetVisibility("speed", exceptPedestrianAndDefault);
|
||||
regWidgetVisibility("max_speed", CAR);
|
||||
regWidgetVisibility("altitude", pedestrianBicycle);
|
||||
regWidgetVisibility("gps_info", none);
|
||||
regWidgetAvailability("intermediate_distance", exceptDefault);
|
||||
regWidgetAvailability("distance", exceptDefault);
|
||||
regWidgetAvailability("time", exceptDefault);
|
||||
regWidgetAvailability("map_marker_1st", none);
|
||||
regWidgetAvailability("map_marker_2nd", none);
|
||||
|
||||
// top
|
||||
regWidget("config", none);
|
||||
regWidget("layers", none);
|
||||
regWidget("compass", all);
|
||||
regWidget("street_name", exceptAirBoatDefault);
|
||||
regWidget("back_to_location", all);
|
||||
regWidget("monitoring_services", none);
|
||||
regWidget("bgService", none);
|
||||
regWidgetVisibility("config", none);
|
||||
regWidgetVisibility("layers", none);
|
||||
regWidgetVisibility("compass", none);
|
||||
regWidgetVisibility("street_name", exceptAirBoatDefault);
|
||||
regWidgetVisibility("back_to_location", all);
|
||||
regWidgetVisibility("monitoring_services", none);
|
||||
regWidgetVisibility("bgService", none);
|
||||
}
|
||||
|
||||
|
||||
|
@ -187,8 +196,8 @@ public class ApplicationMode {
|
|||
|
||||
|
||||
// returns modifiable ! Set<ApplicationMode> to exclude non-wanted derived
|
||||
public static Set<ApplicationMode> regWidget(String widgetId, ApplicationMode... am) {
|
||||
HashSet<ApplicationMode> set = new HashSet<ApplicationMode>();
|
||||
public static Set<ApplicationMode> regWidgetVisibility(String widgetId, ApplicationMode... am) {
|
||||
HashSet<ApplicationMode> set = new HashSet<>();
|
||||
if (am == null) {
|
||||
set.addAll(values);
|
||||
} else {
|
||||
|
@ -200,7 +209,7 @@ public class ApplicationMode {
|
|||
set.add(m);
|
||||
}
|
||||
}
|
||||
widgets.put(widgetId, set);
|
||||
widgetsVisibilityMap.put(widgetId, set);
|
||||
return set;
|
||||
}
|
||||
|
||||
|
@ -209,14 +218,37 @@ public class ApplicationMode {
|
|||
}
|
||||
|
||||
public boolean isWidgetVisible(String key) {
|
||||
Set<ApplicationMode> set = widgets.get(key);
|
||||
Set<ApplicationMode> set = widgetsVisibilityMap.get(key);
|
||||
if (set == null) {
|
||||
return false;
|
||||
}
|
||||
return set.contains(this);
|
||||
}
|
||||
|
||||
public static Set<ApplicationMode> regWidgetAvailability(String widgetId, ApplicationMode... am) {
|
||||
HashSet<ApplicationMode> set = new HashSet<>();
|
||||
if (am == null) {
|
||||
set.addAll(values);
|
||||
} else {
|
||||
Collections.addAll(set, am);
|
||||
}
|
||||
for (ApplicationMode m : values) {
|
||||
// add derived modes
|
||||
if (set.contains(m.getParent())) {
|
||||
set.add(m);
|
||||
}
|
||||
}
|
||||
widgetsAvailabilityMap.put(widgetId, set);
|
||||
return set;
|
||||
}
|
||||
|
||||
public boolean isWidgetAvailable(String key) {
|
||||
Set<ApplicationMode> set = widgetsAvailabilityMap.get(key);
|
||||
if (set == null) {
|
||||
return true;
|
||||
}
|
||||
return set.contains(this);
|
||||
}
|
||||
|
||||
public static List<ApplicationMode> getModesDerivedFrom(ApplicationMode am) {
|
||||
List<ApplicationMode> list = new ArrayList<ApplicationMode>();
|
||||
|
|
|
@ -505,7 +505,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
|
|||
public AudioVideoNotesPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
OsmandSettings settings = app.getSettings();
|
||||
ApplicationMode.regWidget("audionotes", (ApplicationMode[]) null);
|
||||
ApplicationMode.regWidgetVisibility("audionotes", (ApplicationMode[]) null);
|
||||
AV_EXTERNAL_RECORDER = settings.registerBooleanPreference("av_external_recorder", false).makeGlobal();
|
||||
AV_EXTERNAL_PHOTO_CAM = settings.registerBooleanPreference("av_external_cam", true).makeGlobal();
|
||||
AV_VIDEO_FORMAT = settings.registerIntPreference("av_video_format", VIDEO_OUTPUT_MP4).makeGlobal();
|
||||
|
|
|
@ -127,7 +127,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
|
||||
private MapActivity mapActivity;
|
||||
private ImageView actionButton;
|
||||
private View compassButton;
|
||||
private FrameLayout dashboardView;
|
||||
private float cachedRotate = 0;
|
||||
|
||||
private ArrayAdapter<?> listAdapter;
|
||||
private OnItemClickListener listAdapterOnClickListener;
|
||||
|
@ -547,19 +549,19 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
}
|
||||
}
|
||||
|
||||
private FrameLayout.LayoutParams getActionButtonLayoutParams(int btnSizePx) {
|
||||
int topPadPx = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_map_top_padding);
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(btnSizePx, btnSizePx);
|
||||
int marginRight = btnSizePx / 4;
|
||||
params.setMargins(0, landscape ? 0 : topPadPx - 2 * btnSizePx, marginRight, landscape ? marginRight : 0);
|
||||
params.gravity = landscape ? Gravity.BOTTOM | Gravity.RIGHT : Gravity.TOP | Gravity.RIGHT;
|
||||
return params;
|
||||
}
|
||||
|
||||
private void initActionButtons() {
|
||||
actionButton = new ImageView(mapActivity);
|
||||
int btnSize = (int) mapActivity.getResources().getDimension(R.dimen.map_button_size);
|
||||
int topPad = (int) mapActivity.getResources().getDimension(R.dimen.dashboard_map_top_padding);
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
|
||||
btnSize, btnSize
|
||||
);
|
||||
int marginRight = btnSize / 4;
|
||||
params.setMargins(0, landscape ? 0 : topPad - 2 * btnSize,
|
||||
marginRight, landscape ? marginRight : 0);
|
||||
params.gravity = landscape ? Gravity.BOTTOM | Gravity.RIGHT : Gravity.TOP | Gravity.RIGHT;
|
||||
actionButton.setLayoutParams(params);
|
||||
int btnSizePx = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_button_size);
|
||||
actionButton.setLayoutParams(getActionButtonLayoutParams(btnSizePx));
|
||||
actionButton.setScaleType(ScaleType.CENTER);
|
||||
actionButton.setBackgroundResource(R.drawable.btn_circle_blue);
|
||||
hideActionButton();
|
||||
|
@ -690,6 +692,9 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
|
||||
private void hideActionButton() {
|
||||
actionButton.setVisibility(View.GONE);
|
||||
if (compassButton != null) {
|
||||
compassButton.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public net.osmand.Location getMyLocation() {
|
||||
|
@ -784,6 +789,11 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
actionButton.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
hideActionButton();
|
||||
if (visibleType == DashboardType.CONFIGURE_MAP) {
|
||||
int btnSizePx = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_small_button_size);
|
||||
compassButton = mapActivity.getMapLayers().getMapControlsLayer()
|
||||
.moveCompassButton(dashboardView, getActionButtonLayoutParams(btnSizePx), nightMode);
|
||||
}
|
||||
}
|
||||
updateDownloadBtn();
|
||||
View listViewLayout = dashboardView.findViewById(R.id.dash_list_view_layout);
|
||||
|
@ -1111,6 +1121,10 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
}
|
||||
|
||||
private void hide(View view, boolean animation) {
|
||||
if (compassButton != null) {
|
||||
mapActivity.getMapLayers().getMapControlsLayer().restoreCompassButton(nightMode);
|
||||
compassButton = null;
|
||||
}
|
||||
if (!animation) {
|
||||
dashboardView.setVisibility(View.GONE);
|
||||
} else {
|
||||
|
@ -1281,7 +1295,18 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
|
|||
lp.topMargin = originalPosition - scrollY;
|
||||
((FrameLayout) actionButton.getParent()).updateViewLayout(actionButton, lp);
|
||||
}
|
||||
|
||||
} else if (compassButton != null) {
|
||||
double scale = mapActivity.getResources().getDisplayMetrics().density;
|
||||
int originalPosition = mFlexibleSpaceImageHeight - (int) (64 * scale);
|
||||
int minTop = mFlexibleBlurSpaceHeight + (int) (5 * scale);
|
||||
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) compassButton.getLayoutParams();
|
||||
if (minTop > originalPosition - scrollY) {
|
||||
hideActionButton();
|
||||
} else {
|
||||
compassButton.setVisibility(View.VISIBLE);
|
||||
lp.topMargin = originalPosition - scrollY;
|
||||
((FrameLayout) compassButton.getParent()).updateViewLayout(compassButton, lp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ public class OsmandDevelopmentPlugin extends OsmandPlugin {
|
|||
|
||||
public OsmandDevelopmentPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
//ApplicationMode.regWidget("fps", new ApplicationMode[0]);
|
||||
//ApplicationMode.regWidgetVisibility("fps", new ApplicationMode[0]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
|
|||
|
||||
public DistanceCalculatorPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
ApplicationMode.regWidget("distance.measurement", ApplicationMode.DEFAULT);
|
||||
ApplicationMode.regWidgetVisibility("distance.measurement", ApplicationMode.DEFAULT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -56,7 +56,7 @@ public class OsmandMonitoringPlugin extends OsmandPlugin {
|
|||
this.app = app;
|
||||
liveMonitoringHelper = new LiveMonitoringHelper(app);
|
||||
final List<ApplicationMode> am = ApplicationMode.allPossibleValues();
|
||||
ApplicationMode.regWidget("monitoring", am.toArray(new ApplicationMode[am.size()]));
|
||||
ApplicationMode.regWidgetVisibility("monitoring", am.toArray(new ApplicationMode[am.size()]));
|
||||
settings = app.getSettings();
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public class OsMoPlugin extends OsmandPlugin implements OsMoReactor {
|
|||
deviceControl = new OsMoControlDevice(app, this, service, tracker);
|
||||
groups = new OsMoGroups(this, service, tracker, app);
|
||||
}
|
||||
ApplicationMode.regWidget("osmo_control", (ApplicationMode[]) null);
|
||||
ApplicationMode.regWidgetVisibility("osmo_control", (ApplicationMode[]) null);
|
||||
if (app.getSettings().OSMO_AUTO_CONNECT.get() ||
|
||||
(System.currentTimeMillis() - app.getSettings().OSMO_LAST_PING.get() < 5 * 60 * 1000)) {
|
||||
service.connect(true);
|
||||
|
|
|
@ -68,7 +68,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
|||
public ParkingPositionPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
OsmandSettings set = app.getSettings();
|
||||
ApplicationMode. regWidget("parking", (ApplicationMode[]) null);
|
||||
ApplicationMode.regWidgetVisibility("parking", (ApplicationMode[]) null);
|
||||
parkingLat = set.registerFloatPreference(PARKING_POINT_LAT, 0f).makeGlobal();
|
||||
parkingLon = set.registerFloatPreference(PARKING_POINT_LON, 0f).makeGlobal();
|
||||
parkingType = set.registerBooleanPreference(PARKING_TYPE, false).makeGlobal();
|
||||
|
|
|
@ -58,7 +58,7 @@ public class RoutePointsPlugin extends OsmandPlugin {
|
|||
private RoutePointsLayer routePointsLayer;
|
||||
|
||||
public RoutePointsPlugin(OsmandApplication app) {
|
||||
ApplicationMode.regWidget("route_steps", ApplicationMode.CAR, ApplicationMode.DEFAULT);
|
||||
ApplicationMode.regWidgetVisibility("route_steps", ApplicationMode.CAR, ApplicationMode.DEFAULT);
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import android.support.v7.app.AlertDialog;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
@ -96,6 +97,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
private long lastZoom;
|
||||
private boolean hasTargets;
|
||||
private ContextMenuLayer contextMenuLayer;
|
||||
private boolean forceShowCompass;
|
||||
|
||||
public MapControlsLayer(MapActivity activity) {
|
||||
this.mapActivity = activity;
|
||||
|
@ -128,6 +130,39 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
initRouteControls();
|
||||
}
|
||||
|
||||
public View moveCompassButton(ViewGroup destLayout, ViewGroup.LayoutParams layoutParams, boolean night) {
|
||||
View compassView = compassHud.iv;
|
||||
ViewGroup parent = (ViewGroup) compassView.getParent();
|
||||
if (parent != null) {
|
||||
forceShowCompass = true;
|
||||
parent.removeView(compassView);
|
||||
compassView.setLayoutParams(layoutParams);
|
||||
destLayout.addView(compassView);
|
||||
updateCompass(night);
|
||||
return compassView;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void restoreCompassButton(boolean night) {
|
||||
View compassView = compassHud.iv;
|
||||
ViewGroup parent = (ViewGroup) compassView.getParent();
|
||||
if (parent != null) {
|
||||
forceShowCompass = false;
|
||||
parent.removeView(compassView);
|
||||
LinearLayout mapCompassContainer = (LinearLayout) mapActivity.findViewById(R.id.layers_compass_layout);
|
||||
if (mapCompassContainer != null) {
|
||||
int buttonSizePx = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_small_button_size);
|
||||
int topMarginPx = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_small_button_margin);
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(buttonSizePx, buttonSizePx);
|
||||
params.topMargin = topMarginPx;
|
||||
compassView.setLayoutParams(params);
|
||||
mapCompassContainer.addView(compassView);
|
||||
updateCompass(night);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class CompassDrawable extends Drawable {
|
||||
|
||||
private Drawable original;
|
||||
|
@ -566,8 +601,8 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void updateControls(@NonNull RotatedTileBox tileBox, DrawSettings nightMode) {
|
||||
boolean isNight = nightMode != null && nightMode.isNightMode();
|
||||
private void updateControls(@NonNull RotatedTileBox tileBox, DrawSettings drawSettings) {
|
||||
boolean isNight = drawSettings != null && drawSettings.isNightMode();
|
||||
int shadw = isNight ? Color.TRANSPARENT : Color.WHITE;
|
||||
int textColor = isNight ? mapActivity.getResources().getColor(R.color.widgettext_night) : Color.BLACK;
|
||||
if (shadowColor != shadw) {
|
||||
|
@ -634,25 +669,36 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
}
|
||||
}
|
||||
|
||||
private void updateCompass(boolean isNight) {
|
||||
public void updateCompass(boolean isNight) {
|
||||
float mapRotate = mapActivity.getMapView().getRotate();
|
||||
boolean showCompass = forceShowCompass || mapRotate != 0
|
||||
|| settings.ROTATE_MAP.get() != OsmandSettings.ROTATE_MAP_NONE
|
||||
|| mapActivity.getMapLayers().getMapInfoLayer().getMapInfoControls().isVisible("compass");
|
||||
if (mapRotate != cachedRotate) {
|
||||
cachedRotate = mapRotate;
|
||||
// Apply animation to image view
|
||||
compassHud.iv.invalidate();
|
||||
compassHud.updateVisibility(showCompass);
|
||||
}
|
||||
if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_NONE) {
|
||||
compassHud.setIconResId(isNight ? R.drawable.map_compass_niu_white : R.drawable.map_compass_niu);
|
||||
compassHud.iv.setContentDescription(mapActivity.getString(R.string.rotate_map_none_opt));
|
||||
compassHud.updateVisibility(showCompass);
|
||||
} else if (settings.ROTATE_MAP.get() == OsmandSettings.ROTATE_MAP_BEARING) {
|
||||
compassHud.setIconResId(isNight ? R.drawable.map_compass_bearing_white : R.drawable.map_compass_bearing);
|
||||
compassHud.iv.setContentDescription(mapActivity.getString(R.string.rotate_map_bearing_opt));
|
||||
compassHud.updateVisibility(true);
|
||||
} else {
|
||||
compassHud.setIconResId(isNight ? R.drawable.map_compass_white : R.drawable.map_compass);
|
||||
compassHud.iv.setContentDescription(mapActivity.getString(R.string.rotate_map_compass_opt));
|
||||
compassHud.updateVisibility(true);
|
||||
}
|
||||
}
|
||||
|
||||
public CompassDrawable getCompassDrawable(Drawable originalDrawable) {
|
||||
return new CompassDrawable(originalDrawable);
|
||||
}
|
||||
|
||||
private void updateMyLocation(RoutingHelper rh, boolean dialogOpened) {
|
||||
boolean enabled = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation() != null;
|
||||
boolean tracked = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
|
||||
|
|
|
@ -137,6 +137,8 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
rulerControl.setVisibility(false);
|
||||
|
||||
// register left stack
|
||||
registerSideWidget(null, R.drawable.ic_action_aircraft, R.string.map_widget_compass, "compass", true, 4);
|
||||
|
||||
NextTurnInfoWidget bigInfoControl = ric.createNextInfoControl(map, app, false);
|
||||
registerSideWidget(bigInfoControl, R.drawable.ic_action_next_turn, R.string.map_widget_next_turn, "next_turn", true, 5);
|
||||
NextTurnInfoWidget smallInfoControl = ric.createNextInfoControl(map, app, true);
|
||||
|
@ -255,7 +257,7 @@ public class MapInfoLayer extends OsmandMapLayer {
|
|||
}
|
||||
|
||||
private void updateReg(TextState ts, MapWidgetRegInfo reg) {
|
||||
View v = reg.widget.getView().findViewById(R.id.widget_bg);
|
||||
View v = reg.widget != null ? reg.widget.getView().findViewById(R.id.widget_bg) : null;
|
||||
if(v != null) {
|
||||
v.setBackgroundResource(reg.left ? ts.leftRes : ts.rightRes);
|
||||
reg.widget.updateTextColor(ts.textColor, ts.textShadowColor, ts.textBold, ts.textShadowRadius);
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.util.LinkedHashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
|
||||
public class MapWidgetRegistry {
|
||||
|
||||
|
@ -68,14 +69,13 @@ public class MapWidgetRegistry {
|
|||
ApplicationMode mode, boolean left, boolean expanded) {
|
||||
Set<MapWidgetRegInfo> s = left ? this.leftWidgetSet : this.rightWidgetSet;
|
||||
for (MapWidgetRegInfo r : s) {
|
||||
if (r.visible(mode) || r.widget.isExplicitlyVisible()) {
|
||||
if (r.widget != null && (r.visible(mode) || r.widget.isExplicitlyVisible())) {
|
||||
stack.addView(r.widget.getView());
|
||||
}
|
||||
}
|
||||
if (expanded) {
|
||||
for (MapWidgetRegInfo r : s) {
|
||||
if (r.visibleCollapsed(mode) &&
|
||||
!r.widget.isExplicitlyVisible()) {
|
||||
if (r.widget != null && r.visibleCollapsed(mode) && !r.widget.isExplicitlyVisible()) {
|
||||
stack.addView(r.widget.getView());
|
||||
}
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ public class MapWidgetRegistry {
|
|||
|
||||
private void update(ApplicationMode mode, DrawSettings drawSettings, boolean expanded, Set<MapWidgetRegInfo> l) {
|
||||
for (MapWidgetRegInfo r : l) {
|
||||
if (r.visible(mode) || (r.visibleCollapsed(mode) && expanded)) {
|
||||
if (r.widget != null && (r.visible(mode) || (r.visibleCollapsed(mode) && expanded))) {
|
||||
r.widget.updateInfo(drawSettings);
|
||||
}
|
||||
}
|
||||
|
@ -214,6 +214,12 @@ public class MapWidgetRegistry {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isVisible(String key) {
|
||||
ApplicationMode mode = settings.APPLICATION_MODE.get();
|
||||
Set<String> elements = visibleElementsFromSettings.get(mode);
|
||||
return elements != null && elements.contains(key);
|
||||
}
|
||||
|
||||
private void setVisibility(MapWidgetRegInfo m, boolean visible, boolean collapsed) {
|
||||
ApplicationMode mode = settings.APPLICATION_MODE.get();
|
||||
defineDefaultSettingsElement(mode);
|
||||
|
@ -352,14 +358,15 @@ public class MapWidgetRegistry {
|
|||
|
||||
|
||||
public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) {
|
||||
// Right panel
|
||||
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, map)
|
||||
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
|
||||
addControls(map, cm, rightWidgetSet, mode);
|
||||
if (mode != ApplicationMode.DEFAULT) {
|
||||
// Left panel
|
||||
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_left, map)
|
||||
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
|
||||
addControls(map, cm, leftWidgetSet, mode);
|
||||
}
|
||||
// Remaining items
|
||||
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_appearance_rem, map)
|
||||
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
|
||||
addControlsAppearance(map, cm, mode);
|
||||
|
@ -380,14 +387,7 @@ public class MapWidgetRegistry {
|
|||
private void addControls(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter,
|
||||
Set<MapWidgetRegInfo> groupTitle, final ApplicationMode mode) {
|
||||
for (final MapWidgetRegInfo r : groupTitle) {
|
||||
if (mode == ApplicationMode.DEFAULT) {
|
||||
if ("intermediate_distance".equals(r.key)
|
||||
|| "distance".equals(r.key)
|
||||
|| "time".equals(r.key)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ("map_marker_1st".equals(r.key) || "map_marker_2nd".equals(r.key)) {
|
||||
if (!mode.isWidgetAvailable(r.key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,7 @@ public class MapWidgetRegistry {
|
|||
.setIcon(r.getDrawableMenu())
|
||||
.setSelected(selected)
|
||||
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
|
||||
.setSecondaryIcon(R.drawable.ic_action_additional_option)
|
||||
.setSecondaryIcon(r.widget != null ? R.drawable.ic_action_additional_option : ContextMenuItem.INVALID_ID)
|
||||
.setDescription(r.visibleCollapsed(mode) ? desc : null)
|
||||
.setListener(new ContextMenuAdapter.OnRowItemClick() {
|
||||
@Override
|
||||
|
@ -405,6 +405,10 @@ public class MapWidgetRegistry {
|
|||
final View view,
|
||||
final int itemId,
|
||||
final int pos) {
|
||||
if (r.widget == null) {
|
||||
setVisibility(adapter, pos, !r.visible(mode), false);
|
||||
return false;
|
||||
}
|
||||
View textWrapper = view.findViewById(R.id.text_wrapper);
|
||||
IconPopupMenu popup = new IconPopupMenu(view.getContext(), textWrapper);
|
||||
MenuInflater inflater = popup.getMenuInflater();
|
||||
|
@ -686,11 +690,15 @@ public class MapWidgetRegistry {
|
|||
}
|
||||
|
||||
public abstract int getMenuTitleId();
|
||||
|
||||
public abstract int getMenuIconId();
|
||||
|
||||
public abstract int getMenuItemId();
|
||||
|
||||
public abstract int[] getMenuTitleIds();
|
||||
|
||||
public abstract int[] getMenuIconIds();
|
||||
|
||||
public abstract int[] getMenuItemIds();
|
||||
|
||||
public abstract void changeState(int stateId);
|
||||
|
|
Loading…
Reference in a new issue