From 9350515844dfab23e6f97f0213795e8be10f9884 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 8 Mar 2015 20:59:18 +0100 Subject: [PATCH] Add button configure map --- OsmAnd/res/drawable/roundedbutton.xml | 11 ++ OsmAnd/res/layout-land/dashboard_over_map.xml | 56 ++++--- OsmAnd/res/layout/dashboard_over_map.xml | 41 ++++-- OsmAnd/res/values/sizes.xml | 3 + .../src/net/osmand/plus/OsmandSettings.java | 2 +- .../plus/activities/MainMenuActivity.java | 37 ++--- .../osmand/plus/activities/MapActivity.java | 27 ++-- .../activities/search/SearchPOIActivity.java | 3 +- .../plus/base/MapViewTrackingUtilities.java | 17 +++ .../plus/dashboard/DashBaseFragment.java | 2 +- .../plus/dashboard/DashFavoritesFragment.java | 99 +++---------- .../plus/dashboard/DashLocationFragment.java | 138 ++++++++++++------ .../plus/dashboard/DashRecentsFragment.java | 47 +----- .../osmand/plus/dashboard/DashboardOnMap.java | 81 +++++++++- .../parkingpoint/DashParkingFragment.java | 51 ++----- .../osmand/plus/views/DirectionDrawable.java | 28 ++-- 16 files changed, 360 insertions(+), 283 deletions(-) create mode 100644 OsmAnd/res/drawable/roundedbutton.xml diff --git a/OsmAnd/res/drawable/roundedbutton.xml b/OsmAnd/res/drawable/roundedbutton.xml new file mode 100644 index 0000000000..326556d040 --- /dev/null +++ b/OsmAnd/res/drawable/roundedbutton.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout-land/dashboard_over_map.xml b/OsmAnd/res/layout-land/dashboard_over_map.xml index a01fec4345..c1a494bb40 100644 --- a/OsmAnd/res/layout-land/dashboard_over_map.xml +++ b/OsmAnd/res/layout-land/dashboard_over_map.xml @@ -12,32 +12,48 @@ layout="@layout/application_loading" android:visibility="gone" /> - + android:orientation="horizontal" > - + + android:orientation="vertical" > - - - + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/dashboard_over_map.xml b/OsmAnd/res/layout/dashboard_over_map.xml index 1cdfc6e4c2..3d73791271 100644 --- a/OsmAnd/res/layout/dashboard_over_map.xml +++ b/OsmAnd/res/layout/dashboard_over_map.xml @@ -19,25 +19,40 @@ android:layout_height="match_parent" android:fadeScrollbars="true" > - + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + + android:layout_marginTop="@dimen/dashboard_map_top_padding" + android:orientation="vertical" > - - + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index b67ea4109b..ddde34028a 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -44,6 +44,9 @@ 6dp 240dp 90dp + + 40dp + 8dp 14sp diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 0cff3f4a81..56a4aa2822 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -622,7 +622,7 @@ public class OsmandSettings { return p; } - public final CommonPreference USE_DASHBOARD_INSTEAD_OF_DRAWER = new BooleanPreference("use_dashboard_instead_of_drawer", true).makeGlobal().cache(); + public final CommonPreference USE_DASHBOARD_INSTEAD_OF_DRAWER = new BooleanPreference("use_dashboard_instead_of_drawer", false).makeGlobal().cache(); // this value string is synchronized with settings_pref.xml preference name public final CommonPreference USE_INTERNET_TO_DOWNLOAD_TILES = new BooleanPreference("use_internet_to_download_tiles", true).makeGlobal().cache(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java index 418aaefb7f..bf6bba6be8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java @@ -1,40 +1,26 @@ package net.osmand.plus.activities; -import java.io.File; import java.lang.ref.WeakReference; import java.util.List; -import java.util.Random; import net.osmand.Location; -import net.osmand.access.AccessibleAlertBuilder; import net.osmand.plus.AppInitializer; import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmAndLocationProvider; -import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.dashboard.DashDownloadMapsFragment; import net.osmand.plus.dashboard.DashErrorFragment; -import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashUpdatesFragment; import net.osmand.plus.dashboard.NotifyingScrollView; import net.osmand.plus.download.BaseDownloadActivity; -import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.IndexItem; -import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.sherpafy.TourViewActivity; import net.osmand.plus.views.controls.FloatingActionButton; -import android.app.Activity; -import android.app.AlertDialog.Builder; import android.app.Dialog; -import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; -import android.content.pm.ApplicationInfo; -import android.content.pm.PackageManager; -import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Resources; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; @@ -44,7 +30,6 @@ import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.ActionBar; -import android.text.method.LinkMovementMethod; import android.util.TypedValue; import android.view.Gravity; import android.view.Menu; @@ -53,7 +38,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.ScrollView; -import android.widget.TextView; /** @@ -302,22 +286,19 @@ public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLoca @Override public void updateCompassValue(float value) { - for (WeakReference ref : fragList) { - Fragment f = ref.get(); - if (f instanceof DashLocationFragment && !f.isDetached()) { - ((DashLocationFragment) f).updateCompassValue(value); - } - } + // +// throw new UnsupportedOperationException(); } @Override public void updateLocation(Location location) { - for (WeakReference ref : fragList) { - Fragment f = ref.get(); - if (f instanceof DashLocationFragment && !f.isDetached()) { - ((DashLocationFragment) f).updateLocation(location); - } - } +// for (WeakReference ref : fragList) { +// Fragment f = ref.get(); +// if (f instanceof DashLocationFragment && !f.isDetached()) { +// ((DashLocationFragment) f).updateLocation(location); +// } +// } +// throw new UnsupportedOperationException(); } private OsmAndLocationProvider getLocationProvider() { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 2ace5e57d2..50597a22f8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -142,6 +142,9 @@ public class MapActivity extends AccessibleActivity { setContentView(R.layout.main); mapActions = new MapActivityActions(this); mapLayers = new MapActivityLayers(this); + if (mapViewTrackingUtilities == null) { + mapViewTrackingUtilities = new MapViewTrackingUtilities(app); + } dashboardOnMap.createDashboardView(); if (app.isApplicationInitializing() || DashboardOnMap.staticVisible) { @@ -168,11 +171,12 @@ public class MapActivity extends AccessibleActivity { @Override public void onFinish(AppInitializer init) { - applicationInitialized(); if(!openGlSetup) { setupOpenGLView(); } - mapView.refreshMap(); + mapView.refreshMap(true); + findViewById(R.id.init_progress).setVisibility(View.GONE); + findViewById(R.id.ParentLayout).invalidate(); } }; getMyApplication().checkApplicationIsBeingInitialized(this, initListener); @@ -194,9 +198,6 @@ public class MapActivity extends AccessibleActivity { } }); mapView.setAccessibilityActions(new MapAccessibilityActions(this)); - if (mapViewTrackingUtilities == null) { - mapViewTrackingUtilities = new MapViewTrackingUtilities(app); - } mapViewTrackingUtilities.setMapView(mapView); app.getResourceManager().getMapTileDownloader().addDownloaderCallback(new IMapDownloaderCallback() { @@ -243,11 +244,6 @@ public class MapActivity extends AccessibleActivity { } } - private void applicationInitialized() { - mapView.refreshMap(true); - findViewById(R.id.init_progress).setVisibility(View.GONE); - findViewById(R.id.ParentLayout).invalidate(); - } private void setupOpenGLView() { if (settings.USE_OPENGL_RENDER.get() && NativeCoreContext.isInit()) { @@ -259,6 +255,7 @@ public class MapActivity extends AccessibleActivity { atlasMapRendererView.setElevationAngle(90); NativeCoreContext.getMapRendererContext().setMapRendererView(atlasMapRendererView); mapView = ml.getMapView(); + mapViewTrackingUtilities.setMapView(mapView); mapView.setMapRender(atlasMapRendererView); OsmAndMapSurfaceView surf = (OsmAndMapSurfaceView) findViewById(R.id.MapView); surf.setVisibility(View.GONE); @@ -693,8 +690,18 @@ public class MapActivity extends AccessibleActivity { } public LatLon getMapLocation() { + if(mapView == null) { + return settings.getLastKnownMapLocation(); + } return new LatLon(mapView.getLatitude(), mapView.getLongitude()); } + + public float getMapRotate() { + if(mapView == null) { + return 0; + } + return mapView.getRotate(); + } // Duplicate methods to OsmAndApplication public TargetPoint getPointToNavigate() { diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index ef563c2bbe..fc659abf7b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -785,7 +785,8 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa } } if(loc != null){ - DirectionDrawable draw = new DirectionDrawable(SearchPOIActivity.this, width, height, R.drawable.ic_destination_arrow_white); + DirectionDrawable draw = new DirectionDrawable(SearchPOIActivity.this, width, height, + R.drawable.ic_destination_arrow_white, R.color.color_distance); Float h = heading; float a = h != null ? h : 0; diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index ce0478f9b6..18eb311f6c 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -15,6 +15,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.AutoZoomMap; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper.TargetPoint; +import net.osmand.plus.dashboard.DashboardOnMap; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener; import net.osmand.plus.views.AnimateDraggingMapThread; @@ -29,6 +30,7 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc private long lastTimeAutoZooming = 0; private boolean sensorRegistered = false; private OsmandMapTileView mapView; + private DashboardOnMap dashboard; private OsmandSettings settings; private OsmandApplication app; // by default turn off causing unexpected movements due to network establishing @@ -80,6 +82,17 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc mapView.refreshMap(); } } + if(dashboard != null) { + dashboard.updateCompassValue(val); + } + } + + public void setDashboard(DashboardOnMap dashboard) { + this.dashboard = dashboard; + } + + public DashboardOnMap getDashboard() { + return dashboard; } @Override @@ -121,6 +134,10 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc // When location is changed we need to refresh map in order to show movement! mapView.refreshMap(); } + + if(dashboard != null) { + dashboard.updateMyLocation(location); + } } private boolean isSmallSpeedForCompass(Location location) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java index dfc9fbaa68..805c34e466 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java @@ -11,7 +11,7 @@ import net.osmand.plus.activities.MapActivity; */ public abstract class DashBaseFragment extends Fragment { - private DashboardOnMap dashboard; + protected DashboardOnMap dashboard; public OsmandApplication getMyApplication(){ if (getActivity() == null){ diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java index 3fdad84b56..e16aff01be 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java @@ -5,13 +5,11 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import net.osmand.Location; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.OsmAndAppCustomization; -import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.FavoriteImageDrawable; @@ -35,11 +33,8 @@ import android.widget.TextView; /** * Created by Denis on 24.11.2014. */ -public class DashFavoritesFragment extends DashLocationFragment implements FavouritesDbHelper.FavoritesUpdatedListener { +public class DashFavoritesFragment extends DashLocationFragment { public static final String TAG = "DASH_FAVORITES_FRAGMENT"; - private net.osmand.Location location = null; - - private List arrows = new ArrayList(); List points = new ArrayList(); @Override @@ -63,19 +58,8 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou return view; } - @Override - public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - } - @Override public void onOpenDash() { - // This is used as origin for both Fav-list and direction arrows - if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { - loc = getMyApplication().getSettings().getLastKnownMapLocation(); - } else { - loc = new LatLon(0f, 0f); - } setupFavorites(); } @@ -83,25 +67,26 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou View mainView = getView(); final FavouritesDbHelper helper = getMyApplication().getFavorites(); points = new ArrayList(helper.getFavouritePoints()); - arrows.clear(); if (points.size() == 0) { (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE); return; } else { (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE); } - - Collections.sort(points, new Comparator() { - @Override - public int compare(FavouritePoint point, FavouritePoint point2) { - // LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); - int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), loc.getLatitude(), - loc.getLongitude())); - int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(), loc.getLatitude(), - loc.getLongitude())); - return (dist - dist2); - } - }); + final LatLon loc = getDefaultLocation(); + if (loc != null) { + Collections.sort(points, new Comparator() { + @Override + public int compare(FavouritePoint point, FavouritePoint point2) { + // LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); + int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), + loc.getLatitude(), loc.getLongitude())); + int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(), + loc.getLatitude(), loc.getLongitude())); + return (dist - dist2); + } + }); + } LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items); favorites.removeAllViews(); if (points.size() > 3) { @@ -109,12 +94,15 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou points.remove(3); } } + List distances = new ArrayList(); for (final FavouritePoint point : points) { LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.favorites_list_item, null, false); TextView name = (TextView) view.findViewById(R.id.favourite_label); TextView label = (TextView) view.findViewById(R.id.distance); ImageView direction = (ImageView) view.findViewById(R.id.direction); + direction.setVisibility(View.VISIBLE); + label.setVisibility(View.VISIBLE); view.findViewById(R.id.divider).setVisibility(View.VISIBLE); if (point.getCategory().length() > 0) { ((TextView) view.findViewById(R.id.group_name)).setText(point.getCategory()); @@ -124,19 +112,11 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou ((ImageView) view.findViewById(R.id.favourite_icon)).setImageDrawable(FavoriteImageDrawable.getOrCreate( getActivity(), point.getColor())); + DashLocationView dv = new DashLocationView(direction, label, new LatLon(point.getLatitude(), + point.getLongitude())); + distances.add(dv); - if (loc != null) { - direction.setVisibility(View.VISIBLE); - updateArrow(getActivity(), loc, new LatLon(point.getLatitude(), point.getLongitude()), direction, 10, - R.drawable.ic_destination_arrow, heading); - } - arrows.add(direction); name.setText(point.getName()); - - // LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); - int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), loc.getLatitude(), - loc.getLongitude())); - String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " "; view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE); view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() { @Override @@ -146,7 +126,6 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName())); } }); - label.setText(distance, TextView.BufferType.SPANNABLE); label.setTypeface(Typeface.DEFAULT, point.isVisible() ? Typeface.NORMAL : Typeface.ITALIC); view.setOnClickListener(new View.OnClickListener() { @Override @@ -159,42 +138,8 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou }); favorites.addView(view); } - updateLocation(location); + this.distances = distances; } - private void updateArrows() { - if (loc == null) { - return; - } - for (int i = 0; i < arrows.size(); i++) { - arrows.get(i).setVisibility(View.VISIBLE); - updateArrow(getActivity(), loc, new LatLon(points.get(i).getLatitude(), points.get(i).getLongitude()), - arrows.get(i), 10, R.drawable.ic_destination_arrow, heading); - } - } - - @Override - public boolean updateCompassValue(float value) { - if (super.updateCompassValue(value)) { - updateArrows(); - } - return true; - } - - @Override - public void updateLocation(Location location) { - super.updateLocation(location); - updateArrows(); - } - - @Override - public void updateFavourites() { - getActivity().runOnUiThread(new Runnable() { - @Override - public void run() { - setupFavorites(); - } - }); - } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java index 1b14d08daa..b48242efa4 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java @@ -1,51 +1,56 @@ 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.R; import net.osmand.plus.views.DirectionDrawable; -import net.osmand.util.MapUtils; -import android.app.Activity; +import android.annotation.SuppressLint; import android.content.Context; import android.hardware.Sensor; import android.hardware.SensorManager; import android.view.WindowManager; import android.widget.ImageView; +import android.widget.TextView; /** * Created by Denis * on 26.01.2015. */ +@SuppressLint("ResourceAsColor") public abstract class DashLocationFragment extends DashBaseFragment { private static final int ORIENTATION_0 = 0; private static final int ORIENTATION_90 = 3; private static final int ORIENTATION_270 = 1; private static final int ORIENTATION_180 = 2; - - protected Float heading = null; - - protected LatLon loc = null; - - public void updateLocation(Location location) { - //This is used as origin for both Fav-list and direction arrows - if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { - loc = getMyApplication().getSettings().getLastKnownMapLocation(); - } else { - loc = new LatLon(0f, 0f); + protected List distances = new ArrayList(); + private int screenOrientation; + + public static class DashLocationView { + public boolean useOnlyMyLocation; + public ImageView arrow; + public TextView txt; + public LatLon loc; + + public DashLocationView(ImageView arrow, TextView txt, LatLon loc) { + super(); + this.arrow = arrow; + this.txt = txt; + this.loc = loc; } + + } - public static void updateArrow(Activity ctx, LatLon currentLocation, LatLon pointLocation, - ImageView direction, int size, int resourceId, Float heading) { - float[] mes = new float[2]; - Location.distanceBetween(pointLocation.getLatitude(), pointLocation.getLongitude(), currentLocation.getLatitude(), currentLocation.getLongitude(), mes); - DirectionDrawable draw = new DirectionDrawable(ctx, size, size, resourceId); - Float h = heading; - float a = h != null ? h : 0; - + + @Override + public void onOpenDash() { //Hardy: getRotation() is the correction if device's screen orientation != the default display's standard orientation - int screenOrientation = 0; - screenOrientation = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); + screenOrientation = 0; + screenOrientation = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); switch (screenOrientation) { case ORIENTATION_0: // Device default (normally portrait) @@ -61,29 +66,80 @@ public abstract class DashLocationFragment extends DashBaseFragment { screenOrientation = 180; break; } - //Looks like screenOrientation correction must not be applied for devices without compass? - Sensor compass = ((SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); + Sensor compass = ((SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); if (compass == null) { screenOrientation = 0; - } - - draw.setAngle(mes[1] - a + 180 + screenOrientation); - - direction.setImageDrawable(draw); + } } - public boolean updateCompassValue(float value) { - //heading = value; - //updateArrows(); - //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) { - return true; - } else { - heading = lastHeading; + public LatLon getDefaultLocation() { + DashboardOnMap d = dashboard; + if(d == null) { + return null; } - return false; + return d.getMapViewLocation(); + } + + public void updateAllWidgets() { + DashboardOnMap d = dashboard; + if(d == null) { + return; + } + float head = d.getHeading(); + float mapRotation = d.getMapRotation(); + LatLon mw = d.getMapViewLocation(); + 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; + LatLon loc = (useCenter ? mw : myLoc); + float h = useCenter ? -mapRotation : head; + float[] mes = new float[2]; + if (loc != null) { + Location.distanceBetween(lv.loc.getLatitude(), lv.loc.getLongitude(), loc.getLatitude(), + loc.getLongitude(), mes); + } + if (lv.arrow != null) { + if (!(lv.arrow.getDrawable() instanceof DirectionDrawable)) { + DirectionDrawable dd = new DirectionDrawable(getActivity(), 10, 10); + lv.arrow.setImageDrawable(dd); + } + DirectionDrawable dd = (DirectionDrawable) lv.arrow.getDrawable(); + dd.setImage(R.drawable.ic_destination_arrow_white, useCenter ? R.color.color_distance + : R.color.color_myloc_distance); + if (loc == null) { + dd.setAngle(0); + } else { + dd.setAngle(mes[1] - h + 180 + screenOrientation); + } + lv.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())); + } else { + lv.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(); + } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java index 1cce8ebb6a..60d96f787b 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java @@ -3,7 +3,6 @@ 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.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; @@ -18,9 +17,7 @@ import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.util.Algorithms; import android.app.Activity; import android.content.Intent; -import android.graphics.PorterDuff; import android.graphics.Typeface; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; @@ -39,7 +36,6 @@ public class DashRecentsFragment extends DashLocationFragment { private List arrows = new ArrayList(); List points = new ArrayList(); - Drawable icon; @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -63,22 +59,11 @@ public class DashRecentsFragment extends DashLocationFragment { activity.startActivity(search); } }); - icon = getResources().getDrawable(R.drawable.ic_type_coordinates); - if (getMyApplication().getSettings().isLightContent()) { - icon = icon.mutate(); - icon.setColorFilter(getResources().getColor(R.color.icon_color_light), PorterDuff.Mode.MULTIPLY); - } return view; } @Override public void onOpenDash() { - // This is used as origin for both Fav-list and direction arrows - if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { - loc = getMyApplication().getSettings().getLastKnownMapLocation(); - } else { - loc = new LatLon(0f, 0f); - } setupRecents(); } @@ -100,6 +85,8 @@ public class DashRecentsFragment extends DashLocationFragment { if (points.size() > 3) { points = points.subList(0, 3); } + LatLon loc = getDefaultLocation(); + List distances = new ArrayList(); for (final HistoryEntry historyEntry : points) { LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.search_history_list_item, null, false); @@ -120,34 +107,14 @@ public class DashRecentsFragment extends DashLocationFragment { MapActivity.launchMapActivityMoveToTop(getActivity()); } }); + DashLocationView dv = new DashLocationView((ImageView) view.findViewById(R.id.direction), + (TextView) view.findViewById(R.id.distance), new LatLon(historyEntry.getLat(), + historyEntry.getLon())); + distances.add(dv); recents.addView(view); } + this.distances = distances; } - private void updateArrows() { - if (loc == null) { - return; - } - - for (int i = 0; i < arrows.size(); i++) { - arrows.get(i).setVisibility(View.VISIBLE); - updateArrow(getActivity(), loc, new LatLon(points.get(i).getLat(), points.get(i).getLon()), arrows.get(i), - 10, R.drawable.ic_destination_arrow, heading); - } - } - - @Override - public boolean updateCompassValue(float value) { - if (super.updateCompassValue(value)) { - updateArrows(); - } - return true; - } - - @Override - public void updateLocation(Location location) { - super.updateLocation(location); - updateArrows(); - } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index 95daf0c267..ed25685952 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -5,6 +5,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import net.osmand.data.LatLon; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -50,6 +51,11 @@ public class DashboardOnMap { private boolean visible = false; private boolean landscape; private List> fragList = new LinkedList>(); + private net.osmand.Location myLocation; + private LatLon mapViewLocation; + private float heading; + private boolean mapLinkedToLocation; + private float mapRotation; public DashboardOnMap(MapActivity ma) { @@ -71,6 +77,16 @@ public class DashboardOnMap { dashboardView.findViewById(R.id.content).setOnClickListener(listener); dashboardView.setOnClickListener(listener); ((FrameLayout) mapActivity.findViewById(R.id.ParentLayout)).addView(dashboardView); + + dashboardView.findViewById(R.id.map_layers_button).setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + setDashboardVisibility(false); + mapActivity.getMapActions().prepareConfigureMap(); + mapActivity.getMapActions().toggleDrawer(); + } + }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { fabButton = new FloatingActionButton.Builder(mapActivity) @@ -98,17 +114,40 @@ public class DashboardOnMap { } } - - + + public net.osmand.Location getMyLocation() { + return myLocation; + } + + public LatLon getMapViewLocation() { + return mapViewLocation; + } + + public float getHeading() { + return heading; + } + + public float getMapRotation() { + return mapRotation; + } + + public boolean isMapLinkedToLocation() { + return mapLinkedToLocation; + } + protected OsmandApplication getMyApplication() { return mapActivity.getMyApplication(); } - public void setDashboardVisibility(boolean visible) { this.visible = visible; DashboardOnMap.staticVisible = visible; if (visible) { + mapViewLocation = mapActivity.getMapLocation(); + mapRotation = mapActivity.getMapRotate(); + mapLinkedToLocation = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation(); + myLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); + mapActivity.getMapViewTrackingUtilities().setDashboard(this); addOrUpdateDashboardFragments(); setupActionBar(); dashboardView.setVisibility(View.VISIBLE); @@ -117,8 +156,10 @@ public class DashboardOnMap { mapActivity.getMapActions().disableDrawer(); mapActivity.findViewById(R.id.MapInfoControls).setVisibility(View.GONE); mapActivity.findViewById(R.id.MapButtons).setVisibility(View.GONE); + updateLocation(true, true, false); } else { mapActivity.getMapActions().enableDrawer(); + mapActivity.getMapViewTrackingUtilities().setDashboard(null); hide(dashboardView.findViewById(R.id.animateContent)); mapActivity.findViewById(R.id.MapInfoControls).setVisibility(View.VISIBLE); mapActivity.findViewById(R.id.MapButtons).setVisibility(View.VISIBLE); @@ -284,6 +325,7 @@ public class DashboardOnMap { ((FrameLayout) fabButton.getParent()).updateViewLayout(fabButton, lp); } }; + public boolean isVisible() { return visible; @@ -298,8 +340,41 @@ public class DashboardOnMap { } } } + + private boolean inLocationUpdate = false; + public void updateLocation(final boolean centerChanged, final boolean locationChanged, final boolean compassChanged){ + if(inLocationUpdate) { + return ; + } + inLocationUpdate = true; + mapActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + inLocationUpdate = false; + for (WeakReference df : fragList) { + if (df.get() instanceof DashLocationFragment) { + ((DashLocationFragment)df.get()).updateLocation(centerChanged, locationChanged, compassChanged); + } + } + } + }); + + } + + public void updateMyLocation(net.osmand.Location location) { + myLocation = location; + updateLocation(false, true, false); + } + + public void updateCompassValue(double heading) { + this.heading = (float) heading; + updateLocation(false, false, true); + } public void onAttach(DashBaseFragment dashBaseFragment) { fragList.add(new WeakReference(dashBaseFragment)); } + + + } diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java b/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java index 55f42810c7..ee9f917403 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java @@ -50,11 +50,6 @@ public class DashParkingFragment extends DashLocationFragment { @Override public void onOpenDash() { plugin = OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class); - if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { - loc = getMyApplication().getSettings().getLastKnownMapLocation(); - } else { - loc = new LatLon(0f, 0f); - } updateParkingPosition(); } @@ -69,38 +64,18 @@ public class DashParkingFragment extends DashLocationFragment { LatLon position = plugin.getParkingPosition(); - int dist = (int) (MapUtils.getDistance(position.getLatitude(), position.getLongitude(), loc.getLatitude(), - loc.getLongitude())); - String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()); - ((TextView) mainView.findViewById(R.id.distance)).setText(distance); - // TODO add parking time - String parking_name = plugin.getParkingType() ? getString(R.string.parking_place) - : getString(R.string.parking_place); - ((TextView) mainView.findViewById(R.id.name)).setText(parking_name); - ImageView direction = (ImageView) mainView.findViewById(R.id.direction_icon); - if (loc != null) { - direction.setVisibility(View.VISIBLE); - updateArrow(getActivity(), loc, position, direction, 10, R.drawable.ic_destination_arrow, heading); - } - } - - @Override - public boolean updateCompassValue(float value) { - if (plugin == null) { - return true; - } - if (super.updateCompassValue(value)) { - updateParkingPosition(); - } - return true; - } - - @Override - public void updateLocation(Location location) { - super.updateLocation(location); - if (plugin == null) { - return; - } - updateParkingPosition(); +// int dist = (int) (MapUtils.getDistance(position.getLatitude(), position.getLongitude(), loc.getLatitude(), +// loc.getLongitude())); +// String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()); +// ((TextView) mainView.findViewById(R.id.distance)).setText(distance); +// // TODO add parking time +// String parking_name = plugin.getParkingType() ? getString(R.string.parking_place) +// : getString(R.string.parking_place); +// ((TextView) mainView.findViewById(R.id.name)).setText(parking_name); +// ImageView direction = (ImageView) mainView.findViewById(R.id.direction_icon); +// if (loc != null) { +// direction.setVisibility(View.VISIBLE); +// updateArrow(getActivity(), loc, position, direction, 10, R.drawable.ic_destination_arrow, heading); +// } } } diff --git a/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java b/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java index e2be4cc135..e2605b3e0d 100644 --- a/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java +++ b/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java @@ -5,7 +5,7 @@ import android.graphics.*; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.view.WindowManager; - +import net.osmand.plus.IconsCache; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -20,10 +20,17 @@ public class DirectionDrawable extends Drawable { Context ctx; private float angle; int resourceId = -1; + Drawable arrowImage ; - public DirectionDrawable(Context ctx, float width, float height, int resourceId) { + public DirectionDrawable(Context ctx, float width, float height, int resourceId, int clrId) { this(ctx, width, height); - this.resourceId = resourceId; + IconsCache iconsCache = ((OsmandApplication) ctx.getApplicationContext()).getIconsCache(); + arrowImage = iconsCache.getIcon(resourceId, clrId); + } + + public void setImage(int resourceId, int clrId) { + IconsCache iconsCache = ((OsmandApplication) ctx.getApplicationContext()).getIconsCache(); + arrowImage = iconsCache.getIcon(resourceId, clrId); } @@ -54,15 +61,16 @@ public class DirectionDrawable extends Drawable { @Override public void draw(Canvas canvas) { - if (resourceId != -1) { + if (arrowImage != null) { canvas.rotate(angle, canvas.getHeight() / 2, canvas.getWidth() / 2); - - Drawable arrowImage = ctx.getResources().getDrawable(resourceId); - Bitmap arrow = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); - Canvas canv = new Canvas(arrow); arrowImage.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); - arrowImage.draw(canv); - canvas.drawBitmap(arrow, null, new Rect(0, 0, arrow.getHeight(), arrow.getWidth()), null); + arrowImage.draw(canvas); + // TODO delete? +// Bitmap arrow = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); +// Canvas canv = new Canvas(arrow); +// arrowImage.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); +// arrowImage.draw(canv); +// canvas.drawBitmap(arrow, null, new Rect(0, 0, arrow.getHeight(), arrow.getWidth()), null); } else { canvas.rotate(angle, canvas.getHeight()/2, canvas.getWidth() / 2); Path directionPath = createDirectionPath();