Search Address / History / Location - AND-332 Done
This commit is contained in:
parent
04ea247bf8
commit
363832c681
9 changed files with 233 additions and 54 deletions
|
@ -265,26 +265,7 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
|||
PointDescription pd = historyEntry.getName();
|
||||
nameText.setText(pd.getSimpleName(activity, false), BufferType.SPANNABLE);
|
||||
ImageView icon = ((ImageView) row.findViewById(R.id.icon));
|
||||
|
||||
if (historyEntry.getName().isAddress()) {
|
||||
icon.setImageDrawable(ic.getContentIcon(R.drawable.ic_type_address));
|
||||
} else if (historyEntry.getName().isFavorite()) {
|
||||
icon.setImageDrawable(ic.getContentIcon(R.drawable.ic_type_favorites));
|
||||
} else if (historyEntry.getName().isLocation()) {
|
||||
icon.setImageDrawable(ic.getContentIcon(R.drawable.ic_type_coordinates));
|
||||
} else if (historyEntry.getName().isPoi()) {
|
||||
icon.setImageDrawable(ic.getContentIcon(R.drawable.ic_type_info));
|
||||
} else if (historyEntry.getName().isWpt()) {
|
||||
icon.setImageDrawable(ic.getContentIcon(R.drawable.ic_type_waypoint));
|
||||
} else if (historyEntry.getName().isAudioNote()) {
|
||||
icon.setImageDrawable(ic.getContentIcon(R.drawable.ic_type_audio));
|
||||
} else if (historyEntry.getName().isVideoNote()) {
|
||||
icon.setImageDrawable(ic.getContentIcon(R.drawable.ic_type_video));
|
||||
}else if (historyEntry.getName().isPhotoNote()) {
|
||||
icon.setImageDrawable(ic.getContentIcon(R.drawable.ic_type_img));
|
||||
} else {
|
||||
icon.setImageDrawable(ic.getContentIcon(R.drawable.ic_type_address));
|
||||
}
|
||||
icon.setImageDrawable(ic.getContentIcon(getItemIcon(historyEntry.getName())));
|
||||
|
||||
String typeName = historyEntry.getName().getTypeName();
|
||||
if (typeName != null && !typeName.isEmpty()) {
|
||||
|
@ -298,6 +279,30 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA
|
|||
}
|
||||
}
|
||||
|
||||
public static int getItemIcon(PointDescription pd) {
|
||||
int iconId;
|
||||
if (pd.isAddress()) {
|
||||
iconId = R.drawable.ic_type_address;
|
||||
} else if (pd.isFavorite()) {
|
||||
iconId = R.drawable.ic_type_favorites;
|
||||
} else if (pd.isLocation()) {
|
||||
iconId = R.drawable.ic_type_coordinates;
|
||||
} else if (pd.isPoi()) {
|
||||
iconId = R.drawable.ic_type_info;
|
||||
} else if (pd.isWpt()) {
|
||||
iconId = R.drawable.ic_type_waypoint;
|
||||
} else if (pd.isAudioNote()) {
|
||||
iconId = R.drawable.ic_type_audio;
|
||||
} else if (pd.isVideoNote()) {
|
||||
iconId = R.drawable.ic_type_video;
|
||||
}else if (pd.isPhotoNote()) {
|
||||
iconId = R.drawable.ic_type_img;
|
||||
} else {
|
||||
iconId = R.drawable.ic_type_address;
|
||||
}
|
||||
return iconId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu onCreate, MenuInflater inflater) {
|
||||
if (getActivity() instanceof SearchActivity) {
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
package net.osmand.plus.helpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -16,6 +8,14 @@ import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
|||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SearchHistoryHelper {
|
||||
|
||||
private static final int HISTORY_LIMIT = 1500;
|
||||
|
@ -51,7 +51,7 @@ public class SearchHistoryHelper {
|
|||
}
|
||||
};
|
||||
|
||||
public static class HistoryEntry {
|
||||
public static class HistoryEntry implements Serializable {
|
||||
double lat;
|
||||
double lon;
|
||||
PointDescription name;
|
||||
|
|
|
@ -17,8 +17,10 @@ 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.SearchHistoryHelper.HistoryEntry;
|
||||
import net.osmand.plus.mapcontextmenu.details.AmenityMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.details.HistoryMenuController;
|
||||
import net.osmand.plus.mapcontextmenu.details.MenuController;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.ContextMenuLayer;
|
||||
|
@ -200,6 +202,8 @@ public class MapContextMenu {
|
|||
menuController = new AmenityMenuController(app, mapActivity, (Amenity) object);
|
||||
} else if (object instanceof FavouritePoint) {
|
||||
menuController = new FavouritePointMenuController(app, mapActivity, (FavouritePoint) object);
|
||||
} else if (object instanceof HistoryEntry) {
|
||||
menuController = new HistoryMenuController(app, mapActivity, (HistoryEntry) object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
LinearLayout ll = new LinearLayout(view.getContext());
|
||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
//llParams.setMargins(0, dpToPx(14f), 0, dpToPx(14f));
|
||||
ll.setLayoutParams(llParams);
|
||||
|
||||
// Icon
|
||||
|
@ -118,15 +117,6 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
rowBuilt();
|
||||
}
|
||||
|
||||
public int dpToPx(float dp) {
|
||||
Resources r = app.getResources();
|
||||
return (int) TypedValue.applyDimension(
|
||||
COMPLEX_UNIT_DIP,
|
||||
dp,
|
||||
r.getDisplayMetrics()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(View view) {
|
||||
super.build(view);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package net.osmand.plus.mapcontextmenu.details;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.PointDescription;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package net.osmand.plus.mapcontextmenu.details;
|
||||
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.TypedValue;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -16,8 +14,6 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||
|
||||
public class FavouritePointMenuBuilder extends MenuBuilder {
|
||||
|
||||
private final FavouritePoint fav;
|
||||
|
@ -37,7 +33,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
|||
LinearLayout ll = new LinearLayout(view.getContext());
|
||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
//llParams.setMargins(0, dpToPx(14f), 0, dpToPx(14f));
|
||||
ll.setLayoutParams(llParams);
|
||||
|
||||
// Icon
|
||||
|
@ -95,15 +90,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
|||
rowBuilt();
|
||||
}
|
||||
|
||||
public int dpToPx(float dp) {
|
||||
Resources r = app.getResources();
|
||||
return (int) TypedValue.applyDimension(
|
||||
COMPLEX_UNIT_DIP,
|
||||
dp,
|
||||
r.getDisplayMetrics()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(View view) {
|
||||
super.build(view);
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
package net.osmand.plus.mapcontextmenu.details;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.util.Linkify;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
||||
|
||||
public class HistoryMenuBuilder extends MenuBuilder {
|
||||
private final HistoryEntry entry;
|
||||
|
||||
public HistoryMenuBuilder(OsmandApplication app, final HistoryEntry entry) {
|
||||
super(app);
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
private void buildRow(View view, int iconId, String text, int textColor) {
|
||||
buildRow(view, getRowIcon(iconId), text, textColor);
|
||||
}
|
||||
|
||||
private void buildRow(final View view, Drawable icon, String text, int textColor) {
|
||||
boolean light = app.getSettings().isLightContent();
|
||||
|
||||
LinearLayout ll = new LinearLayout(view.getContext());
|
||||
ll.setOrientation(LinearLayout.HORIZONTAL);
|
||||
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
ll.setLayoutParams(llParams);
|
||||
|
||||
// Icon
|
||||
LinearLayout llIcon = new LinearLayout(view.getContext());
|
||||
llIcon.setOrientation(LinearLayout.HORIZONTAL);
|
||||
llIcon.setLayoutParams(new LinearLayout.LayoutParams(dpToPx(72f), isFirstRow() ? dpToPx(48f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(48f)));
|
||||
llIcon.setGravity(Gravity.CENTER_VERTICAL);
|
||||
ll.addView(llIcon);
|
||||
|
||||
ImageView iconView = new ImageView(view.getContext());
|
||||
LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
llIconParams.setMargins(dpToPx(16f), isFirstRow() ? dpToPx(12f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP / 2f) : dpToPx(12f), dpToPx(32f), dpToPx(12f));
|
||||
llIconParams.gravity = Gravity.CENTER_VERTICAL;
|
||||
iconView.setLayoutParams(llIconParams);
|
||||
iconView.setScaleType(ImageView.ScaleType.CENTER);
|
||||
iconView.setImageDrawable(icon);
|
||||
llIcon.addView(iconView);
|
||||
|
||||
// Text
|
||||
LinearLayout llText = new LinearLayout(view.getContext());
|
||||
llText.setOrientation(LinearLayout.VERTICAL);
|
||||
ll.addView(llText);
|
||||
|
||||
TextView textView = new TextView(view.getContext());
|
||||
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
llTextParams.setMargins(0, isFirstRow() ? dpToPx(8f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(8f), 0, dpToPx(8f));
|
||||
textView.setLayoutParams(llTextParams);
|
||||
textView.setTextSize(16);
|
||||
textView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_info_text_light : R.color.ctx_menu_info_text_dark));
|
||||
|
||||
textView.setAutoLinkMask(Linkify.ALL);
|
||||
textView.setLinksClickable(true);
|
||||
textView.setText(text);
|
||||
if (textColor > 0) {
|
||||
textView.setTextColor(view.getResources().getColor(textColor));
|
||||
}
|
||||
|
||||
LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
llTextViewParams.setMargins(0, 0, dpToPx(10f), 0);
|
||||
llTextViewParams.gravity = Gravity.CENTER_VERTICAL;
|
||||
llText.setLayoutParams(llTextViewParams);
|
||||
llText.addView(textView);
|
||||
|
||||
((LinearLayout) view).addView(ll);
|
||||
|
||||
View horizontalLine = new View(view.getContext());
|
||||
LinearLayout.LayoutParams llHorLineParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(1f));
|
||||
llHorLineParams.gravity = Gravity.BOTTOM;
|
||||
horizontalLine.setLayoutParams(llHorLineParams);
|
||||
|
||||
horizontalLine.setBackgroundColor(app.getResources().getColor(light ? R.color.ctx_menu_info_divider_light : R.color.ctx_menu_info_divider_dark));
|
||||
|
||||
((LinearLayout) view).addView(horizontalLine);
|
||||
|
||||
rowBuilt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void build(View view) {
|
||||
super.build(view);
|
||||
|
||||
for (PlainMenuItem item : plainMenuItems) {
|
||||
buildRow(view, item.getIconId(), item.getText(), 0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package net.osmand.plus.mapcontextmenu.details;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.search.SearchHistoryFragment;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
||||
|
||||
public class HistoryMenuController extends MenuController {
|
||||
|
||||
private HistoryEntry entry;
|
||||
|
||||
public HistoryMenuController(OsmandApplication app, MapActivity mapActivity, final HistoryEntry entry) {
|
||||
super(new HistoryMenuBuilder(app, entry), mapActivity);
|
||||
this.entry = entry;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getInitialMenuStatePortrait() {
|
||||
return MenuState.HEADER_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSupportedMenuStatesPortrait() {
|
||||
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needTypeStr() {
|
||||
String typeName = entry.getName().getTypeName();
|
||||
return (typeName != null && !typeName.isEmpty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getLeftIcon() {
|
||||
return getIcon(SearchHistoryFragment.getItemIcon(entry.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getSecondLineIcon() {
|
||||
if (needTypeStr()) {
|
||||
return getIcon(R.drawable.ic_small_group);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNameStr() {
|
||||
return entry.getName().getSimpleName(getMapActivity(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeStr() {
|
||||
if (needTypeStr()) {
|
||||
return entry.getName().getTypeName();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needStreetName() {
|
||||
return !entry.getName().isAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPlainMenuItems(String typeStr, PointDescription pointDescription) {
|
||||
if (pointDescription != null) {
|
||||
addPlainMenuItem(R.drawable.map_my_location, PointDescription.getLocationName(getMapActivity(),
|
||||
entry.getLat(), entry.getLon(), true).replaceAll("\n", ""));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveEntityState(Bundle bundle, String key) {
|
||||
bundle.putSerializable(key, entry);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
package net.osmand.plus.mapcontextmenu.details;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.plus.IconsCache;
|
||||
|
@ -13,6 +15,8 @@ import net.osmand.plus.render.RenderingIcons;
|
|||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
|
||||
|
||||
public abstract class MenuBuilder {
|
||||
|
||||
public class PlainMenuItem {
|
||||
|
@ -76,4 +80,13 @@ public abstract class MenuBuilder {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public int dpToPx(float dp) {
|
||||
Resources r = app.getResources();
|
||||
return (int) TypedValue.applyDimension(
|
||||
COMPLEX_UNIT_DIP,
|
||||
dp,
|
||||
r.getDisplayMetrics()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue