diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index f3531437eb..140b98c2a1 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -4,37 +4,41 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="56dp" + android:background="?attr/bg_color" android:descendantFocusability="blocksDescendants"> + android:background="?attr/selectableItemBackground"> diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index febf7a53ed..2e3c5e4a75 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -463,4 +463,34 @@ public class MapMarkersHelper { ctx.getGeocodingLookupService().cancel(latLon); } } + + public static int getMapMarkerColorId(int colorIndex) { + int colorId; + switch (colorIndex) { + case 0: + colorId = R.color.marker_blue; + break; + case 1: + colorId = R.color.marker_green; + break; + case 2: + colorId = R.color.marker_orange; + break; + case 3: + colorId = R.color.marker_red; + break; + case 4: + colorId = R.color.marker_yellow; + break; + case 5: + colorId = R.color.marker_teal; + break; + case 6: + colorId = R.color.marker_purple; + break; + default: + colorId = R.color.marker_blue; + } + return colorId; + } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java index 4d8c4a35e0..f74f7c32ff 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java @@ -43,7 +43,6 @@ import net.osmand.plus.views.DirectionDrawable; import net.osmand.plus.views.controls.DynamicListView; import net.osmand.plus.views.controls.ListDividerShape; import net.osmand.plus.views.controls.StableArrayAdapter; -import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.io.File; @@ -784,37 +783,7 @@ public class MapMarkerDialogHelper { } public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) { - return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, getMapMarkerColorId(colorIndex)); - } - - public static int getMapMarkerColorId(int colorIndex) { - int colorId; - switch (colorIndex) { - case 0: - colorId = R.color.marker_blue; - break; - case 1: - colorId = R.color.marker_green; - break; - case 2: - colorId = R.color.marker_orange; - break; - case 3: - colorId = R.color.marker_red; - break; - case 4: - colorId = R.color.marker_yellow; - break; - case 5: - colorId = R.color.marker_teal; - break; - case 6: - colorId = R.color.marker_purple; - break; - default: - colorId = R.color.marker_blue; - } - return colorId; + return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, MapMarkersHelper.getMapMarkerColorId(colorIndex)); } public void updateLocation(ListView listView, boolean compassChanged) { @@ -896,7 +865,7 @@ public class MapMarkerDialogHelper { WptPt wpt = new WptPt(); wpt.lat = marker.getLatitude(); wpt.lon = marker.getLongitude(); - wpt.setColor(mapActivity.getResources().getColor(getMapMarkerColorId(marker.colorIndex))); + wpt.setColor(mapActivity.getResources().getColor(MapMarkersHelper.getMapMarkerColorId(marker.colorIndex))); wpt.name = marker.getOnlyName(); //wpt.link = r.getFileName(); //wpt.time = r.getFile().lastModified(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index 10178b2cd7..a3268f01c6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -1,20 +1,46 @@ package net.osmand.plus.mapmarkers; +import android.app.Activity; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; +import android.widget.Toast; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter; +import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter.MapMarkersActiveAdapterListener; public class MapMarkersActiveFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - TextView textView = new TextView(getContext()); - textView.setText("active fragment"); - return textView; + final RecyclerView recyclerView = new RecyclerView(getContext()); + recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); + OsmandApplication app = getMyApplication(); + if (app != null) { + MapMarkersActiveAdapter adapter = new MapMarkersActiveAdapter(app); + adapter.setAdapterListener(new MapMarkersActiveAdapterListener() { + @Override + public void onItemClick(View view) { + Toast.makeText(getContext(), recyclerView.indexOfChild(view) + "", Toast.LENGTH_SHORT).show(); + } + }); + recyclerView.setAdapter(adapter); + } + return recyclerView; + } + + private OsmandApplication getMyApplication() { + Activity activity = getActivity(); + if (activity != null) { + return (OsmandApplication) activity.getApplication(); + } + return null; } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java new file mode 100644 index 0000000000..8775a599f9 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerItemViewHolder.java @@ -0,0 +1,33 @@ +package net.osmand.plus.mapmarkers.adapters; + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.plus.R; + +public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder { + + final ImageView iconDirection; + final ImageView iconReorder; + final ImageView icon; + final TextView title; + final TextView distance; + final TextView point; + final TextView description; + final ImageButton options; + + public MapMarkerItemViewHolder(View view) { + super(view); + iconDirection = (ImageView) view.findViewById(R.id.map_marker_direction_icon); + iconReorder = (ImageView) view.findViewById(R.id.map_marker_reorder_icon); + icon = (ImageView) view.findViewById(R.id.map_marker_icon); + title = (TextView) view.findViewById(R.id.map_marker_title); + distance = (TextView) view.findViewById(R.id.map_marker_distance); + point = (TextView) view.findViewById(R.id.map_marker_point_text_view); + description = (TextView) view.findViewById(R.id.map_marker_description); + options = (ImageButton) view.findViewById(R.id.map_marker_options_button); + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java new file mode 100644 index 0000000000..4ca0f41e25 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -0,0 +1,72 @@ +package net.osmand.plus.mapmarkers.adapters; + +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; + +import net.osmand.plus.IconsCache; +import net.osmand.plus.MapMarkersHelper; +import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; + +import java.util.List; + +public class MapMarkersActiveAdapter extends RecyclerView.Adapter { + + private OsmandApplication application; + private List markers; + private MapMarkersActiveAdapterListener listener; + + public MapMarkersActiveAdapter(OsmandApplication application) { + this.application = application; + markers = application.getMapMarkersHelper().getMapMarkers(); + } + + public void setAdapterListener(MapMarkersActiveAdapterListener listener) { + this.listener = listener; + } + + @Override + public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false); + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + listener.onItemClick(view); + } + }); + return new MapMarkerItemViewHolder(view); + } + + @Override + public void onBindViewHolder(MapMarkerItemViewHolder holder, int pos) { + IconsCache iconsCache = application.getIconsCache(); + MapMarker marker = markers.get(pos); + + holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_reorder)); + holder.iconReorder.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + return false; + } + }); + + int color = MapMarkersHelper.getMapMarkerColorId(marker.colorIndex); + holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, color)); + + holder.title.setText(marker.getName(application)); + } + + @Override + public int getItemCount() { + return markers.size(); + } + + public interface MapMarkersActiveAdapterListener { + + void onItemClick(View view); + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index 78dc836f2f..da924a42dc 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -17,7 +17,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.helpers.AndroidUiHelper; -import net.osmand.plus.helpers.MapMarkerDialogHelper; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.DirectionDrawable; @@ -251,7 +250,7 @@ public class MapMarkersWidgetsFactory { } else { dd = (DirectionDrawable) arrowImg.getDrawable(); } - dd.setImage(R.drawable.ic_arrow_marker_diretion, MapMarkerDialogHelper.getMapMarkerColorId(marker.colorIndex)); + dd.setImage(R.drawable.ic_arrow_marker_diretion, MapMarkersHelper.getMapMarkerColorId(marker.colorIndex)); if (heading != null && loc != null) { dd.setAngle(mes[1] - heading + 180 + screenOrientation); } @@ -365,7 +364,7 @@ public class MapMarkersWidgetsFactory { setImageDrawable(map.getMyApplication().getIconsCache() .getIcon(isNight() ? R.drawable.widget_marker_night : R.drawable.widget_marker_day, R.drawable.widget_marker_triangle, - MapMarkerDialogHelper.getMapMarkerColorId(marker.colorIndex))); + MapMarkersHelper.getMapMarkerColorId(marker.colorIndex))); cachedMarkerColorIndex = marker.colorIndex; cachedNightMode = isNight(); res = true;