Merge branch 'master' of ssh://github.com/osmandapp/Osmand into waypoint_categories_import

This commit is contained in:
Alexander Sytnyk 2018-03-17 15:12:06 +02:00
commit c582434499
8 changed files with 732 additions and 54 deletions

View file

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_selected_item_title_height"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingLeft="@dimen/content_padding">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="Some Title" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/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_sub_text_size"
tools:text="Some description" />
</LinearLayout>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/text_button"
android:layout_width="wrap_content"
android:layout_height="@dimen/bottom_sheet_selected_item_title_height"
android:background="?attr/selectableItemBackground"
android:drawablePadding="@dimen/content_padding"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:drawableRight="@drawable/ic_action_sort_by_name"
tools:text="Some button" />
</LinearLayout>

View file

@ -0,0 +1,97 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/change_color_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/list_item_height"
android:orientation="horizontal"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding">
<ImageView
android:id="@+id/favourite_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/route_info_icon_padding_right"
android:layout_marginRight="@dimen/route_info_icon_padding_right"
android:src="@drawable/map_favorite" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/map_marker_title_height">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/favourite_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:ellipsize="end"
android:maxLines="1"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="@+id/favourite_direction_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/text_margin_small"
android:layout_marginRight="@dimen/text_margin_small"
tools:src="@drawable/ic_direction_arrow" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/favourite_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" />
<View
android:id="@+id/favourite_left_point_space"
android:layout_width="@dimen/text_margin_small"
android:layout_height="match_parent" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/favourite_point_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="•"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
tools:visibility="visible" />
<View
android:id="@+id/favourite_right_point_space"
android:layout_width="@dimen/text_margin_small"
android:layout_height="match_parent" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/favourite_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>
</LinearLayout>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:clipToPadding="false"
android:orientation="vertical"
android:scrollbars="vertical" />

View file

@ -0,0 +1,122 @@
package net.osmand.plus.base.bottomsheetmenu;
import android.graphics.drawable.Drawable;
import android.support.annotation.ColorRes;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
public class BottomSheetItemTitleWithDescrAndButton extends BottomSheetItemWithDescription {
private View.OnClickListener onButtonClickListener;
private Drawable leftCompoundDrawable;
private Drawable rightCompoundDrawable;
private String buttonTitle;
@ColorRes
private int buttonTextColor = INVALID_ID;
private TextView textButtonTV;
public BottomSheetItemTitleWithDescrAndButton(View customView,
@LayoutRes int layoutId,
Object tag,
boolean disabled,
View.OnClickListener onClickListener,
int position,
Drawable icon,
String title,
@ColorRes int titleColorId,
CharSequence description,
@ColorRes int descriptionColorId,
String buttonTitle,
View.OnClickListener onButtonClickListener,
Drawable leftCompoundDrawable,
Drawable rightCompoundDrawable,
@ColorRes int buttonTextColor) {
super(customView, layoutId, tag, disabled, onClickListener, position, icon, title, titleColorId, description, descriptionColorId);
this.buttonTitle = buttonTitle;
this.onButtonClickListener = onButtonClickListener;
this.leftCompoundDrawable = leftCompoundDrawable;
this.rightCompoundDrawable = rightCompoundDrawable;
this.buttonTextColor = buttonTextColor;
}
public void setButtonIcons(@Nullable Drawable leftCompoundDrawable, @Nullable Drawable rightCompoundDrawable) {
this.leftCompoundDrawable = leftCompoundDrawable;
this.rightCompoundDrawable = rightCompoundDrawable;
textButtonTV.setCompoundDrawablesWithIntrinsicBounds(leftCompoundDrawable, null, rightCompoundDrawable, null);
}
public void setButtonText(String buttonTitle) {
this.buttonTitle = buttonTitle;
textButtonTV.setText(buttonTitle);
}
@Override
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
super.inflate(app, container, nightMode);
textButtonTV = (TextView) view.findViewById(R.id.text_button);
textButtonTV.setOnClickListener(onButtonClickListener);
textButtonTV.setCompoundDrawablesWithIntrinsicBounds(leftCompoundDrawable, null, rightCompoundDrawable, null);
textButtonTV.setText(buttonTitle);
if (buttonTextColor != INVALID_ID) {
textButtonTV.setTextColor(ContextCompat.getColor(app, buttonTextColor));
}
}
public static class Builder extends BottomSheetItemWithDescription.Builder {
protected String buttonTitle;
protected View.OnClickListener onButtonClickListener;
protected Drawable leftCompoundDrawable;
protected Drawable rightCompoundDrawable;
@ColorRes
protected int buttonTextColor = INVALID_ID;
public BottomSheetItemTitleWithDescrAndButton.Builder setButtonIcons(Drawable leftCompoundDrawable, Drawable rightCompoundDrawable) {
this.leftCompoundDrawable = leftCompoundDrawable;
this.rightCompoundDrawable = rightCompoundDrawable;
return this;
}
public BottomSheetItemTitleWithDescrAndButton.Builder setonButtonClickListener(View.OnClickListener onButtonClickListener) {
this.onButtonClickListener = onButtonClickListener;
return this;
}
public BottomSheetItemTitleWithDescrAndButton.Builder setButtonTitle(String buttonTitle) {
this.buttonTitle = buttonTitle;
return this;
}
public BottomSheetItemTitleWithDescrAndButton.Builder setButtonTextColor(@ColorRes int buttonTextColor) {
this.buttonTextColor = buttonTextColor;
return this;
}
public BottomSheetItemTitleWithDescrAndButton create() {
return new BottomSheetItemTitleWithDescrAndButton(customView,
layoutId,
tag,
disabled,
onClickListener,
position,
icon,
title,
titleColorId,
description,
descriptionColorId,
buttonTitle,
onButtonClickListener,
leftCompoundDrawable,
rightCompoundDrawable,
buttonTextColor);
}
}
}

View file

@ -17,6 +17,8 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
@ColorRes
private int descriptionColorId = INVALID_ID;
private TextView descriptionTv;
public BottomSheetItemWithDescription(View customView,
@LayoutRes int layoutId,
Object tag,
@ -37,11 +39,16 @@ public class BottomSheetItemWithDescription extends SimpleBottomSheetItem {
}
public void setDescription(CharSequence description) {
this.description = description;
descriptionTv.setText(description);
}
@Override
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
super.inflate(app, container, nightMode);
if (description != null) {
TextView descriptionTv = (TextView) view.findViewById(R.id.description);
descriptionTv = (TextView) view.findViewById(R.id.description);
if (descriptionTv != null) {
descriptionTv.setText(description);
if (descriptionColorId != INVALID_ID) {
descriptionTv.setTextColor(ContextCompat.getColor(app, descriptionColorId));

View file

@ -0,0 +1,122 @@
package net.osmand.plus.mapcontextmenu.other;
import android.app.Activity;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.Location;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.util.MapUtils;
import java.util.List;
public class FavouritesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private final Context context;
private final List<FavouritePoint> favouritePoints;
private View.OnClickListener listener;
private LatLon location;
private Float heading;
private boolean useCenter;
private int screenOrientation;
public FavouritesAdapter(Context context, List<FavouritePoint> FavouritePoints) {
this.favouritePoints = FavouritePoints;
this.context = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.favourite_list_item, viewGroup, false);
view.setOnClickListener(listener);
return new FavouritesViewHolder(view);
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof FavouritesViewHolder) {
OsmandApplication app = (OsmandApplication) ((Activity) context).getApplication();
IconsCache iconsCache = app.getIconsCache();
FavouritesViewHolder favouritesViewHolder = (FavouritesViewHolder) holder;
FavouritePoint favouritePoint = getItem(position);
favouritesViewHolder.title.setText(favouritePoint.getName());
if (favouritePoint.getCategory().equals("")) {
favouritesViewHolder.description.setText(R.string.shared_string_favorites);
} else {
favouritesViewHolder.description.setText(favouritePoint.getCategory());
}
Location myloc = app.getLocationProvider().getLastKnownLocation();
favouritesViewHolder.favouriteImage.setImageDrawable(FavoriteImageDrawable.getOrCreate(context, favouritePoint.getColor(), false));
if (myloc == null) {
return;
}
float dist = (float) MapUtils.getDistance(favouritePoint.getLatitude(), favouritePoint.getLongitude(), myloc.getLatitude(), myloc.getLongitude());
favouritesViewHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
favouritesViewHolder.arrowImage.setImageDrawable(iconsCache.getIcon(R.drawable.ic_direction_arrow));
DashLocationFragment.updateLocationView(useCenter, location, heading, favouritesViewHolder.arrowImage,
favouritesViewHolder.distance, favouritePoint.getLatitude(), favouritePoint.getLongitude(),
screenOrientation, app, context);
}
}
@Override
public int getItemCount() {
return favouritePoints.size();
}
private FavouritePoint getItem(int position) {
return favouritePoints.get(position);
}
public void setItemClickListener(View.OnClickListener listener) {
this.listener = listener;
}
public void setScreenOrientation(int screenOrientation) {
this.screenOrientation = screenOrientation;
}
public void setLocation(LatLon location) {
this.location = location;
}
public void setHeading(Float heading) {
this.heading = heading;
}
public void setUseCenter(boolean useCenter) {
this.useCenter = useCenter;
}
class FavouritesViewHolder extends RecyclerView.ViewHolder {
final TextView title;
final TextView description;
final TextView distance;
final ImageView arrowImage;
final ImageView favouriteImage;
public FavouritesViewHolder(View itemView) {
super(itemView);
favouriteImage = (ImageView) itemView.findViewById(R.id.favourite_icon);
title = (TextView) itemView.findViewById(R.id.favourite_title);
description = (TextView) itemView.findViewById(R.id.favourite_description);
distance = (TextView) itemView.findViewById(R.id.favourite_distance);
arrowImage = (ImageView) itemView.findViewById(R.id.favourite_direction_icon);
}
}
}

View file

@ -0,0 +1,292 @@
package net.osmand.plus.mapcontextmenu.other;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ContextThemeWrapper;
import android.view.View;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemTitleWithDescrAndButton;
import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.util.MapUtils;
import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFragment
implements OsmAndLocationProvider.OsmAndCompassListener, OsmAndLocationProvider.OsmAndLocationListener {
public static final String TARGET = "target";
public static final String INTERMEDIATE = "intermediate";
public static final String TAG = "FavouritesBottomSheetMenuFragment";
private static final String IS_SORTED = "sorted";
private static final String SORTED_BY_TYPE = "sortedByType";
private Location location;
private LatLon latLon;
private Float heading;
private List<FavouritePoint> favouritePoints;
private FavouritesAdapter adapter;
private RecyclerView recyclerView;
private boolean sortByDist = true;
private boolean isSorted = false;
private boolean locationUpdateStarted;
private boolean compassUpdateAllowed = true;
private boolean target;
private boolean intermediate;
@Override
public void createMenuItems(final Bundle savedInstanceState) {
Bundle args = getArguments();
if (args != null) {
target = args.getBoolean(TARGET);
intermediate = args.getBoolean(INTERMEDIATE);
}
if (savedInstanceState != null && savedInstanceState.getBoolean(IS_SORTED)) {
sortByDist = savedInstanceState.getBoolean(SORTED_BY_TYPE);
}
favouritePoints = getMyApplication().getFavorites().getVisibleFavouritePoints();
recyclerView = new RecyclerView(getContext());
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
recyclerView = (RecyclerView) View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.recyclerview, null);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
location = getMyApplication().getLocationProvider().getLastKnownLocation();
if (location != null) {
latLon = new LatLon(location.getLatitude(), location.getLongitude());
}
adapter = new FavouritesAdapter(getContext(), favouritePoints);
sortFavourites();
final BottomSheetItemTitleWithDescrAndButton[] title = new BottomSheetItemTitleWithDescrAndButton[1];
title[0] = (BottomSheetItemTitleWithDescrAndButton) new BottomSheetItemTitleWithDescrAndButton.Builder()
.setButtonIcons(null, getIconForButton())
.setButtonTitle(getTextForButton(sortByDist))
.setonButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sortFavourites();
title[0].setButtonIcons(null, getIconForButton());
title[0].setButtonText(getTextForButton(sortByDist));
title[0].setDescription(getTextForButton(!sortByDist));
}
})
.setDescription(getTextForButton(!sortByDist))
.setTitle(getString(R.string.favourites))
.setLayoutId(R.layout.bottom_sheet_item_title_with_descr_and_button)
.create();
items.add(title[0]);
adapter.setItemClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = recyclerView.getChildAdapterPosition(v);
if (position == RecyclerView.NO_POSITION) {
return;
}
selectFavorite(favouritePoints.get(position));
}
});
recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
}
});
items.add(new BaseBottomSheetItem.Builder()
.setCustomView(recyclerView)
.create());
}
private Drawable getIconForButton() {
return getIcon(sortByDist ? R.drawable.ic_action_list_sort : R.drawable.ic_action_sort_by_name,
nightMode ? R.color.multi_selection_menu_close_btn_dark : R.color.multi_selection_menu_close_btn_light);
}
private String getTextForButton(boolean sortByDist) {
return getString(sortByDist ? R.string.sort_by_distance : R.string.sort_by_name);
}
private void selectFavorite(FavouritePoint point) {
TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
LatLon ll = new LatLon(point.getLatitude(), point.getLongitude());
if (intermediate) {
targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), point.getPointDescription());
} else if (target) {
targetPointsHelper.navigateToPoint(ll, true, -1, point.getPointDescription());
} else {
targetPointsHelper.setStartPoint(ll, true, point.getPointDescription());
}
MapRouteInfoMenu routeMenu = getMapRouteInfoMenu();
if (routeMenu != null) {
setupMapRouteInfoMenuSpinners(routeMenu);
updateMapRouteInfoMenuFromIcon(routeMenu);
}
dismiss();
}
private void setupMapRouteInfoMenuSpinners(MapRouteInfoMenu routeMenu) {
if (routeMenu != null) {
routeMenu.setupSpinners(target, intermediate);
}
}
private void updateMapRouteInfoMenuFromIcon(MapRouteInfoMenu routeMenu) {
if (!intermediate) {
routeMenu.updateFromIcon();
}
}
private MapRouteInfoMenu getMapRouteInfoMenu() {
Activity activity = getActivity();
if (activity instanceof MapActivity) {
MapActivity map = ((MapActivity) activity);
return map.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu();
} else {
return null;
}
}
@Override
public void onResume() {
super.onResume();
adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity()));
startLocationUpdate();
}
@Override
public void onPause() {
super.onPause();
stopLocationUpdate();
setupMapRouteInfoMenuSpinners(getMapRouteInfoMenu());
}
@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 void updateLocationUi() {
if (!compassUpdateAllowed) {
return;
}
final MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null && adapter != null) {
mapActivity.getMyApplication().runInUIThread(new Runnable() {
@Override
public void run() {
if (location == null) {
location = getMyApplication().getLocationProvider().getLastKnownLocation();
}
if (location == null) {
return;
}
adapter.setUseCenter(false);
adapter.setLocation(new LatLon(location.getLatitude(), location.getLongitude()));
adapter.setHeading(heading != null ? heading : 99);
adapter.notifyDataSetChanged();
}
});
}
}
private void startLocationUpdate() {
OsmandApplication app = getMyApplication();
if (app != null && !locationUpdateStarted) {
locationUpdateStarted = true;
app.getLocationProvider().removeCompassListener(app.getLocationProvider().getNavigationInfo());
app.getLocationProvider().addCompassListener(this);
app.getLocationProvider().addLocationListener(this);
updateLocationUi();
}
}
private void stopLocationUpdate() {
OsmandApplication app = getMyApplication();
if (app != null && locationUpdateStarted) {
locationUpdateStarted = false;
app.getLocationProvider().removeLocationListener(this);
app.getLocationProvider().removeCompassListener(this);
app.getLocationProvider().addCompassListener(app.getLocationProvider().getNavigationInfo());
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(IS_SORTED, isSorted);
outState.putBoolean(SORTED_BY_TYPE, !sortByDist);
}
@Override
protected boolean useScrollableItemsContainer() {
return false;
}
private void sortFavourites() {
if (location != null) {
latLon = new LatLon(location.getLatitude(), location.getLongitude());
} else if (sortByDist) {
return;
}
final Collator inst = Collator.getInstance();
Collections.sort(favouritePoints, new Comparator<FavouritePoint>() {
@Override
public int compare(FavouritePoint lhs, FavouritePoint rhs) {
if (sortByDist) {
double ld = MapUtils.getDistance(latLon, lhs.getLatitude(),
lhs.getLongitude());
double rd = MapUtils.getDistance(latLon, rhs.getLatitude(),
rhs.getLongitude());
return Double.compare(ld, rd);
}
return inst.compare(lhs.getName(), rhs.getName());
}
});
sortByDist = !sortByDist;
isSorted = true;
adapter.notifyDataSetChanged();
recyclerView.getLayoutManager().scrollToPosition(0);
}
@Override
protected int getCustomHeight() {
return AndroidUtils.dpToPx(getContext(), 300);
}
}

View file

@ -1,20 +1,19 @@
package net.osmand.plus.mapcontextmenu.other;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
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.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
@ -23,7 +22,6 @@ import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.Location;
import net.osmand.ValueHolder;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox;
@ -39,11 +37,9 @@ import net.osmand.plus.OsmandSettings.OsmandPreference;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.FavoritesListFragment.FavouritesAdapter;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.ShowRouteInfoDialogFragment;
import net.osmand.plus.activities.actions.AppModeDialog;
import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.MapMarkerDialogHelper;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
@ -85,6 +81,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
private OnDismissListener onDismissListener;
private OnMarkerSelectListener onMarkerSelectListener;
private View mainView;
private static final long SPINNER_MY_LOCATION_ID = 1;
public static final long SPINNER_FAV_ID = 2;
@ -201,6 +198,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
}
public void updateInfo(final View main) {
mainView = main;
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
updateViaView(main);
updateFromSpinner(main);
@ -246,7 +244,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
ViewGroup vg = (ViewGroup) parentView.findViewById(R.id.app_modes);
vg.removeAllViews();
AppModeDialog.prepareAppModeView(mapActivity, selected, false,
vg, true, false,true, new View.OnClickListener() {
vg, true,false,true, new View.OnClickListener() {
@Override
public void onClick(View v) {
if (selected.size() > 0) {
@ -475,25 +473,23 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
}
public void selectFavorite(@Nullable final View parentView, final boolean target, final boolean intermediate) {
final FavouritesAdapter favouritesAdapter = new FavouritesAdapter(mapActivity, mapActivity.getMyApplication()
.getFavorites().getVisibleFavouritePoints(), false);
Dialog[] dlgHolder = new Dialog[1];
OnItemClickListener click = getOnFavoriteClickListener(target, intermediate, favouritesAdapter, dlgHolder);
OnDismissListener dismissListener = null;
if (!intermediate && parentView != null) {
dismissListener = new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (target) {
setupToSpinner(parentView);
} else {
setupFromSpinner(parentView);
}
}
};
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
FavouritesBottomSheetMenuFragment fragment = new FavouritesBottomSheetMenuFragment();
Bundle args = new Bundle();
args.putBoolean(FavouritesBottomSheetMenuFragment.TARGET, target);
args.putBoolean(FavouritesBottomSheetMenuFragment.INTERMEDIATE, intermediate);
fragment.setArguments(args);
fragment.show(fragmentManager, FavouritesBottomSheetMenuFragment.TAG);
}
public void setupSpinners(final boolean target, final boolean intermediate) {
if (!intermediate && mainView != null) {
if (target) {
setupToSpinner(mainView);
} else {
setupFromSpinner(mainView);
}
}
favouritesAdapter.updateLocation(mapActivity.getMapLocation());
FavoriteDialogs.showFavoritesDialog(mapActivity, favouritesAdapter, click, dismissListener, dlgHolder, true);
}
public void selectMapMarker(final int index, final boolean target, final boolean intermediate) {
@ -525,33 +521,6 @@ public class MapRouteInfoMenu implements IRouteInformationListener {
return iconsCache.getIcon(iconId, 0);
}
private OnItemClickListener getOnFavoriteClickListener(final boolean target,
final boolean intermediate,
final FavouritesAdapter favouritesAdapter,
final Dialog[] dlg) {
return new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
FavouritePoint fp = favouritesAdapter.getItem(position);
LatLon point = new LatLon(fp.getLatitude(), fp.getLongitude());
if (intermediate) {
getTargets().navigateToPoint(point, true, getTargets().getIntermediatePoints().size(), fp.getPointDescription());
} else if (target) {
getTargets().navigateToPoint(point, true, -1, fp.getPointDescription());
} else {
getTargets().setStartPoint(point, true, fp.getPointDescription());
}
if (dlg != null && dlg.length > 0 && dlg[0] != null) {
dlg[0].dismiss();
}
if (!intermediate) {
updateFromIcon();
}
}
};
}
public static int getDirectionInfo() {
return directionInfo;
}