Added move marker bottom sheet. Finalized move marker functionality.

This commit is contained in:
GaidamakUA 2016-05-05 11:23:22 +03:00
parent c0aa920c6a
commit cf697098c5
10 changed files with 255 additions and 20 deletions

View file

@ -64,6 +64,11 @@
android:layout_gravity="bottom|left"
android:visibility="gone"/>
<include layout="@layout/move_marker_bottom_sheet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View file

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/move_marker_bottom_sheet"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/left_menu_view_bg"
android:clickable="true"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:src="@drawable/ic_action_photo_dark"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/TextAppearance.ContextMenuTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="@string/move_marker_bottom_sheet_title"/>
<TextView
android:id="@+id/description"
style="@style/TextAppearance.ContextMenuSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
tools:text="Lat: 50.45375 Lon: 30.48693"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp">
<android.support.v7.widget.AppCompatButton
android:id="@+id/apply_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shared_string_apply"/>
<android.support.v7.widget.AppCompatButton
android:id="@+id/cancel_button"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shared_string_cancel"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -75,10 +75,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/search_address_building"
android:maxLines="6"
android:ellipsize="end"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size_large"/>
style="@style/TextAppearance.ContextMenuTitle"/>
</LinearLayout>
@ -128,8 +125,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/amenity_type_finance"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"/>
style="@style/TextAppearance.ContextMenuSubtitle"/>
</LinearLayout>

View file

@ -188,7 +188,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/recording_note_fragment"/>
<include layout="@layout/recording_note_fragment"
tools:visibility="gone"/>
<include layout="@layout/move_marker_bottom_sheet"/>
<LinearLayout
android:id="@+id/map_context_menu_layout"

View file

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/move_marker_bottom_sheet"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/bottom_menu_view_bg"
android:clickable="true"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:src="@drawable/ic_action_photo_dark"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/TextAppearance.ContextMenuTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:text="@string/move_marker_bottom_sheet_title"/>
<TextView
android:id="@+id/description"
style="@style/TextAppearance.ContextMenuSubtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
tools:text="Lat: 50.45375 Lon: 30.48693"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp">
<android.support.v7.widget.AppCompatButton
android:id="@+id/apply_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shared_string_apply"/>
<android.support.v7.widget.AppCompatButton
android:id="@+id/cancel_button"
style="@style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shared_string_cancel"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -10,6 +10,8 @@
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="move_marker_bottom_sheet_title">Move the map to change marker\'s position</string>
<string name="lat_lon_pattern">Lat: %1$.6f Lon: %2$.6f</string>
<string name="follow_us">Follow us</string>
<string name="access_direction_audio_feedback">Direction audio feedback</string>
<string name="access_direction_audio_feedback_descr">Indicate target point direction by sound</string>
@ -1153,7 +1155,7 @@
<string name="rendering_attr_hikingRoutesOSMC_description">Render paths according to OSMC traces</string>
<string name="rendering_attr_noAdminboundaries_name">Hide boundaries</string>
<string name="rendering_attr_noAdminboundaries_description">Suppress display of regional boundaries (admin levels 5-9)</string>
<string name="rendering_attr_noAdminboundaries_description">Suppress display of regional boundaries (admin levels 59)</string>
<string name="map_widget_max_speed">Speed limit</string>
<string name="monitoring_control_start">GPX</string>
<string name="no_buildings_found">No buildings found.</string>

View file

@ -377,4 +377,17 @@
<item name="typeface">@string/font_roboto_medium</item>
<item name="android:textSize">@dimen/default_list_text_size</item>
</style>
<style name="TextAppearance.ContextMenuTitle" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textSize">@dimen/default_list_text_size_large</item>
<item name="android:maxLines">6</item>
<item name="android:ellipsize">end</item>
</style>
<style name="TextAppearance.ContextMenuSubtitle" parent="TextAppearance.AppCompat.Subhead">
<item name="android:textColor">?android:textColorSecondary</item>
<item name="android:textSize">@dimen/default_desc_text_size</item>
</style>
</resources>

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.WptPt;
@ -58,7 +59,7 @@ public class WptPtMenuController extends MenuController {
@Override
public Drawable getLeftIcon() {
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(),
wpt.getColor(getMapActivity().getResources().getColor(R.color.gpx_color_point)), false);
wpt.getColor(ContextCompat.getColor(getMapActivity(), R.color.gpx_color_point)), false);
}
@Override

View file

@ -11,6 +11,7 @@ import android.graphics.Rect;
import android.os.Vibrator;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresPermission;
import android.support.v4.content.ContextCompat;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.ArrayAdapter;
@ -56,6 +57,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
private GestureDetector movementListener;
private final MoveMarkerBottomSheetHelper mMoveMarkerBottomSheetHelper;
private boolean mInChangeMarkerPositionMode;
public ContextMenuLayer(MapActivity activity) {
@ -63,6 +65,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
menu = activity.getContextMenu();
multiSelectionMenu = menu.getMultiSelectionMenu();
movementListener = new GestureDetector(activity, new MenuLayerOnGestureListener());
mMoveMarkerBottomSheetHelper = new MoveMarkerBottomSheetHelper(activity, this);
}
@Override
@ -73,9 +76,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
public void initLayer(OsmandMapTileView view) {
this.view = view;
contextMarker = new ImageView(view.getContext());
Context context = view.getContext();
contextMarker = new ImageView(context);
contextMarker.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
contextMarker.setImageDrawable(view.getResources().getDrawable(R.drawable.map_pin_context_menu));
contextMarker.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.map_pin_context_menu));
contextMarker.setClickable(true);
int minw = contextMarker.getDrawable().getMinimumWidth();
int minh = contextMarker.getDrawable().getMinimumHeight();
@ -150,14 +154,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_SHORT);
mInChangeMarkerPositionMode = !mInChangeMarkerPositionMode;
if (!mInChangeMarkerPositionMode) {
int newMarkerX = tileBox.getCenterPixelX();
int newMarkerY = tileBox.getCenterPixelY();
PointF newMarkerPosition = new PointF(newMarkerX, newMarkerY);
showContextMenu(newMarkerPosition, tileBox, true);
view.refreshMap();
}
mInChangeMarkerPositionMode = true;
activity.getContextMenu().hide();
LatLon latLon = tileBox.getCenterLatLon();
mMoveMarkerBottomSheetHelper.show(latLon.getLatitude(), latLon.getLongitude());
return true;
}
@ -166,8 +166,26 @@ public class ContextMenuLayer extends OsmandMapLayer {
return true;
}
public void applyNewMarkerPosition() {
if (!mInChangeMarkerPositionMode) {
throw new IllegalStateException("Not in change marker position mode");
}
mInChangeMarkerPositionMode = false;
RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox();
int newMarkerX = tileBox.getCenterPixelX();
int newMarkerY = tileBox.getCenterPixelY();
PointF newMarkerPosition = new PointF(newMarkerX, newMarkerY);
showContextMenu(newMarkerPosition, tileBox, true);
view.refreshMap();
}
public void cancelMovingMarker() {
mInChangeMarkerPositionMode = false;
activity.getContextMenu().show();
}
public boolean showContextMenu(double latitude, double longitude, boolean showUnknownLocation) {
RotatedTileBox cp = activity.getMapView().getCurrentRotatedTileBox().copy();
RotatedTileBox cp = activity.getMapView().getCurrentRotatedTileBox();
float x = cp.getPixXFromLatLon(latitude, longitude);
float y = cp.getPixYFromLatLon(latitude, longitude);
return showContextMenu(new PointF(x, y), activity.getMapView().getCurrentRotatedTileBox(), showUnknownLocation);
@ -216,6 +234,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
}
public boolean disableSingleTap() {
if (mInChangeMarkerPositionMode) {
return true;
}
boolean res = false;
for (OsmandMapLayer lt : view.getLayers()) {
if (lt instanceof ContextMenuLayer.IContextMenuProvider) {
@ -229,6 +250,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
}
public boolean disableLongPressOnMap() {
if (mInChangeMarkerPositionMode) {
return true;
}
boolean res = false;
for (OsmandMapLayer lt : view.getLayers()) {
if (lt instanceof ContextMenuLayer.IContextMenuProvider) {

View file

@ -0,0 +1,51 @@
package net.osmand.plus.views;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.plus.IconsCache;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
public class MoveMarkerBottomSheetHelper {
private final View mView;
private final TextView mDescription;
private final Context mContext;
private final ContextMenuLayer mContextMenuLayer;
public MoveMarkerBottomSheetHelper(MapActivity activity, ContextMenuLayer contextMenuLayer) {
mContextMenuLayer = contextMenuLayer;
this.mView = activity.findViewById(R.id.move_marker_bottom_sheet);
ImageView icon = (ImageView) mView.findViewById(R.id.icon);
this.mDescription = (TextView) mView.findViewById(R.id.description);
this.mContext = activity;
IconsCache iconsCache = activity.getMyApplication().getIconsCache();
icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_photo_dark, R.color.marker_green));
mView.findViewById(R.id.apply_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hide();
mContextMenuLayer.applyNewMarkerPosition();
}
});
mView.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hide();
mContextMenuLayer.cancelMovingMarker();
}
});
}
public void show(double lat, double lon) {
mView.setVisibility(View.VISIBLE);
mDescription.setText(mContext.getString(R.string.lat_lon_pattern, lat, lon));
}
public void hide() {
mView.setVisibility(View.GONE);
}
}