quick action fab in different application modes

This commit is contained in:
Korusn Oleksandr 2016-12-30 16:42:25 +02:00
parent 6a21b0c6ef
commit efef417757
5 changed files with 37 additions and 12 deletions

View file

@ -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_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();

View file

@ -981,6 +981,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
if (mapLayers.getMapInfoLayer() != null) {
mapLayers.getMapInfoLayer().recreateControls();
}
if (mapLayers.getMapQuickActionLayer() != null) {
mapLayers.getMapQuickActionLayer().refreshLayer();
}
mapLayers.updateLayers(mapView);
mapActions.updateDrawerMenu();
mapView.setComplexZoom(mapView.getZoom(), mapView.getSettingsMapDensity());

View file

@ -2,10 +2,16 @@ package net.osmand.plus.quickaction;
import android.content.Context;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import net.osmand.plus.OsmandSettings;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created by rosty on 12/27/16.
@ -22,6 +28,7 @@ public class QuickActionRegistry {
private final OsmandSettings settings;
private final List<QuickAction> quickActions;
private final Map<String, Boolean> fabStateMap;
private QuickActionUpdatesListener updatesListener;
@ -31,6 +38,7 @@ public class QuickActionRegistry {
this.settings = settings;
quickActions = factory.parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
fabStateMap = getQuickActionFabStateMapFromJson(settings.QUICK_ACTION.get());
}
public void setUpdatesListener(QuickActionUpdatesListener updatesListener) {
@ -136,4 +144,22 @@ public class QuickActionRegistry {
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>();
}
}

View file

@ -67,8 +67,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
quickActionsWidget = (QuickActionsWidget) mapActivity.findViewById(R.id.quick_action_widget);
quickActionButton = (ImageButton) mapActivity.findViewById(R.id.map_quick_actions_button);
setQuickActionButtonMargin();
isLayerOn = settings.QUICK_ACTION.get();
// quickActionButton.setVisibility(isLayerOn ? View.VISIBLE : View.GONE);
isLayerOn = quickActionRegistry.isQuickActionOn();
quickActionButton.setImageResource(R.drawable.map_quick_action);
quickActionButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -102,8 +101,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
public void refreshLayer() {
setLayerState(true);
isLayerOn = settings.QUICK_ACTION.get();
// quickActionButton.setVisibility(settings.QUICK_ACTION.get() ? View.VISIBLE : View.GONE);
isLayerOn = quickActionRegistry.isQuickActionOn();
}
private void setQuickActionButtonMargin() {
@ -227,15 +225,13 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
@Override
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings settings) {
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());
contextMarker.draw(canvas);
}
boolean hideQuickButton = !isLayerOn ||
contextMenuLayer.isInChangeMarkerPositionMode() ||
mapActivity.getContextMenu().isVisible() ||
mapActivity.getContextMenu().getMultiSelectionMenu().isVisible() ||
mapActivity.getRoutingHelper().isRoutePlanningMode();
mapActivity.getContextMenu().getMultiSelectionMenu().isVisible();
quickActionButton.setVisibility(hideQuickButton ? View.GONE : View.VISIBLE);
}

View file

@ -359,7 +359,7 @@ public class MapWidgetRegistry {
public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) {
addQuickActionControl(map, cm);
addQuickActionControl(map, cm, 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());
@ -386,12 +386,12 @@ public class MapWidgetRegistry {
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)
.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()
.setTitleId(R.string.configure_screen_quick_action, mapActivity)
.setIcon(R.drawable.map_quick_action)
@ -422,7 +422,7 @@ public class MapWidgetRegistry {
int position,
boolean visible) {
settings.QUICK_ACTION.set(visible);
mapActivity.getMapLayers().getQuickActionRegistry().setQuickActionFabState(visible);
MapQuickActionLayer mil = mapActivity.getMapLayers().getMapQuickActionLayer();
if (mil != null) {