From 9159870021ec9826aa679c0e5201af009c9705a8 Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 10 Feb 2015 14:00:52 +0200 Subject: [PATCH 01/11] Change size of split toolbar --- OsmAnd/res/layout/search_activity_single.xml | 2 +- OsmAnd/res/layout/searchpoi.xml | 2 +- OsmAnd/res/layout/tab_content.xml | 2 +- OsmAnd/res/values/sizes.xml | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/search_activity_single.xml b/OsmAnd/res/layout/search_activity_single.xml index 94896b49da..3b86307ca6 100644 --- a/OsmAnd/res/layout/search_activity_single.xml +++ b/OsmAnd/res/layout/search_activity_single.xml @@ -16,5 +16,5 @@ android:orientation="horizontal" android:id="@+id/bottomControls" android:layout_width="fill_parent" - android:layout_height="wrap_content"/> + android:layout_height="@dimen/bottom_tool_bar_size"/> \ No newline at end of file diff --git a/OsmAnd/res/layout/searchpoi.xml b/OsmAnd/res/layout/searchpoi.xml index e9ac1dea59..6bc24a5438 100644 --- a/OsmAnd/res/layout/searchpoi.xml +++ b/OsmAnd/res/layout/searchpoi.xml @@ -42,6 +42,6 @@ android:background="?attr/bottomToolBarColor" android:id="@+id/bottomControls" android:layout_width="fill_parent" - android:layout_height="wrap_content"/> + android:layout_height="@dimen/bottom_tool_bar_size"/> \ No newline at end of file diff --git a/OsmAnd/res/layout/tab_content.xml b/OsmAnd/res/layout/tab_content.xml index 49772045b3..cfba713a53 100644 --- a/OsmAnd/res/layout/tab_content.xml +++ b/OsmAnd/res/layout/tab_content.xml @@ -20,6 +20,6 @@ android:id="@+id/bottomControls" android:background="?attr/bottomToolBarColor" android:layout_width="fill_parent" - android:layout_height="wrap_content"/> + android:layout_height="@dimen/bottom_tool_bar_size"/> \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 5bb6c505b2..90f63dc307 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -26,6 +26,7 @@ 8dp 48dp 50dp + 48dp 12sp From 55b058293cfcb1c99bede8fe1a2ddf9f2492059f Mon Sep 17 00:00:00 2001 From: Denis Date: Tue, 10 Feb 2015 19:18:44 +0200 Subject: [PATCH 02/11] Favorites list item view changed --- OsmAnd/res/layout/favourites_list_item.xml | 88 +++++++++++++++---- OsmAnd/res/values/sizes.xml | 1 + .../plus/activities/FavoritesActivity.java | 45 +++++++++- .../activities/FavoritesTreeFragment.java | 56 ++++++++++-- .../plus/activities/MainMenuActivity.java | 7 +- .../plus/dashboard/DashFavoritesFragment.java | 8 +- .../plus/dashboard/DashLocationFragment.java | 12 +-- .../parkingpoint/DashParkingFragment.java | 2 +- 8 files changed, 179 insertions(+), 40 deletions(-) diff --git a/OsmAnd/res/layout/favourites_list_item.xml b/OsmAnd/res/layout/favourites_list_item.xml index e9aa13ad9e..246b24c3c4 100644 --- a/OsmAnd/res/layout/favourites_list_item.xml +++ b/OsmAnd/res/layout/favourites_list_item.xml @@ -3,12 +3,12 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="wrap_content" + android:background="?attr/expandable_list_item_background" android:minHeight="@dimen/list_item_height" android:orientation="horizontal" android:paddingBottom="5dp" android:paddingLeft="@dimen/list_content_padding" android:paddingRight="@dimen/list_content_padding" - android:background="?attr/expandable_list_item_background" android:paddingTop="5dp"> + - + - + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 90f63dc307..2c9ad066f5 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -27,6 +27,7 @@ 48dp 50dp 48dp + 18dp 12sp diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java index 9e9a64b54c..4c552b759b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java @@ -18,7 +18,10 @@ import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.style.ImageSpan; import android.view.MenuItem; + +import net.osmand.Location; import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -35,12 +38,14 @@ import android.widget.TabHost; import android.widget.TabHost.TabSpec; import android.widget.TabWidget; import android.widget.TextView; + +import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.views.controls.PagerSlidingTabStrip; /** * */ -public class FavoritesActivity extends TabActivity { +public class FavoritesActivity extends TabActivity implements OsmAndLocationProvider.OsmAndCompassListener, OsmAndLocationProvider.OsmAndLocationListener { private static final String FAVOURITES_INFO = "FAVOURITES_INFO"; private static final String TRACKS = "TRACKS"; @@ -119,12 +124,28 @@ public class FavoritesActivity extends TabActivity { updateSelectedTracks(); } }); + + if (getMyApplication().getFavorites().getFavouritePoints().size() > 0) { + getLocationProvider().addCompassListener(this); + getLocationProvider().registerOrUnregisterCompassListener(true); + } } - + + public OsmandApplication getMyApplication() { + return (OsmandApplication) getApplication(); + } + + private OsmAndLocationProvider getLocationProvider() { + return getMyApplication().getLocationProvider(); + } + @Override protected void onPause() { super.onPause(); ((OsmandApplication) getApplication()).getSelectedGpxHelper().setUiListener(FavoritesActivity.class, null); + getLocationProvider().pauseAllUpdates(); + getLocationProvider().removeLocationListener(this); + getLocationProvider().removeCompassListener(this); } public void updateSelectedTracks() { @@ -196,5 +217,25 @@ public class FavoritesActivity extends TabActivity { } } + + @Override + public void updateCompassValue(float value) { + for (WeakReference ref : fragList) { + Fragment f = ref.get(); + if (f instanceof FavoritesTreeFragment && !f.isDetached()) { + ((FavoritesTreeFragment) f).updateCompassValue(value); + } + } + } + + @Override + public void updateLocation(Location location) { + for (WeakReference ref : fragList) { + Fragment f = ref.get(); + if (f instanceof FavoritesTreeFragment && !f.isDetached()) { + ((FavoritesTreeFragment) f).updateLocation(location); + } + } + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 511944fa47..8dbc7aa1c9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -18,6 +18,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import net.osmand.Location; import net.osmand.access.AccessibleToast; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; @@ -33,6 +34,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.base.FavoriteImageDrawable; +import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.helpers.ColorDialogs; import net.osmand.plus.helpers.ScreenOrientationHelper; @@ -62,6 +64,8 @@ import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; +import org.w3c.dom.Text; + public class FavoritesTreeFragment extends OsmandExpandableListFragment { @@ -83,6 +87,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { private ActionMode actionMode; private SearchView searchView; + protected LatLon loc = null; + protected Float heading = null; + @Override public void onAttach(Activity activity) { super.onAttach(activity); @@ -125,6 +132,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { // final LatLon mapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); favouritesAdapter.synchronizeGroups(); + loc = getMyApplication().getSettings().getLastKnownMapLocation(); if(favouritesAdapter.getGroupCount() > 0 && "".equals(favouritesAdapter.getGroup(0).name)) { getExpandableListView().expandGroup(0); @@ -761,7 +769,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { row = inflater.inflate(R.layout.favourites_list_item, parent, false); } - TextView label = (TextView) row.findViewById(R.id.favourite_label); + TextView name = (TextView) row.findViewById(R.id.favourite_label); + TextView distanceText = (TextView) row.findViewById(R.id.distance); ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon); final FavouritePoint model = (FavouritePoint) getChild(groupPosition, childPosition); row.setTag(model); @@ -770,11 +779,19 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(), lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude())); String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " "; - label.setText(distance + model.getName(), TextView.BufferType.SPANNABLE); - label.setTypeface(Typeface.DEFAULT, model.isVisible() ? Typeface.NORMAL : Typeface.ITALIC); - ((Spannable) label.getText()).setSpan( - new ForegroundColorSpan(getResources().getColor(R.color.color_distance)), 0, distance.length() - 1, - 0); + name.setText(model.getName(), TextView.BufferType.SPANNABLE); + name.setTypeface(Typeface.DEFAULT, model.isVisible() ? Typeface.NORMAL : Typeface.ITALIC); + distanceText.setText(distance); + distanceText.setTextColor(getResources().getColor(R.color.color_distance)); + row.findViewById(R.id.group_image).setVisibility(View.GONE); + + if(loc != null){ + ImageView direction = (ImageView) row.findViewById(R.id.direction); + direction.setVisibility(View.VISIBLE); + DashLocationFragment.updateArrow(getActivity(), loc, new LatLon(model.getLatitude(), model.getLongitude()), direction, + 10, R.drawable.ic_destination_arrow, heading); + } + final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item); if (selectionMode) { ch.setVisibility(View.VISIBLE); @@ -862,5 +879,32 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { } } + 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); + } + updateArrows(); + } + 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) { + updateArrows(); + return true; + } else { + heading = lastHeading; + } + return false; + } + + private void updateArrows(){ + favouritesAdapter.notifyDataSetChanged(); + } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java index 1a128bce0a..2f967f7d68 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MainMenuActivity.java @@ -26,7 +26,6 @@ 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; import android.app.AlertDialog.Builder; import android.app.Dialog; import android.content.DialogInterface; @@ -139,9 +138,9 @@ public class MainMenuActivity extends BaseDownloadActivity implements OsmAndLoca @Override public void onPause() { super.onPause(); - getMyApplication().getLocationProvider().pauseAllUpdates(); - getMyApplication().getLocationProvider().removeLocationListener(this); - getMyApplication().getLocationProvider().removeCompassListener(this); + getLocationProvider().pauseAllUpdates(); + getLocationProvider().removeLocationListener(this); + getLocationProvider().removeCompassListener(this); } @Override diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java index 844a4723bc..19af772606 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java @@ -139,8 +139,8 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou if(loc != null){ direction.setVisibility(View.VISIBLE); - updateArrow(new LatLon(point.getLatitude(), point.getLongitude()), direction, - 10, R.drawable.ic_destination_arrow); + updateArrow(getActivity(), loc, new LatLon(point.getLatitude(), point.getLongitude()), direction, + 10, R.drawable.ic_destination_arrow, heading); } arrows.add(direction); name.setText(point.getName()); @@ -177,8 +177,8 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou for (int i = 0; i < arrows.size(); i++) { arrows.get(i).setVisibility(View.VISIBLE); - updateArrow(new LatLon(points.get(i).getLatitude(),points.get(i).getLongitude()), - arrows.get(i), 10, R.drawable.ic_destination_arrow); + updateArrow(getActivity(), loc, new LatLon(points.get(i).getLatitude(), points.get(i).getLongitude()), + arrows.get(i), 10, R.drawable.ic_destination_arrow, heading); } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java index 78140a9310..0953380ddb 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java @@ -1,5 +1,6 @@ package net.osmand.plus.dashboard; +import android.app.Activity; import android.content.Context; import android.hardware.Sensor; import android.hardware.SensorManager; @@ -36,16 +37,17 @@ public class DashLocationFragment extends DashBaseFragment { } } - protected void updateArrow(LatLon l, ImageView direction, int size, int resourceId) { + 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(l.getLatitude(), l.getLongitude(), loc.getLatitude(), loc.getLongitude(), mes); - DirectionDrawable draw = new DirectionDrawable(getActivity(), size, size, resourceId); + 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; //Hardy: getRotation() is the correction if device's screen orientation != the default display's standard orientation int screenOrientation = 0; - screenOrientation = ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); + screenOrientation = ((WindowManager) ctx.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); switch (screenOrientation) { case ORIENTATION_0: // Device default (normally portrait) @@ -63,7 +65,7 @@ public class DashLocationFragment extends DashBaseFragment { } //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) ctx.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); if (compass == null) { screenOrientation = 0; } diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java b/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java index 184b33f5c3..9a706542bb 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java @@ -86,7 +86,7 @@ public class DashParkingFragment extends DashLocationFragment { ImageView direction = (ImageView) mainView.findViewById(R.id.direction_icon); if (loc != null){ direction.setVisibility(View.VISIBLE); - updateArrow(position, direction, 10, R.drawable.ic_destination_arrow); + updateArrow(getActivity(), loc, position, direction, 10, R.drawable.ic_destination_arrow, heading); } } From 4a2f288d50a5d9dba8ae51831b7c2e57371b9924 Mon Sep 17 00:00:00 2001 From: Denis Date: Wed, 11 Feb 2015 13:29:25 +0200 Subject: [PATCH 03/11] Updated lists design --- OsmAnd/res/layout/expandable_list.xml | 1 + .../layout/expandable_list_item_category.xml | 63 +++++++-------- .../expandable_list_item_category_btn.xml | 68 +++++++--------- OsmAnd/res/layout/favourites_list_item.xml | 10 +-- OsmAnd/res/layout/searchpoi_list.xml | 78 +++++++++++-------- OsmAnd/res/values/attrs.xml | 2 + OsmAnd/res/values/colors.xml | 7 +- OsmAnd/res/values/sizes.xml | 7 ++ OsmAnd/res/values/styles.xml | 10 ++- .../activities/FavoritesTreeFragment.java | 3 - .../activities/search/SearchPOIActivity.java | 17 +++- .../DashAudioVideoNotesActivity.java | 2 +- .../osmand/plus/views/DirectionDrawable.java | 13 +++- 13 files changed, 154 insertions(+), 127 deletions(-) diff --git a/OsmAnd/res/layout/expandable_list.xml b/OsmAnd/res/layout/expandable_list.xml index 79266d46b4..952f2196f5 100644 --- a/OsmAnd/res/layout/expandable_list.xml +++ b/OsmAnd/res/layout/expandable_list.xml @@ -20,6 +20,7 @@ style="@style/OsmandListView" android:layout_width="fill_parent" android:layout_height="fill_parent" + android:background="?attr/expandable_list_background" android:layout_marginLeft="0dp" android:layout_marginRight="0dp" android:layout_marginTop="0dp" diff --git a/OsmAnd/res/layout/expandable_list_item_category.xml b/OsmAnd/res/layout/expandable_list_item_category.xml index 6c6a9c13f5..b50ecbe710 100644 --- a/OsmAnd/res/layout/expandable_list_item_category.xml +++ b/OsmAnd/res/layout/expandable_list_item_category.xml @@ -1,43 +1,34 @@ + xmlns:tools="http://schemas.android.com/tools" + android:orientation="horizontal" + android:layout_width="fill_parent" + android:layout_height="@dimen/list_header_height" + android:paddingLeft="@dimen/list_header_padding"> - + - - - - - - + + \ No newline at end of file diff --git a/OsmAnd/res/layout/expandable_list_item_category_btn.xml b/OsmAnd/res/layout/expandable_list_item_category_btn.xml index 343423d46f..5cdce8360a 100644 --- a/OsmAnd/res/layout/expandable_list_item_category_btn.xml +++ b/OsmAnd/res/layout/expandable_list_item_category_btn.xml @@ -1,45 +1,35 @@ + xmlns:tools="http://schemas.android.com/tools" + android:orientation="horizontal" + android:layout_width="fill_parent" + android:layout_height="@dimen/list_header_height" + android:paddingLeft="@dimen/list_header_padding"> - - - - - - - - - + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/favourites_list_item.xml b/OsmAnd/res/layout/favourites_list_item.xml index 246b24c3c4..d265123266 100644 --- a/OsmAnd/res/layout/favourites_list_item.xml +++ b/OsmAnd/res/layout/favourites_list_item.xml @@ -6,18 +6,18 @@ android:background="?attr/expandable_list_item_background" android:minHeight="@dimen/list_item_height" android:orientation="horizontal" - android:paddingBottom="5dp" android:paddingLeft="@dimen/list_content_padding" - android:paddingRight="@dimen/list_content_padding" - android:paddingTop="5dp"> + android:paddingRight="@dimen/list_content_padding"> + android:visibility="gone" + tools:visibility="visible"/> - + android:orientation="horizontal" + android:paddingLeft="@dimen/list_content_padding" + android:paddingRight="@dimen/list_content_padding"> - + + + android:orientation="vertical" + android:paddingRight="3dp"> - + - + - + - + - + - + \ No newline at end of file diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index 3f6266e4d8..c436fe633f 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -31,6 +31,8 @@ + + diff --git a/OsmAnd/res/values/colors.xml b/OsmAnd/res/values/colors.xml index a065c2a553..af1706e18d 100644 --- a/OsmAnd/res/values/colors.xml +++ b/OsmAnd/res/values/colors.xml @@ -1,7 +1,10 @@ - #292f33 + #292f33 + #475259 @color/color_white + #333b40 + #39464d #CC080B0D @@ -108,7 +111,7 @@ #ffffff #ffffff - #333b40 + #dbdbdb #2d3438 diff --git a/OsmAnd/res/values/sizes.xml b/OsmAnd/res/values/sizes.xml index 2c9ad066f5..5599a81812 100644 --- a/OsmAnd/res/values/sizes.xml +++ b/OsmAnd/res/values/sizes.xml @@ -26,10 +26,17 @@ 8dp 48dp 50dp + 40dp + 16dp + 10dp + 12dp + 8dp 48dp 18dp + 13dp + 14sp 12sp 14sp 16sp diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 33f958587e..0e7edd36e8 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -161,6 +161,8 @@ @drawable/ic_world_globe_light #727272 @color/expandable_list_item_light + @color/color_white + @drawable/ic_overflow_menu_light + @color/list_item_background_dark + @color/list_background_dark + @drawable/ic_overflow_menu_dark +