quick action fab in different application modes
This commit is contained in:
parent
6a21b0c6ef
commit
efef417757
5 changed files with 37 additions and 12 deletions
|
@ -2454,7 +2454,7 @@ public class OsmandSettings {
|
||||||
public static final String QUICK_FAB_MARGIN_X_LANDSCAPE_MARGIN = "quick_fab_margin_x_landscape_margin";
|
public static final String QUICK_FAB_MARGIN_X_LANDSCAPE_MARGIN = "quick_fab_margin_x_landscape_margin";
|
||||||
public static final String QUICK_FAB_MARGIN_Y_LANDSCAPE_MARGIN = "quick_fab_margin_y_landscape_margin";
|
public static final String QUICK_FAB_MARGIN_Y_LANDSCAPE_MARGIN = "quick_fab_margin_y_landscape_margin";
|
||||||
|
|
||||||
public final CommonPreference<Boolean> QUICK_ACTION = new BooleanPreference("quick_action", false).makeProfile();
|
public final CommonPreference<String> QUICK_ACTION = new StringPreference("quick_action", "").makeProfile();
|
||||||
|
|
||||||
public final CommonPreference<String> QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeProfile();
|
public final CommonPreference<String> QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeProfile();
|
||||||
|
|
||||||
|
|
|
@ -981,6 +981,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
if (mapLayers.getMapInfoLayer() != null) {
|
if (mapLayers.getMapInfoLayer() != null) {
|
||||||
mapLayers.getMapInfoLayer().recreateControls();
|
mapLayers.getMapInfoLayer().recreateControls();
|
||||||
}
|
}
|
||||||
|
if (mapLayers.getMapQuickActionLayer() != null) {
|
||||||
|
mapLayers.getMapQuickActionLayer().refreshLayer();
|
||||||
|
}
|
||||||
mapLayers.updateLayers(mapView);
|
mapLayers.updateLayers(mapView);
|
||||||
mapActions.updateDrawerMenu();
|
mapActions.updateDrawerMenu();
|
||||||
mapView.setComplexZoom(mapView.getZoom(), mapView.getSettingsMapDensity());
|
mapView.setComplexZoom(mapView.getZoom(), mapView.getSettingsMapDensity());
|
||||||
|
|
|
@ -2,10 +2,16 @@ package net.osmand.plus.quickaction;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by rosty on 12/27/16.
|
* Created by rosty on 12/27/16.
|
||||||
|
@ -22,6 +28,7 @@ public class QuickActionRegistry {
|
||||||
private final OsmandSettings settings;
|
private final OsmandSettings settings;
|
||||||
|
|
||||||
private final List<QuickAction> quickActions;
|
private final List<QuickAction> quickActions;
|
||||||
|
private final Map<String, Boolean> fabStateMap;
|
||||||
|
|
||||||
private QuickActionUpdatesListener updatesListener;
|
private QuickActionUpdatesListener updatesListener;
|
||||||
|
|
||||||
|
@ -31,6 +38,7 @@ public class QuickActionRegistry {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
|
|
||||||
quickActions = factory.parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
|
quickActions = factory.parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
|
||||||
|
fabStateMap = getQuickActionFabStateMapFromJson(settings.QUICK_ACTION.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUpdatesListener(QuickActionUpdatesListener updatesListener) {
|
public void setUpdatesListener(QuickActionUpdatesListener updatesListener) {
|
||||||
|
@ -136,4 +144,22 @@ public class QuickActionRegistry {
|
||||||
if (isNameUnique(action, context)) return action;
|
if (isNameUnique(action, context)) return action;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isQuickActionOn() {
|
||||||
|
Boolean result = fabStateMap.get(settings.APPLICATION_MODE.get().getStringKey());
|
||||||
|
return result != null && result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuickActionFabState(boolean isOn) {
|
||||||
|
fabStateMap.put(settings.APPLICATION_MODE.get().getStringKey(), isOn);
|
||||||
|
settings.QUICK_ACTION.set(new Gson().toJson(fabStateMap));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Boolean> getQuickActionFabStateMapFromJson(String json) {
|
||||||
|
Type type = new TypeToken<HashMap<String, Boolean>>() {
|
||||||
|
}.getType();
|
||||||
|
HashMap<String, Boolean> quickActions = new Gson().fromJson(json, type);
|
||||||
|
|
||||||
|
return quickActions != null ? quickActions : new HashMap<String, Boolean>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
||||||
quickActionsWidget = (QuickActionsWidget) mapActivity.findViewById(R.id.quick_action_widget);
|
quickActionsWidget = (QuickActionsWidget) mapActivity.findViewById(R.id.quick_action_widget);
|
||||||
quickActionButton = (ImageButton) mapActivity.findViewById(R.id.map_quick_actions_button);
|
quickActionButton = (ImageButton) mapActivity.findViewById(R.id.map_quick_actions_button);
|
||||||
setQuickActionButtonMargin();
|
setQuickActionButtonMargin();
|
||||||
isLayerOn = settings.QUICK_ACTION.get();
|
isLayerOn = quickActionRegistry.isQuickActionOn();
|
||||||
// quickActionButton.setVisibility(isLayerOn ? View.VISIBLE : View.GONE);
|
|
||||||
quickActionButton.setImageResource(R.drawable.map_quick_action);
|
quickActionButton.setImageResource(R.drawable.map_quick_action);
|
||||||
quickActionButton.setOnClickListener(new View.OnClickListener() {
|
quickActionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,8 +101,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
||||||
|
|
||||||
public void refreshLayer() {
|
public void refreshLayer() {
|
||||||
setLayerState(true);
|
setLayerState(true);
|
||||||
isLayerOn = settings.QUICK_ACTION.get();
|
isLayerOn = quickActionRegistry.isQuickActionOn();
|
||||||
// quickActionButton.setVisibility(settings.QUICK_ACTION.get() ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setQuickActionButtonMargin() {
|
private void setQuickActionButtonMargin() {
|
||||||
|
@ -227,15 +225,13 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings settings) {
|
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings settings) {
|
||||||
if (isInChangeMarkerPositionMode()) {
|
if (isInChangeMarkerPositionMode()) {
|
||||||
// canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight());
|
|
||||||
canvas.translate(box.getCenterPixelX() - contextMarker.getWidth() / 2, box.getCenterPixelY() - contextMarker.getHeight());
|
canvas.translate(box.getCenterPixelX() - contextMarker.getWidth() / 2, box.getCenterPixelY() - contextMarker.getHeight());
|
||||||
contextMarker.draw(canvas);
|
contextMarker.draw(canvas);
|
||||||
}
|
}
|
||||||
boolean hideQuickButton = !isLayerOn ||
|
boolean hideQuickButton = !isLayerOn ||
|
||||||
contextMenuLayer.isInChangeMarkerPositionMode() ||
|
contextMenuLayer.isInChangeMarkerPositionMode() ||
|
||||||
mapActivity.getContextMenu().isVisible() ||
|
mapActivity.getContextMenu().isVisible() ||
|
||||||
mapActivity.getContextMenu().getMultiSelectionMenu().isVisible() ||
|
mapActivity.getContextMenu().getMultiSelectionMenu().isVisible();
|
||||||
mapActivity.getRoutingHelper().isRoutePlanningMode();
|
|
||||||
quickActionButton.setVisibility(hideQuickButton ? View.GONE : View.VISIBLE);
|
quickActionButton.setVisibility(hideQuickButton ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -359,7 +359,7 @@ public class MapWidgetRegistry {
|
||||||
|
|
||||||
|
|
||||||
public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) {
|
public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) {
|
||||||
addQuickActionControl(map, cm);
|
addQuickActionControl(map, cm, mode);
|
||||||
// Right panel
|
// Right panel
|
||||||
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, map)
|
cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, map)
|
||||||
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
|
.setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
|
||||||
|
@ -386,12 +386,12 @@ public class MapWidgetRegistry {
|
||||||
return leftWidgetSet;
|
return leftWidgetSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addQuickActionControl(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter) {
|
private void addQuickActionControl(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter, ApplicationMode mode) {
|
||||||
|
|
||||||
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, mapActivity)
|
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, mapActivity)
|
||||||
.setCategory(true).setLayout(R.layout.list_group_empty_title_with_switch).createItem());
|
.setCategory(true).setLayout(R.layout.list_group_empty_title_with_switch).createItem());
|
||||||
|
|
||||||
boolean selected = settings.QUICK_ACTION.get();
|
boolean selected = mapActivity.getMapLayers().getQuickActionRegistry().isQuickActionOn();
|
||||||
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
.setTitleId(R.string.configure_screen_quick_action, mapActivity)
|
.setTitleId(R.string.configure_screen_quick_action, mapActivity)
|
||||||
.setIcon(R.drawable.map_quick_action)
|
.setIcon(R.drawable.map_quick_action)
|
||||||
|
@ -422,7 +422,7 @@ public class MapWidgetRegistry {
|
||||||
int position,
|
int position,
|
||||||
boolean visible) {
|
boolean visible) {
|
||||||
|
|
||||||
settings.QUICK_ACTION.set(visible);
|
mapActivity.getMapLayers().getQuickActionRegistry().setQuickActionFabState(visible);
|
||||||
|
|
||||||
MapQuickActionLayer mil = mapActivity.getMapLayers().getMapQuickActionLayer();
|
MapQuickActionLayer mil = mapActivity.getMapLayers().getMapQuickActionLayer();
|
||||||
if (mil != null) {
|
if (mil != null) {
|
||||||
|
|
Loading…
Reference in a new issue