Add new marker menu on map
This commit is contained in:
parent
e09acfce48
commit
2c5995da19
4 changed files with 481 additions and 2 deletions
191
OsmAnd/res/layout/fragment_marker_menu_on_map.xml
Normal file
191
OsmAnd/res/layout/fragment_marker_menu_on_map.xml
Normal file
|
@ -0,0 +1,191 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/color_transparent">
|
||||
|
||||
<LinearLayout
|
||||
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:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_selected_item_title_height"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/marker_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_content_padding"
|
||||
tools:src="@drawable/ic_action_flag_dark"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.AppCompatTextView
|
||||
android:id="@+id/marker_title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="Van Gogh Museum"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/marker_direction_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
tools:src="@drawable/ic_direction_arrow"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatTextView
|
||||
android:id="@+id/marker_distance"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
tools:text="213 m"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatTextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=" • "
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatTextView
|
||||
android:id="@+id/marker_description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
tools:text="Amsterdam Weekend"/>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/marker_visited_button"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="56dp"
|
||||
android:focusableInTouchMode="true"
|
||||
tools:background="@drawable/marker_circle_background_dark_with_inset"
|
||||
tools:src="@drawable/ic_action_marker_passed"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="@dimen/measurement_tool_bottom_divider_margin_bottom"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/rename_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/rename_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_content_padding"
|
||||
tools:src="@drawable/ic_action_edit_dark"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="@string/shared_string_rename"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginBottom="@dimen/measurement_tool_bottom_divider_margin_bottom"
|
||||
android:layout_marginLeft="@dimen/measurement_tool_bottom_divider_margin_start"
|
||||
android:layout_marginStart="@dimen/measurement_tool_bottom_divider_margin_start"
|
||||
android:layout_marginTop="@dimen/measurement_tool_bottom_divider_margin_top"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/delete_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_list_item_height"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/delete_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_content_padding"
|
||||
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_content_padding"
|
||||
tools:src="@drawable/ic_action_delete_dark"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="@string/shared_string_delete"
|
||||
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="@dimen/measurement_tool_bottom_divider_margin_top"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/back_row"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:text="@string/shared_string_back"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
android:textStyle="bold"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
|
@ -9,6 +9,7 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
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="shared_string_back">Back</string>
|
||||
<string name="wrong_format">Wrong format</string>
|
||||
<string name="shared_string_road">Road</string>
|
||||
<string name="show_map">Show map</string>
|
||||
|
|
|
@ -56,9 +56,10 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL
|
|||
public void onItemClick(View view) {
|
||||
int pos = recyclerView.getChildAdapterPosition(view);
|
||||
MapMarker marker = adapter.getItem(pos);
|
||||
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
|
||||
15, marker.getPointDescription(mapActivity), true, marker);
|
||||
mapActivity.getMyApplication().getSettings()
|
||||
.setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), 15, null, false, null);
|
||||
MapActivity.launchMapActivityMoveToTop(mapActivity);
|
||||
MarkerMenuOnMapFragment.showInstance(mapActivity, marker);
|
||||
((DialogFragment) getParentFragment()).dismiss();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,286 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.DrawableRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT;
|
||||
import static net.osmand.plus.OsmandSettings.MIDDLE_TOP_CONSTANT;
|
||||
|
||||
public class MarkerMenuOnMapFragment extends Fragment implements OsmAndCompassListener, OsmAndLocationListener {
|
||||
|
||||
public static final String TAG = "MarkerMenuOnMapFragment";
|
||||
|
||||
private IconsCache iconsCache;
|
||||
private MapMarker marker;
|
||||
|
||||
private boolean night;
|
||||
private boolean portrait;
|
||||
|
||||
private int previousMapPosition;
|
||||
|
||||
private Float heading;
|
||||
private Location location;
|
||||
|
||||
private ImageView arrowIv;
|
||||
private TextView distanceTv;
|
||||
|
||||
public void setMarker(MapMarker marker) {
|
||||
this.marker = marker;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
OsmandApplication app = (OsmandApplication) getActivity().getApplication();
|
||||
night = app.getDaynightHelper().isNightModeForMapControls();
|
||||
iconsCache = app.getIconsCache();
|
||||
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
|
||||
final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
|
||||
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_menu_on_map, null);
|
||||
mainView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
((ImageView) mainView.findViewById(R.id.marker_icon))
|
||||
.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(marker.colorIndex)));
|
||||
((ImageView) mainView.findViewById(R.id.rename_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_edit_dark));
|
||||
((ImageView) mainView.findViewById(R.id.delete_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_delete_dark));
|
||||
|
||||
((TextView) mainView.findViewById(R.id.marker_title)).setText(marker.getName(getActivity()));
|
||||
|
||||
arrowIv = (ImageView) mainView.findViewById(R.id.marker_direction_icon);
|
||||
distanceTv = (TextView) mainView.findViewById(R.id.marker_distance);
|
||||
|
||||
String descr;
|
||||
if ((descr = marker.groupName) != null) {
|
||||
if (descr.equals("")) {
|
||||
descr = getActivity().getString(R.string.shared_string_favorites);
|
||||
}
|
||||
} else {
|
||||
Date date = new Date(marker.creationDate);
|
||||
String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
|
||||
if (month.length() > 1) {
|
||||
month = Character.toUpperCase(month.charAt(0)) + month.substring(1);
|
||||
}
|
||||
month = month.replaceAll("\\.", "");
|
||||
String day = new SimpleDateFormat("d", Locale.getDefault()).format(date);
|
||||
descr = month + " " + day;
|
||||
}
|
||||
((TextView) mainView.findViewById(R.id.marker_description)).setText(descr);
|
||||
|
||||
ImageButton visitedBtn = (ImageButton) mainView.findViewById(R.id.marker_visited_button);
|
||||
visitedBtn.setBackgroundDrawable(ContextCompat.getDrawable(getContext(),
|
||||
night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
|
||||
visitedBtn.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_marker_passed, night ? 0 : R.color.icon_color));
|
||||
visitedBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Toast.makeText(getContext(), "Passed", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
mainView.findViewById(R.id.rename_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Toast.makeText(getContext(), "Rename", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
mainView.findViewById(R.id.delete_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Toast.makeText(getContext(), "Delete", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
mainView.findViewById(R.id.back_row).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
MapMarkersDialogFragment.showInstance(mapActivity);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
enterMenuMode();
|
||||
startLocationUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
exitMenuMode();
|
||||
stopLocationUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLocation(Location location) {
|
||||
boolean newLocation = this.location == null && location != null;
|
||||
boolean locationChanged = this.location != null && location != null
|
||||
&& this.location.getLatitude() != location.getLatitude()
|
||||
&& this.location.getLongitude() != location.getLongitude();
|
||||
if (newLocation || locationChanged) {
|
||||
this.location = location;
|
||||
updateLocationUi();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCompassValue(float value) {
|
||||
// 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction)
|
||||
// on non-compass devices
|
||||
float lastHeading = heading != null ? heading : 99;
|
||||
heading = value;
|
||||
if (Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) {
|
||||
updateLocationUi();
|
||||
} else {
|
||||
heading = lastHeading;
|
||||
}
|
||||
}
|
||||
|
||||
private OsmandApplication getMyApplication() {
|
||||
if (getActivity() != null) {
|
||||
return ((MapActivity) getActivity()).getMyApplication();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private MapActivity getMapActivity() {
|
||||
return (MapActivity) getActivity();
|
||||
}
|
||||
|
||||
private Drawable getContentIcon(@DrawableRes int id) {
|
||||
return iconsCache.getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
|
||||
}
|
||||
|
||||
private void startLocationUpdate() {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||
app.getLocationProvider().addCompassListener(this);
|
||||
app.getLocationProvider().addLocationListener(this);
|
||||
updateLocationUi();
|
||||
}
|
||||
}
|
||||
|
||||
private void stopLocationUpdate() {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
app.getLocationProvider().removeLocationListener(this);
|
||||
app.getLocationProvider().removeCompassListener(this);
|
||||
app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLocationUi() {
|
||||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMyApplication().runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (location == null) {
|
||||
location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||
}
|
||||
MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities();
|
||||
|
||||
boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null);
|
||||
LatLon loc = useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude());
|
||||
float head = useCenter ? -mapActivity.getMapRotate() : heading != null ? heading : 99;
|
||||
|
||||
DashLocationFragment.updateLocationView(useCenter, loc, head, arrowIv,
|
||||
R.drawable.ic_direction_arrow, 0, distanceTv, marker.point,
|
||||
DashLocationFragment.getScreenOrientation(mapActivity), mapActivity.getMyApplication(), mapActivity, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void enterMenuMode() {
|
||||
final MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.disableDrawer();
|
||||
mapActivity.getMapLayers().getMapControlsLayer().hideMapControls();
|
||||
OsmandMapTileView tileView = mapActivity.getMapView();
|
||||
previousMapPosition = tileView.getMapPosition();
|
||||
tileView.setMapPosition(portrait ? MIDDLE_TOP_CONSTANT : LANDSCAPE_MIDDLE_RIGHT_CONSTANT);
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
}
|
||||
|
||||
private void exitMenuMode() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.enableDrawer();
|
||||
mapActivity.getMapLayers().getMapControlsLayer().showMapControls();
|
||||
mapActivity.getMapView().setMapPosition(previousMapPosition);
|
||||
mapActivity.refreshMap();
|
||||
}
|
||||
}
|
||||
|
||||
private void dismiss() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getSupportFragmentManager().popBackStackImmediate(TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean showInstance(MapActivity mapActivity, @NonNull MapMarker marker) {
|
||||
try {
|
||||
MarkerMenuOnMapFragment fragment = new MarkerMenuOnMapFragment();
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.setMarker(marker);
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragmentContainer, fragment, TAG)
|
||||
.addToBackStack(TAG)
|
||||
.commitAllowingStateLoss();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue