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