Move method from MapMarkerDialogHelper to MapMarkersHelper; add some code for new map markers

This commit is contained in:
Alex 2017-08-29 18:59:26 +03:00
parent 489e228e3f
commit 103b285f15
7 changed files with 192 additions and 60 deletions

View file

@ -4,37 +4,41 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="56dp" android:layout_height="56dp"
android:background="?attr/bg_color"
android:descendantFocusability="blocksDescendants"> android:descendantFocusability="blocksDescendants">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="?attr/bg_color"> android:background="?attr/selectableItemBackground">
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:id="@+id/marker_reorder_icon" android:id="@+id/map_marker_reorder_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:padding="16dp" android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:tint="?attr/secondary_icon_color" android:tint="?attr/secondary_icon_color"
tools:src="@drawable/ic_action_reorder"/> tools:src="@drawable/ic_action_reorder"/>
<android.support.v7.widget.AppCompatImageView <android.support.v7.widget.AppCompatImageView
android:id="@+id/marker_icon" android:id="@+id/map_marker_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_marginEnd="16dp" android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:layout_toEndOf="@id/marker_reorder_icon" android:layout_toEndOf="@id/map_marker_reorder_icon"
android:layout_toRightOf="@id/marker_reorder_icon" android:layout_toRightOf="@id/map_marker_reorder_icon"
tools:src="@drawable/ic_action_flag_dark"/> tools:src="@drawable/ic_action_flag_dark"/>
<ImageButton <ImageButton
android:id="@+id/marker_options_button" android:id="@+id/map_marker_options_button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
@ -52,14 +56,14 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:layout_centerVertical="true"
android:layout_toEndOf="@+id/marker_icon" android:layout_toEndOf="@+id/map_marker_icon"
android:layout_toLeftOf="@id/marker_options_button" android:layout_toLeftOf="@id/map_marker_options_button"
android:layout_toRightOf="@+id/marker_icon" android:layout_toRightOf="@+id/map_marker_icon"
android:layout_toStartOf="@id/marker_options_button" android:layout_toStartOf="@id/map_marker_options_button"
android:orientation="vertical"> android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView <android.support.v7.widget.AppCompatTextView
android:id="@+id/measure_point_title" android:id="@+id/map_marker_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
@ -71,13 +75,13 @@
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<ImageView <ImageView
android:id="@+id/direction_icon" android:id="@+id/map_marker_direction_icon"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
tools:src="@drawable/ic_direction_arrow"/> tools:src="@drawable/ic_direction_arrow"/>
<android.support.v7.widget.AppCompatTextView <android.support.v7.widget.AppCompatTextView
android:id="@+id/marker_distance" android:id="@+id/map_marker_distance"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="4dp" android:layout_marginLeft="4dp"
@ -88,7 +92,7 @@
tools:text="213 m"/> tools:text="213 m"/>
<android.support.v7.widget.AppCompatTextView <android.support.v7.widget.AppCompatTextView
android:id="@+id/point_icon_text_view" android:id="@+id/map_marker_point_text_view"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="•" android:text="•"
@ -96,7 +100,7 @@
android:textSize="@dimen/default_sub_text_size"/> android:textSize="@dimen/default_sub_text_size"/>
<android.support.v7.widget.AppCompatTextView <android.support.v7.widget.AppCompatTextView
android:id="@+id/marker_description" android:id="@+id/map_marker_description"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="4dp" android:layout_marginLeft="4dp"
@ -110,12 +114,11 @@
</LinearLayout> </LinearLayout>
<View <View
android:id="@+id/points_divider"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="1dp" android:layout_height="1dp"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true"
android:layout_toEndOf="@+id/marker_reorder_icon" android:layout_marginLeft="56dp"
android:layout_toRightOf="@+id/marker_reorder_icon" android:layout_marginStart="56dp"
android:background="?attr/dashboard_divider"/> android:background="?attr/dashboard_divider"/>
</RelativeLayout> </RelativeLayout>

View file

@ -463,4 +463,34 @@ public class MapMarkersHelper {
ctx.getGeocodingLookupService().cancel(latLon); 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;
}
} }

View file

@ -43,7 +43,6 @@ import net.osmand.plus.views.DirectionDrawable;
import net.osmand.plus.views.controls.DynamicListView; import net.osmand.plus.views.controls.DynamicListView;
import net.osmand.plus.views.controls.ListDividerShape; import net.osmand.plus.views.controls.ListDividerShape;
import net.osmand.plus.views.controls.StableArrayAdapter; import net.osmand.plus.views.controls.StableArrayAdapter;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import java.io.File; import java.io.File;
@ -784,37 +783,7 @@ public class MapMarkerDialogHelper {
} }
public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) { public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) {
return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, getMapMarkerColorId(colorIndex)); return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, MapMarkersHelper.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;
} }
public void updateLocation(ListView listView, boolean compassChanged) { public void updateLocation(ListView listView, boolean compassChanged) {
@ -896,7 +865,7 @@ public class MapMarkerDialogHelper {
WptPt wpt = new WptPt(); WptPt wpt = new WptPt();
wpt.lat = marker.getLatitude(); wpt.lat = marker.getLatitude();
wpt.lon = marker.getLongitude(); 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.name = marker.getOnlyName();
//wpt.link = r.getFileName(); //wpt.link = r.getFileName();
//wpt.time = r.getFile().lastModified(); //wpt.time = r.getFile().lastModified();

View file

@ -1,20 +1,46 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; 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.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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 { public class MapMarkersActiveFragment extends Fragment {
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
TextView textView = new TextView(getContext()); final RecyclerView recyclerView = new RecyclerView(getContext());
textView.setText("active fragment"); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
return textView; 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;
} }
} }

View file

@ -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);
}
}

View file

@ -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<MapMarkerItemViewHolder> {
private OsmandApplication application;
private List<MapMarker> 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);
}
}

View file

@ -17,7 +17,6 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.MapMarkerDialogHelper;
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.DirectionDrawable; import net.osmand.plus.views.DirectionDrawable;
@ -251,7 +250,7 @@ public class MapMarkersWidgetsFactory {
} else { } else {
dd = (DirectionDrawable) arrowImg.getDrawable(); 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) { if (heading != null && loc != null) {
dd.setAngle(mes[1] - heading + 180 + screenOrientation); dd.setAngle(mes[1] - heading + 180 + screenOrientation);
} }
@ -365,7 +364,7 @@ public class MapMarkersWidgetsFactory {
setImageDrawable(map.getMyApplication().getIconsCache() setImageDrawable(map.getMyApplication().getIconsCache()
.getIcon(isNight() ? R.drawable.widget_marker_night : R.drawable.widget_marker_day, .getIcon(isNight() ? R.drawable.widget_marker_night : R.drawable.widget_marker_day,
R.drawable.widget_marker_triangle, R.drawable.widget_marker_triangle,
MapMarkerDialogHelper.getMapMarkerColorId(marker.colorIndex))); MapMarkersHelper.getMapMarkerColorId(marker.colorIndex)));
cachedMarkerColorIndex = marker.colorIndex; cachedMarkerColorIndex = marker.colorIndex;
cachedNightMode = isNight(); cachedNightMode = isNight();
res = true; res = true;