fab position save; fab visibility fix
This commit is contained in:
parent
37a2c95e54
commit
7f1fa6636a
4 changed files with 112 additions and 33 deletions
|
@ -4,6 +4,12 @@
|
|||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:padding="@dimen/map_button_margin">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/map_quick_actions_button"
|
||||
android:layout_width="@dimen/map_button_size"
|
||||
|
@ -11,11 +17,10 @@
|
|||
android:background="@drawable/btn_circle_blue"
|
||||
android:contentDescription="@string/zoomIn"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:layout_marginBottom="196dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
tools:src="@drawable/ic_action_test_light"/>
|
||||
</FrameLayout>
|
||||
|
||||
<net.osmand.plus.quickaction.QuickActionsWidget
|
||||
android:id="@+id/quick_action_widget"
|
||||
|
|
|
@ -14,6 +14,8 @@ import android.os.Environment;
|
|||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.util.Pair;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.ValueHolder;
|
||||
|
@ -1101,10 +1103,6 @@ public class OsmandSettings {
|
|||
}
|
||||
}
|
||||
|
||||
public final CommonPreference<Boolean> QUICK_ACTION = new BooleanPreference("quick_action", false).makeProfile();
|
||||
|
||||
public final CommonPreference<String> QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeProfile();
|
||||
|
||||
public final OsmandPreference<String> OSMO_DEVICE_KEY = new StringPreference("osmo_device_token", "").makeGlobal();
|
||||
|
||||
public final OsmandPreference<String> OSMO_USER_NAME = new StringPreference("osmo_user_name", "").makeGlobal();
|
||||
|
@ -2447,6 +2445,45 @@ public class OsmandSettings {
|
|||
return mImpassableRoadsStorage.movePoint(latLonEx, latLonNew);
|
||||
}
|
||||
|
||||
/**
|
||||
* quick actions prefs
|
||||
*/
|
||||
|
||||
public static final String QUICK_FAB_MARGIN_X_PORTRAIT_MARGIN = "quick_fab_margin_x_portrait_margin";
|
||||
public static final String QUICK_FAB_MARGIN_Y_PORTRAIT_MARGIN = "quick_fab_margin_y_portrait_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 final CommonPreference<Boolean> QUICK_ACTION = new BooleanPreference("quick_action", false).makeProfile();
|
||||
|
||||
public final CommonPreference<String> QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeProfile();
|
||||
|
||||
public boolean setPortraitFabMargin(int x, int y) {
|
||||
return settingsAPI.edit(globalPreferences).putInt(QUICK_FAB_MARGIN_X_PORTRAIT_MARGIN, x)
|
||||
.putInt(QUICK_FAB_MARGIN_Y_PORTRAIT_MARGIN, y).commit();
|
||||
}
|
||||
|
||||
public boolean setLandscapeFabMargin(int x, int y) {
|
||||
return settingsAPI.edit(globalPreferences).putInt(QUICK_FAB_MARGIN_X_LANDSCAPE_MARGIN, x)
|
||||
.putInt(QUICK_FAB_MARGIN_Y_LANDSCAPE_MARGIN, y).commit();
|
||||
}
|
||||
|
||||
public Pair<Integer, Integer> getPortraitFabMargin() {
|
||||
if (settingsAPI.contains(globalPreferences, QUICK_FAB_MARGIN_X_PORTRAIT_MARGIN) && settingsAPI.contains(globalPreferences, QUICK_FAB_MARGIN_Y_PORTRAIT_MARGIN)) {
|
||||
return new Pair<>(settingsAPI.getInt(globalPreferences, QUICK_FAB_MARGIN_X_PORTRAIT_MARGIN, 0),
|
||||
settingsAPI.getInt(globalPreferences, QUICK_FAB_MARGIN_Y_PORTRAIT_MARGIN, 0));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Pair<Integer, Integer> getLandscapeFabMargin() {
|
||||
if (settingsAPI.contains(globalPreferences, QUICK_FAB_MARGIN_X_LANDSCAPE_MARGIN) && settingsAPI.contains(globalPreferences, QUICK_FAB_MARGIN_Y_LANDSCAPE_MARGIN)) {
|
||||
return new Pair<>(settingsAPI.getInt(globalPreferences, QUICK_FAB_MARGIN_X_LANDSCAPE_MARGIN, 0),
|
||||
settingsAPI.getInt(globalPreferences, QUICK_FAB_MARGIN_Y_LANDSCAPE_MARGIN, 0));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* the location of a parked car
|
||||
*/
|
||||
|
|
|
@ -4,7 +4,9 @@ import android.content.Context;
|
|||
import android.graphics.Canvas;
|
||||
import android.graphics.PointF;
|
||||
import android.os.Vibrator;
|
||||
import android.support.annotation.DimenRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
@ -17,6 +19,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
import net.osmand.plus.quickaction.QuickActionFactory;
|
||||
|
@ -46,6 +49,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
|
||||
|
||||
private boolean inChangeMarkerPositionMode;
|
||||
private boolean isLayerOn;
|
||||
|
||||
public MapQuickActionLayer(MapActivity activity, ContextMenuLayer contextMenuLayer) {
|
||||
this.mapActivity = activity;
|
||||
|
@ -62,7 +66,9 @@ 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);
|
||||
quickActionButton.setVisibility(settings.QUICK_ACTION.get() ? View.VISIBLE : View.GONE);
|
||||
setQuickActionButtonMargin();
|
||||
isLayerOn = settings.QUICK_ACTION.get();
|
||||
// quickActionButton.setVisibility(isLayerOn ? View.VISIBLE : View.GONE);
|
||||
quickActionButton.setImageResource(R.drawable.map_quick_action);
|
||||
quickActionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -94,6 +100,42 @@ 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);
|
||||
}
|
||||
|
||||
private void setQuickActionButtonMargin() {
|
||||
FrameLayout.LayoutParams param = (FrameLayout.LayoutParams) quickActionButton.getLayoutParams();
|
||||
if (AndroidUiHelper.isOrientationPortrait(mapActivity)) {
|
||||
Pair<Integer, Integer> fabMargin = settings.getPortraitFabMargin();
|
||||
if (fabMargin != null) {
|
||||
param.rightMargin = fabMargin.first;
|
||||
param.bottomMargin = fabMargin.second;
|
||||
} else {
|
||||
param.bottomMargin = calculateTotalSizePx(R.dimen.map_button_size, R.dimen.map_button_spacing) * 2;
|
||||
}
|
||||
} else {
|
||||
Pair<Integer, Integer> fabMargin = settings.getLandscapeFabMargin();
|
||||
if (fabMargin != null) {
|
||||
param.rightMargin = fabMargin.first;
|
||||
param.bottomMargin = fabMargin.second;
|
||||
} else {
|
||||
param.rightMargin = calculateTotalSizePx(R.dimen.map_button_size, R.dimen.map_button_spacing_land) * 2;
|
||||
}
|
||||
}
|
||||
quickActionButton.setLayoutParams(param);
|
||||
}
|
||||
|
||||
private int calculateTotalSizePx(@DimenRes int... dimensId) {
|
||||
int result = 0;
|
||||
for (int id : dimensId) {
|
||||
result += mapActivity.getResources().getDimensionPixelSize(id);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param isClosed
|
||||
* @return true, if state was changed
|
||||
|
@ -116,14 +158,6 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
quickActionsWidget.setSelectionListener(MapQuickActionLayer.this);
|
||||
}
|
||||
|
||||
// if (isClosed) {
|
||||
// contextMenuLayer.quitMovingMarker();
|
||||
// }
|
||||
// else {
|
||||
// LatLon centerLatLon = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
|
||||
// contextMenuLayer.showContextMenu(centerLatLon.getLatitude(), centerLatLon.getLongitude(), false);
|
||||
// contextMenuLayer.enterMovingMode(mapActivity.getMapView().getCurrentRotatedTileBox());
|
||||
// }
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -190,18 +224,15 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
return py <= quickActionsWidget.getHeight();
|
||||
}
|
||||
|
||||
public void refreshLayer() {
|
||||
quickActionButton.setVisibility(settings.QUICK_ACTION.get() ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings settings) {
|
||||
if (inChangeMarkerPositionMode) {
|
||||
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 = contextMenuLayer.isInChangeMarkerPositionMode() ||
|
||||
boolean hideQuickButton = !isLayerOn ||
|
||||
contextMenuLayer.isInChangeMarkerPositionMode() ||
|
||||
mapActivity.getContextMenu().isVisible() ||
|
||||
mapActivity.getContextMenu().getMultiSelectionMenu().isVisible() ||
|
||||
mapActivity.getRoutingHelper().isRoutePlanningMode();
|
||||
|
@ -227,6 +258,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
@Override
|
||||
public void onActionSelected(QuickAction action) {
|
||||
QuickActionFactory.produceAction(action).execute(mapActivity);
|
||||
setLayerState(true);
|
||||
}
|
||||
|
||||
public PointF getMovableCenterPoint(RotatedTileBox tb) {
|
||||
|
@ -234,7 +266,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
}
|
||||
|
||||
public boolean isInChangeMarkerPositionMode() {
|
||||
return inChangeMarkerPositionMode;
|
||||
return isLayerOn && inChangeMarkerPositionMode;
|
||||
}
|
||||
|
||||
public boolean onBackPressed() {
|
||||
|
@ -255,6 +287,11 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
|
|||
return true;
|
||||
case MotionEvent.ACTION_UP:
|
||||
quickActionButton.setOnTouchListener(null);
|
||||
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) v.getLayoutParams();
|
||||
if (AndroidUiHelper.isOrientationPortrait(mapActivity))
|
||||
settings.setPortraitFabMargin(params.rightMargin, params.bottomMargin);
|
||||
else
|
||||
settings.setLandscapeFabMargin(params.rightMargin, params.bottomMargin);
|
||||
return true;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (initialMarginX == 0 && initialMarginY == 0 && initialTouchX == 0 && initialTouchY == 0)
|
||||
|
|
|
@ -3,7 +3,7 @@ buildscript {
|
|||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:2.1.3'
|
||||
classpath 'com.android.tools.build:gradle:2.2.3'
|
||||
classpath 'com.google.gms:google-services:3.0.0'
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue