Markers in progress

This commit is contained in:
Alexey Kulish 2016-02-05 22:59:57 +03:00
parent acb85240eb
commit 494ae4b4d0
6 changed files with 248 additions and 55 deletions

View file

@ -166,6 +166,7 @@
<activity android:name="net.osmand.plus.activities.PluginsActivity" />
<activity android:name="net.osmand.plus.activities.PluginActivity" />
<activity android:name="net.osmand.plus.activities.ContributionVersionActivity" android:configChanges="keyboardHidden|orientation" android:label="@string/contribution_activity" />
<activity android:name="net.osmand.plus.activities.MapMarkersActivity"/>
<activity android:name="net.osmand.plus.osmo.SettingsOsMoActivity" android:configChanges="keyboardHidden|orientation" />

View file

@ -32,4 +32,15 @@
<include layout="@layout/check_item_rel"/>
<Button
android:id="@+id/header_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:layout_marginRight="-16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="@string/shared_string_clear"
android:visibility="gone"/>
</LinearLayout>

View file

@ -9,6 +9,7 @@ import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.data.LocationPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapMarkersActivity;
import net.osmand.plus.activities.PluginsActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.activities.TrackActivity;
@ -67,7 +68,10 @@ public class OsmAndAppCustomization {
return FavoritesActivity.class;
}
public Class<MapMarkersActivity> getMapMarkersActivity(){
return MapMarkersActivity.class;
}
public Class<? extends Activity> getDownloadIndexActivity() {
return DownloadActivity.class;
}

View file

@ -564,12 +564,15 @@ public class MapActivityActions implements DialogProvider {
return true;
}
}).reg();
optionsMenuHelper.item(R.string.waypoints).iconColor(R.drawable.ic_action_waypoint)
optionsMenuHelper.item(R.string.map_markers).iconColor(R.drawable.ic_action_waypoint)
.listen(new OnContextMenuClick() {
@Override
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.WAYPOINTS);
return false;
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization()
.getMapMarkersActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
mapActivity.startActivity(newIntent);
return true;
}
}).reg();
optionsMenuHelper.item(R.string.get_directions).iconColor(R.drawable.ic_action_gdirections_dark)

View file

@ -1,21 +1,30 @@
package net.osmand.plus.activities;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.Shape;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.helpers.WaypointHelper;
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.util.ArrayList;
import java.util.List;
@ -34,7 +43,8 @@ public class MapMarkersActivity extends OsmandListActivity {
setContentView(R.layout.map_markers);
getSupportActionBar().setTitle(R.string.map_markers);
nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
//nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
nightMode = !getMyApplication().getSettings().isLightContent();
setListAdapter(getMapMarkersListAdapter());
}
@ -65,29 +75,27 @@ public class MapMarkersActivity extends OsmandListActivity {
@Override
public void buildDividers() {
dividers = getCustomDividers(ctx, getObjects(), nightMode);
dividers = getCustomDividers(getObjects());
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// User super class to create the View
View v = convertView;
final ArrayAdapter<Object> thisAdapter = this;
Object obj = getItem(position);
boolean labelView = (obj instanceof Integer);
boolean topDividerView = (obj instanceof Boolean) && ((Boolean) obj);
boolean bottomDividerView = (obj instanceof Boolean) && !((Boolean) obj);
if (labelView) {
v = createItemForCategory(ctx, (Integer) obj, running, position, thisAdapter, nightMode);
v = createItemForCategory((Integer) obj);
AndroidUtils.setListItemBackground(MapMarkersActivity.this, v, nightMode);
} else if (topDividerView) {
v = ctx.getLayoutInflater().inflate(R.layout.card_top_divider, null);
v = getLayoutInflater().inflate(R.layout.card_top_divider, null);
} else if (bottomDividerView) {
v = ctx.getLayoutInflater().inflate(R.layout.card_bottom_divider, null);
v = getLayoutInflater().inflate(R.layout.card_bottom_divider, null);
} else if (obj instanceof MapMarker) {
MapMarker marker = (MapMarker) obj;
v = updateWaypointItemView(edit, deletedPoints, app, ctx, helper, v, marker, this,
nightMode, flat);
v = updateMapMarkerItemView(v, marker);
AndroidUtils.setListItemBackground(MapMarkersActivity.this, v, nightMode);
}
return v;
@ -103,11 +111,7 @@ public class MapMarkersActivity extends OsmandListActivity {
= new GeocodingLookupService.AddressLookupRequest(marker.point, new GeocodingLookupService.OnAddressLookupResult() {
@Override
public void geocodingDone(String address) {
if (helperCallbacks != null) {
helperCallbacks.reloadAdapter();
} else {
reloadListAdapter(listAdapter);
}
reloadListAdapter();
}
}, null);
getMyApplication().getGeocodingLookupService().lookupAddress(lookupRequest);
@ -118,36 +122,158 @@ public class MapMarkersActivity extends OsmandListActivity {
return listAdapter;
}
protected View createItemForCategory(final int type, final int position, final ArrayAdapter<Object> thisAdapter, boolean nightMode) {
View v = getLayoutInflater().inflate(R.layout.waypoint_header, null);
final CompoundButton btn = (CompoundButton) v.findViewById(R.id.check_item);
btn.setVisibility(waypointHelper.isTypeConfigurable(type) ? View.VISIBLE : View.GONE);
btn.setOnCheckedChangeListener(null);
final boolean checked = waypointHelper.isTypeEnabled(type);
btn.setChecked(checked);
btn.setEnabled(running[0] == -1);
v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
private List<Drawable> getCustomDividers(List<Object> points) {
int color;
if (nightMode) {
color = getResources().getColor(R.color.dashboard_divider_dark);
} else {
color = getResources().getColor(R.color.dashboard_divider_light);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
running[0] = position;
thisAdapter.notifyDataSetInvalidated();
if (type == WaypointHelper.POI && isChecked) {
selectPoi(running, thisAdapter, type, isChecked, ctx);
} else {
enableType(running, thisAdapter, type, isChecked);
}
Shape fullDividerShape = new ListDividerShape(color, 0);
Shape halfDividerShape = new ListDividerShape(color, AndroidUtils.dpToPx(this, 56f));
final ShapeDrawable fullDivider = new ShapeDrawable(fullDividerShape);
final ShapeDrawable halfDivider = new ShapeDrawable(halfDividerShape);
int divHeight = AndroidUtils.dpToPx(this, 1f);
fullDivider.setIntrinsicHeight(divHeight);
halfDivider.setIntrinsicHeight(divHeight);
List<Drawable> res = new ArrayList<>();
for (int i = 0; i < points.size(); i++) {
Object obj = points.get(i);
Object objNext = i + 1 < points.size() ? points.get(i + 1) : null;
if (objNext == null) {
break;
}
boolean bottomDividerViewNext = (objNext instanceof Boolean) && !((Boolean) objNext);
boolean mapMarker = (obj instanceof MapMarker);
boolean mapMarkerNext = (objNext instanceof MapMarker);
Drawable d = null;
if (mapMarkerNext) {
if (mapMarker) {
d = halfDivider;
} else {
d = fullDivider;
}
} else if (mapMarker && !bottomDividerViewNext) {
d = fullDivider;
}
res.add(d);
}
return res;
}
protected View createItemForCategory(final int type) {
View v = getLayoutInflater().inflate(R.layout.waypoint_header, null);
v.findViewById(R.id.check_item).setVisibility(View.GONE);
v.findViewById(R.id.ProgressBar).setVisibility(View.GONE);
final Button btn = (Button) v.findViewById(R.id.header_button);
btn.setTextColor(!nightMode ? getResources().getColor(R.color.map_widget_blue)
: getResources().getColor(R.color.osmand_orange));
btn.setText(getString(R.string.shared_string_clear));
btn.setVisibility(View.VISIBLE);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getListAdapter().notifyDataSetInvalidated();
reloadListAdapter();
}
});
TextView tv = (TextView) v.findViewById(R.id.header_text);
AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
tv.setText(getHeader(type, checked, ctx));
AndroidUtils.setTextPrimaryColor(this, tv, nightMode);
tv.setText(getHeader(type));
return v;
}
protected View updateMapMarkerItemView(View v, final MapMarker marker) {
if (v == null || v.findViewById(R.id.info_close) == null) {
v = getLayoutInflater().inflate(R.layout.waypoint_reached, null);
}
updateMapMarkerInfoView(v, marker);
final View more = v.findViewById(R.id.all_points);
final View move = v.findViewById(R.id.info_move);
final View remove = v.findViewById(R.id.info_close);
remove.setVisibility(View.GONE);
move.setVisibility(View.GONE);
more.setVisibility(View.GONE);
return v;
}
protected void updateMapMarkerInfoView(View localView, final MapMarker marker) {
OsmandApplication app = getMyApplication();
TextView text = (TextView) localView.findViewById(R.id.waypoint_text);
AndroidUtils.setTextPrimaryColor(this, text, nightMode);
TextView textShadow = (TextView) localView.findViewById(R.id.waypoint_text_shadow);
localView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showOnMap(marker);
}
});
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
((ImageView) localView.findViewById(R.id.waypoint_icon))
.setImageDrawable(getMapMarkerIcon(marker.colorIndex));
LatLon lastKnownMapLocation = app.getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(marker.getLatitude(), marker.getLongitude(),
lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
if (dist > 0) {
textDist.setText(OsmAndFormatter.getFormattedDistance(dist, app));
} else {
textDist.setText("");
}
localView.findViewById(R.id.waypoint_deviation).setVisibility(View.GONE);
String descr;
PointDescription pd = marker.getPointDescription(app);
if (Algorithms.isEmpty(pd.getName())) {
descr = pd.getTypeName();
} else {
descr = pd.getName();
}
if (textShadow != null) {
textShadow.setText(descr);
}
text.setText(descr);
String pointDescription = "";
TextView descText = (TextView) localView.findViewById(R.id.waypoint_desc_text);
if (descText != null) {
AndroidUtils.setTextSecondaryColor(this, descText, nightMode);
pointDescription = marker.getPointDescription(this).getTypeName();
}
if (descr.equals(pointDescription)) {
pointDescription = "";
}
if (dist > 0 && !Algorithms.isEmpty(pointDescription)) {
pointDescription = "" + pointDescription;
}
if (descText != null) {
descText.setText(pointDescription);
}
}
public void showOnMap(MapMarker marker) {
getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, marker.getPointDescription(this), true, marker);
MapActivity.launchMapActivityMoveToTop(this);
}
protected String getHeader(int type) {
String str = getString(R.string.map_markers);
switch (type) {
@ -161,10 +287,17 @@ public class MapMarkersActivity extends OsmandListActivity {
return str;
}
//LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
//int dist = (int) (MapUtils.getDistance(marker.getLatitude(), marker.getLongitude(),
//lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()));
public void reloadListAdapter() {
StableArrayAdapter listAdapter = getListAdapter();
listAdapter.setNotifyOnChange(false);
listAdapter.clear();
List<Object> objects = getListObjects();
for (Object point : objects) {
listAdapter.add(point);
}
listAdapter.updateObjects(objects, getActiveObjects(objects));
listAdapter.notifyDataSetChanged();
}
protected List<Object> getListObjects() {
final List<Object> objects = new ArrayList<>();
@ -198,4 +331,22 @@ public class MapMarkersActivity extends OsmandListActivity {
}
return activeObjects;
}
private Drawable getMapMarkerIcon(int colorIndex) {
IconsCache iconsCache = getMyApplication().getIconsCache();
switch (colorIndex) {
case 0:
return iconsCache.getIcon(R.drawable.map_marker_blue);
case 1:
return iconsCache.getIcon(R.drawable.map_marker_green);
case 2:
return iconsCache.getIcon(R.drawable.map_marker_orange);
case 3:
return iconsCache.getIcon(R.drawable.map_marker_red);
case 4:
return iconsCache.getIcon(R.drawable.map_marker_yellow);
default:
return iconsCache.getIcon(R.drawable.map_marker_blue);
}
}
}

View file

@ -12,7 +12,6 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity;
import java.util.List;
@ -22,7 +21,11 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
private OsmandMapTileView view;
private Paint bitmapPaint;
private Bitmap markerBitmap;
private Bitmap markerBitmapBlue;
private Bitmap markerBitmapGreen;
private Bitmap markerBitmapOrange;
private Bitmap markerBitmapRed;
private Bitmap markerBitmapYellow;
public MapMarkersLayer(MapActivity map) {
this.map = map;
@ -33,7 +36,28 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
bitmapPaint.setDither(true);
bitmapPaint.setAntiAlias(true);
bitmapPaint.setFilterBitmap(true);
markerBitmap = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_intermediate_point);
markerBitmapBlue = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_blue);
markerBitmapGreen = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_green);
markerBitmapOrange = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_orange);
markerBitmapRed = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_red);
markerBitmapYellow = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_marker_yellow);
}
private Bitmap getMapMarkerBitmap(int colorIndex) {
switch (colorIndex) {
case 0:
return markerBitmapBlue;
case 1:
return markerBitmapGreen;
case 2:
return markerBitmapOrange;
case 3:
return markerBitmapRed;
case 4:
return markerBitmapYellow;
default:
return markerBitmapBlue;
}
}
@Override
@ -49,16 +73,15 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
}
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
int index = 0;
for (MapMarker marker : markersHelper.getActiveMapMarkers()) {
index++;
if (isLocationVisible(tb, marker)) {
int marginX = markerBitmap.getWidth() / 6;
int marginY = markerBitmap.getHeight();
Bitmap bmp = getMapMarkerBitmap(marker.colorIndex);
int marginX = bmp.getWidth() / 6;
int marginY = bmp.getHeight();
int locationX = tb.getPixXFromLonNoRot(marker.getLongitude());
int locationY = tb.getPixYFromLatNoRot(marker.getLatitude());
canvas.rotate(-tb.getRotate(), locationX, locationY);
canvas.drawBitmap(markerBitmap, locationX - marginX, locationY - marginY, bitmapPaint);
canvas.drawBitmap(bmp, locationX - marginX, locationY - marginY, bitmapPaint);
canvas.rotate(tb.getRotate(), locationX, locationY);
}
}
@ -119,7 +142,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements ContextMenuLayer.
}
public int getRadiusPoi(RotatedTileBox tb) {
int r = 0;
int r;
final double zoom = tb.getZoom();
if (zoom <= 15) {
r = 10;