Added Map markers selection for route preparation. Fixes
This commit is contained in:
parent
cf39638abd
commit
867a983f5c
7 changed files with 350 additions and 18 deletions
49
OsmAnd/res/layout/map_marker_selection_fragment.xml
Normal file
49
OsmAnd/res/layout/map_marker_selection_fragment.xml
Normal file
|
@ -0,0 +1,49 @@
|
|||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
android:background="?attr/pstsTabBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/closeButton"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"
|
||||
android:src="@drawable/ic_action_mode_back"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/titleTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:text="@string/select_map_marker"
|
||||
android:textColor="@color/color_white"
|
||||
android:textSize="@dimen/default_list_text_size_large"
|
||||
android:textStyle="bold"
|
||||
app:typeface="@string/font_roboto_regular"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include layout="@layout/card_bottom_divider"/>
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:drawSelectorOnTop="true"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -9,6 +9,8 @@
|
|||
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="select_map_marker">Select Map marker</string>
|
||||
<string name="map_markers_other">Other markers</string>
|
||||
<string name="download_files_error_not_enough_space">Not enough space!
|
||||
This would need {3} MB temporarily and {1} MB permanently.
|
||||
Currently, there are only {2} MB available.</string>
|
||||
|
|
|
@ -1137,7 +1137,7 @@ public class OsmandSettings {
|
|||
|
||||
public final OsmandPreference<Boolean> SHOULD_SHOW_FREE_VERSION_BANNER = new BooleanPreference("should_show_free_version_banner", false).makeGlobal().cache();
|
||||
|
||||
public final OsmandPreference<Boolean> USE_MAP_MARKERS = new BooleanPreference("use_map_markers", false).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> USE_MAP_MARKERS = new BooleanPreference("use_map_markers", true).makeGlobal().cache();
|
||||
public final OsmandPreference<Boolean> SHOW_MAP_MARKERS_TOOLBAR = new BooleanPreference("show_map_markers_toolbar", true).makeGlobal().cache();
|
||||
|
||||
public ITileSource getMapTileSource(boolean warnWhenSelected) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
|
@ -328,7 +329,7 @@ public class MapMarkerDialogHelper {
|
|||
if (v == null || v.findViewById(R.id.info_close) == null) {
|
||||
v = mapActivity.getLayoutInflater().inflate(R.layout.map_marker_item, null);
|
||||
}
|
||||
updateMapMarkerInfoView(v, marker);
|
||||
updateMapMarkerInfoView(mapActivity, v, loc, heading, useCenter, nightMode, screenOrientation, marker);
|
||||
final View more = v.findViewById(R.id.all_points);
|
||||
final View move = v.findViewById(R.id.info_move);
|
||||
final View remove = v.findViewById(R.id.info_close);
|
||||
|
@ -368,7 +369,9 @@ public class MapMarkerDialogHelper {
|
|||
return v;
|
||||
}
|
||||
|
||||
protected void updateMapMarkerInfoView(View localView, final MapMarker marker) {
|
||||
public static void updateMapMarkerInfoView(Context ctx, View localView, LatLon loc,
|
||||
Float heading, boolean useCenter, boolean nightMode,
|
||||
int screenOrientation, final MapMarker marker) {
|
||||
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
|
||||
TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
|
||||
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
|
||||
|
@ -389,7 +392,7 @@ public class MapMarkerDialogHelper {
|
|||
DirectionDrawable dd;
|
||||
if (!(arrow.getDrawable() instanceof DirectionDrawable)) {
|
||||
newImage = true;
|
||||
dd = new DirectionDrawable(mapActivity, arrow.getWidth(), arrow.getHeight());
|
||||
dd = new DirectionDrawable(ctx, arrow.getWidth(), arrow.getHeight());
|
||||
} else {
|
||||
dd = (DirectionDrawable) arrow.getDrawable();
|
||||
}
|
||||
|
@ -409,16 +412,18 @@ public class MapMarkerDialogHelper {
|
|||
arrow.setVisibility(View.VISIBLE);
|
||||
arrow.invalidate();
|
||||
|
||||
OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
|
||||
|
||||
if (!marker.history) {
|
||||
waypointIcon.setImageDrawable(getMapMarkerIcon(app, marker.colorIndex));
|
||||
AndroidUtils.setTextPrimaryColor(mapActivity, text, nightMode);
|
||||
textDist.setTextColor(mapActivity.getResources()
|
||||
AndroidUtils.setTextPrimaryColor(ctx, text, nightMode);
|
||||
textDist.setTextColor(ctx.getResources()
|
||||
.getColor(useCenter ? R.color.color_distance : R.color.color_myloc_distance));
|
||||
} else {
|
||||
waypointIcon.setImageDrawable(app.getIconsCache()
|
||||
.getContentIcon(R.drawable.ic_action_flag_dark, !nightMode));
|
||||
AndroidUtils.setTextSecondaryColor(mapActivity, text, nightMode);
|
||||
AndroidUtils.setTextSecondaryColor(mapActivity, textDist, nightMode);
|
||||
AndroidUtils.setTextSecondaryColor(ctx, text, nightMode);
|
||||
AndroidUtils.setTextSecondaryColor(ctx, textDist, nightMode);
|
||||
}
|
||||
|
||||
int dist = (int) mes[0];
|
||||
|
@ -654,7 +659,7 @@ public class MapMarkerDialogHelper {
|
|||
Object obj = listView.getItemAtPosition(i);
|
||||
View v = listView.getChildAt(i - listView.getFirstVisiblePosition());
|
||||
if (obj == marker) {
|
||||
updateMapMarkerInfoView(v, (MapMarker) obj);
|
||||
updateMapMarkerInfoView(mapActivity, v, loc, heading, useCenter, nightMode, screenOrientation, marker);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
|
@ -28,6 +28,8 @@ import net.osmand.plus.ApplicationMode;
|
|||
import net.osmand.plus.GeocodingLookupService;
|
||||
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
|
@ -41,7 +43,9 @@ import net.osmand.plus.activities.actions.AppModeDialog;
|
|||
import net.osmand.plus.activities.search.SearchAddressActivity;
|
||||
import net.osmand.plus.dialogs.FavoriteDialogs;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.MapMarkerDialogHelper;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
|
||||
import net.osmand.plus.routing.RouteDirectionInfo;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
|
||||
|
@ -82,6 +86,10 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
private static final long SPINNER_START_ID = 5;
|
||||
private static final long SPINNER_FINISH_ID = 6;
|
||||
private static final long SPINNER_HINT_ID = 100;
|
||||
private static final long SPINNER_MAP_MARKER_1_ID = 301;
|
||||
private static final long SPINNER_MAP_MARKER_2_ID = 302;
|
||||
private static final long SPINNER_MAP_MARKER_3_ID = 303;
|
||||
private static final long SPINNER_MAP_MARKER_MORE_ID = 350;
|
||||
|
||||
public MapRouteInfoMenu(MapActivity mapActivity, MapControlsLayer mapControlsLayer) {
|
||||
this.mapActivity = mapActivity;
|
||||
|
@ -255,6 +263,14 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
intent.putExtra(TARGET_SELECT, true);
|
||||
mapActivity.startActivityForResult(intent, MapControlsLayer.REQUEST_ADDRESS_SELECT);
|
||||
} else if (id == SPINNER_MAP_MARKER_MORE_ID) {
|
||||
selectMapMarker(parentView, -1, true);
|
||||
} else if (id == SPINNER_MAP_MARKER_1_ID) {
|
||||
selectMapMarker(parentView, 0, true);
|
||||
} else if (id == SPINNER_MAP_MARKER_2_ID) {
|
||||
selectMapMarker(parentView, 1, true);
|
||||
} else if (id == SPINNER_MAP_MARKER_3_ID) {
|
||||
selectMapMarker(parentView, 2, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -303,6 +319,14 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
intent.putExtra(TARGET_SELECT, false);
|
||||
mapActivity.startActivityForResult(intent, MapControlsLayer.REQUEST_ADDRESS_SELECT);
|
||||
} else if (id == SPINNER_MAP_MARKER_MORE_ID) {
|
||||
selectMapMarker(parentView, -1, false);
|
||||
} else if (id == SPINNER_MAP_MARKER_1_ID) {
|
||||
selectMapMarker(parentView, 0, false);
|
||||
} else if (id == SPINNER_MAP_MARKER_2_ID) {
|
||||
selectMapMarker(parentView, 1, false);
|
||||
} else if (id == SPINNER_MAP_MARKER_3_ID) {
|
||||
selectMapMarker(parentView, 2, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,7 +380,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
final FavouritesAdapter favouritesAdapter = new FavouritesAdapter(mapActivity, mapActivity.getMyApplication()
|
||||
.getFavorites().getFavouritePoints(), false);
|
||||
Dialog[] dlgHolder = new Dialog[1];
|
||||
OnItemClickListener click = getOnClickListener(target, favouritesAdapter, dlgHolder);
|
||||
OnItemClickListener click = getOnFavoriteClickListener(target, favouritesAdapter, dlgHolder);
|
||||
OnDismissListener dismissListener = new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
|
@ -372,6 +396,43 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
FavoriteDialogs.showFavoritesDialog(mapActivity, favouritesAdapter, click, dismissListener, dlgHolder, true);
|
||||
}
|
||||
|
||||
private void selectMapMarker(final View parentView, final int index, final boolean target) {
|
||||
if (index != -1) {
|
||||
MapMarker m = mapActivity.getMyApplication().getMapMarkersHelper().getActiveMapMarkers().get(index);
|
||||
LatLon point = new LatLon(m.getLatitude(), m.getLongitude());
|
||||
if (target) {
|
||||
getTargets().navigateToPoint(point, true, -1, m.getPointDescription(mapActivity));
|
||||
} else {
|
||||
getTargets().setStartPoint(point, true, m.getPointDescription(mapActivity));
|
||||
}
|
||||
updateFromIcon();
|
||||
|
||||
} else {
|
||||
OnItemClickListener click = new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
selectMapMarker(parentView, position, target);
|
||||
}
|
||||
};
|
||||
OnDismissListener dismissListener = new DialogInterface.OnDismissListener() {
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (target) {
|
||||
setupToSpinner(parentView);
|
||||
} else {
|
||||
setupFromSpinner(parentView);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
MapMarkerSelectionFragment selectionFragment = new MapMarkerSelectionFragment();
|
||||
selectionFragment.setClickListener(click);
|
||||
selectionFragment.setDismissListener(dismissListener);
|
||||
selectionFragment.show(mapActivity.getSupportFragmentManager(), MapMarkerSelectionFragment.TAG);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isLight() {
|
||||
return !nightMode;
|
||||
}
|
||||
|
@ -381,7 +442,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
return iconsCache.getIcon(iconId, 0, 0f);
|
||||
}
|
||||
|
||||
private OnItemClickListener getOnClickListener(final boolean target, final FavouritesAdapter favouritesAdapter,
|
||||
private OnItemClickListener getOnFavoriteClickListener(final boolean target, final FavouritesAdapter favouritesAdapter,
|
||||
final Dialog[] dlg) {
|
||||
return new AdapterView.OnItemClickListener() {
|
||||
|
||||
|
@ -577,7 +638,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
}
|
||||
|
||||
private Spinner setupFromSpinner(View view) {
|
||||
ArrayList<RouteSpinnerRow> fromActions = new ArrayList<>();
|
||||
List<RouteSpinnerRow> fromActions = new ArrayList<>();
|
||||
fromActions.add(new RouteSpinnerRow(SPINNER_MY_LOCATION_ID, R.drawable.ic_action_get_my_location,
|
||||
mapActivity.getString(R.string.shared_string_my_location)));
|
||||
fromActions.add(new RouteSpinnerRow(SPINNER_FAV_ID, R.drawable.ic_action_fav_dark,
|
||||
|
@ -608,6 +669,9 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
geocodingLookupService.lookupAddress(startPointRequest);
|
||||
}
|
||||
}
|
||||
|
||||
addMarkersToSpinner(fromActions);
|
||||
|
||||
final Spinner fromSpinner = ((Spinner) view.findViewById(R.id.FromSpinner));
|
||||
RouteSpinnerArrayAdapter fromAdapter = new RouteSpinnerArrayAdapter(view.getContext());
|
||||
fromAdapter.addAll(fromActions);
|
||||
|
@ -626,7 +690,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
private Spinner setupToSpinner(View view) {
|
||||
final Spinner toSpinner = ((Spinner) view.findViewById(R.id.ToSpinner));
|
||||
final TargetPointsHelper targets = getTargets();
|
||||
ArrayList<RouteSpinnerRow> toActions = new ArrayList<>();
|
||||
List<RouteSpinnerRow> toActions = new ArrayList<>();
|
||||
|
||||
TargetPoint finish = getTargets().getPointToNavigate();
|
||||
if (finish != null) {
|
||||
|
@ -661,12 +725,41 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
toActions.add(new RouteSpinnerRow(SPINNER_ADDRESS_ID, R.drawable.ic_action_home_dark,
|
||||
mapActivity.getString(R.string.shared_string_address) + mapActivity.getString(R.string.shared_string_ellipsis)));
|
||||
|
||||
addMarkersToSpinner(toActions);
|
||||
|
||||
RouteSpinnerArrayAdapter toAdapter = new RouteSpinnerArrayAdapter(view.getContext());
|
||||
toAdapter.addAll(toActions);
|
||||
toSpinner.setAdapter(toAdapter);
|
||||
return toSpinner;
|
||||
}
|
||||
|
||||
private void addMarkersToSpinner(List<RouteSpinnerRow> actions) {
|
||||
MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
|
||||
List<MapMarker> markers = markersHelper.getActiveMapMarkers();
|
||||
if (markers.size() > 0) {
|
||||
MapMarker m = markers.get(0);
|
||||
actions.add(new RouteSpinnerRow(SPINNER_MAP_MARKER_1_ID,
|
||||
MapMarkerDialogHelper.getMapMarkerIcon(mapActivity.getMyApplication(), m.colorIndex),
|
||||
m.getOnlyName()));
|
||||
}
|
||||
if (markers.size() > 1) {
|
||||
MapMarker m = markers.get(1);
|
||||
actions.add(new RouteSpinnerRow(SPINNER_MAP_MARKER_2_ID,
|
||||
MapMarkerDialogHelper.getMapMarkerIcon(mapActivity.getMyApplication(), m.colorIndex),
|
||||
m.getOnlyName()));
|
||||
}
|
||||
if (markers.size() > 2) {
|
||||
MapMarker m = markers.get(2);
|
||||
actions.add(new RouteSpinnerRow(SPINNER_MAP_MARKER_3_ID,
|
||||
MapMarkerDialogHelper.getMapMarkerIcon(mapActivity.getMyApplication(), m.colorIndex),
|
||||
m.getOnlyName()));
|
||||
}
|
||||
if (markers.size() > 3) {
|
||||
actions.add(new RouteSpinnerRow(SPINNER_MAP_MARKER_MORE_ID, 0,
|
||||
mapActivity.getString(R.string.map_markers_other)));
|
||||
}
|
||||
}
|
||||
|
||||
private TargetPointsHelper getTargets() {
|
||||
return mapActivity.getMyApplication().getTargetPointsHelper();
|
||||
}
|
||||
|
@ -737,13 +830,24 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
private class RouteSpinnerRow {
|
||||
long id;
|
||||
int iconId;
|
||||
Drawable icon;
|
||||
String text;
|
||||
|
||||
public RouteSpinnerRow(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public RouteSpinnerRow(long id, int iconId, String text) {
|
||||
this.id = id;
|
||||
this.iconId = iconId;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public RouteSpinnerRow(long id, Drawable icon, String text) {
|
||||
this.id = id;
|
||||
this.icon = icon;
|
||||
this.text = text;
|
||||
}
|
||||
}
|
||||
|
||||
private class RouteSpinnerArrayAdapter extends ArrayAdapter<RouteSpinnerRow> {
|
||||
|
@ -766,7 +870,8 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
|
||||
@Override
|
||||
public boolean isEnabled(int position) {
|
||||
return getItemId(position) != SPINNER_HINT_ID;
|
||||
long id = getItemId(position);
|
||||
return id != SPINNER_HINT_ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -781,19 +886,31 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
|
|||
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
long id = getItemId(position);
|
||||
TextView label = (TextView) super.getDropDownView(position, convertView, parent);
|
||||
|
||||
RouteSpinnerRow row = getItem(position);
|
||||
long id = getItemId(position);
|
||||
label.setText(row.text);
|
||||
if (id != SPINNER_HINT_ID) {
|
||||
Drawable icon = mapActivity.getMyApplication().getIconsCache().getContentIcon(row.iconId);
|
||||
Drawable icon = null;
|
||||
if (row.icon != null) {
|
||||
icon = row.icon;
|
||||
} else if (row.iconId > 0) {
|
||||
icon = mapActivity.getMyApplication().getIconsCache().getContentIcon(row.iconId);
|
||||
}
|
||||
label.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
||||
label.setCompoundDrawablePadding(AndroidUtils.dpToPx(mapActivity, 16f));
|
||||
} else {
|
||||
label.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
||||
label.setCompoundDrawablePadding(0);
|
||||
}
|
||||
|
||||
if (id == SPINNER_MAP_MARKER_MORE_ID) {
|
||||
label.setTextColor(!mapActivity.getMyApplication().getSettings().isLightContent() ?
|
||||
mapActivity.getResources().getColor(R.color.color_dialog_buttons_dark) : mapActivity.getResources().getColor(R.color.color_dialog_buttons_light));
|
||||
} else {
|
||||
label.setTextColor(!mapActivity.getMyApplication().getSettings().isLightContent() ?
|
||||
ContextCompat.getColorStateList(mapActivity, android.R.color.primary_text_dark) : ContextCompat.getColorStateList(mapActivity, android.R.color.primary_text_light));
|
||||
}
|
||||
label.setPadding(AndroidUtils.dpToPx(mapActivity, 16f), 0, 0, 0);
|
||||
|
||||
|
|
|
@ -0,0 +1,159 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.Shape;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
import net.osmand.plus.helpers.MapMarkerDialogHelper;
|
||||
import net.osmand.plus.views.controls.ListDividerShape;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment {
|
||||
public static final String TAG = "MapMarkerSelectionFragment";
|
||||
|
||||
private LatLon loc;
|
||||
private Float heading;
|
||||
private boolean useCenter;
|
||||
private boolean nightMode;
|
||||
private int screenOrientation;
|
||||
|
||||
private OnItemClickListener clickListener;
|
||||
private OnDismissListener dismissListener;
|
||||
|
||||
public void setClickListener(OnItemClickListener clickListener) {
|
||||
this.clickListener = clickListener;
|
||||
}
|
||||
|
||||
public void setDismissListener(OnDismissListener dismissListener) {
|
||||
this.dismissListener = dismissListener;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (mapActivity != null) {
|
||||
screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity);
|
||||
|
||||
MapViewTrackingUtilities trackingUtils = mapActivity.getMapViewTrackingUtilities();
|
||||
float head = trackingUtils.getHeading();
|
||||
float mapRotation = mapActivity.getMapRotate();
|
||||
LatLon mw = mapActivity.getMapLocation();
|
||||
Location l = trackingUtils.getMyLocation();
|
||||
boolean mapLinked = trackingUtils.isMapLinkedToLocation() && l != null;
|
||||
LatLon myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude());
|
||||
useCenter = !mapLinked;
|
||||
loc = (useCenter ? mw : myLoc);
|
||||
heading = useCenter ? -mapRotation : head;
|
||||
}
|
||||
nightMode = !app.getSettings().isLightContent();
|
||||
|
||||
View view = inflater.inflate(R.layout.map_marker_selection_fragment, container, false);
|
||||
ImageButton closeButton = (ImageButton) view.findViewById(R.id.closeButton);
|
||||
closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_mode_back));
|
||||
closeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
ListView listView = (ListView) view.findViewById(android.R.id.list);
|
||||
int color;
|
||||
if (nightMode) {
|
||||
color = mapActivity.getResources().getColor(R.color.dashboard_divider_dark);
|
||||
} else {
|
||||
color = mapActivity.getResources().getColor(R.color.dashboard_divider_light);
|
||||
}
|
||||
Shape dividerShape = new ListDividerShape(color, 0);
|
||||
final ShapeDrawable divider = new ShapeDrawable(dividerShape);
|
||||
int divHeight = AndroidUtils.dpToPx(getContext(), 1f);
|
||||
divider.setIntrinsicHeight(divHeight);
|
||||
listView.setDivider(divider);
|
||||
|
||||
final ArrayAdapter<MapMarker> adapter = new MapMarkersListAdapter();
|
||||
List<MapMarker> markers = getMyApplication().getMapMarkersHelper().getActiveMapMarkers();
|
||||
if (markers.size() > 0) {
|
||||
adapter.addAll(markers);
|
||||
}
|
||||
listView.setAdapter(adapter);
|
||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (clickListener != null) {
|
||||
clickListener.onItemClick(parent, view, position, id);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
if (dismissListener != null) {
|
||||
dismissListener.onDismiss(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
private class MapMarkersListAdapter extends ArrayAdapter<MapMarker> {
|
||||
|
||||
public MapMarkersListAdapter() {
|
||||
super(getMapActivity(), R.layout.map_marker_item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
MapMarker marker = getItem(position);
|
||||
if (convertView == null) {
|
||||
convertView = getMapActivity().getLayoutInflater().inflate(R.layout.map_marker_item, null);
|
||||
}
|
||||
MapMarkerDialogHelper.updateMapMarkerInfoView(getContext(), convertView, loc, heading,
|
||||
useCenter, nightMode, screenOrientation, marker);
|
||||
final View remove = convertView.findViewById(R.id.info_close);
|
||||
remove.setVisibility(View.GONE);
|
||||
AndroidUtils.setListItemBackground(getMapActivity(), convertView, nightMode);
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
||||
public MapActivity getMapActivity() {
|
||||
Context ctx = getContext();
|
||||
if (ctx instanceof MapActivity) {
|
||||
return (MapActivity) ctx;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getContext().getApplicationContext();
|
||||
}
|
||||
}
|
|
@ -250,7 +250,7 @@ public class MapMarkersWidgetsFactory {
|
|||
if (loc != null) {
|
||||
txt = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
|
||||
} else {
|
||||
txt = "— " + map.getString(R.string.m);
|
||||
txt = "—";
|
||||
}
|
||||
distText.setText(txt);
|
||||
updateVisibility(okButton, !customLocation && loc != null && dist < MIN_DIST_OK_VISIBLE);
|
||||
|
|
Loading…
Reference in a new issue