Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
4a352e273b
5 changed files with 157 additions and 86 deletions
|
@ -6,26 +6,27 @@ package net.osmand.plus.activities;
|
|||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.*;
|
||||
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.search.SearchActivity;
|
||||
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v7.widget.PopupMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
|
@ -35,7 +36,7 @@ import android.widget.TextView;
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public class FavoritesListFragment extends ListFragment implements SearchActivityChild {
|
||||
public class FavoritesListFragment extends ListFragment implements SearchActivityChild, OsmAndCompassListener {
|
||||
|
||||
public static final String SELECT_FAVORITE_POINT_INTENT_KEY = "SELECT_FAVORITE_POINT_INTENT_KEY";
|
||||
public static final int SELECT_FAVORITE_POINT_RESULT_OK = 1;
|
||||
|
@ -44,7 +45,8 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
|
||||
private boolean selectFavoriteMode;
|
||||
private OsmandSettings settings;
|
||||
private LatLon location;
|
||||
private boolean compassRegistered;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
|
@ -76,23 +78,42 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
}
|
||||
}
|
||||
|
||||
if (location == null && getActivity() instanceof SearchActivity) {
|
||||
location = ((SearchActivity) getActivity()).getSearchPoint();
|
||||
if (favouritesAdapter.location == null && getActivity() instanceof SearchActivity) {
|
||||
favouritesAdapter.location = ((SearchActivity) getActivity()).getSearchPoint();
|
||||
}
|
||||
if (location == null) {
|
||||
location = settings.getLastKnownMapLocation();
|
||||
if (favouritesAdapter.location == null) {
|
||||
favouritesAdapter.location = settings.getLastKnownMapLocation();
|
||||
}
|
||||
|
||||
locationUpdate(location);
|
||||
|
||||
favouritesAdapter.screenOrientation = DashLocationFragment.getScreenOrientation(getActivity());
|
||||
locationUpdate(favouritesAdapter.location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void locationUpdate(LatLon l) {
|
||||
location = l;
|
||||
if (getActivity() instanceof SearchActivity) {
|
||||
if (((SearchActivity) getActivity()).isSearchAroundCurrentLocation() && l != null) {
|
||||
if (!compassRegistered) {
|
||||
((OsmandApplication) getActivity().getApplication()).getLocationProvider().addCompassListener(this);
|
||||
compassRegistered = true;
|
||||
}
|
||||
favouritesAdapter.searchAroundLocation = true;
|
||||
} else {
|
||||
favouritesAdapter.searchAroundLocation = false;
|
||||
}
|
||||
}
|
||||
if (favouritesAdapter != null) {
|
||||
favouritesAdapter.updateLocation(l);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if(getActivity() instanceof SearchActivity) {
|
||||
((OsmandApplication) getActivity().getApplication()).getLocationProvider().removeCompassListener(this);
|
||||
compassRegistered = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isSelectFavoriteMode() {
|
||||
|
@ -129,7 +150,9 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
private Activity activity;
|
||||
private LatLon location;
|
||||
private OsmandApplication app;
|
||||
Drawable arrowImage;
|
||||
private boolean searchAroundLocation;
|
||||
private int screenOrientation;
|
||||
private Float heading;
|
||||
|
||||
public LatLon getLocation() {
|
||||
return location;
|
||||
|
@ -160,14 +183,6 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
super(activity, R.layout.favorites_list_item, list);
|
||||
this.activity = activity;
|
||||
this.app = ((OsmandApplication) activity.getApplication());
|
||||
boolean light = app.getSettings().isLightContent();
|
||||
arrowImage = activity.getResources().getDrawable(R.drawable.ic_destination_arrow_white);
|
||||
arrowImage.mutate();
|
||||
if (light) {
|
||||
arrowImage.setColorFilter(activity.getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
|
||||
} else {
|
||||
arrowImage.setColorFilter(activity.getResources().getColor(R.color.color_distance), PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
}
|
||||
|
||||
public String getName(FavouritePoint model) {
|
||||
|
@ -186,7 +201,6 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
TextView distanceText = (TextView) row.findViewById(R.id.distance);
|
||||
ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon);
|
||||
ImageView direction = (ImageView) row.findViewById(R.id.direction);
|
||||
direction.setImageDrawable(arrowImage);
|
||||
direction.setVisibility(View.VISIBLE);
|
||||
final FavouritePoint favorite = getItem(position);
|
||||
if (!favorite.getCategory().isEmpty()) {
|
||||
|
@ -197,13 +211,9 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
((TextView) row.findViewById(R.id.group_name)).setText(favorite.getCategory());
|
||||
|
||||
icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(activity, favorite.getColor()));
|
||||
String distance = "";
|
||||
if (location != null) {
|
||||
int dist = (int) (MapUtils.getDistance(favorite.getLatitude(), favorite.getLongitude(), location.getLatitude(), location
|
||||
.getLongitude()));
|
||||
distance = OsmAndFormatter.getFormattedDistance(dist, app) + " ";
|
||||
}
|
||||
distanceText.setText(distance);
|
||||
DashLocationFragment.updateLocationView(!searchAroundLocation, location, heading, direction, distanceText,
|
||||
favorite.getLatitude(), favorite.getLongitude(), screenOrientation, app, activity);
|
||||
|
||||
name.setText(getName(favorite));
|
||||
final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item);
|
||||
row.findViewById(R.id.favourite_icon).setVisibility(View.VISIBLE);
|
||||
|
@ -216,4 +226,17 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit
|
|||
public OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCompassValue(float value) {
|
||||
// 99 in next line used to one-time initalize arrows (with reference vs. fixed-north direction) on non-compass
|
||||
// devices
|
||||
float lastHeading = favouritesAdapter.heading != null ? favouritesAdapter.heading : 99;
|
||||
favouritesAdapter.heading = value;
|
||||
if (favouritesAdapter.heading != null && Math.abs(MapUtils.degreesDiff(lastHeading, favouritesAdapter.heading)) > 5) {
|
||||
favouritesAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
favouritesAdapter.heading = lastHeading;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -206,11 +206,11 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
|||
if (position != 0) {
|
||||
if (position == POSITION_CURRENT_LOCATION) {
|
||||
net.osmand.Location loc = getLocationProvider().getLastKnownLocation();
|
||||
searchAroundCurrentLocation = true;
|
||||
if(loc != null && System.currentTimeMillis() - loc.getTime() < 10000) {
|
||||
updateLocation(loc);
|
||||
} else {
|
||||
startSearchCurrentLocation();
|
||||
searchAroundCurrentLocation = true;
|
||||
}
|
||||
} else {
|
||||
searchAroundCurrentLocation = false;
|
||||
|
@ -281,9 +281,10 @@ public class SearchActivity extends TabActivity implements OsmAndLocationListene
|
|||
if (location != null) {
|
||||
updateSearchPoint(new LatLon(location.getLatitude(), location.getLongitude()),
|
||||
getString(R.string.select_search_position) + " " + getString(R.string.search_position_current_location_found), false);
|
||||
if (location.getAccuracy() < 20) {
|
||||
endSearchCurrentLocation();
|
||||
}
|
||||
// don't stop in case we want to see updates
|
||||
// if (location.getAccuracy() < 20) {
|
||||
// endSearchCurrentLocation();
|
||||
// }
|
||||
}
|
||||
}
|
||||
public void startSearchCurrentLocation(){
|
||||
|
|
|
@ -9,7 +9,9 @@ import net.osmand.plus.OsmAndFormatter;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
||||
import net.osmand.plus.dashboard.DashLocationFragment;
|
||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
||||
|
@ -41,14 +43,17 @@ import android.widget.TextView;
|
|||
import android.widget.TextView.BufferType;
|
||||
|
||||
|
||||
public class SearchHistoryFragment extends ListFragment implements SearchActivityChild {
|
||||
public class SearchHistoryFragment extends ListFragment implements SearchActivityChild, OsmAndCompassListener {
|
||||
private LatLon location;
|
||||
private SearchHistoryHelper helper;
|
||||
private Button clearButton;
|
||||
public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT;
|
||||
public static final String SEARCH_LON = SearchActivity.SEARCH_LON;
|
||||
private HistoryAdapter historyAdapter;
|
||||
|
||||
private Float heading;
|
||||
private boolean searchAroundLocation;
|
||||
private boolean compassRegistered;
|
||||
private int screenOrientation;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -117,17 +122,37 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
|
|||
}
|
||||
locationUpdate(location);
|
||||
clearButton.setVisibility(historyAdapter.isEmpty() ? View.GONE : View.VISIBLE);
|
||||
|
||||
screenOrientation = DashLocationFragment.getScreenOrientation(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void locationUpdate(LatLon l) {
|
||||
//location = l;
|
||||
if (getActivity() instanceof SearchActivity) {
|
||||
if (((SearchActivity) getActivity()).isSearchAroundCurrentLocation() && l != null) {
|
||||
if (!compassRegistered) {
|
||||
((OsmandApplication) getActivity().getApplication()).getLocationProvider().addCompassListener(this);
|
||||
compassRegistered = true;
|
||||
}
|
||||
searchAroundLocation = true;
|
||||
} else {
|
||||
searchAroundLocation = false;
|
||||
}
|
||||
}
|
||||
if (historyAdapter != null) {
|
||||
historyAdapter.updateLocation(l);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if(getActivity() instanceof SearchActivity) {
|
||||
((OsmandApplication) getActivity().getApplication()).getLocationProvider().removeCompassListener(this);
|
||||
compassRegistered = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
||||
|
@ -178,6 +203,10 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
|
|||
}
|
||||
final HistoryEntry historyEntry = getItem(position);
|
||||
udpateHistoryItem(historyEntry, row, location, getActivity(), getMyApplication());
|
||||
TextView distanceText = (TextView) row.findViewById(R.id.distance);
|
||||
ImageView direction = (ImageView) row.findViewById(R.id.direction);
|
||||
DashLocationFragment.updateLocationView(!searchAroundLocation, location, heading, direction, distanceText,
|
||||
historyEntry.getLat(), historyEntry.getLon(), screenOrientation, getMyApplication(), getActivity());
|
||||
ImageButton options = (ImageButton) row.findViewById(R.id.options);
|
||||
options.setVisibility(View.VISIBLE);
|
||||
options.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -248,4 +277,17 @@ public class SearchHistoryFragment extends ListFragment implements SearchActivit
|
|||
public OsmandApplication getMyApplication() {
|
||||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCompassValue(float value) {
|
||||
// 99 in next line used to one-time initalize arrows (with reference vs. fixed-north direction) on non-compass
|
||||
// devices
|
||||
float lastHeading = heading != null ? heading : 99;
|
||||
heading = value;
|
||||
if (heading != null && Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) {
|
||||
historyAdapter.notifyDataSetChanged();
|
||||
} else {
|
||||
heading = lastHeading;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,15 @@ package net.osmand.plus.dashboard;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.views.DirectionDrawable;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorManager;
|
||||
|
@ -30,7 +33,6 @@ public abstract class DashLocationFragment extends DashBaseFragment {
|
|||
private int screenOrientation;
|
||||
|
||||
public static class DashLocationView {
|
||||
public boolean useOnlyMyLocation;
|
||||
public ImageView arrow;
|
||||
public TextView txt;
|
||||
public LatLon loc;
|
||||
|
@ -49,8 +51,11 @@ public abstract class DashLocationFragment extends DashBaseFragment {
|
|||
@Override
|
||||
public void onOpenDash() {
|
||||
//Hardy: getRotation() is the correction if device's screen orientation != the default display's standard orientation
|
||||
screenOrientation = 0;
|
||||
screenOrientation = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
|
||||
screenOrientation = getScreenOrientation(getActivity());
|
||||
}
|
||||
|
||||
public static int getScreenOrientation(Activity a) {
|
||||
int screenOrientation = ((WindowManager) a.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation();
|
||||
switch (screenOrientation)
|
||||
{
|
||||
case ORIENTATION_0: // Device default (normally portrait)
|
||||
|
@ -67,10 +72,11 @@ public abstract class DashLocationFragment extends DashBaseFragment {
|
|||
break;
|
||||
}
|
||||
//Looks like screenOrientation correction must not be applied for devices without compass?
|
||||
Sensor compass = ((SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
||||
Sensor compass = ((SensorManager) a.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
||||
if (compass == null) {
|
||||
screenOrientation = 0;
|
||||
}
|
||||
return screenOrientation;
|
||||
}
|
||||
|
||||
public LatLon getDefaultLocation() {
|
||||
|
@ -92,54 +98,53 @@ public abstract class DashLocationFragment extends DashBaseFragment {
|
|||
Location l = d.getMyLocation();
|
||||
boolean mapLinked = d.isMapLinkedToLocation() && l != null;
|
||||
LatLon myLoc = l == null ? null : new LatLon(l.getLatitude(), l.getLongitude());
|
||||
for (DashLocationView lv : distances) {
|
||||
boolean useCenter = !mapLinked && !lv.useOnlyMyLocation;
|
||||
boolean useCenter = !mapLinked;
|
||||
LatLon loc = (useCenter ? mw : myLoc);
|
||||
float h = useCenter ? -mapRotation : head;
|
||||
for (DashLocationView lv : distances) {
|
||||
updateLocationView(useCenter, loc, h, lv.arrow, lv.txt, lv.loc.getLatitude(), lv.loc.getLongitude(),
|
||||
screenOrientation, getMyApplication(), getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h,
|
||||
ImageView arrow, TextView txt, double toLat, double toLon,
|
||||
int screenOrientation, OsmandApplication app, Context ctx) {
|
||||
float[] mes = new float[2];
|
||||
if (loc != null) {
|
||||
Location.distanceBetween(lv.loc.getLatitude(), lv.loc.getLongitude(), loc.getLatitude(),
|
||||
loc.getLongitude(), mes);
|
||||
if (fromLoc != null) {
|
||||
Location.distanceBetween(toLat, toLon, fromLoc.getLatitude(),
|
||||
fromLoc.getLongitude(), mes);
|
||||
}
|
||||
if (lv.arrow != null) {
|
||||
if (!(lv.arrow.getDrawable() instanceof DirectionDrawable)) {
|
||||
DirectionDrawable dd = new DirectionDrawable(getActivity(), 10, 10);
|
||||
lv.arrow.setImageDrawable(dd);
|
||||
if (arrow != null) {
|
||||
if (!(arrow.getDrawable() instanceof DirectionDrawable)) {
|
||||
DirectionDrawable dd = new DirectionDrawable(ctx, 10, 10);
|
||||
arrow.setImageDrawable(dd);
|
||||
}
|
||||
DirectionDrawable dd = (DirectionDrawable) lv.arrow.getDrawable();
|
||||
DirectionDrawable dd = (DirectionDrawable) arrow.getDrawable();
|
||||
dd.setImage(R.drawable.ic_destination_arrow_white, useCenter ? R.color.color_distance
|
||||
: R.color.color_myloc_distance);
|
||||
if (loc == null) {
|
||||
if (fromLoc == null || h == null) {
|
||||
dd.setAngle(0);
|
||||
} else {
|
||||
dd.setAngle(mes[1] - h + 180 + screenOrientation);
|
||||
}
|
||||
lv.arrow.invalidate();
|
||||
arrow.invalidate();
|
||||
}
|
||||
if (loc != null) {
|
||||
lv.txt.setTextColor(getActivity().getResources().getColor(useCenter ? R.color.color_distance
|
||||
: R.color.color_myloc_distance));
|
||||
lv.txt.setText(OsmAndFormatter.getFormattedDistance(mes[0], dashboard.getMyApplication()));
|
||||
if (txt != null) {
|
||||
if (fromLoc != null) {
|
||||
txt.setTextColor(app.getResources().getColor(
|
||||
useCenter ? R.color.color_distance : R.color.color_myloc_distance));
|
||||
txt.setText(OsmAndFormatter.getFormattedDistance(mes[0], app));
|
||||
} else {
|
||||
lv.txt.setText("");
|
||||
txt.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateLocation(boolean centerChanged, boolean locationChanged, boolean compassChanged) {
|
||||
if(compassChanged && !dashboard.isMapLinkedToLocation()) {
|
||||
boolean update = false;
|
||||
for (DashLocationView lv : distances) {
|
||||
if(lv.useOnlyMyLocation) {
|
||||
update = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!update) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
updateAllWidgets();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -208,7 +208,7 @@ public class MapRoutePreferencesControl extends MapControls {
|
|||
if (gpxParam.id == R.string.fast_route_mode) {
|
||||
settings.FAST_ROUTE_MODE.set(selected);
|
||||
}
|
||||
if (gpxParam.id == R.string.announce_nearby_favorites){
|
||||
if (gpxParam.id == R.string.speak_favorites){
|
||||
settings.ANNOUNCE_NEARBY_FAVORITES.set(selected);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue