Display markers in list
This commit is contained in:
parent
afe0ffa037
commit
3c66c6e2e8
5 changed files with 256 additions and 5 deletions
|
@ -140,6 +140,10 @@
|
|||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:paddingTop="16dp"
|
||||
android:paddingBottom="72dp"
|
||||
android:id="@+id/markers_recycler_view"
|
||||
android:clipToPadding="false"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
|
@ -190,11 +194,11 @@
|
|||
android:background="?attr/dashboard_divider"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatTextView
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:paddingTop="6dp"
|
||||
android:paddingBottom="6dp"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="end"
|
||||
android:id="@+id/add_marker"
|
||||
android:id="@+id/add_marker_button"
|
||||
android:textAllCaps="true"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
|
|
|
@ -28,6 +28,17 @@
|
|||
android:layout_height="@dimen/map_button_shadow_width"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
|
||||
<android.support.v7.widget.AppCompatTextView
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="3"
|
||||
android:gravity="center"
|
||||
android:id="@+id/map_marker_number_text_view"
|
||||
android:layout_width="@dimen/map_button_shadow_width"
|
||||
android:layout_height="@dimen/map_button_shadow_width"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<android.support.v7.widget.AppCompatImageView
|
||||
android:id="@+id/map_marker_reorder_icon"
|
||||
android:layout_width="@dimen/map_button_shadow_width"
|
||||
|
|
|
@ -9,7 +9,9 @@ import android.support.annotation.Nullable;
|
|||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.TextViewCompat;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
|
@ -30,14 +32,21 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.OsmandTextFieldBoxes;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.widgets.IconPopupMenu;
|
||||
import net.osmand.plus.base.MapViewTrackingUtilities;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -47,7 +56,7 @@ import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
|
|||
import static android.content.ClipDescription.MIMETYPE_TEXT_PLAIN;
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
|
||||
public class CoordinateInputDialogFragment extends DialogFragment {
|
||||
public class CoordinateInputDialogFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener {
|
||||
|
||||
public static final String TAG = "CoordinateInputDialogFragment";
|
||||
|
||||
|
@ -66,6 +75,7 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
private static final String LONGITUDE_LABEL = "longitude";
|
||||
private static final String NAME_LABEL = "name";
|
||||
|
||||
private CoordinateInputAdapter adapter;
|
||||
private boolean lightTheme;
|
||||
private boolean useOsmandKeyboard = true;
|
||||
private int coordinateFormat = -1;
|
||||
|
@ -73,6 +83,10 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
private List<ExtendedEditText> extendedEditTexts;
|
||||
private View mainView;
|
||||
private IconsCache iconsCache;
|
||||
private Location location;
|
||||
private Float heading;
|
||||
private boolean locationUpdateStarted;
|
||||
private boolean compassUpdateAllowed = true;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -162,6 +176,30 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
|
||||
changeKeyboardInBoxes();
|
||||
|
||||
RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
adapter = new CoordinateInputAdapter(mapActivity);
|
||||
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;
|
||||
}
|
||||
});
|
||||
|
||||
TextView addMarkerButton = (TextView) mainView.findViewById(R.id.add_marker_button);
|
||||
addMarkerButton.setBackgroundResource(lightTheme ? R.drawable.keyboard_item_light_bg : R.drawable.keyboard_item_dark_bg);
|
||||
addMarkerButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String latitude = latitudeEditText.getText().toString();
|
||||
String longitude = longitudeEditText.getText().toString();
|
||||
String name = nameEditText.getText().toString();
|
||||
adapter.addMapMarker(latitude, longitude, name);
|
||||
}
|
||||
});
|
||||
|
||||
View keyboardLayout = mainView.findViewById(R.id.keyboard_layout);
|
||||
AndroidUtils.setBackground(mapActivity, keyboardLayout, !lightTheme, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
|
||||
|
||||
|
@ -214,6 +252,19 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity()));
|
||||
startLocationUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
stopLocationUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (getDialog() != null && getRetainInstance()) {
|
||||
|
@ -516,6 +567,76 @@ public class CoordinateInputDialogFragment extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@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 = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
|
||||
}
|
||||
MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities();
|
||||
boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null);
|
||||
|
||||
adapter.setUseCenter(useCenter);
|
||||
adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude()));
|
||||
adapter.setHeading(useCenter ? -mapActivity.getMapRotate() : 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());
|
||||
}
|
||||
}
|
||||
|
||||
private class KeyboardAdapter extends ArrayAdapter<String> {
|
||||
|
||||
KeyboardAdapter(@NonNull Context context, @NonNull String[] objects) {
|
||||
|
|
|
@ -0,0 +1,113 @@
|
|||
package net.osmand.plus.mapmarkers.adapters;
|
||||
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.MapMarkersHelper.MAP_MARKERS_COLORS_COUNT;
|
||||
|
||||
public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemViewHolder> {
|
||||
|
||||
private MapActivity mapActivity;
|
||||
private boolean nightTheme;
|
||||
private IconsCache iconsCache;
|
||||
private List<MapMarker> mapMarkers = new ArrayList<>();
|
||||
private LatLon location;
|
||||
private Float heading;
|
||||
private boolean useCenter;
|
||||
private int screenOrientation;
|
||||
|
||||
public CoordinateInputAdapter (MapActivity mapActivity) {
|
||||
this.mapActivity = mapActivity;
|
||||
nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent();
|
||||
iconsCache = mapActivity.getMyApplication().getIconsCache();
|
||||
}
|
||||
|
||||
public void setLocation(LatLon location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public void setHeading(Float heading) {
|
||||
this.heading = heading;
|
||||
}
|
||||
|
||||
public void setUseCenter(boolean useCenter) {
|
||||
this.useCenter = useCenter;
|
||||
}
|
||||
|
||||
public void setScreenOrientation(int screenOrientation) {
|
||||
this.screenOrientation = screenOrientation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.map_marker_item_new, parent, false);
|
||||
return new MapMarkerItemViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(MapMarkerItemViewHolder holder, int position) {
|
||||
MapMarker mapMarker = getItem(position);
|
||||
holder.iconDirection.setVisibility(View.VISIBLE);
|
||||
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(mapMarker.colorIndex)));
|
||||
holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, nightTheme ? R.color.bg_color_dark : R.color.bg_color_light));
|
||||
holder.title.setTextColor(ContextCompat.getColor(mapActivity, nightTheme ? R.color.color_white : R.color.color_black));
|
||||
holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, nightTheme ? R.color.actionbar_dark_color : R.color.dashboard_divider_light));
|
||||
holder.optionsBtn.setBackgroundDrawable(mapActivity.getResources().getDrawable(nightTheme ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
|
||||
holder.optionsBtn.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_remove_dark));
|
||||
holder.iconReorder.setVisibility(View.GONE);
|
||||
holder.numberText.setVisibility(View.VISIBLE);
|
||||
holder.numberText.setText(Integer.toString(position + 1));
|
||||
holder.description.setVisibility(View.GONE);
|
||||
|
||||
boolean fistItem = position == 0;
|
||||
boolean lastItem = position == getItemCount() - 1;
|
||||
holder.topDivider.setVisibility(fistItem ? View.VISIBLE : View.GONE);
|
||||
holder.divider.setVisibility((getItemCount() > 1 && !lastItem) ? View.VISIBLE : View.GONE);
|
||||
holder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
|
||||
|
||||
holder.title.setText(mapMarker.getName(mapActivity));
|
||||
|
||||
DashLocationFragment.updateLocationView(useCenter, location,
|
||||
heading, holder.iconDirection, R.drawable.ic_direction_arrow,
|
||||
holder.distance, new LatLon(mapMarker.getLatitude(), mapMarker.getLongitude()),
|
||||
screenOrientation, mapActivity.getMyApplication(), mapActivity, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mapMarkers.size();
|
||||
}
|
||||
|
||||
public MapMarker getItem(int position) {
|
||||
return mapMarkers.get(position);
|
||||
}
|
||||
|
||||
public void addMapMarker(String latitude, String longitude, String name) {
|
||||
PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, name);
|
||||
LatLon latLon = new LatLon(30.537020, 50.443477);
|
||||
int colorIndex = mapMarkers.size() > 0 ? mapMarkers.get(mapMarkers.size() - 1).colorIndex : -1;
|
||||
if (colorIndex == -1) {
|
||||
colorIndex = 0;
|
||||
} else {
|
||||
colorIndex = (colorIndex + 1) % MAP_MARKERS_COLORS_COUNT;
|
||||
}
|
||||
MapMarker mapMarker = new MapMarker(latLon, pointDescription, colorIndex, false, 0);
|
||||
mapMarkers.add(mapMarker);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
|
|||
final View mainLayout;
|
||||
final View topDivider;
|
||||
final ImageView iconDirection;
|
||||
final TextView numberText;
|
||||
final ImageView iconReorder;
|
||||
final ImageView icon;
|
||||
final TextView title;
|
||||
|
@ -35,6 +36,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
|
|||
mainLayout = view.findViewById(R.id.main_layout);
|
||||
topDivider = view.findViewById(R.id.top_divider);
|
||||
iconDirection = (ImageView) view.findViewById(R.id.map_marker_direction_icon);
|
||||
numberText = (TextView) view.findViewById(R.id.map_marker_number_text_view);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue