Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
b15139b9d9
1 changed files with 35 additions and 33 deletions
|
@ -3,7 +3,6 @@ package net.osmand.plus.views;
|
|||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.PointF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Vibrator;
|
||||
import android.support.annotation.DimenRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
@ -53,10 +52,11 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
private boolean wasCollapseButtonVisible;
|
||||
private int previousMapPosition;
|
||||
|
||||
|
||||
private boolean inChangeMarkerPositionMode;
|
||||
private boolean isLayerOn;
|
||||
|
||||
private boolean nightMode;
|
||||
|
||||
public MapQuickActionLayer(MapActivity activity, ContextMenuLayer contextMenuLayer) {
|
||||
this.mapActivity = activity;
|
||||
this.contextMenuLayer = contextMenuLayer;
|
||||
|
@ -74,13 +74,14 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
quickActionButton = (ImageButton) mapActivity.findViewById(R.id.map_quick_actions_button);
|
||||
setQuickActionButtonMargin();
|
||||
isLayerOn = quickActionRegistry.isQuickActionOn();
|
||||
setUpQuickActionBtnResources(app.getDaynightHelper().isNightModeForMapControls());
|
||||
nightMode = app.getDaynightHelper().isNightModeForMapControls();
|
||||
updateQuickActionButton(false);
|
||||
quickActionButton.setContentDescription(mapActivity.getString(R.string.configure_screen_quick_action));
|
||||
quickActionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!showTutorialIfNeeded())
|
||||
setLayerState(quickActionsWidget.getVisibility() == View.VISIBLE);
|
||||
setLayerState(!isWidgetVisible());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -110,9 +111,9 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
}
|
||||
|
||||
public void refreshLayer() {
|
||||
setLayerState(true);
|
||||
setLayerState(false);
|
||||
isLayerOn = quickActionRegistry.isQuickActionOn();
|
||||
setUpQuickActionBtnVisibility();
|
||||
setupQuickActionBtnVisibility();
|
||||
}
|
||||
|
||||
private boolean showTutorialIfNeeded() {
|
||||
|
@ -173,19 +174,22 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
return result;
|
||||
}
|
||||
|
||||
private boolean isWidgetVisible() {
|
||||
return quickActionsWidget.getVisibility() == View.VISIBLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isClosed
|
||||
* @param showWidget
|
||||
* @return true, if state was changed
|
||||
*/
|
||||
public boolean setLayerState(boolean isClosed) {
|
||||
if ((quickActionsWidget.getVisibility() == View.VISIBLE) != isClosed) // check if state change is needed
|
||||
public boolean setLayerState(boolean showWidget) {
|
||||
if (isWidgetVisible() == showWidget) // check if state change is needed
|
||||
return false;
|
||||
|
||||
quickActionButton.setImageResource(isClosed ? R.drawable.map_quick_action : R.drawable.map_action_cancel);
|
||||
quickActionButton.setContentDescription(mapActivity.getString(isClosed ? R.string.configure_screen_quick_action : R.string.shared_string_cancel));
|
||||
quickActionsWidget.setVisibility(isClosed ? View.GONE : View.VISIBLE);
|
||||
updateQuickActionButton(showWidget);
|
||||
quickActionsWidget.setVisibility(!showWidget ? View.GONE : View.VISIBLE);
|
||||
|
||||
if (isClosed) {
|
||||
if (!showWidget) {
|
||||
quitMovingMarker();
|
||||
quickActionRegistry.setUpdatesListener(null);
|
||||
quickActionsWidget.setSelectionListener(null);
|
||||
|
@ -199,6 +203,14 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
return true;
|
||||
}
|
||||
|
||||
private void updateQuickActionButton(boolean widgetVisible) {
|
||||
quickActionButton.setImageDrawable(app.getIconsCache().getIcon(
|
||||
!widgetVisible ? R.drawable.map_quick_action : R.drawable.map_action_cancel, !nightMode));
|
||||
quickActionButton.setBackgroundResource(
|
||||
nightMode ? R.drawable.btn_circle_night : R.drawable.btn_circle_trans);
|
||||
quickActionButton.setContentDescription(mapActivity.getString(!widgetVisible ? R.string.configure_screen_quick_action : R.string.shared_string_cancel));
|
||||
}
|
||||
|
||||
private void enterMovingMode(RotatedTileBox tileBox) {
|
||||
previousMapPosition = view.getMapPosition();
|
||||
view.setMapPosition(OsmandSettings.MIDDLE_CONSTANT);
|
||||
|
@ -277,7 +289,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
@Override
|
||||
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
|
||||
if (isInChangeMarkerPositionMode() && !pressedQuickActionWidget(point.x, point.y)) {
|
||||
setLayerState(true);
|
||||
setLayerState(false);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
|
@ -289,15 +301,19 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings settings) {
|
||||
boolean nightMode = settings != null && settings.isNightMode();
|
||||
if (isInChangeMarkerPositionMode()) {
|
||||
canvas.translate(box.getCenterPixelX() - contextMarker.getWidth() / 2, box.getCenterPixelY() - contextMarker.getHeight());
|
||||
contextMarker.draw(canvas);
|
||||
}
|
||||
setUpQuickActionBtnVisibility();
|
||||
setUpQuickActionBtnResources(settings.isNightMode());
|
||||
if (this.nightMode != nightMode) {
|
||||
this.nightMode = nightMode;
|
||||
updateQuickActionButton(isWidgetVisible());
|
||||
}
|
||||
setupQuickActionBtnVisibility();
|
||||
}
|
||||
|
||||
private void setUpQuickActionBtnVisibility() {
|
||||
private void setupQuickActionBtnVisibility() {
|
||||
boolean hideQuickButton = !isLayerOn ||
|
||||
contextMenuLayer.isInChangeMarkerPositionMode() ||
|
||||
contextMenuLayer.isInGpxDetailsMode() ||
|
||||
|
@ -308,20 +324,6 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
quickActionButton.setVisibility(hideQuickButton ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
private void setUpQuickActionBtnResources(boolean nightMode) {
|
||||
Drawable icon;
|
||||
int backgroundId;
|
||||
if (nightMode) {
|
||||
backgroundId = R.drawable.btn_circle_night;
|
||||
icon = app.getIconsCache().getIcon(R.drawable.map_quick_action, 0);
|
||||
} else {
|
||||
backgroundId = R.drawable.btn_circle_trans;
|
||||
icon = app.getIconsCache().getIcon(R.drawable.map_quick_action, R.color.icon_color);
|
||||
}
|
||||
quickActionButton.setBackgroundResource(backgroundId);
|
||||
quickActionButton.setImageDrawable(icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyLayer() {
|
||||
|
||||
|
@ -341,7 +343,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
@Override
|
||||
public void onActionSelected(QuickAction action) {
|
||||
QuickActionFactory.produceAction(action).execute(mapActivity);
|
||||
setLayerState(true);
|
||||
setLayerState(false);
|
||||
}
|
||||
|
||||
public PointF getMovableCenterPoint(RotatedTileBox tb) {
|
||||
|
@ -357,7 +359,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
}
|
||||
|
||||
public boolean onBackPressed() {
|
||||
return setLayerState(true);
|
||||
return setLayerState(false);
|
||||
}
|
||||
|
||||
View.OnTouchListener onQuickActionTouchListener = new View.OnTouchListener() {
|
||||
|
|
Loading…
Reference in a new issue