From 6eeb65f31e5500b81eeb98fb9debe05936ea90ed Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 24 May 2018 02:06:13 +0200 Subject: [PATCH 1/4] Refactor update location view --- .../src/net/osmand/plus/AppInitializer.java | 4 +- .../net/osmand/plus/ContextMenuAdapter.java | 8 +- .../src/net/osmand/plus/ContextMenuItem.java | 2 +- OsmAnd/src/net/osmand/plus/IconsCache.java | 88 ------- .../osmand/plus/OsmAndLocationProvider.java | 9 +- .../net/osmand/plus/OsmandApplication.java | 15 +- OsmAnd/src/net/osmand/plus/UiUtilities.java | 225 ++++++++++++++++++ .../ActionBarPreferenceActivity.java | 2 +- .../EditFavoriteGroupDialogFragment.java | 4 +- .../activities/FavoritesListFragment.java | 153 +++++++----- .../activities/FavoritesSearchFragment.java | 4 +- .../activities/FavoritesTreeFragment.java | 8 +- .../activities/IntermediatePointsDialog.java | 2 +- .../osmand/plus/activities/MapActivity.java | 12 +- .../plus/activities/MapActivityLayers.java | 4 +- .../activities/NavigatePointFragment.java | 2 +- .../plus/activities/OpeningHoursView.java | 2 +- .../activities/OsmandActionBarActivity.java | 2 +- .../OsmandBaseExpandableListAdapter.java | 8 +- .../plus/activities/OsmandListActivity.java | 2 +- .../plus/activities/PluginActivity.java | 4 +- .../plus/activities/PluginsActivity.java | 2 +- .../activities/SettingsGeneralActivity.java | 52 ++-- .../ShowRouteInfoDialogFragment.java | 18 +- .../activities/actions/AppModeDialog.java | 8 +- .../search/SearchAddressFragment.java | 2 +- .../search/SearchHistoryFragment.java | 83 +++---- .../activities/search/SearchPOIActivity.java | 99 ++++---- .../search/SearchPoiFilterFragment.java | 8 +- .../AudioVideoNoteRecordingMenu.java | 4 +- .../DashAudioVideoNotesFragment.java | 8 +- .../audionotes/adapters/NotesAdapter.java | 4 +- .../plus/base/BaseOsmAndDialogFragment.java | 8 +- .../osmand/plus/base/BaseOsmAndFragment.java | 14 +- .../plus/base/BottomSheetDialogFragment.java | 4 +- .../plus/base/MapViewTrackingUtilities.java | 14 ++ .../plus/dashboard/DashErrorFragment.java | 2 +- .../plus/dashboard/DashFavoritesFragment.java | 4 +- .../plus/dashboard/DashLocationFragment.java | 164 ++----------- .../dashboard/DashNavigationFragment.java | 6 +- .../plus/dashboard/DashRecentsFragment.java | 2 +- .../plus/dashboard/DashSearchFragment.java | 2 +- .../plus/dashboard/DashWaypointsFragment.java | 12 +- .../osmand/plus/dashboard/DashboardOnMap.java | 6 +- .../development/DashSimulateFragment.java | 4 +- .../osmand/plus/dialogs/ConfigureMapMenu.java | 14 +- .../plus/dialogs/ErrorBottomSheetDialog.java | 2 +- .../osmand/plus/dialogs/FavoriteDialogs.java | 34 +-- .../download/ui/DownloadGroupViewHolder.java | 8 +- .../ui/DownloadResourceGroupFragment.java | 14 +- .../plus/download/ui/ItemViewHolder.java | 8 +- .../download/ui/LocalIndexesFragment.java | 8 +- .../plus/helpers/AvoidSpecificRoads.java | 4 +- .../net/osmand/plus/helpers/GpxUiHelper.java | 18 +- .../plus/helpers/MapMarkerDialogHelper.java | 4 +- .../plus/helpers/WaypointDialogHelper.java | 8 +- .../osmand/plus/helpers/WaypointHelper.java | 4 +- .../plus/liveupdates/LiveUpdatesFragment.java | 4 +- .../liveupdates/SubscriptionFragment.java | 4 +- ...ionalActionsBottomSheetDialogFragment.java | 2 +- .../mapcontextmenu/BaseMenuController.java | 10 +- .../plus/mapcontextmenu/MapContextMenu.java | 24 +- .../MapContextMenuFragment.java | 76 +++--- .../plus/mapcontextmenu/MenuBuilder.java | 8 +- .../builders/AmenityMenuBuilder.java | 4 +- .../builders/FavouritePointMenuBuilder.java | 2 +- .../builders/GpxItemMenuBuilder.java | 2 +- .../builders/WptPtMenuBuilder.java | 2 +- .../builders/cards/AbstractCard.java | 2 +- .../builders/cards/ImageCard.java | 6 +- .../builders/cards/NoImagesCard.java | 4 +- .../editors/PointEditorFragment.java | 2 +- .../editors/SelectCategoryDialogFragment.java | 4 +- .../other/DestinationReachedMenuFragment.java | 4 +- .../other/FavouritesAdapter.java | 41 +--- .../FavouritesBottomSheetMenuFragment.java | 46 +--- .../other/MapRouteInfoMenu.java | 22 +- .../other/MultiSelectionArrayAdapter.java | 4 +- .../other/RoutePreferencesMenu.java | 8 +- .../other/TrackDetailsMenu.java | 4 +- .../MapillaryAutoCompleteAdapter.java | 2 +- .../plus/mapillary/MapillaryImageDialog.java | 10 +- .../CoordinateInputDialogFragment.java | 16 +- .../MapMarkerSelectionFragment.java | 6 +- .../mapmarkers/MapMarkersActiveFragment.java | 7 - .../mapmarkers/MapMarkersDialogFragment.java | 2 +- .../mapmarkers/MapMarkersGroupsFragment.java | 69 ++---- .../adapters/CoordinateInputAdapter.java | 49 ++-- .../adapters/FavouritesGroupsAdapter.java | 2 +- .../mapmarkers/adapters/GroupsAdapter.java | 6 +- .../adapters/MapMarkersActiveAdapter.java | 37 +-- .../adapters/MapMarkersGroupsAdapter.java | 37 +-- .../adapters/MapMarkersHistoryAdapter.java | 4 +- .../adapters/MapMarkersListAdapter.java | 4 +- .../SnapToRoadBottomSheetDialogFragment.java | 2 +- .../adapter/MeasurementToolAdapter.java | 4 +- .../plus/monitoring/DashTrackFragment.java | 14 +- .../plus/myplaces/AvailableGPXFragment.java | 30 +-- .../EditTrackGroupDialogFragment.java | 2 +- .../myplaces/SplitSegmentDialogFragment.java | 10 +- .../TrackActivityFragmentAdapter.java | 6 +- .../plus/myplaces/TrackPointFragment.java | 10 +- .../plus/myplaces/TrackSegmentFragment.java | 8 +- .../plus/osmedit/DashOsmEditsFragment.java | 2 +- .../osmand/plus/osmedit/OsmEditsAdapter.java | 6 +- .../osmand/plus/osmedit/OsmEditsFragment.java | 4 +- .../osmedit/OsmEditsUploadListenerHelper.java | 4 +- .../quickaction/CreateEditActionDialog.java | 6 +- .../quickaction/QuickActionListFragment.java | 10 +- .../plus/quickaction/QuickActionsWidget.java | 6 +- .../quickaction/actions/AddPOIAction.java | 4 +- .../actions/ShowHidePoiAction.java | 2 +- .../QuickSearchCoordinatesFragment.java | 113 +++------ .../search/QuickSearchCustomPoiFragment.java | 6 +- .../search/QuickSearchDialogFragment.java | 18 +- .../plus/search/QuickSearchListAdapter.java | 58 +---- .../plus/search/QuickSearchListFragment.java | 8 +- .../search/QuickSearchPoiFilterFragment.java | 12 +- .../listitems/QuickSearchButtonListItem.java | 2 +- .../search/listitems/QuickSearchListItem.java | 8 +- .../views/AddGpxPointBottomSheetHelper.java | 6 +- .../osmand/plus/views/DirectionDrawable.java | 10 +- .../osmand/plus/views/MapControlsLayer.java | 16 +- .../plus/views/MapQuickActionLayer.java | 2 +- .../views/MoveMarkerBottomSheetHelper.java | 4 +- .../net/osmand/plus/views/POIMapLayer.java | 2 +- .../mapwidgets/MapInfoWidgetsFactory.java | 18 +- .../mapwidgets/MapMarkersWidgetsFactory.java | 8 +- .../views/mapwidgets/MapWidgetRegistry.java | 4 +- .../plus/views/mapwidgets/TextInfoWidget.java | 2 +- .../explore/SavedArticlesRvAdapter.java | 4 +- .../explore/WikivoyageExploreActivity.java | 2 +- .../explore/travelcards/BaseTravelCard.java | 2 +- .../search/SearchRecyclerViewAdapter.java | 2 +- 134 files changed, 972 insertions(+), 1217 deletions(-) delete mode 100644 OsmAnd/src/net/osmand/plus/IconsCache.java create mode 100644 OsmAnd/src/net/osmand/plus/UiUtilities.java diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 9fb04f29ba..b19a20700f 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -13,7 +13,6 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.support.v7.app.AlertDialog; - import net.osmand.IProgress; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; @@ -27,6 +26,7 @@ import net.osmand.plus.activities.DayNightHelper; import net.osmand.plus.activities.LocalIndexHelper; import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.activities.SavingTrackHelper; +import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.helpers.AvoidSpecificRoads; @@ -67,7 +67,6 @@ import java.util.Locale; import java.util.Random; import btools.routingapp.BRouterServiceConnection; - import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn; @@ -448,6 +447,7 @@ public class AppInitializer implements IProgress { app.mapMarkersDbHelper = startupInit(new MapMarkersDbHelper(app), MapMarkersDbHelper.class); app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class); app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class); + app.mapViewTrackingUtilities = startupInit(new MapViewTrackingUtilities(app), MapViewTrackingUtilities.class); app.travelDbHelper = new TravelDbHelper(app); if (app.getSettings().SELECTED_TRAVEL_BOOK.get() != null) { app.travelDbHelper.initTravelBooks(); diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index ba2a6d89b0..7a37d2860b 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -110,7 +110,7 @@ public class ContextMenuAdapter { @LayoutRes private int layoutId; private final ConfigureMapMenu.OnClickListener changeAppModeListener; - private final IconsCache mIconsCache; + private final UiUtilities mIconsCache; public ContextMenuArrayAdapter(Activity context, @LayoutRes int layoutRes, @@ -124,7 +124,7 @@ public class ContextMenuAdapter { this.lightTheme = lightTheme; this.layoutId = layoutRes; this.changeAppModeListener = changeAppModeListener; - mIconsCache = app.getIconsCache(); + mIconsCache = app.getUIUtilities(); } @Override @@ -169,7 +169,7 @@ public class ContextMenuAdapter { } if (layoutId == R.layout.help_to_improve_item) { TextView feedbackButton = (TextView) convertView.findViewById(R.id.feedbackButton); - Drawable pollIcon = app.getIconsCache().getThemedIcon(R.drawable.ic_action_big_poll); + Drawable pollIcon = app.getUIUtilities().getThemedIcon(R.drawable.ic_action_big_poll); feedbackButton.setCompoundDrawablesWithIntrinsicBounds(null, pollIcon, null, null); feedbackButton.setOnClickListener(new View.OnClickListener() { @Override @@ -181,7 +181,7 @@ public class ContextMenuAdapter { }); TextView contactUsButton = (TextView) convertView.findViewById(R.id.contactUsButton); Drawable contactUsIcon = - app.getIconsCache().getThemedIcon(R.drawable.ic_action_big_feedback); + app.getUIUtilities().getThemedIcon(R.drawable.ic_action_big_feedback); contactUsButton.setCompoundDrawablesWithIntrinsicBounds(null, contactUsIcon, null, null); final String email = app.getString(R.string.support_email); diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java index f8f4c92fc6..3143a28f39 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuItem.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuItem.java @@ -107,7 +107,7 @@ public class ContextMenuItem { if (skipPaintingWithoutColor || getColorRes() != INVALID_ID) { return getColorRes(); } else { - return IconsCache.getDefaultColorRes(context); + return UiUtilities.getDefaultColorRes(context); } } diff --git a/OsmAnd/src/net/osmand/plus/IconsCache.java b/OsmAnd/src/net/osmand/plus/IconsCache.java deleted file mode 100644 index b483d14b17..0000000000 --- a/OsmAnd/src/net/osmand/plus/IconsCache.java +++ /dev/null @@ -1,88 +0,0 @@ -package net.osmand.plus; - -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.LayerDrawable; -import android.support.annotation.ColorInt; -import android.support.annotation.ColorRes; -import android.support.annotation.DrawableRes; -import android.support.v4.content.ContextCompat; -import android.support.v4.graphics.drawable.DrawableCompat; -import android.view.MenuItem; - -import gnu.trove.map.hash.TLongObjectHashMap; - -public class IconsCache { - - private TLongObjectHashMap drawable = new TLongObjectHashMap<>(); - private OsmandApplication app; - - public IconsCache(OsmandApplication app) { - this.app = app; - } - - private Drawable getDrawable(@DrawableRes int resId, @ColorRes int clrId) { - long hash = ((long)resId << 31l) + clrId; - Drawable d = drawable.get(hash); - if (d == null) { - d = ContextCompat.getDrawable(app, resId); - d = DrawableCompat.wrap(d); - d.mutate(); - if (clrId != 0) { - DrawableCompat.setTint(d, ContextCompat.getColor(app, clrId)); - } - drawable.put(hash, d); - } - return d; - } - - private Drawable getPaintedDrawable(@DrawableRes int resId, @ColorInt int color){ - long hash = ((long)resId << 31l) + color; - Drawable d = drawable.get(hash); - if(d == null) { - d = ContextCompat.getDrawable(app, resId); - d = DrawableCompat.wrap(d); - d.mutate(); - DrawableCompat.setTint(d, color); - - drawable.put(hash, d); - } - return d; - } - - public Drawable getPaintedIcon(@DrawableRes int id, @ColorInt int color){ - return getPaintedDrawable(id, color); - } - - public Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) { - return getDrawable(id, colorId); - } - - public Drawable getIcon(@DrawableRes int backgroundId, @DrawableRes int id, @ColorRes int colorId) { - Drawable b = getDrawable(backgroundId, 0); - Drawable f = getDrawable(id, colorId); - Drawable[] layers = new Drawable[2]; - layers[0] = b; - layers[1] = f; - return new LayerDrawable(layers); - } - - public Drawable getThemedIcon(@DrawableRes int id) { - return getDrawable(id, app.getSettings().isLightContent() ? R.color.icon_color : 0); - } - - public Drawable getIcon(@DrawableRes int id) { - return getDrawable(id, 0); - } - - public Drawable getIcon(@DrawableRes int id, boolean light) { - return getDrawable(id, light ? R.color.icon_color : 0); - } - - @ColorRes - public static int getDefaultColorRes(Context context) { - final OsmandApplication app = (OsmandApplication) context.getApplicationContext(); - boolean light = app.getSettings().isLightContent(); - return light ? R.color.icon_color : R.color.color_white; - } -} diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index 5b2611e2c2..ba3d388a39 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -556,14 +556,7 @@ public class OsmAndLocationProvider implements SensorEventListener { } } - public synchronized Float getHeading() { -// if (heading != null && lastValSin != avgValSin && System.currentTimeMillis() - lastHeadingCalcTime > 700) { -// avgValSin = lastValSin; -// avgValCos = lastValCos; -// Arrays.fill(previousCompassValuesA, avgValSin); -// Arrays.fill(previousCompassValuesB, avgValCos); -// updateCompassVal(); -// } + public Float getHeading() { return heading; } diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 1203adafe8..1dcaca042b 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -42,6 +42,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.api.SQLiteAPI; import net.osmand.plus.api.SQLiteAPIImpl; +import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.dialogs.RateUsBottomSheetDialog; import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.helpers.AvoidSpecificRoads; @@ -87,7 +88,7 @@ public class OsmandApplication extends MultiDexApplication { OsmAndAppCustomization appCustomization; private final SQLiteAPI sqliteAPI = new SQLiteAPIImpl(this); private final OsmAndTaskManager taskManager = new OsmAndTaskManager(this); - private final IconsCache iconsCache = new IconsCache(this); + private final UiUtilities iconsCache = new UiUtilities(this); Handler uiHandler; private boolean plusVersionInApp; @@ -122,6 +123,7 @@ public class OsmandApplication extends MultiDexApplication { QuickSearchHelper searchUICore; TravelDbHelper travelDbHelper; InAppPurchaseHelper inAppPurchaseHelper; + MapViewTrackingUtilities mapViewTrackingUtilities; RoutingConfiguration.Builder defaultRoutingConfig; private Locale preferredLocale = null; @@ -214,10 +216,11 @@ public class OsmandApplication extends MultiDexApplication { }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } - public IconsCache getIconsCache() { + public UiUtilities getUIUtilities() { return iconsCache; } + @Override public void onTerminate() { super.onTerminate(); @@ -420,7 +423,7 @@ public class OsmandApplication extends MultiDexApplication { View view = uiContext.getLayoutInflater().inflate(R.layout.select_voice_first, null); ((ImageView) view.findViewById(R.id.icon)) - .setImageDrawable(getIconsCache().getIcon(R.drawable.ic_action_volume_up, getSettings().isLightContent())); + .setImageDrawable(getUIUtilities().getIcon(R.drawable.ic_action_volume_up, getSettings().isLightContent())); view.findViewById(R.id.spinner).setOnClickListener(new View.OnClickListener() { @Override @@ -441,7 +444,7 @@ public class OsmandApplication extends MultiDexApplication { }); ((ImageView) view.findViewById(R.id.dropDownIcon)) - .setImageDrawable(getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, getSettings().isLightContent())); + .setImageDrawable(getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, getSettings().isLightContent())); builder.setCancelable(true); builder.setNegativeButton(R.string.shared_string_cancel, null); @@ -1003,4 +1006,8 @@ public class OsmandApplication extends MultiDexApplication { }); bld.show(); } + + public MapViewTrackingUtilities getMapViewTrackingUtilities() { + return mapViewTrackingUtilities; + } } diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java new file mode 100644 index 0000000000..036f632891 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -0,0 +1,225 @@ +package net.osmand.plus; + +import gnu.trove.map.hash.TLongObjectHashMap; +import net.osmand.Location; +import net.osmand.data.LatLon; +import net.osmand.plus.views.DirectionDrawable; +import android.app.Activity; +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; +import android.hardware.Sensor; +import android.hardware.SensorManager; +import android.support.annotation.ColorInt; +import android.support.annotation.ColorRes; +import android.support.annotation.DrawableRes; +import android.support.v4.content.ContextCompat; +import android.support.v4.graphics.drawable.DrawableCompat; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.TextView; + +public class UiUtilities { + + private TLongObjectHashMap drawableCache = new TLongObjectHashMap<>(); + private OsmandApplication app; + 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; + + + public UiUtilities(OsmandApplication app) { + this.app = app; + } + + private Drawable getDrawable(@DrawableRes int resId, @ColorRes int clrId) { + long hash = ((long) resId << 31l) + clrId; + Drawable d = drawableCache.get(hash); + if (d == null) { + d = ContextCompat.getDrawable(app, resId); + d = DrawableCompat.wrap(d); + d.mutate(); + if (clrId != 0) { + DrawableCompat.setTint(d, ContextCompat.getColor(app, clrId)); + } + drawableCache.put(hash, d); + } + return d; + } + + private Drawable getPaintedDrawable(@DrawableRes int resId, @ColorInt int color) { + long hash = ((long) resId << 31l) + color; + Drawable d = drawableCache.get(hash); + if (d == null) { + d = ContextCompat.getDrawable(app, resId); + d = DrawableCompat.wrap(d); + d.mutate(); + DrawableCompat.setTint(d, color); + + drawableCache.put(hash, d); + } + return d; + } + + public Drawable getPaintedIcon(@DrawableRes int id, @ColorInt int color) { + return getPaintedDrawable(id, color); + } + + public Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) { + return getDrawable(id, colorId); + } + + public Drawable getIcon(@DrawableRes int backgroundId, @DrawableRes int id, @ColorRes int colorId) { + Drawable b = getDrawable(backgroundId, 0); + Drawable f = getDrawable(id, colorId); + Drawable[] layers = new Drawable[2]; + layers[0] = b; + layers[1] = f; + return new LayerDrawable(layers); + } + + public Drawable getThemedIcon(@DrawableRes int id) { + return getDrawable(id, app.getSettings().isLightContent() ? R.color.icon_color : 0); + } + + public Drawable getIcon(@DrawableRes int id) { + return getDrawable(id, 0); + } + + public Drawable getIcon(@DrawableRes int id, boolean light) { + return getDrawable(id, light ? R.color.icon_color : 0); + } + + @ColorRes + public static int getDefaultColorRes(Context context) { + final OsmandApplication app = (OsmandApplication) context.getApplicationContext(); + boolean light = app.getSettings().isLightContent(); + return light ? R.color.icon_color : R.color.color_white; + } + + + public UpdateLocationViewCache getUpdateLocationViewCache(Activity a){ + UpdateLocationViewCache uvc = new UpdateLocationViewCache(); + uvc.screenOrientation = getScreenOrientation(a); + return uvc; + } + + public static class UpdateLocationViewCache { + int screenOrientation; + public boolean paintTxt = true; + public int arrowResId; + public int arrowColor; + public int textColor; + public LatLon specialFrom; + } + + public void updateLocationView(UpdateLocationViewCache cache, ImageView arrow, TextView txt, + double toLat, double toLon) { + updateLocationView(cache, arrow, txt, new LatLon(toLat, toLon)); + } + public void updateLocationView(UpdateLocationViewCache cache, ImageView arrow, TextView txt, + LatLon toLoc) { + float[] mes = new float[2]; + boolean stale = false; + LatLon fromLoc = cache.specialFrom; + boolean useCenter = cache.specialFrom != null; + Float h = null; + if (cache.specialFrom == null) { + Location loc = app.getLocationProvider().getLastKnownLocation(); + h = app.getLocationProvider().getHeading(); + if (loc == null) { + loc = app.getLocationProvider().getLastStaleKnownLocation(); + stale = true; + } + if (loc != null) { + fromLoc = new LatLon(loc.getLatitude(), loc.getLongitude()); + } else { + useCenter = true; + fromLoc = app.getMapViewTrackingUtilities().getMapLocation(); + h = app.getMapViewTrackingUtilities().getHeading(); + if(h != null) { + h = -h; + } + } + } + if (fromLoc != null && toLoc != null) { + Location.distanceBetween(toLoc.getLatitude(), toLoc.getLongitude(), fromLoc.getLatitude(), + fromLoc.getLongitude(), mes); + } + + if (arrow != null) { + boolean newImage = false; + int arrowResId = cache.arrowResId; + if (arrowResId == 0) { + arrowResId = R.drawable.ic_direction_arrow; + } + DirectionDrawable dd; + if (!(arrow.getDrawable() instanceof DirectionDrawable)) { + newImage = true; + dd = new DirectionDrawable(app, arrow.getWidth(), arrow.getHeight()); + } else { + dd = (DirectionDrawable) arrow.getDrawable(); + } + int imgColorSet = cache.arrowColor; + if (imgColorSet == 0) { + imgColorSet = useCenter ? R.color.color_distance : R.color.color_myloc_distance; + if (stale) { + imgColorSet = R.color.icon_color; + } + } + dd.setImage(arrowResId, imgColorSet); + if (fromLoc == null || h == null || toLoc == null) { + dd.setAngle(0); + } else { + dd.setAngle(mes[1] - h + 180 + cache.screenOrientation); + } + if (newImage) { + arrow.setImageDrawable(dd); + } + arrow.invalidate(); + } + if (txt != null) { + if (fromLoc != null && toLoc != null) { + if (cache.paintTxt) { + int textColorSet = cache.textColor; + if (textColorSet == 0) { + textColorSet = useCenter ? R.color.color_distance : R.color.color_myloc_distance; + if (stale) { + textColorSet = R.color.icon_color; + } + } + txt.setTextColor(app.getResources().getColor(textColorSet)); + } + txt.setText(OsmAndFormatter.getFormattedDistance(mes[0], app)); + } else { + txt.setText(""); + } + } + } + + 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) + screenOrientation = 0; + break; + case ORIENTATION_90: // Landscape right + screenOrientation = 90; + break; + case ORIENTATION_270: // Landscape left + screenOrientation = 270; + break; + case ORIENTATION_180: // Upside down + screenOrientation = 180; + break; + } + //Looks like screenOrientation correction must not be applied for devices without compass? + Sensor compass = ((SensorManager) a.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); + if (compass == null) { + screenOrientation = 0; + } + return screenOrientation; + } + +} diff --git a/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java b/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java index 93abbc07dd..9eec370077 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ActionBarPreferenceActivity.java @@ -44,7 +44,7 @@ public abstract class ActionBarPreferenceActivity extends AppCompatPreferenceAct shadowView = null; } tb.setClickable(true); - tb.setNavigationIcon(((OsmandApplication) getApplication()).getIconsCache().getIcon(R.drawable.ic_arrow_back)); + tb.setNavigationIcon(((OsmandApplication) getApplication()).getUIUtilities().getIcon(R.drawable.ic_arrow_back)); tb.setNavigationContentDescription(R.string.access_shared_string_navigate_up); tb.setBackgroundColor(getResources().getColor(getResIdFromAttribute(this, R.attr.pstsTabBackground))); tb.setTitleTextColor(getResources().getColor(getResIdFromAttribute(this, R.attr.pstsTextColor))); diff --git a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java index 3d463dafab..1392594bed 100644 --- a/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/EditFavoriteGroupDialogFragment.java @@ -244,7 +244,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme if (color == 0) { colorImageView.setImageDrawable(getContentIcon(R.drawable.ic_action_circle)); } else { - colorImageView.setImageDrawable(getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_circle, color)); + colorImageView.setImageDrawable(getMyApplication().getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, color)); } } @@ -284,7 +284,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme TextView textView = (TextView) v.findViewById(R.id.text1); textView.setText(app.getString(ColorDialogs.paletteColors[position])); textView.setCompoundDrawablesWithIntrinsicBounds(null, null, - app.getIconsCache().getPaintedIcon(R.drawable.ic_action_circle, color), null); + app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, color), null); textView.setCompoundDrawablePadding(AndroidUtils.dpToPx(getContext(), 10f)); v.findViewById(R.id.divider).setVisibility(View.GONE); } diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java index a72fbcab6e..6f1b283c78 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java @@ -3,6 +3,24 @@ */ package net.osmand.plus.activities; +import java.text.Collator; +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.OsmAndLocationProvider.OsmAndCompassListener; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; +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.base.OsmAndListFragment; +import net.osmand.util.MapUtils; import android.app.Activity; import android.content.Intent; import android.support.v4.app.FragmentActivity; @@ -20,23 +38,6 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; -import net.osmand.data.FavouritePoint; -import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; -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.base.OsmAndListFragment; -import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.util.MapUtils; - -import java.util.Comparator; -import java.util.List; - public class FavoritesListFragment extends OsmAndListFragment implements SearchActivityChild, OsmAndCompassListener { public static final String SELECT_FAVORITE_POINT_INTENT_KEY = "SELECT_FAVORITE_POINT_INTENT_KEY"; @@ -48,7 +49,7 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA private OsmandSettings settings; private boolean compassRegistered; - + float lastHeading ; @Override public void onAttach(Activity activity) { @@ -67,7 +68,7 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA double lat = intent.getDoubleExtra(SearchActivity.SEARCH_LAT, 0); double lon = intent.getDoubleExtra(SearchActivity.SEARCH_LON, 0); if (lat != 0 || lon != 0) { - favouritesAdapter.location = new LatLon(lat, lon); + favouritesAdapter.cache.specialFrom = new LatLon(lat, lon); } } } @@ -85,15 +86,10 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA @Override public void onResume() { super.onResume(); - - if (favouritesAdapter.location == null && getActivity() instanceof SearchActivity) { - favouritesAdapter.location = ((SearchActivity) getActivity()).getSearchPoint(); + if (getActivity() instanceof SearchActivity && ((SearchActivity) getActivity()).getSearchPoint() != null) { + favouritesAdapter.cache.specialFrom = ((SearchActivity) getActivity()).getSearchPoint(); } - if (favouritesAdapter.location == null) { - favouritesAdapter.location = settings.getLastKnownMapLocation(); - } - favouritesAdapter.screenOrientation = DashLocationFragment.getScreenOrientation(getActivity()); - locationUpdate(favouritesAdapter.location); + locationUpdate(favouritesAdapter.cache.specialFrom); } @Override @@ -106,13 +102,17 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA app.getLocationProvider().addCompassListener(this); compassRegistered = true; } - favouritesAdapter.searchAroundLocation = true; + favouritesAdapter.cache.specialFrom = null; } else { - favouritesAdapter.searchAroundLocation = false; + favouritesAdapter.cache.specialFrom = ((SearchActivity) getActivity()).getSearchPoint(); } } if (favouritesAdapter != null) { - favouritesAdapter.updateLocation(l); + if(l != null) { + favouritesAdapter.sortByName(); + } else { + favouritesAdapter.sortByDistance(l); + } } } @@ -156,33 +156,27 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA public static class FavouritesAdapter extends ArrayAdapter { private Activity activity; - private LatLon location; private OsmandApplication app; - private boolean searchAroundLocation; - private int screenOrientation; - private Float heading; - private boolean shoudShowMenuButton; + private boolean shouldShowMenuButton; + private UpdateLocationViewCache cache; public FavouritesAdapter(Activity activity, List list, - boolean shoudShowMenuButton) { + boolean shouldShowMenuButton) { super(activity, R.layout.favorites_list_item, list); this.activity = activity; this.app = ((OsmandApplication) activity.getApplication()); - this.shoudShowMenuButton = shoudShowMenuButton; + this.shouldShowMenuButton = shouldShowMenuButton; + cache = app.getUIUtilities().getUpdateLocationViewCache(activity); } - public LatLon getLocation() { - return location; - } - public void updateLocation(LatLon l) { - location = l; + public void updateLocation(final LatLon l) { sort(new Comparator() { @Override public int compare(FavouritePoint object1, FavouritePoint object2) { - if (location != null) { - double d1 = MapUtils.getDistance(location, object1.getLatitude(), object1.getLongitude()); - double d2 = MapUtils.getDistance(location, object2.getLatitude(), object2.getLongitude()); + if (l != null) { + double d1 = MapUtils.getDistance(l, object1.getLatitude(), object1.getLongitude()); + double d2 = MapUtils.getDistance(l, object2.getLatitude(), object2.getLongitude()); if (d1 == d2) { return 0; } else if (d1 > d2) { @@ -204,7 +198,7 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; if (row == null) { - LayoutInflater inflater = activity.getLayoutInflater(); // favourite dank + LayoutInflater inflater = activity.getLayoutInflater(); row = inflater.inflate(R.layout.favorites_list_item, parent, false); } @@ -212,14 +206,14 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA 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); - ImageView giImage= (ImageView)row.findViewById(R.id.group_image); + ImageView giImage = (ImageView) row.findViewById(R.id.group_image); direction.setVisibility(View.VISIBLE); final FavouritePoint favorite = getItem(position); - if (shoudShowMenuButton) { + if (shouldShowMenuButton) { ImageButton options = (ImageButton) row.findViewById(R.id.options); options.setFocusable(false); - options.setImageDrawable(((OsmandApplication) activity.getApplication()) - .getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white)); + options.setImageDrawable(((OsmandApplication) activity.getApplication()).getUIUtilities() + .getThemedIcon(R.drawable.ic_overflow_menu_white)); options.setVisibility(View.VISIBLE); options.setOnClickListener(new View.OnClickListener() { @Override @@ -230,25 +224,65 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA } if (!favorite.getCategory().isEmpty()) { giImage.setVisibility(View.VISIBLE); - giImage.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_small_group)); + giImage.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_small_group)); } else { giImage.setVisibility(View.GONE); } ((TextView) row.findViewById(R.id.group_name)).setText(favorite.getCategory()); icon.setImageDrawable(FavoriteImageDrawable.getOrCreate(activity, favorite.getColor(), false)); - DashLocationFragment.updateLocationView(!searchAroundLocation, location, heading, direction, distanceText, - favorite.getLatitude(), favorite.getLongitude(), screenOrientation, app); - + + app.getUIUtilities().updateLocationView(cache, direction, distanceText, + favorite.getLatitude(), favorite.getLongitude()); name.setText(getName(favorite)); final CheckBox ch = (CheckBox) row.findViewById(R.id.toggle_item); icon.setVisibility(View.VISIBLE); ch.setVisibility(View.GONE); if (activity instanceof SearchActivity) - ViewCompat.setAccessibilityDelegate(row, ((SearchActivity)activity).getAccessibilityAssistant()); + ViewCompat.setAccessibilityDelegate(row, ((SearchActivity) activity).getAccessibilityAssistant()); return row; } + public void sortByName() { + final Collator inst = Collator.getInstance(); + sort(new Comparator() { + @Override + public int compare(FavouritePoint o1, FavouritePoint o2) { + return inst.compare(o1.getName(), o2.getName()); + } + + }); + + } + public void sortByDistance(final LatLon loc) { + sort(new Comparator() { + @Override + public int compare(FavouritePoint lhs, FavouritePoint rhs) { + if (loc == null) { + return 0; + } + double ld = MapUtils.getDistance(loc, lhs.getLatitude(), lhs.getLongitude()); + double rd = MapUtils.getDistance(loc, rhs.getLatitude(), rhs.getLongitude()); + return Double.compare(ld, rd); + + } + }); + + } + + + public void sortByDefault() { + Location loc = app.getLocationProvider().getLastStaleKnownLocation(); + LatLon map = app.getMapViewTrackingUtilities().getMapLocation(); + if (loc != null) { + sortByDistance(new LatLon(loc.getLatitude(), loc.getLongitude())); + } else if(map != null){ + sortByDistance(map); + } else{ + sortByName(); + } + } + } public OsmandApplication getMyApplication() { @@ -260,9 +294,8 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA // 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction) on non-compass // devices FragmentActivity activity = getActivity(); - float lastHeading = favouritesAdapter.heading != null ? favouritesAdapter.heading : 99; - favouritesAdapter.heading = value; - if (Math.abs(MapUtils.degreesDiff(lastHeading, favouritesAdapter.heading)) > 5) { + if (Math.abs(MapUtils.degreesDiff(lastHeading, value)) > 5) { + lastHeading = value; if (activity instanceof SearchActivity) { ((SearchActivity)activity).getAccessibilityAssistant().lockEvents(); favouritesAdapter.notifyDataSetChanged(); @@ -270,8 +303,6 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA } else { favouritesAdapter.notifyDataSetChanged(); } - } else { - favouritesAdapter.heading = lastHeading; } if (activity instanceof SearchActivity) { final View selected = ((SearchActivity)activity).getAccessibilityAssistant().getFocusedView(); @@ -281,7 +312,7 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) { FavouritePoint point = favouritesAdapter.getItem(position - getListView().getHeaderViewsCount()); LatLon location = new LatLon(point.getLatitude(), point.getLongitude()); - ((SearchActivity)activity).getNavigationInfo().updateTargetDirection(location, favouritesAdapter.heading.floatValue()); + ((SearchActivity)activity).getNavigationInfo().updateTargetDirection(location, value); } } catch (Exception e) { return; diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java index e4419afe3b..f9c73ed087 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesSearchFragment.java @@ -105,7 +105,7 @@ public class FavoritesSearchFragment extends DialogFragment { } toolbar = (Toolbar) view.findViewById(R.id.toolbar); - toolbar.setNavigationIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_arrow_back)); + toolbar.setNavigationIcon(app.getUIUtilities().getThemedIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); toolbar.setNavigationOnClickListener( new View.OnClickListener() { @@ -141,7 +141,7 @@ public class FavoritesSearchFragment extends DialogFragment { progressBar = (ProgressBar) view.findViewById(R.id.searchProgressBar); clearButton = (ImageButton) view.findViewById(R.id.clearButton); - clearButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark)); + clearButton.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark)); clearButton.setOnClickListener( new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 8d78cec590..8cbb03c761 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -149,7 +149,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { View searchView = inflater.inflate(R.layout.search_fav_list_item, null); searchView.setBackgroundResource(light ? R.color.bg_color_light : R.color.bg_color_dark); TextView title = (TextView) searchView.findViewById(R.id.title); - title.setCompoundDrawablesWithIntrinsicBounds(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_search_dark), null, null, null); + title.setCompoundDrawablesWithIntrinsicBounds(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_search_dark), null, null, null); title.setHint(R.string.shared_string_search); searchView.setOnClickListener(new View.OnClickListener() { @Override @@ -783,7 +783,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { int disabledColor = light ? R.color.secondary_text_light : R.color.secondary_text_dark; row.findViewById(R.id.group_divider).setVisibility(groupPosition == 0 ? View.GONE : View.VISIBLE); int color = model.color == 0 || model.color == Color.BLACK ? getResources().getColor(R.color.color_favorite) : model.color; - setCategoryIcon(app, app.getIconsCache().getPaintedIcon( + setCategoryIcon(app, app.getUIUtilities().getPaintedIcon( R.drawable.ic_action_fav_dark, visible ? (color | 0xff000000) : getResources().getColor(disabledColor)), groupPosition, isExpanded, row, light); adjustIndicator(app, groupPosition, isExpanded, row, light); @@ -833,7 +833,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { } final View ch = row.findViewById(R.id.options); if (!selectionMode) { - ((ImageView) ch).setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white)); + ((ImageView) ch).setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_overflow_menu_white)); ch.setVisibility(View.VISIBLE); ch.setContentDescription(getString(R.string.shared_string_settings)); ch.setOnClickListener(new View.OnClickListener() { @@ -877,7 +877,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { if (showOptionsButton) { ImageView options = (ImageView) row.findViewById(R.id.options); options.setFocusable(false); - options.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon( + options.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon( R.drawable.ic_overflow_menu_white)); options.setVisibility(View.VISIBLE); options.setOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java b/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java index 9b95a3e3a5..3075ec1ce9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/IntermediatePointsDialog.java @@ -252,7 +252,7 @@ public class IntermediatePointsDialog { } else { int icon = position == intermediates.size() - 1? R.drawable.ic_action_target: R.drawable.ic_action_intermediate; - tv.setCompoundDrawablesWithIntrinsicBounds(app.getIconsCache().getThemedIcon(icon), null, null, null); + tv.setCompoundDrawablesWithIntrinsicBounds(app.getUIUtilities().getThemedIcon(icon), null, null, null); tv.setCompoundDrawablePadding(padding); final CheckBox ch = ((CheckBox) v.findViewById(R.id.toggle_item)); ch.setVisibility(View.VISIBLE); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 60a5450718..5287bd8e4c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -160,7 +160,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven private static final Log LOG = PlatformUtil.getLog(MapActivity.class); - private static MapViewTrackingUtilities mapViewTrackingUtilities; + private MapViewTrackingUtilities mapViewTrackingUtilities; private static MapContextMenu mapContextMenu = new MapContextMenu(); private static Intent prevActivityIntent = null; @@ -220,7 +220,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven boolean portraitMode = AndroidUiHelper.isOrientationPortrait(this); boolean largeDevice = AndroidUiHelper.isXLargeDevice(this); landscapeLayout = !portraitMode && !largeDevice; - + mapViewTrackingUtilities = app.getMapViewTrackingUtilities(); mapContextMenu.setMapActivity(this); super.onCreate(savedInstanceState); @@ -1226,10 +1226,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } public LatLon getMapLocation() { - if (mapView == null) { - return settings.getLastKnownMapLocation(); - } - return new LatLon(mapView.getLatitude(), mapView.getLongitude()); + return mapViewTrackingUtilities.getMapLocation(); } public float getMapRotate() { @@ -1451,9 +1448,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return mapViewTrackingUtilities; } - public static MapViewTrackingUtilities getSingleMapViewTrackingUtilities() { - return mapViewTrackingUtilities; - } protected void parseLaunchIntentLocation() { Intent intent = getIntent(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java index 3a44bbaf61..1a7a063378 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityLayers.java @@ -327,7 +327,7 @@ public class MapActivityLayers { @Override public void onShow(DialogInterface dialog) { Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL); - Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_singleselect); + Drawable drawable = app.getUIUtilities().getThemedIcon(R.drawable.ic_action_singleselect); neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); neutralButton.setContentDescription(app.getString(R.string.shared_string_filters)); } @@ -391,7 +391,7 @@ public class MapActivityLayers { @Override public void onShow(DialogInterface dialog) { Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL); - Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_multiselect); + Drawable drawable = app.getUIUtilities().getThemedIcon(R.drawable.ic_action_multiselect); neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); neutralButton.setContentDescription(app.getString(R.string.apply_filters)); } diff --git a/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java b/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java index daf1be419e..e66b0738bc 100644 --- a/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/NavigatePointFragment.java @@ -106,7 +106,7 @@ public class NavigatePointFragment extends Fragment implements SearchActivityChi } MenuItem menuItem = menu.add(0, SHOW_ON_MAP, 0, R.string.shared_string_show_on_map); MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); - menuItem = menuItem.setIcon(app.getIconsCache().getIcon(R.drawable.ic_action_marker_dark, light)); + menuItem = menuItem.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_marker_dark, light)); menuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/OpeningHoursView.java b/OsmAnd/src/net/osmand/plus/activities/OpeningHoursView.java index d4dd64b7ee..cd6dddec3d 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OpeningHoursView.java +++ b/OsmAnd/src/net/osmand/plus/activities/OpeningHoursView.java @@ -122,7 +122,7 @@ public class OpeningHoursView { } TextView label = (TextView)row.findViewById(R.id.label); ImageView icon = (ImageView)row.findViewById(R.id.remove); - icon.setBackgroundDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark)); + icon.setBackgroundDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark)); if(selectedRule == position){ label.setTypeface(null, Typeface.BOLD); label.setTextSize(22); diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java b/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java index 5162339969..108baf0176 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandActionBarActivity.java @@ -19,7 +19,7 @@ public class OsmandActionBarActivity extends OsmandInAppPurchaseActivity { //should be called after set content view protected void setupHomeButton(){ - Drawable back = ((OsmandApplication)getApplication()).getIconsCache().getIcon(R.drawable.ic_arrow_back); + Drawable back = ((OsmandApplication)getApplication()).getUIUtilities().getIcon(R.drawable.ic_arrow_back); back.setColorFilter(ContextCompat.getColor(this, R.color.color_white), PorterDuff.Mode.MULTIPLY); final ActionBar supportActionBar = getSupportActionBar(); if (supportActionBar != null) { diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandBaseExpandableListAdapter.java b/OsmAnd/src/net/osmand/plus/activities/OsmandBaseExpandableListAdapter.java index 55873e5102..792780859a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandBaseExpandableListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandBaseExpandableListAdapter.java @@ -13,10 +13,10 @@ public abstract class OsmandBaseExpandableListAdapter extends BaseExpandableList protected void adjustIndicator(OsmandApplication app, int groupPosition, boolean isExpanded, View row, boolean light) { ImageView indicator = (ImageView) row.findViewById(R.id.explist_indicator); if (!isExpanded) { - indicator.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_arrow_down, light)); + indicator.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_down, light)); indicator.setContentDescription(row.getContext().getString(R.string.access_collapsed_list)); } else { - indicator.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_arrow_up, light)); + indicator.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_up, light)); indicator.setContentDescription(row.getContext().getString(R.string.access_expanded_list)); } indicator.setVisibility(getChildrenCount(groupPosition) > 0 ? View.VISIBLE : View.GONE); @@ -25,9 +25,9 @@ public abstract class OsmandBaseExpandableListAdapter extends BaseExpandableList protected void setCategoryIcon(OsmandApplication app, int resId, int groupPosition, boolean isExpanded, View row, boolean light) { ImageView icon = (ImageView) row.findViewById(R.id.category_icon); if (resId == 0) { - icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_folder_stroke, light)); + icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_folder_stroke, light)); } else { - icon.setImageDrawable(app.getIconsCache().getIcon(resId, light)); + icon.setImageDrawable(app.getUIUtilities().getIcon(resId, light)); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/OsmandListActivity.java b/OsmAnd/src/net/osmand/plus/activities/OsmandListActivity.java index cc6294e4c2..2d7f8d3c77 100644 --- a/OsmAnd/src/net/osmand/plus/activities/OsmandListActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/OsmandListActivity.java @@ -54,7 +54,7 @@ public abstract class OsmandListActivity extends public MenuItem createMenuItem(Menu m, int id, int titleRes, int iconDark, int menuItemType) { MenuItem menuItem = m.add(0, id, 0, titleRes); if (iconDark != 0) { - menuItem.setIcon(getMyApplication().getIconsCache().getIcon(iconDark)); + menuItem.setIcon(getMyApplication().getUIUtilities().getIcon(iconDark)); } menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java b/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java index 656f3079cf..0ea1b94b3c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/PluginActivity.java @@ -132,7 +132,7 @@ public class PluginActivity extends OsmandActionBarActivity { Button getButton = (Button)findViewById(R.id.plugin_get); Button settingsButton = (Button)findViewById(R.id.plugin_settings); settingsButton.setCompoundDrawablesWithIntrinsicBounds( - getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_settings), + getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_settings), null, null, null); View installHeader = findViewById(R.id.plugin_install_header); @@ -142,7 +142,7 @@ public class PluginActivity extends OsmandActionBarActivity { settingsButton.setVisibility(View.GONE); installHeader.setVisibility(View.VISIBLE); View worldGlobeIcon = installHeader.findViewById(R.id.ic_world_globe); - Drawable worldGlobeDrawable = getMyApplication().getIconsCache().getThemedIcon( + Drawable worldGlobeDrawable = getMyApplication().getUIUtilities().getThemedIcon( R.drawable.ic_world_globe_dark); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { worldGlobeIcon.setBackground(worldGlobeDrawable); diff --git a/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java b/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java index 2adf4973d2..219c4145c4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/PluginsActivity.java @@ -124,7 +124,7 @@ public class PluginsActivity extends OsmandListActivity { ImageView pluginOptions = (ImageView) view.findViewById(R.id.plugin_options); - pluginOptions.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white)); + pluginOptions.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_overflow_menu_white)); pluginOptions.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index 9fc8c3867e..272dea98f7 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -1,6 +1,30 @@ package net.osmand.plus.activities; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.osmand.IProgress; +import net.osmand.IndexConstants; +import net.osmand.data.PointDescription; +import net.osmand.osm.io.NetworkUtils; +import net.osmand.plus.ApplicationMode; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.DrivingRegion; +import net.osmand.plus.OsmandSettings.MetricsConstants; +import net.osmand.plus.R; +import net.osmand.plus.Version; +import net.osmand.plus.base.MapViewTrackingUtilities; +import net.osmand.plus.dashboard.DashChooseAppDirFragment; +import net.osmand.plus.dashboard.DashChooseAppDirFragment.ChooseAppDirFragment; +import net.osmand.plus.dashboard.DashChooseAppDirFragment.MoveFilesToDifferentDirectory; +import net.osmand.plus.dialogs.ConfigureMapMenu; +import net.osmand.plus.download.DownloadActivity; +import net.osmand.plus.render.NativeOsmandLibrary; +import net.osmand.render.RenderingRulesStorage; import android.app.Dialog; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; @@ -31,32 +55,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; -import net.osmand.IProgress; -import net.osmand.IndexConstants; -import net.osmand.data.PointDescription; -import net.osmand.osm.io.NetworkUtils; -import net.osmand.plus.ApplicationMode; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.OsmandSettings.DrivingRegion; -import net.osmand.plus.OsmandSettings.MetricsConstants; -import net.osmand.plus.R; -import net.osmand.plus.Version; -import net.osmand.plus.base.MapViewTrackingUtilities; -import net.osmand.plus.dashboard.DashChooseAppDirFragment; -import net.osmand.plus.dashboard.DashChooseAppDirFragment.ChooseAppDirFragment; -import net.osmand.plus.dashboard.DashChooseAppDirFragment.MoveFilesToDifferentDirectory; -import net.osmand.plus.dialogs.ConfigureMapMenu; -import net.osmand.plus.download.DownloadActivity; -import net.osmand.plus.inapp.InAppPurchaseHelper; -import net.osmand.plus.render.NativeOsmandLibrary; -import net.osmand.render.RenderingRulesStorage; - -import java.io.File; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - public class SettingsGeneralActivity extends SettingsBaseActivity implements OnRequestPermissionsResultCallback { @@ -168,7 +166,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR public void onClick(DialogInterface dialog, int which) { if (drs.get(which) == null) { settings.DRIVING_REGION_AUTOMATIC.set(true); - MapViewTrackingUtilities mapViewTrackingUtilities = MapActivity.getSingleMapViewTrackingUtilities(); + MapViewTrackingUtilities mapViewTrackingUtilities = getMyApplication().getMapViewTrackingUtilities(); if (mapViewTrackingUtilities != null) { mapViewTrackingUtilities.resetDrivingRegionUpdate(); } diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java index abdb4839ce..4ba8569454 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java @@ -46,7 +46,7 @@ import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -108,7 +108,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { view = inflater.inflate(R.layout.route_info_layout, container, false); Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); - toolbar.setNavigationIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_arrow_back)); + toolbar.setNavigationIcon(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationContentDescription(R.string.shared_string_close); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override @@ -118,9 +118,9 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { }); ((ImageView) view.findViewById(R.id.distance_icon)) - .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_route_distance)); + .setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_route_distance)); ((ImageView) view.findViewById(R.id.time_icon)) - .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_time_span)); + .setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_time_span)); buildMenuButtons(); @@ -337,13 +337,13 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { ((TextView) headerView.findViewById(R.id.ascent_text)).setText(asc); ((ImageView) headerView.findViewById(R.id.average_icon)) - .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_average)); + .setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_altitude_average)); ((ImageView) headerView.findViewById(R.id.range_icon)) - .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_average)); + .setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_altitude_average)); ((ImageView) headerView.findViewById(R.id.descent_icon)) - .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_descent)); + .setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_altitude_descent)); ((ImageView) headerView.findViewById(R.id.ascent_icon)) - .setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_ascent)); + .setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_altitude_ascent)); headerView.findViewById(R.id.details_view).setOnClickListener(new View.OnClickListener() { @Override @@ -415,7 +415,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { } private void buildMenuButtons() { - IconsCache iconsCache = getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMyApplication().getUIUtilities(); ImageButton printRoute = (ImageButton) view.findViewById(R.id.print_route); printRoute.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_gprint_dark)); printRoute.setOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java index 47ebe3098d..dbc59ddadb 100644 --- a/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java +++ b/OsmAnd/src/net/osmand/plus/activities/actions/AppModeDialog.java @@ -76,15 +76,15 @@ public class AppModeDialog { ImageView iv = (ImageView) tb.findViewById(R.id.app_mode_icon); boolean nightMode = isNightMode(ctx, useMapTheme); if (checked) { - iv.setImageDrawable(ctx.getIconsCache().getIcon(mode.getSmallIconDark(), nightMode ? R.color.route_info_checked_mode_icon_color_dark : R.color.route_info_checked_mode_icon_color_light)); + iv.setImageDrawable(ctx.getUIUtilities().getIcon(mode.getSmallIconDark(), nightMode ? R.color.route_info_checked_mode_icon_color_dark : R.color.route_info_checked_mode_icon_color_light)); iv.setContentDescription(String.format("%s %s", mode.toHumanString(ctx), ctx.getString(R.string.item_checked))); tb.findViewById(R.id.selection).setVisibility(View.VISIBLE); } else { if (useMapTheme) { - iv.setImageDrawable(ctx.getIconsCache().getIcon(mode.getSmallIconDark(), R.color.route_info_unchecked_mode_icon_color)); + iv.setImageDrawable(ctx.getUIUtilities().getIcon(mode.getSmallIconDark(), R.color.route_info_unchecked_mode_icon_color)); iv.setBackgroundResource(AndroidUtils.resolveAttribute(ctx, android.R.attr.selectableItemBackground)); } else { - iv.setImageDrawable(ctx.getIconsCache().getThemedIcon(mode.getSmallIconDark())); + iv.setImageDrawable(ctx.getUIUtilities().getThemedIcon(mode.getSmallIconDark())); } iv.setContentDescription(String.format("%s %s", mode.toHumanString(ctx), ctx.getString(R.string.item_unchecked))); tb.findViewById(R.id.selection).setVisibility(View.INVISIBLE); @@ -123,7 +123,7 @@ public class AppModeDialog { int metricsY = (int) ctx.getResources().getDimension(R.dimen.route_info_modes_height); View tb = layoutInflater.inflate(R.layout.mode_view, null); ImageView iv = (ImageView) tb.findViewById(R.id.app_mode_icon); - iv.setImageDrawable(ctx.getIconsCache().getIcon(mode.getSmallIconDark(), isNightMode(ctx, useMapTheme) ? R.color.route_info_checked_mode_icon_color_dark : R.color.route_info_checked_mode_icon_color_light)); + iv.setImageDrawable(ctx.getUIUtilities().getIcon(mode.getSmallIconDark(), isNightMode(ctx, useMapTheme) ? R.color.route_info_checked_mode_icon_color_dark : R.color.route_info_checked_mode_icon_color_light)); iv.setContentDescription(mode.toHumanString(ctx)); // tb.setCompoundDrawablesWithIntrinsicBounds(null, ctx.getIconsCache().getIcon(mode.getIconId(), R.color.app_mode_icon_color), null, null); LayoutParams lp = new LinearLayout.LayoutParams(metricsX, metricsY); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java index 479f88c1ec..1fe5410bf1 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchAddressFragment.java @@ -179,7 +179,7 @@ public class SearchAddressFragment extends Fragment { } }); OsmandApplication app = getApplication(); - Drawable icon = getApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark); + Drawable icon = getApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark); ((ImageView)findViewById(R.id.ResetBuilding)).setBackgroundDrawable(icon); findViewById(R.id.ResetBuilding).setOnClickListener(new View.OnClickListener(){ @Override diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java index dd081e1dce..83191ef1da 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java @@ -1,5 +1,22 @@ package net.osmand.plus.activities.search; +import java.util.List; + +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +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.UiUtilities; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild; +import net.osmand.plus.base.OsmAndListFragment; +import net.osmand.plus.helpers.SearchHistoryHelper; +import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; +import net.osmand.util.MapUtils; import android.app.Activity; import android.content.DialogInterface; import android.content.Intent; @@ -24,24 +41,6 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.TextView.BufferType; -import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; -import net.osmand.plus.IconsCache; -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.MapActivity; -import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild; -import net.osmand.plus.base.OsmAndListFragment; -import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.plus.helpers.SearchHistoryHelper; -import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; -import net.osmand.util.MapUtils; - -import java.util.List; - public class SearchHistoryFragment extends OsmAndListFragment implements SearchActivityChild, OsmAndCompassListener { private LatLon location; @@ -51,9 +50,9 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA public static final String SEARCH_LON = SearchActivity.SEARCH_LON; private HistoryAdapter historyAdapter; private Float heading; - private boolean searchAroundLocation; private boolean compassRegistered; - private int screenOrientation; + private UpdateLocationViewCache updateLocationViewCache; + private double lastHeading; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -125,19 +124,18 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA //Hardy: onResume() code is needed so that search origin is properly reflected in tab contents when origin has been changed on one tab, then tab is changed to another one. location = null; FragmentActivity activity = getActivity(); + updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(getActivity()); Intent intent = activity.getIntent(); if (intent != null) { double lat = intent.getDoubleExtra(SEARCH_LAT, 0); double lon = intent.getDoubleExtra(SEARCH_LON, 0); if (lat != 0 || lon != 0) { - historyAdapter.location = new LatLon(lat, lon); + updateLocationViewCache.specialFrom = new LatLon(lat, lon); + } } - if (location == null && activity instanceof SearchActivity) { - location = ((SearchActivity) activity).getSearchPoint(); - } - if (location == null) { - location = ((OsmandApplication) activity.getApplication()).getSettings().getLastKnownMapLocation(); + if (activity instanceof SearchActivity && ((SearchActivity) activity).getSearchPoint() != null) { + updateLocationViewCache.specialFrom = ((SearchActivity) activity).getSearchPoint(); } historyAdapter.clear(); for (HistoryEntry entry : helper.getHistoryEntries()) { @@ -145,12 +143,11 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA } 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) { @@ -159,13 +156,13 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA app.getLocationProvider().addCompassListener(this); compassRegistered = true; } - searchAroundLocation = true; + updateLocationViewCache.specialFrom = null; } else { - searchAroundLocation = false; + updateLocationViewCache.specialFrom = ((SearchActivity) getActivity()).getSearchPoint(); } } if (historyAdapter != null) { - historyAdapter.updateLocation(l); + historyAdapter.updateLocation(); } } @@ -205,7 +202,7 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA final PopupMenu optionsMenu = new PopupMenu(getActivity(), v); MenuItem item = optionsMenu.getMenu().add( R.string.shared_string_remove).setIcon( - getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_delete_dark)); + getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_delete_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { @@ -218,11 +215,9 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA } class HistoryAdapter extends ArrayAdapter { - private LatLon location; - public void updateLocation(LatLon l) { - location = l; + public void updateLocation() { notifyDataSetChanged(); } @@ -241,10 +236,11 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA 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()); + getMyApplication().getUIUtilities().updateLocationView(updateLocationViewCache, + direction, distanceText, historyEntry.getLat(), + historyEntry.getLon()); ImageButton options = (ImageButton) row.findViewById(R.id.options); - options.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white)); + options.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_overflow_menu_white)); options.setVisibility(View.VISIBLE); options.setOnClickListener(new View.OnClickListener() { @Override @@ -264,7 +260,7 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA TextView nameText = (TextView) row.findViewById(R.id.name); TextView distanceText = (TextView) row.findViewById(R.id.distance); ImageView direction = (ImageView) row.findViewById(R.id.direction); - IconsCache ic = app.getIconsCache(); + UiUtilities ic = app.getUIUtilities(); direction.setImageDrawable(ic.getIcon(R.drawable.ic_direction_arrow, R.color.color_distance)); String distance = ""; if (location != null) { @@ -326,12 +322,9 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA @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 FragmentActivity activity = getActivity(); - float lastHeading = heading != null ? heading : 99; - heading = value; - if (heading != null && Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) { + if (Math.abs(MapUtils.degreesDiff(lastHeading, value)) > 5) { + lastHeading = value; if (activity instanceof SearchActivity) { ((SearchActivity)activity).getAccessibilityAssistant().lockEvents(); historyAdapter.notifyDataSetChanged(); @@ -339,8 +332,6 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA } else { historyAdapter.notifyDataSetChanged(); } - } else { - heading = lastHeading; } if (activity instanceof SearchActivity) { final View selected = ((SearchActivity)activity).getAccessibilityAssistant().getFocusedView(); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index dcc5abf3f9..7d8e02e032 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -3,6 +3,45 @@ */ package net.osmand.plus.activities.search; +import gnu.trove.set.hash.TLongHashSet; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import net.osmand.Location; +import net.osmand.ResultMatcher; +import net.osmand.access.AccessibilityAssistant; +import net.osmand.access.NavigationInfo; +import net.osmand.data.Amenity; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.osm.PoiType; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; +import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.R.color; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.EditPOIFilterActivity; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.OsmandListActivity; +import net.osmand.plus.poi.NominatimPoiFilter; +import net.osmand.plus.poi.PoiUIFilter; +import net.osmand.plus.poi.PoiUIFilter.AmenityNameFilter; +import net.osmand.plus.render.RenderingIcons; +import net.osmand.plus.views.DirectionDrawable; +import net.osmand.util.Algorithms; +import net.osmand.util.MapUtils; +import net.osmand.util.OpeningHoursParser; +import net.osmand.util.OpeningHoursParser.OpeningHours; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -36,47 +75,6 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; -import net.osmand.Location; -import net.osmand.ResultMatcher; -import net.osmand.access.AccessibilityAssistant; -import net.osmand.access.NavigationInfo; -import net.osmand.data.Amenity; -import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; -import net.osmand.osm.PoiType; -import net.osmand.plus.IconsCache; -import net.osmand.plus.OsmAndFormatter; -import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; -import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; -import net.osmand.plus.R.color; -import net.osmand.plus.activities.EditPOIFilterActivity; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.OsmandListActivity; -import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.plus.poi.NominatimPoiFilter; -import net.osmand.plus.poi.PoiUIFilter; -import net.osmand.plus.poi.PoiUIFilter.AmenityNameFilter; -import net.osmand.plus.render.RenderingIcons; -import net.osmand.plus.views.DirectionDrawable; -import net.osmand.util.Algorithms; -import net.osmand.util.MapUtils; -import net.osmand.util.OpeningHoursParser; -import net.osmand.util.OpeningHoursParser.OpeningHours; - -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import gnu.trove.set.hash.TLongHashSet; - /** * Search poi activity */ @@ -133,7 +131,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa }); showFilterItem = menu.add(0, FILTER, 0, R.string.search_poi_filter); MenuItemCompat.setShowAsAction(showFilterItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); - showFilterItem = showFilterItem.setIcon(getMyApplication().getIconsCache().getIcon( + showFilterItem = showFilterItem.setIcon(getMyApplication().getUIUtilities().getIcon( R.drawable.ic_action_filter_dark)); showFilterItem.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override @@ -156,7 +154,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa showOnMapItem = menu.add(0, SHOW_ON_MAP, 0, R.string.shared_string_show_on_map); MenuItemCompat.setShowAsAction(showOnMapItem, MenuItemCompat.SHOW_AS_ACTION_ALWAYS); - showOnMapItem = showOnMapItem.setIcon(getMyApplication().getIconsCache().getIcon( + showOnMapItem = showOnMapItem.setIcon(getMyApplication().getUIUtilities().getIcon( R.drawable.ic_show_on_map)); showOnMapItem.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override @@ -264,9 +262,9 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa }); searchFilter.setHint(R.string.filter_poi_hint); ((ImageView) findViewById(R.id.search_icon)).setImageDrawable( - getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_filter_dark)); + getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_filter_dark)); ((ImageView) findViewById(R.id.options)). - setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white)); + setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_overflow_menu_white)); findViewById(R.id.options).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -346,7 +344,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa private void showOptionsMenu(View v) { // Show menu with search all, name finder, name finder poi - IconsCache iconsCache = getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMyApplication().getUIUtilities(); final PopupMenu optionsMenu = new PopupMenu(this, v); final PoiUIFilter f = this.filter; @@ -380,7 +378,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa } private void addFilter(PopupMenu optionsMenu, final String value) { - IconsCache iconsCache = getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMyApplication().getUIUtilities(); MenuItem item = optionsMenu.getMenu().add(getString(R.string.search_poi_filter) + ": " + value) .setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_filter_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @@ -557,7 +555,8 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa try { int position = getListView().getPositionForView(selected); if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) { - navigationInfo.updateTargetDirection(amenityAdapter.getItem(position - getListView().getHeaderViewsCount()).getLocation(), heading.floatValue()); + navigationInfo.updateTargetDirection(amenityAdapter.getItem(position - getListView().getHeaderViewsCount()). + getLocation(), heading.floatValue()); } } catch (Exception e) { return; @@ -731,7 +730,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa public void setNewModel(List amenityList) { setNotifyOnChange(false); - screenOrientation = DashLocationFragment.getScreenOrientation(SearchPOIActivity.this); + screenOrientation = getMyApplication().getUIUtilities().getScreenOrientation(SearchPOIActivity.this); originalAmenityList = new ArrayList(amenityList); clear(); for (Amenity obj : amenityList) { @@ -768,7 +767,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa timeIcon.setVisibility(View.VISIBLE); timeText.setVisibility(View.VISIBLE); - timeIcon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_small_time, colorId)); + timeIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_small_time, colorId)); timeText.setTextColor(app.getResources().getColor(colorId)); String rt = rs.getCurrentRuleTime(inst); timeText.setText(rt == null ? "" : rt); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java index cc55f1a2f5..15b4791da6 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterFragment.java @@ -30,7 +30,7 @@ import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.data.LatLon; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.PoiType; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -67,7 +67,7 @@ public class SearchPoiFilterFragment extends OsmAndListFragment implements Searc v.findViewById(R.id.SearchFilterLayout).setVisibility(View.VISIBLE); ((EditText) v.findViewById(R.id.searchEditText)).setHint(R.string.search_poi_category_hint); ((ImageView) v.findViewById(R.id.search_icon)).setImageDrawable( - getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_search_dark)); + getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_search_dark)); setupSearchEditText((EditText) v.findViewById(R.id.searchEditText)); setupOptions((ImageView) v.findViewById(R.id.options)); @@ -76,7 +76,7 @@ public class SearchPoiFilterFragment extends OsmAndListFragment implements Searc } private void setupOptions(ImageView options) { - options.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white)); + options.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_overflow_menu_white)); options.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -326,7 +326,7 @@ public class SearchPoiFilterFragment extends OsmAndListFragment implements Searc private void showOptionsMenu(View v) { // Show menu with search all, name finder, name finder poi - IconsCache iconsCache = getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMyApplication().getUIUtilities(); final PopupMenu optionsMenu = new PopupMenu(getActivity(), v); MenuItem item = optionsMenu.getMenu().add(R.string.poi_filter_custom_filter) diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenu.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenu.java index 0386a0dc72..71d0d85a27 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenu.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNoteRecordingMenu.java @@ -10,7 +10,7 @@ import android.widget.LinearLayout; import android.widget.TextView; import net.osmand.AndroidUtils; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.AVActionType; @@ -124,7 +124,7 @@ public class AudioVideoNoteRecordingMenu { public void update() { CurrentRecording recording = plugin.getCurrentRecording(); - IconsCache iconsCache = plugin.getMapActivity().getMyApplication().getIconsCache(); + UiUtilities iconsCache = plugin.getMapActivity().getMyApplication().getUIUtilities(); ImageView leftButtonIcon = (ImageView) view.findViewById(R.id.leftButtonIcon); View leftButtonView = view.findViewById(R.id.leftButtonView); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java index c1248da2a0..4ae2e79cfc 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java @@ -94,7 +94,7 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { View view = inflater.inflate(R.layout.note, null, false); getNoteView(recording, view, getMyApplication()); - ((ImageView) view.findViewById(R.id.play)).setImageDrawable(getMyApplication().getIconsCache() + ((ImageView) view.findViewById(R.id.play)).setImageDrawable(getMyApplication().getUIUtilities() .getThemedIcon(R.drawable.ic_play_dark)); view.findViewById(R.id.play).setOnClickListener(new View.OnClickListener() { @Override @@ -146,11 +146,11 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { Drawable iconDrawable; if (recording.isAudio()) { - iconDrawable = ctx.getIconsCache().getIcon(R.drawable.ic_type_audio, R.color.color_distance); + iconDrawable = ctx.getUIUtilities().getIcon(R.drawable.ic_type_audio, R.color.color_distance); } else if (recording.isVideo()) { - iconDrawable = ctx.getIconsCache().getIcon(R.drawable.ic_type_video, R.color.color_distance); + iconDrawable = ctx.getUIUtilities().getIcon(R.drawable.ic_type_video, R.color.color_distance); } else { - iconDrawable = ctx.getIconsCache().getIcon(R.drawable.ic_type_img, R.color.color_distance); + iconDrawable = ctx.getUIUtilities().getIcon(R.drawable.ic_type_img, R.color.color_distance); } icon.setImageDrawable(iconDrawable); return iconDrawable; diff --git a/OsmAnd/src/net/osmand/plus/audionotes/adapters/NotesAdapter.java b/OsmAnd/src/net/osmand/plus/audionotes/adapters/NotesAdapter.java index 1fe1548665..99660a24c1 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/adapters/NotesAdapter.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/adapters/NotesAdapter.java @@ -212,7 +212,7 @@ public class NotesAdapter extends ArrayAdapter { int iconRes = recording.isAudio() ? R.drawable.ic_type_audio : (recording.isVideo() ? R.drawable.ic_type_video : R.drawable.ic_type_img); int colorRes = app.getSettings().isLightContent() ? R.color.icon_color : R.color.ctx_menu_info_text_dark; - holder.icon.setImageDrawable(app.getIconsCache().getIcon(iconRes, colorRes)); + holder.icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes, colorRes)); } holder.bottomDivider.setVisibility(hideBottomDivider(position) ? View.GONE : View.VISIBLE); @@ -230,7 +230,7 @@ public class NotesAdapter extends ArrayAdapter { } }); } else { - holder.options.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white)); + holder.options.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_overflow_menu_white)); holder.options.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/base/BaseOsmAndDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/BaseOsmAndDialogFragment.java index 79f21ac682..3045caba3b 100644 --- a/OsmAnd/src/net/osmand/plus/base/BaseOsmAndDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/BaseOsmAndDialogFragment.java @@ -10,14 +10,14 @@ import android.support.v7.app.AppCompatActivity; import android.view.WindowManager; import android.widget.ImageView; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; public class BaseOsmAndDialogFragment extends DialogFragment { - private IconsCache iconsCache; + private UiUtilities iconsCache; @Override public void onCreate(Bundle savedInstanceState) { @@ -35,9 +35,9 @@ public class BaseOsmAndDialogFragment extends DialogFragment { return (AppCompatActivity) getActivity(); } - protected IconsCache getIconsCache() { + protected UiUtilities getIconsCache() { if (iconsCache == null) { - iconsCache = getMyApplication().getIconsCache(); + iconsCache = getMyApplication().getUIUtilities(); } return iconsCache; } diff --git a/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java b/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java index 72ffcf57b2..79a1e79b78 100644 --- a/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/BaseOsmAndFragment.java @@ -18,7 +18,7 @@ import android.view.ViewTreeObserver; import android.view.animation.Animation; import android.widget.ImageView; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.activities.MapActivity; @@ -26,7 +26,7 @@ import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.activities.OsmandInAppPurchaseActivity; public class BaseOsmAndFragment extends Fragment implements TransitionAnimator { - private IconsCache iconsCache; + private UiUtilities iconsCache; private int statusBarColor = -1; private boolean transitionAnimationAllowed = true; @@ -165,26 +165,26 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator { } @Nullable - protected IconsCache getIconsCache() { + protected UiUtilities getIconsCache() { OsmandApplication app = getMyApplication(); if (iconsCache == null && app != null) { - iconsCache = app.getIconsCache(); + iconsCache = app.getUIUtilities(); } return iconsCache; } protected Drawable getPaintedContentIcon(@DrawableRes int id, @ColorInt int color) { - IconsCache cache = getIconsCache(); + UiUtilities cache = getIconsCache(); return cache != null ? cache.getPaintedIcon(id, color) : null; } protected Drawable getIcon(@DrawableRes int id, @ColorRes int colorId) { - IconsCache cache = getIconsCache(); + UiUtilities cache = getIconsCache(); return cache != null ? cache.getIcon(id, colorId) : null; } protected Drawable getContentIcon(@DrawableRes int id) { - IconsCache cache = getIconsCache(); + UiUtilities cache = getIconsCache(); return cache != null ? cache.getThemedIcon(id) : null; } diff --git a/OsmAnd/src/net/osmand/plus/base/BottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/BottomSheetDialogFragment.java index 2ee718b55f..1e8714aec6 100644 --- a/OsmAnd/src/net/osmand/plus/base/BottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/BottomSheetDialogFragment.java @@ -79,7 +79,7 @@ public abstract class BottomSheetDialogFragment extends DialogFragment { protected Drawable getIcon(@DrawableRes int drawableRes, @ColorRes int color) { OsmandApplication app = getMyApplication(); if (app != null) { - return app.getIconsCache().getIcon(drawableRes, color); + return app.getUIUtilities().getIcon(drawableRes, color); } else { return null; } @@ -89,7 +89,7 @@ public abstract class BottomSheetDialogFragment extends DialogFragment { protected Drawable getContentIcon(@DrawableRes int drawableRes) { OsmandApplication app = getMyApplication(); if (app != null) { - return app.getIconsCache().getThemedIcon(drawableRes); + return app.getUIUtilities().getThemedIcon(drawableRes); } else { return null; } diff --git a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java index 6d9db21c34..2864df1036 100644 --- a/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java +++ b/OsmAnd/src/net/osmand/plus/base/MapViewTrackingUtilities.java @@ -440,6 +440,20 @@ public class MapViewTrackingUtilities implements OsmAndLocationListener, IMapLoc mapView.refreshMap(); } } + + public LatLon getMapLocation() { + if (mapView == null) { + return settings.getLastKnownMapLocation(); + } + return new LatLon(mapView.getLatitude(), mapView.getLongitude()); + } + + public Float getMapRotate() { + if (mapView == null) { + return null; + } + return mapView.getRotate(); + } @Override public void newRouteIsCalculated(boolean newRoute, ValueHolder showToast) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java index 6b1add72db..ee5e798f45 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java @@ -49,7 +49,7 @@ public class DashErrorFragment extends DashBaseFragment { String msg = MessageFormat.format(getString(R.string.previous_run_crashed), OsmandApplication.EXCEPTION_PATH); Typeface typeface = FontCache.getRobotoMedium(getActivity()); ImageView iv = ((ImageView) view.findViewById(R.id.error_icon)); - iv.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_crashlog)); + iv.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_crashlog)); TextView message = ((TextView) view.findViewById(R.id.error_header)); message.setTypeface(typeface); message.setText(msg); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java index 67a36dfd53..2ddc7319c1 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java @@ -105,7 +105,7 @@ public class DashFavoritesFragment extends DashLocationFragment { ImageView groupImage = (ImageView)view.findViewById(R.id.group_image); if (point.getCategory().length() > 0) { ((TextView) view.findViewById(R.id.group_name)).setText(point.getCategory()); - groupImage.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_small_group)); + groupImage.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_small_group)); } else { groupImage.setVisibility(View.GONE); } @@ -120,7 +120,7 @@ public class DashFavoritesFragment extends DashLocationFragment { name.setTypeface(Typeface.DEFAULT, point.isVisible() ? Typeface.NORMAL : Typeface.ITALIC); view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE); - ((ImageView) view.findViewById(R.id.navigate_to)).setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_gdirections_dark)); + ((ImageView) view.findViewById(R.id.navigate_to)).setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_gdirections_dark)); view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java index e651ab77cf..db1b8511ad 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java @@ -1,24 +1,15 @@ package net.osmand.plus.dashboard; -import android.annotation.SuppressLint; -import android.app.Activity; -import android.content.Context; -import android.hardware.Sensor; -import android.hardware.SensorManager; -import android.view.WindowManager; -import android.widget.ImageView; -import android.widget.TextView; - -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 java.util.ArrayList; import java.util.List; +import net.osmand.data.LatLon; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; +import android.annotation.SuppressLint; +import android.widget.ImageView; +import android.widget.TextView; + /** * Created by Denis * on 26.01.2015. @@ -26,10 +17,6 @@ import java.util.List; @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 List distances = new ArrayList(); private int screenOrientation; @@ -46,40 +33,15 @@ public abstract class DashLocationFragment extends DashBaseFragment { this.txt = txt; this.loc = loc; } - - } @Override public void onOpenDash() { //Hardy: getRotation() is the correction if device's screen orientation != the default display's standard orientation - screenOrientation = getScreenOrientation(getActivity()); + screenOrientation = UiUtilities.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) - screenOrientation = 0; - break; - case ORIENTATION_90: // Landscape right - screenOrientation = 90; - break; - case ORIENTATION_270: // Landscape left - screenOrientation = 270; - break; - case ORIENTATION_180: // Upside down - screenOrientation = 180; - break; - } - //Looks like screenOrientation correction must not be applied for devices without compass? - Sensor compass = ((SensorManager) a.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); - if (compass == null) { - screenOrientation = 0; - } - return screenOrientation; - } public LatLon getDefaultLocation() { DashboardOnMap d = dashboard; @@ -94,114 +56,16 @@ public abstract class DashLocationFragment extends DashBaseFragment { if (d == null) { return; } - float head = d.getHeading(); - float mapRotation = d.getMapRotation(); - LatLon mw = d.getMapViewLocation(); - boolean useCenter = !d.isMapLinkedToLocation(); - float h = useCenter ? -mapRotation : head; + UiUtilities ic = getMyApplication().getUIUtilities(); + UpdateLocationViewCache cache = ic.getUpdateLocationViewCache(getActivity()); for (DashLocationView lv : distances) { - updateLocationView(useCenter, mw, h, lv.arrow, lv.arrowResId, lv.txt, lv.loc, screenOrientation, - getMyApplication(), lv.paint); + cache.arrowResId = lv.arrowResId; + cache.paintTxt = lv.paint; + ic.updateLocationView(cache, lv.arrow, lv.txt, lv.loc); } } - public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h, - ImageView arrow, int imgColor, TextView txt, int textColor, double toLat, double toLon, - int screenOrientation, OsmandApplication app, Context ctx) { - updateLocationView(useCenter, fromLoc, h, arrow, 0, imgColor, txt, textColor, new LatLon(toLat, toLon), screenOrientation, app, true); - } - - public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h, - ImageView arrow, TextView txt, double toLat, double toLon, - int screenOrientation, OsmandApplication app) { - updateLocationView(useCenter, fromLoc, h, arrow, 0, txt, new LatLon(toLat, toLon), screenOrientation, app, true); - } - - public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h, - ImageView arrow, int arrowResId, TextView txt, LatLon toLoc, - int screenOrientation, OsmandApplication app, boolean paint) { - updateLocationView(useCenter, fromLoc, h, arrow, arrowResId, 0, txt, 0, toLoc, screenOrientation, app, paint); - } - - public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h, - ImageView arrow, int arrowResId, int imgColor, TextView txt, LatLon toLoc, - int screenOrientation, OsmandApplication app, boolean paint) { - updateLocationView(useCenter, fromLoc, h, arrow, arrowResId, imgColor, txt, 0, toLoc, screenOrientation, app, paint); - } - - public static void updateLocationView(boolean useCenter, LatLon fromLoc, Float h, - ImageView arrow, int arrowResId, int imgColor, TextView txt, int textColor, LatLon toLoc, - int screenOrientation, OsmandApplication app, boolean paint) { - float[] mes = new float[2]; - boolean stale = false; - if(!useCenter) { - Location loc = app.getLocationProvider().getLastKnownLocation(); - if(loc == null) { - loc = app.getLocationProvider().getLastStaleKnownLocation(); - stale = true; - } - - if(loc != null) { - fromLoc = new LatLon(loc.getLatitude(), loc.getLongitude()); - } else { - fromLoc = null; - } - } - if (fromLoc != null && toLoc != null) { - Location.distanceBetween(toLoc.getLatitude(), toLoc.getLongitude(), fromLoc.getLatitude(), fromLoc.getLongitude(), mes); - } - - - if (arrow != null) { - boolean newImage = false; - if (arrowResId == 0) { - arrowResId = R.drawable.ic_direction_arrow; - } - DirectionDrawable dd; - if(!(arrow.getDrawable() instanceof DirectionDrawable)) { - newImage = true; - dd = new DirectionDrawable(app, arrow.getWidth(), arrow.getHeight()); - } else { - dd = (DirectionDrawable) arrow.getDrawable(); - } - int imgColorSet = imgColor; - if (imgColorSet == 0) { - imgColorSet = useCenter ? R.color.color_distance : R.color.color_myloc_distance; - if(stale) { - imgColorSet = R.color.icon_color; - } - } - dd.setImage(arrowResId, imgColorSet); - if (fromLoc == null || h == null || toLoc == null) { - dd.setAngle(0); - } else { - dd.setAngle(mes[1] - h + 180 + screenOrientation); - } - if (newImage) { - arrow.setImageDrawable(dd); - } - arrow.invalidate(); - } - if (txt != null) { - if (fromLoc != null && toLoc != null) { - if (paint) { - int textColorSet = textColor; - if(textColorSet == 0) { - textColorSet = useCenter ? R.color.color_distance : R.color.color_myloc_distance ; - if(stale) { - textColorSet = R.color.icon_color; - } - } - txt.setTextColor(app.getResources().getColor(textColorSet)); - } - txt.setText(OsmAndFormatter.getFormattedDistance(mes[0], app)); - } else { - txt.setText(""); - } - } - } - - public void updateLocation(boolean centerChanged, boolean locationChanged, boolean compassChanged) { + public void updateLocation(boolean centerChanged, boolean locationChanged, boolean compassChanged) { if (compassChanged && !dashboard.isMapLinkedToLocation()) { return; } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java index b988f9a3a0..02b229732e 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java @@ -72,9 +72,9 @@ public class DashNavigationFragment extends DashBaseFragment { ImageView cancel = (ImageView) view.findViewById(R.id.cancel); ImageView play = (ImageView) view.findViewById(R.id.play); name.setText(routingHelper.getGeneralRouteInformation()); - icon.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_start_navigation, + icon.setImageDrawable(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_start_navigation, R.color.color_myloc_distance)); - cancel.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark) + cancel.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark) ); cancel.setOnClickListener(new OnClickListener() { @@ -107,7 +107,7 @@ public class DashNavigationFragment extends DashBaseFragment { private void updatePlayButton(final RoutingHelper routingHelper, final MapActivity map, final ImageView play) { boolean toContinueNavigation = routingHelper.isRoutePlanningMode(); - play.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon( + play.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon( toContinueNavigation ? R.drawable.ic_play_dark : R.drawable.ic_pause) ); play.setContentDescription(getString(toContinueNavigation ? R.string.continue_navigation : diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java index 0aaf108562..c1e5315517 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java @@ -89,7 +89,7 @@ public class DashRecentsFragment extends DashLocationFragment { SearchHistoryFragment.udpateHistoryItem(historyEntry, view, loc, getActivity(), getMyApplication()); view.findViewById(R.id.divider).setVisibility(View.VISIBLE); view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE); - ((ImageView) view.findViewById(R.id.navigate_to)).setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_gdirections_dark)); + ((ImageView) view.findViewById(R.id.navigate_to)).setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_gdirections_dark)); view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashSearchFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashSearchFragment.java index c084742dbc..37d7f4aedf 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashSearchFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashSearchFragment.java @@ -30,7 +30,7 @@ public class DashSearchFragment extends DashBaseFragment { View view = getActivity().getLayoutInflater().inflate(R.layout.dash_search_fragment, container, false); TextView searchFor = (TextView) view.findViewById(R.id.search_for); - searchFor.setCompoundDrawablesWithIntrinsicBounds(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_search_dark), null, null, null); + searchFor.setCompoundDrawablesWithIntrinsicBounds(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_search_dark), null, null, null); searchFor.setCompoundDrawablePadding(AndroidUtils.dpToPx(getActivity(), 16f)); view.findViewById(R.id.search_card).setOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java index 3752d8c585..ad33e49600 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashWaypointsFragment.java @@ -150,7 +150,7 @@ public class DashWaypointsFragment extends DashLocationFragment { id = R.drawable.list_destination; } - ((ImageView) view.findViewById(R.id.favourite_icon)).setImageDrawable(getMyApplication().getIconsCache() + ((ImageView) view.findViewById(R.id.favourite_icon)).setImageDrawable(getMyApplication().getUIUtilities() .getIcon(id, 0)); DashLocationView dv = new DashLocationView(direction, label, new LatLon(point.getLatitude(), point.getLongitude())); @@ -161,7 +161,7 @@ public class DashWaypointsFragment extends DashLocationFragment { options.setVisibility(View.VISIBLE); final boolean optionsVisible = (SHOW_ALL && getMyApplication().getTargetPointsHelper().getIntermediatePoints().size() > 0); - options.setImageDrawable(getMyApplication().getIconsCache(). + options.setImageDrawable(getMyApplication().getUIUtilities(). getThemedIcon(optionsVisible ? R.drawable.ic_overflow_menu_white : R.drawable.ic_action_remove_dark)); options.setOnClickListener(new View.OnClickListener() { @@ -176,7 +176,7 @@ public class DashWaypointsFragment extends DashLocationFragment { }); ImageButton navigate = ((ImageButton)view.findViewById(R.id.navigate_to)); - navigate.setImageDrawable(getMyApplication().getIconsCache(). + navigate.setImageDrawable(getMyApplication().getUIUtilities(). getThemedIcon(R.drawable.ic_action_gdirections_dark)); navigate.setVisibility(target? View.VISIBLE : View.GONE); navigate.setOnClickListener(new View.OnClickListener() { @@ -241,7 +241,7 @@ public class DashWaypointsFragment extends DashLocationFragment { if (point.index > 0 || target) { final int ind = target ? allTargets.size() - 1 : point.index; item = optionsMenu.getMenu().add(R.string.waypoint_visit_before) - .setIcon(getMyApplication().getIconsCache(). + .setIcon(getMyApplication().getUIUtilities(). getThemedIcon(R.drawable.ic_action_up_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override @@ -256,7 +256,7 @@ public class DashWaypointsFragment extends DashLocationFragment { } if (!target) { item = optionsMenu.getMenu().add(R.string.waypoint_visit_after) - .setIcon(getMyApplication().getIconsCache(). + .setIcon(getMyApplication().getUIUtilities(). getThemedIcon(R.drawable.ic_action_down_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override @@ -271,7 +271,7 @@ public class DashWaypointsFragment extends DashLocationFragment { } } item = optionsMenu.getMenu().add( - R.string.shared_string_remove).setIcon(getMyApplication().getIconsCache(). + R.string.shared_string_remove).setIcon(getMyApplication().getUIUtilities(). getThemedIcon(R.drawable.ic_action_remove_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index fce85160f1..03101a3fa3 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -51,7 +51,7 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.OnRowItemClick; import net.osmand.plus.ContextMenuItem; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -443,12 +443,12 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis flat.setVisibility(View.GONE); ImageView settingsButton = (ImageView) dashboardView.findViewById(R.id.toolbar_settings); settingsButton.setVisibility(View.GONE); - IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); + UiUtilities iconsCache = mapActivity.getMyApplication().getUIUtilities(); ImageView lst = (ImageView) dashboardView.findViewById(R.id.toolbar_list); lst.setVisibility(View.GONE); ImageView back = (ImageView) dashboardView.findViewById(R.id.toolbar_back); back.setImageDrawable( - getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back)); + getMyApplication().getUIUtilities().getIcon(R.drawable.ic_arrow_back)); back.setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/development/DashSimulateFragment.java b/OsmAnd/src/net/osmand/plus/development/DashSimulateFragment.java index 8a8acf1750..321be1ab87 100644 --- a/OsmAnd/src/net/osmand/plus/development/DashSimulateFragment.java +++ b/OsmAnd/src/net/osmand/plus/development/DashSimulateFragment.java @@ -41,8 +41,8 @@ public class DashSimulateFragment extends DashBaseFragment { : R.string.animate_route); ImageButton actionButton = (ImageButton) getView().findViewById(R.id.stop); actionButton.setImageDrawable( - !routeAnimating ? getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_play_dark) - : getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_rec_stop)); + !routeAnimating ? getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_play_dark) + : getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_rec_stop)); actionButton.setContentDescription(getString(routeAnimating ? R.string.animate_route_off : R.string.animate_route)); } diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java index b002634c17..642525902c 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ConfigureMapMenu.java @@ -387,9 +387,9 @@ public class ConfigureMapMenu { View v = super.getView(position, convertView, parent); final ImageView icon = (ImageView) v.findViewById(R.id.icon); if (checkedItems[position]) { - icon.setImageDrawable(app.getIconsCache().getIcon(iconIds[position], R.color.osmand_orange)); + icon.setImageDrawable(app.getUIUtilities().getIcon(iconIds[position], R.color.osmand_orange)); } else { - icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconIds[position])); + icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconIds[position])); } v.findViewById(R.id.divider).setVisibility(View.GONE); v.findViewById(R.id.description).setVisibility(View.GONE); @@ -402,9 +402,9 @@ public class ConfigureMapMenu { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { checkedItems[position] = isChecked; if (checkedItems[position]) { - icon.setImageDrawable(app.getIconsCache().getIcon(iconIds[position], R.color.osmand_orange)); + icon.setImageDrawable(app.getUIUtilities().getIcon(iconIds[position], R.color.osmand_orange)); } else { - icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconIds[position])); + icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconIds[position])); } } }); @@ -1385,14 +1385,14 @@ public class ConfigureMapMenu { iconId = R.drawable.ic_action_gpx_width_thin; } textView.setCompoundDrawablesWithIntrinsicBounds(null, null, - app.getIconsCache().getPaintedIcon(iconId, currentColor), null); + app.getUIUtilities().getPaintedIcon(iconId, currentColor), null); } else { if (item.color == -1) { textView.setCompoundDrawablesWithIntrinsicBounds(null, null, - app.getIconsCache().getThemedIcon(R.drawable.ic_action_circle), null); + app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle), null); } else { textView.setCompoundDrawablesWithIntrinsicBounds(null, null, - app.getIconsCache().getPaintedIcon(R.drawable.ic_action_circle, item.color), null); + app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, item.color), null); } } textView.setCompoundDrawablePadding(AndroidUtils.dpToPx(getContext(), 10f)); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java b/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java index 65da97272a..40006974f3 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/ErrorBottomSheetDialog.java @@ -36,7 +36,7 @@ public class ErrorBottomSheetDialog extends BottomSheetDialogFragment { String msg = MessageFormat.format(getString(R.string.previous_run_crashed), OsmandApplication.EXCEPTION_PATH); Typeface typeface = FontCache.getRobotoMedium(getActivity()); ImageView iv = ((ImageView) view.findViewById(R.id.error_icon)); - iv.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_crashlog)); + iv.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_crashlog)); TextView message = ((TextView) view.findViewById(R.id.error_header)); message.setTypeface(typeface); message.setText(msg); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java b/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java index d03424ba53..df55ef2332 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java @@ -19,8 +19,8 @@ import android.widget.EditText; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; - import net.osmand.AndroidUtils; +import net.osmand.Location; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -42,11 +42,10 @@ public class FavoriteDialogs { public static final String KEY_FAVORITE = "favorite"; public static Dialog createReplaceFavouriteDialog(final Activity activity, final Bundle args) { - final FavouritesDbHelper helper = ((OsmandApplication) activity.getApplication()).getFavorites(); + OsmandApplication app = (OsmandApplication) activity.getApplication(); + final FavouritesDbHelper helper = app.getFavorites(); final List points = new ArrayList(helper.getFavouritePoints()); - final FavouritesAdapter favouritesAdapter = new FavouritesAdapter(activity, - ((OsmandApplication) activity.getApplication()).getFavorites().getFavouritePoints(), - false); + final FavouritesAdapter favouritesAdapter = new FavouritesAdapter(activity, points,false); final Dialog[] dlgHolder = new Dialog[1]; OnItemClickListener click = new AdapterView.OnItemClickListener() { @@ -56,9 +55,8 @@ public class FavoriteDialogs { } }; - if (activity instanceof MapActivity) { - favouritesAdapter.updateLocation(((MapActivity) activity).getMapLocation()); - } + favouritesAdapter.sortByDefault(); + if(points.size() == 0){ Toast.makeText(activity, activity.getString(R.string.fav_points_not_exist), Toast.LENGTH_SHORT).show(); return null; @@ -210,25 +208,7 @@ public class FavoriteDialogs { final OnDismissListener dismissListener, final Dialog[] dialogHolder, final boolean sortByDist) { ListView listView = new ListView(uiContext); AlertDialog.Builder bld = new AlertDialog.Builder(uiContext); - final Collator inst = Collator.getInstance(); - favouritesAdapter.sort(new Comparator() { - - @Override - public int compare(FavouritePoint lhs, FavouritePoint rhs) { - if (sortByDist) { - if (favouritesAdapter.getLocation() == null) { - return 0; - } - double ld = MapUtils.getDistance(favouritesAdapter.getLocation(), lhs.getLatitude(), - lhs.getLongitude()); - double rd = MapUtils.getDistance(favouritesAdapter.getLocation(), rhs.getLatitude(), - rhs.getLongitude()); - return Double.compare(ld, rd); - } - return inst.compare(lhs.getName(), rhs.getName()); - } - }); - + favouritesAdapter.sortByDefault(); listView.setAdapter(favouritesAdapter); listView.setOnItemClickListener(click); bld.setPositiveButton(sortByDist ? R.string.sort_by_name : diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java index 0801b8368d..86ef9e6995 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadGroupViewHolder.java @@ -4,7 +4,7 @@ import android.graphics.drawable.Drawable; import android.view.View; import android.widget.TextView; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.R; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivityType; @@ -29,11 +29,11 @@ public class DownloadGroupViewHolder { Drawable iconLeft; if (group.getType() == DownloadResourceGroup.DownloadResourceGroupType.VOICE_REC || group.getType() == DownloadResourceGroup.DownloadResourceGroupType.VOICE_TTS) { - iconLeft = ctx.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_volume_up); + iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_volume_up); } else if (group.getType() == DownloadResourceGroup.DownloadResourceGroupType.FONTS) { - iconLeft = ctx.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_map_language); + iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_map_language); } else { - IconsCache cache = ctx.getMyApplication().getIconsCache(); + UiUtilities cache = ctx.getMyApplication().getUIUtilities(); if (isParentWorld(group) || isParentWorld(group.getParentGroup())) { iconLeft = cache.getThemedIcon(R.drawable.ic_world_globe_dark); } else { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java index a7fb4db8c4..0e0e49ebd0 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/DownloadResourceGroupFragment.java @@ -28,7 +28,7 @@ import android.widget.TextView; import net.osmand.AndroidNetworkUtils; import net.osmand.AndroidUtils; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -105,7 +105,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow activity.getAccessibilityAssistant().registerPage(view, DownloadActivity.DOWNLOAD_TAB_NUMBER); toolbar = (Toolbar) view.findViewById(R.id.toolbar); - toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back)); + toolbar.setNavigationIcon(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override @@ -159,7 +159,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow if (!openAsDialog() && purchaseHelper != null && !purchaseHelper.hasInventory()) { restorePurchasesView = activity.getLayoutInflater().inflate(R.layout.restore_purchases_list_footer, null); ((ImageView) restorePurchasesView.findViewById(R.id.icon)).setImageDrawable( - getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_reset_to_default_dark)); + getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_reset_to_default_dark)); restorePurchasesView.findViewById(R.id.button).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -181,7 +181,7 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow searchView = activity.getLayoutInflater().inflate(R.layout.simple_list_menu_item, null); searchView.setBackgroundResource(android.R.drawable.list_selector_background); TextView title = (TextView) searchView.findViewById(R.id.title); - title.setCompoundDrawablesWithIntrinsicBounds(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_search_dark), null, null, null); + title.setCompoundDrawablesWithIntrinsicBounds(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_search_dark), null, null, null); title.setHint(R.string.search_map_hint); searchView.setOnClickListener(new OnClickListener() { @Override @@ -532,11 +532,11 @@ public class DownloadResourceGroupFragment extends DialogFragment implements Dow Drawable iconLeft; if (group.getType() == DownloadResourceGroupType.VOICE_REC || group.getType() == DownloadResourceGroupType.VOICE_TTS) { - iconLeft = ctx.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_volume_up); + iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_volume_up); } else if (group.getType() == DownloadResourceGroupType.FONTS) { - iconLeft = ctx.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_map_language); + iconLeft = ctx.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_map_language); } else { - IconsCache cache = ctx.getMyApplication().getIconsCache(); + UiUtilities cache = ctx.getMyApplication().getUIUtilities(); if (isParentWorld(group) || isParentWorld(group.getParentGroup())) { iconLeft = cache.getThemedIcon(R.drawable.ic_world_globe_dark); } else { diff --git a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java index 863d5d8595..72cb9f1414 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/ItemViewHolder.java @@ -384,7 +384,7 @@ public class ItemViewHolder { final File fl = indexItem.getTargetFile(context.getMyApplication()); if (fl.exists()) { item = optionsMenu.getMenu().add(R.string.shared_string_remove).setIcon( - context.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark)); + context.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { @@ -424,7 +424,7 @@ public class ItemViewHolder { }); } item = optionsMenu.getMenu().add(R.string.shared_string_download) - .setIcon(context.getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_import)); + .setIcon(context.getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_import)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { @@ -437,10 +437,10 @@ public class ItemViewHolder { } private Drawable getContentIcon(DownloadActivity context, int resourceId) { - return context.getMyApplication().getIconsCache().getThemedIcon(resourceId); + return context.getMyApplication().getUIUtilities().getThemedIcon(resourceId); } private Drawable getContentIcon(DownloadActivity context, int resourceId, int color) { - return context.getMyApplication().getIconsCache().getPaintedIcon(resourceId, color); + return context.getMyApplication().getUIUtilities().getPaintedIcon(resourceId, color); } } diff --git a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java index 256db522a8..62ae0c83b1 100644 --- a/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java +++ b/OsmAnd/src/net/osmand/plus/download/ui/LocalIndexesFragment.java @@ -21,7 +21,7 @@ import net.osmand.map.ITileSource; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuItem; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -1100,7 +1100,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement public void bindLocalIndexInfo(final LocalIndexInfo child) { - options.setImageDrawable(ctx.getMyApplication().getIconsCache() + options.setImageDrawable(ctx.getMyApplication().getUIUtilities() .getThemedIcon(R.drawable.ic_overflow_menu_white)); options.setContentDescription(ctx.getString(R.string.shared_string_more)); options.setOnClickListener(new View.OnClickListener() { @@ -1177,14 +1177,14 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement } private Drawable getContentIcon(DownloadActivity context, int resourceId, int colorId) { - return context.getMyApplication().getIconsCache().getIcon(resourceId, colorId); + return context.getMyApplication().getUIUtilities().getIcon(resourceId, colorId); } } } private void openPopUpMenu(View v, final LocalIndexInfo info) { - IconsCache iconsCache = getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMyApplication().getUIUtilities(); final PopupMenu optionsMenu = new PopupMenu(getActivity(), v); DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); final boolean restore = info.isBackupedData(); diff --git a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java index e43f76a30a..7b10e23a8f 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java +++ b/OsmAnd/src/net/osmand/plus/helpers/AvoidSpecificRoads.java @@ -72,7 +72,7 @@ public class AvoidSpecificRoads { final RouteDataObject obj = getItem(position); v.findViewById(R.id.all_points).setVisibility(View.GONE); ((ImageView) v.findViewById(R.id.waypoint_icon)).setImageDrawable( - app.getIconsCache().getThemedIcon(R.drawable.ic_action_road_works_dark)); + app.getUIUtilities().getThemedIcon(R.drawable.ic_action_road_works_dark)); double dist = MapUtils.getDistance(mapLocation, MapUtils.get31LatitudeY(obj.getPoint31YTile(0)), MapUtils.get31LongitudeX(obj.getPoint31XTile(0))); ((TextView) v.findViewById(R.id.waypoint_dist)).setText(OsmAndFormatter.getFormattedDistance((float) dist, app)); @@ -80,7 +80,7 @@ public class AvoidSpecificRoads { ((TextView) v.findViewById(R.id.waypoint_text)).setText(getText(obj)); ImageButton remove = (ImageButton) v.findViewById(R.id.info_close); remove.setVisibility(View.VISIBLE); - remove.setImageDrawable(app.getIconsCache().getThemedIcon( + remove.setImageDrawable(app.getUIUtilities().getThemedIcon( R.drawable.ic_action_remove_dark)); remove.setOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 3ccc4f4cf9..01cde4b350 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -67,7 +67,7 @@ import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXUtilities.Speed; import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -327,7 +327,7 @@ public class GpxUiHelper { final List list, final ContextMenuAdapter adapter) { final OsmandApplication app = (OsmandApplication) activity.getApplication(); - final IconsCache iconsCache = app.getIconsCache(); + final UiUtilities iconsCache = app.getUIUtilities(); final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR); AlertDialog.Builder builder = new AlertDialog.Builder(activity); final int layout = R.layout.list_menu_item_native_singlechoice; @@ -747,13 +747,13 @@ public class GpxUiHelper { v.findViewById(R.id.unknown_section).setVisibility(View.GONE); ImageView distanceI = (ImageView) v.findViewById(R.id.distance_icon); distanceI.setVisibility(View.VISIBLE); - distanceI.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_small_distance)); + distanceI.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_small_distance)); ImageView pointsI = (ImageView) v.findViewById(R.id.points_icon); pointsI.setVisibility(View.VISIBLE); - pointsI.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_small_point)); + pointsI.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_small_point)); ImageView timeI = (ImageView) v.findViewById(R.id.time_icon); timeI.setVisibility(View.VISIBLE); - timeI.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_small_time)); + timeI.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_small_time)); TextView time = (TextView) v.findViewById(R.id.time); TextView distance = (TextView) v.findViewById(R.id.distance); TextView pointsCount = (TextView) v.findViewById(R.id.points_count); @@ -817,9 +817,9 @@ public class GpxUiHelper { } int color = GpxAppearanceAdapter.parseTrackColor(renderer, prefColorValue); if (color == -1) { - colorImageView.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_circle)); + colorImageView.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle)); } else { - colorImageView.setImageDrawable(app.getIconsCache().getPaintedIcon(R.drawable.ic_action_circle, color)); + colorImageView.setImageDrawable(app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, color)); } } @@ -1610,7 +1610,7 @@ public class GpxUiHelper { } public Drawable getImageDrawable(@NonNull OsmandApplication app) { - return app.getIconsCache().getThemedIcon(imageId); + return app.getUIUtilities().getThemedIcon(imageId); } public static String getName(@NonNull Context ctx, @NonNull GPXDataSetType[] types) { @@ -1663,7 +1663,7 @@ public class GpxUiHelper { } public Drawable getImageDrawable(OsmandApplication app) { - return app.getIconsCache().getThemedIcon(imageId); + return app.getUIUtilities().getThemedIcon(imageId); } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java index d8ffde109f..ba03ff372d 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/MapMarkerDialogHelper.java @@ -82,7 +82,7 @@ public class MapMarkerDialogHelper { textDist.setTextColor(ctx.getResources() .getColor(useCenter ? R.color.color_distance : R.color.color_myloc_distance)); } else { - waypointIcon.setImageDrawable(app.getIconsCache() + waypointIcon.setImageDrawable(app.getUIUtilities() .getIcon(R.drawable.ic_action_flag_dark, !nightMode)); AndroidUtils.setTextSecondaryColor(ctx, text, nightMode); AndroidUtils.setTextSecondaryColor(ctx, textDist, nightMode); @@ -124,6 +124,6 @@ public class MapMarkerDialogHelper { } public static Drawable getMapMarkerIcon(OsmandApplication app, int colorIndex) { - return app.getIconsCache().getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(colorIndex)); + return app.getUIUtilities().getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(colorIndex)); } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index ffb7a46515..0699b83425 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -147,11 +147,11 @@ public class WaypointDialogHelper { AndroidUtils.setTextSecondaryColor(activity, textDeviation, nightMode); if (ps.deviationDirectionRight) { textDeviation.setCompoundDrawablesWithIntrinsicBounds( - app.getIconsCache().getIcon(R.drawable.ic_small_turn_right, colorId), + app.getUIUtilities().getIcon(R.drawable.ic_small_turn_right, colorId), null, null, null); } else { textDeviation.setCompoundDrawablesWithIntrinsicBounds( - app.getIconsCache().getIcon(R.drawable.ic_small_turn_left, colorId), + app.getUIUtilities().getIcon(R.drawable.ic_small_turn_left, colorId), null, null, null); } } @@ -404,7 +404,7 @@ public class WaypointDialogHelper { int iconResId = nightMode ? R.color.marker_circle_button_color_dark : R.color.ctx_menu_title_color_dark; remove.setVisibility(View.VISIBLE); - remove.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark, iconResId)); + remove.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_remove_dark, iconResId)); remove.setEnabled(canRemove); remove.setAlpha(canRemove ? 1 : .5f); if (canRemove) { @@ -434,7 +434,7 @@ public class WaypointDialogHelper { move.setVisibility(notFlatTargets ? View.VISIBLE : View.GONE); if (notFlatTargets) { - move.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_reorder, iconResId)); + move.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_reorder, iconResId)); move.setTag(new DragIcon() { @Override public void onClick() { diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java index 266e034af1..319746c432 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointHelper.java @@ -13,7 +13,7 @@ import net.osmand.data.LocationPoint; import net.osmand.data.PointDescription; import net.osmand.osm.PoiType; import net.osmand.plus.ApplicationMode; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings.MetricsConstants; @@ -704,7 +704,7 @@ public class WaypointHelper { return null; } else if (type == TARGETS) { - IconsCache iconsCache = app.getIconsCache(); + UiUtilities iconsCache = app.getUIUtilities(); if (((TargetPoint) point).start) { if (app.getTargetPointsHelper().getPointToStart() == null) { return iconsCache.getIcon(R.drawable.ic_action_location_color, 0); diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java index f7c46f4b84..87193a86cd 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/LiveUpdatesFragment.java @@ -179,7 +179,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc TextView regionNameHeaderTextView = (TextView) subscriptionHeader.findViewById(R.id.regionHeaderTextView); TextView regionNameTextView = (TextView) subscriptionHeader.findViewById(R.id.regionTextView); statusTextView.setText(getString(R.string.osm_live_active)); - statusIcon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_done)); + statusIcon.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_done)); regionNameHeaderTextView.setText(R.string.osm_live_support_region); String countryName = getSettings().BILLING_USER_COUNTRY.get(); if (Algorithms.isEmpty(countryName)) { @@ -618,7 +618,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc } private Drawable getSecondaryColorPaintedIcon(@DrawableRes int drawable) { - return fragment.getMyActivity().getMyApplication().getIconsCache() + return fragment.getMyActivity().getMyApplication().getUIUtilities() .getPaintedIcon(drawable, secondaryColor); } } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java index 4af19d6cb7..726c625cd0 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/SubscriptionFragment.java @@ -135,9 +135,9 @@ public class SubscriptionFragment extends BaseOsmAndDialogFragment implements In View view = inflater.inflate(R.layout.subscription_fragment, container, false); ImageButton closeButton = (ImageButton) view.findViewById(R.id.closeButton); if (editMode) { - closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_mode_back)); + closeButton.setImageDrawable(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_mode_back)); } else { - closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_remove_dark)); + closeButton.setImageDrawable(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_remove_dark)); } closeButton.setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java index 258a20a012..1aae887bc7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/AdditionalActionsBottomSheetDialogFragment.java @@ -158,7 +158,7 @@ public class AdditionalActionsBottomSheetDialogFragment extends net.osmand.plus. @Override protected Drawable getContentIcon(@DrawableRes int id) { - return getMyApplication().getIconsCache().getIcon(id, nightMode ? R.color.grid_menu_icon_dark : R.color.on_map_icon_color); + return getMyApplication().getUIUtilities().getIcon(id, nightMode ? R.color.grid_menu_icon_dark : R.color.on_map_icon_color); } private int getCancelRowBgResId() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java index bd2323d4ef..6c4f135285 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/BaseMenuController.java @@ -2,7 +2,7 @@ package net.osmand.plus.mapcontextmenu; import android.graphics.drawable.Drawable; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; @@ -71,7 +71,7 @@ public abstract class BaseMenuController { } protected Drawable getIconOrig(int iconId) { - IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMapActivity().getMyApplication().getUIUtilities(); return iconsCache.getIcon(iconId, 0); } @@ -80,17 +80,17 @@ public abstract class BaseMenuController { } protected Drawable getIcon(int iconId, int colorId) { - IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMapActivity().getMyApplication().getUIUtilities(); return iconsCache.getIcon(iconId, colorId); } protected Drawable getPaintedIcon(int iconId, int color) { - IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMapActivity().getMyApplication().getUIUtilities(); return iconsCache.getPaintedIcon(iconId, color); } protected Drawable getIcon(int iconId, int colorLightId, int colorDarkId) { - IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMapActivity().getMyApplication().getUIUtilities(); return iconsCache.getIcon(iconId, isLight() ? colorLightId : colorDarkId); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index a8b604bd1d..45e61fe30f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -85,7 +85,6 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL private int mapZoom; private LatLon myLocation; - private Float heading; private boolean inLocationUpdate = false; private boolean cachedMyLocation; private boolean appModeChanged; @@ -1249,18 +1248,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL return getCurrentMenuState() == MenuState.HEADER_ONLY; } - public LatLon getMyLocation() { - return myLocation; - } - - public boolean isCachedMyLocation() { - return cachedMyLocation; - } - - public Float getHeading() { - return heading; - } - + private void updateMyLocation(Location location, boolean updateLocationUi) { if (location == null) { location = getMapActivity().getMyApplication().getLocationProvider().getLastStaleKnownLocation(); @@ -1284,15 +1272,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL public void updateCompassValue(float value) { if (active && displayDistanceDirection()) { - // 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction) - // on non-compass devices - float lastHeading = heading != null ? heading : 99; - heading = value; - if (Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) { - updateLocation(false, false, true); - } else { - heading = lastHeading; - } + updateLocation(false, false, true); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 06b4717b21..16efb55e97 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -1,5 +1,36 @@ package net.osmand.plus.mapcontextmenu; +import static android.util.TypedValue.COMPLEX_UNIT_DIP; +import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP; + +import java.util.List; + +import net.osmand.AndroidUtils; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.data.QuadPoint; +import net.osmand.data.RotatedTileBox; +import net.osmand.plus.LockableScrollView; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.BaseOsmAndFragment; +import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; +import net.osmand.plus.mapcontextmenu.MenuController.MenuState; +import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; +import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; +import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; +import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; +import net.osmand.plus.transport.TransportStopRoute; +import net.osmand.plus.views.AnimateDraggingMapThread; +import net.osmand.plus.views.OsmandMapTileView; +import net.osmand.plus.views.TransportStopsLayer; +import net.osmand.plus.views.controls.HorizontalSwipeConfirm; +import net.osmand.plus.views.controls.SingleTapConfirm; +import net.osmand.util.Algorithms; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.TargetApi; @@ -35,38 +66,6 @@ import android.widget.OverScroller; import android.widget.ProgressBar; import android.widget.TextView; -import net.osmand.AndroidUtils; -import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; -import net.osmand.data.QuadPoint; -import net.osmand.data.RotatedTileBox; -import net.osmand.plus.LockableScrollView; -import net.osmand.plus.OsmAndFormatter; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.BaseOsmAndFragment; -import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents; -import net.osmand.plus.mapcontextmenu.MenuController.MenuState; -import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController; -import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; -import net.osmand.plus.mapcontextmenu.controllers.TransportStopController; -import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; -import net.osmand.plus.transport.TransportStopRoute; -import net.osmand.plus.views.AnimateDraggingMapThread; -import net.osmand.plus.views.OsmandMapTileView; -import net.osmand.plus.views.TransportStopsLayer; -import net.osmand.plus.views.controls.HorizontalSwipeConfirm; -import net.osmand.plus.views.controls.SingleTapConfirm; -import net.osmand.util.Algorithms; - -import java.util.List; - -import static android.util.TypedValue.COMPLEX_UNIT_DIP; -import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP; - public class MapContextMenuFragment extends BaseOsmAndFragment implements DownloadEvents { public static final String TAG = "MapContextMenuFragment"; @@ -134,6 +133,8 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo private int screenOrientation; private boolean created; + private UpdateLocationViewCache updateLocationViewCache; + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -751,7 +752,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo } private void updateImageButton(ImageButton button, int iconLightId, int iconDarkId, int bgLightId, int bgDarkId, boolean night) { - button.setImageDrawable(getMapActivity().getMyApplication().getIconsCache().getIcon(night ? iconDarkId : iconLightId)); + button.setImageDrawable(getMapActivity().getMyApplication().getUIUtilities().getIcon(night ? iconDarkId : iconLightId)); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) { button.setBackground(getMapActivity().getResources().getDrawable(night ? bgDarkId : bgLightId, getMapActivity().getTheme())); @@ -1171,7 +1172,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo dismissMenu(); return; } - screenOrientation = DashLocationFragment.getScreenOrientation(getActivity()); + updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(getMapActivity()); getMapActivity().getMapViewTrackingUtilities().setContextMenu(menu); getMapActivity().getMapViewTrackingUtilities().setMapLinkedToLocation(false); wasDrawerDisabled = getMapActivity().isDrawerDisabled(); @@ -1495,7 +1496,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo OsmandApplication app = getMyApplication(); if (app != null && view != null) { View compassView = view.findViewById(R.id.compass_layout); - if (menu.getMyLocation() != null && menu.displayDistanceDirection() && menu.getCurrentMenuState() != MenuState.FULL_SCREEN) { + if (menu.displayDistanceDirection() && menu.getCurrentMenuState() != MenuState.FULL_SCREEN) { updateDistanceDirection(); compassView.setVisibility(View.VISIBLE); } else { @@ -1534,10 +1535,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo if (app != null && activity != null && view != null) { TextView distanceText = (TextView) view.findViewById(R.id.distance); ImageView direction = (ImageView) view.findViewById(R.id.direction); - float myHeading = menu.getHeading() == null ? 0f : menu.getHeading(); - int color = menu.isCachedMyLocation() ? R.color.icon_color : 0; - DashLocationFragment.updateLocationView(false, menu.getMyLocation(), myHeading, direction, color, distanceText, - color, menu.getLatLon().getLatitude(), menu.getLatLon().getLongitude(), screenOrientation, app, activity); + getMyApplication().getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon()); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 6bd5beaf65..4a6145d76e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -35,7 +35,7 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; import net.osmand.osm.PoiCategory; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -745,7 +745,7 @@ public class MenuBuilder { } public Drawable getRowIcon(int iconId) { - IconsCache iconsCache = app.getIconsCache(); + UiUtilities iconsCache = app.getUIUtilities(); return iconsCache.getIcon(iconId, light ? R.color.ctx_menu_bottom_view_icon_light : R.color.ctx_menu_bottom_view_icon_dark); } @@ -782,7 +782,7 @@ public class MenuBuilder { } public Drawable getCollapseIcon(boolean collapsed) { - return app.getIconsCache().getIcon(collapsed ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up, + return app.getUIUtilities().getIcon(collapsed ? R.drawable.ic_action_arrow_down : R.drawable.ic_action_arrow_up, light ? R.color.ctx_menu_collapse_icon_color_light : R.color.ctx_menu_collapse_icon_color_dark); } @@ -826,7 +826,7 @@ public class MenuBuilder { titleView.setTextSize(16); titleView.setTextColor(app.getResources().getColor(light ? R.color.ctx_menu_bottom_view_text_color_light : R.color.ctx_menu_bottom_view_text_color_dark)); String desc = route.getDescription(getMapActivity().getMyApplication(), true); - Drawable arrow = app.getIconsCache().getIcon(R.drawable.ic_arrow_right_16, light ? R.color.ctx_menu_route_icon_color_light : R.color.ctx_menu_route_icon_color_dark); + Drawable arrow = app.getUIUtilities().getIcon(R.drawable.ic_arrow_right_16, light ? R.color.ctx_menu_route_icon_color_light : R.color.ctx_menu_route_icon_color_dark); arrow.setBounds(0, 0, arrow.getIntrinsicWidth(), arrow.getIntrinsicHeight()); titleView.setText(AndroidUtils.replaceCharsWithIcon(desc, arrow, arrowChars)); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java index 6e820a0622..0661f82246 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/AmenityMenuBuilder.java @@ -260,9 +260,9 @@ public class AmenityMenuBuilder extends MenuBuilder { }); button.setAllCaps(true); button.setText(R.string.context_menu_read_full_article); - Drawable normal = app.getIconsCache().getIcon(R.drawable.ic_action_read_text, + Drawable normal = app.getUIUtilities().getIcon(R.drawable.ic_action_read_text, light ? R.color.ctx_menu_controller_button_text_color_light_n : R.color.ctx_menu_controller_button_text_color_dark_n); - Drawable pressed = app.getIconsCache().getIcon(R.drawable.ic_action_read_text, + Drawable pressed = app.getUIUtilities().getIcon(R.drawable.ic_action_read_text, light ? R.color.ctx_menu_controller_button_text_color_light_p : R.color.ctx_menu_controller_button_text_color_dark_p); button.setCompoundDrawablesWithIntrinsicBounds(Build.VERSION.SDK_INT >= 21 ? AndroidUtils.createPressedStateListDrawable(normal, pressed) : normal, null, null, null); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index 25d1696e7e..6fd79fb9da 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -93,7 +93,7 @@ public class FavouritePointMenuBuilder extends MenuBuilder { int disabledColor = light ? R.color.secondary_text_light : R.color.secondary_text_dark; color = favoriteGroup.visible ? (color | 0xff000000) : view.getResources().getColor(disabledColor); String name = view.getContext().getString(R.string.context_menu_points_of_group); - buildRow(view, app.getIconsCache().getPaintedIcon(R.drawable.ic_action_folder, color), null, name, 0, null, + buildRow(view, app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_folder, color), null, name, 0, null, true, getCollapsableFavouritesView(view.getContext(), true, favoriteGroup, fav), false, 0, false, null, false); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java index 2058c4ca03..03ec70798f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/GpxItemMenuBuilder.java @@ -65,7 +65,7 @@ public class GpxItemMenuBuilder extends MenuBuilder { llIconParams.setMargins(0, 0, gpxSmallIconMargin, 0); llIconParams.gravity = Gravity.CENTER_VERTICAL; icon.setLayoutParams(llIconParams); - icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconId)); + icon.setImageDrawable(app.getUIUtilities().getThemedIcon(iconId)); ll.addView(icon); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java index 6be885f05d..eaf8c5320a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/WptPtMenuBuilder.java @@ -109,7 +109,7 @@ public class WptPtMenuBuilder extends MenuBuilder { File file = new File(gpx.path); String gpxName = file.getName().replace(".gpx", "").replace("/", " ").replace("_", " "); int color = getPointColor(wpt, getFileColor(selectedGpxFile)); - buildRow(view, app.getIconsCache().getPaintedIcon(R.drawable.ic_type_waypoints_group, color), null, title, 0, gpxName, + buildRow(view, app.getUIUtilities().getPaintedIcon(R.drawable.ic_type_waypoints_group, color), null, title, 0, gpxName, true, getCollapsableWaypointsView(view.getContext(), true, gpx, wpt), false, 0, false, null, false); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java index 9fccd2fced..1f0f7b8b75 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/AbstractCard.java @@ -76,7 +76,7 @@ public abstract class AbstractCard { final Toolbar topBar = new Toolbar(ctx); topBar.setClickable(true); - Drawable back = app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark); + Drawable back = app.getUIUtilities().getIcon(R.drawable.ic_action_remove_dark); topBar.setNavigationIcon(back); topBar.setNavigationContentDescription(R.string.shared_string_close); topBar.setTitle(title); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java index 05f87ea17d..0f1ac451fd 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/ImageCard.java @@ -328,7 +328,7 @@ public abstract class ImageCard extends AbstractCard { R.drawable.context_menu_card_light, R.drawable.context_menu_card_dark); if (icon == null && topIconId != 0) { - icon = getMyApplication().getIconsCache().getIcon(topIconId); + icon = getMyApplication().getUIUtilities().getIcon(topIconId); } if (icon == null) { iconImageView.setVisibility(View.GONE); @@ -373,9 +373,9 @@ public abstract class ImageCard extends AbstractCard { } if (buttonIcon == null && buttonIconId != 0) { if (buttonIconColor != 0) { - buttonIcon = getMyApplication().getIconsCache().getPaintedIcon(buttonIconId, buttonIconColor); + buttonIcon = getMyApplication().getUIUtilities().getPaintedIcon(buttonIconId, buttonIconColor); } else { - buttonIcon = getMyApplication().getIconsCache().getIcon(buttonIconId); + buttonIcon = getMyApplication().getUIUtilities().getIcon(buttonIconId); } } button.setCompoundDrawablesWithIntrinsicBounds(buttonIcon, null, null, null); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java index 9a0e493d10..ff2632eb58 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/cards/NoImagesCard.java @@ -6,7 +6,7 @@ import android.widget.ImageView; import android.widget.TextView; import net.osmand.AndroidUtils; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapillary.MapillaryPlugin; @@ -25,7 +25,7 @@ public class NoImagesCard extends AbstractCard { @Override public void update() { if (view != null) { - IconsCache ic = getMyApplication().getIconsCache(); + UiUtilities ic = getMyApplication().getUIUtilities(); boolean night = getMyApplication().getDaynightHelper().isNightModeForMapControls(); MapActivity ctx = getMapActivity(); AndroidUtils.setBackgroundColor(ctx, view, night, R.color.bg_color_light, R.color.bg_color_dark); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java index 50239351eb..85d2f4f653 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java @@ -47,7 +47,7 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment { Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); toolbar.setTitle(getToolbarTitle()); - toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back)); + toolbar.setNavigationIcon(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); toolbar.setTitleTextColor(getResources().getColor(getResIdFromAttribute(getMapActivity(), R.attr.pstsTextColor))); toolbar.setNavigationOnClickListener(new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java index 91d187f996..7faecd2978 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectCategoryDialogFragment.java @@ -18,7 +18,7 @@ import net.osmand.AndroidUtils; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -168,7 +168,7 @@ public class SelectCategoryDialogFragment extends DialogFragment { private static Drawable getIcon(final Activity activity, int iconId) { OsmandApplication app = (OsmandApplication)activity.getApplication(); - IconsCache iconsCache = app.getIconsCache(); + UiUtilities iconsCache = app.getUIUtilities(); boolean light = app.getSettings().isLightContent(); return iconsCache.getIcon(iconId, light ? R.color.icon_color : R.color.icon_color_light); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/DestinationReachedMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/DestinationReachedMenuFragment.java index 42c35fe2cc..0f0397ab1b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/DestinationReachedMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/DestinationReachedMenuFragment.java @@ -15,7 +15,7 @@ import android.widget.TextView; import net.osmand.AndroidUtils; import net.osmand.data.LatLon; import net.osmand.plus.ApplicationMode; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; @@ -55,7 +55,7 @@ public class DestinationReachedMenuFragment extends Fragment { } }); - IconsCache iconsCache = getMapActivity().getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMapActivity().getMyApplication().getUIUtilities(); ImageButton closeImageButton = (ImageButton) view.findViewById(R.id.closeImageButton); closeImageButton.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_remove_dark, menu.isLight())); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java index 0dd81666f2..98cfe4b180 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java @@ -1,18 +1,19 @@ package net.osmand.plus.mapcontextmenu.other; +import android.app.Activity; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; - import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.util.MapUtils; @@ -24,18 +25,14 @@ public class FavouritesAdapter extends RecyclerView.Adapter favouritePoints; private OsmandApplication app; - private IconsCache iconsCache; private View.OnClickListener listener; - private LatLon location; - private Float heading; - private boolean useCenter; - private int screenOrientation; + private UpdateLocationViewCache cache; - public FavouritesAdapter(OsmandApplication app, List FavouritePoints) { + public FavouritesAdapter(OsmandApplication app, Activity a, List FavouritePoints) { this.app = app; - iconsCache = app.getIconsCache(); this.favouritePoints = FavouritePoints; + cache = app.getUIUtilities().getUpdateLocationViewCache(a); } @Override @@ -57,15 +54,8 @@ public class FavouritesAdapter extends RecyclerView.Adapter favouritePoints; private FavouritesAdapter adapter; private RecyclerView recyclerView; @@ -49,6 +46,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag private boolean compassUpdateAllowed = true; private boolean target; private boolean intermediate; + private float lastHeading; @Override public void createMenuItems(final Bundle savedInstanceState) { @@ -66,16 +64,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag recyclerView = (RecyclerView) View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.recyclerview, null); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - location = getMyApplication().getLocationProvider().getLastStaleKnownLocation(); - adapter = new FavouritesAdapter(getMyApplication(), favouritePoints); - if (location != null) { - latLon = new LatLon(location.getLatitude(), location.getLongitude()); - adapter.setUseCenter(false); - } else { - latLon = ((MapActivity) getActivity()).getMapLocation(); - adapter.setUseCenter(true); - } - adapter.setLocation(latLon); + adapter = new FavouritesAdapter(getMyApplication(), getActivity(), favouritePoints); sortFavourites(); final BottomSheetItemTitleWithDescrAndButton[] title = new BottomSheetItemTitleWithDescrAndButton[1]; title[0] = (BottomSheetItemTitleWithDescrAndButton) new BottomSheetItemTitleWithDescrAndButton.Builder() @@ -171,7 +160,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag @Override public void onResume() { super.onResume(); - adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); startLocationUpdate(); } @@ -184,26 +172,14 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag @Override public void updateLocation(Location location) { - boolean newLocation = this.location == null && location != null; - boolean locationChanged = this.location != null && location != null - && this.location.getLatitude() != location.getLatitude() - && this.location.getLongitude() != location.getLongitude(); - if (newLocation || locationChanged) { - this.location = location; - updateLocationUi(); - } + updateLocationUi(); } @Override public void updateCompassValue(float value) { - // 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction) - // on non-compass devices - float lastHeading = heading != null ? heading : 99; - heading = value; - if (Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) { + if (Math.abs(MapUtils.degreesDiff(lastHeading, value)) > 5) { + lastHeading = value; updateLocationUi(); - } else { - heading = lastHeading; } } @@ -216,15 +192,6 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag mapActivity.getMyApplication().runInUIThread(new Runnable() { @Override public void run() { - if (location == null) { - location = getMyApplication().getLocationProvider().getLastStaleKnownLocation(); - } - - boolean useCenter = location == null; - latLon = useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude()); - adapter.setUseCenter(useCenter); - adapter.setLocation(latLon); - adapter.setHeading(useCenter ? -mapActivity.getMapRotate() : heading != null ? heading : 99); adapter.notifyDataSetChanged(); } }); @@ -266,6 +233,9 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag private void sortFavourites() { final Collator inst = Collator.getInstance(); + Location stale = getMyApplication().getLocationProvider().getLastStaleKnownLocation(); + final LatLon latLon = stale != null ? new LatLon(stale.getLatitude(), stale.getLongitude()) : + getMyApplication().getMapViewTrackingUtilities().getMapLocation(); Collections.sort(favouritePoints, new Comparator() { @Override public int compare(FavouritePoint lhs, FavouritePoint rhs) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java index f75d78d842..7ac86066d8 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapRouteInfoMenu.java @@ -28,7 +28,7 @@ import net.osmand.data.RotatedTileBox; import net.osmand.plus.ApplicationMode; import net.osmand.plus.GeocodingLookupService; import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndFormatter; @@ -231,7 +231,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { main.findViewById(R.id.InfoDuration).setVisibility(View.GONE); textView.setText(R.string.route_is_too_long_v2); textView.setVisibility(View.VISIBLE); - iconView.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_warning, isLight())); + iconView.setImageDrawable(mapActivity.getMyApplication().getUIUtilities().getIcon(R.drawable.ic_warning, isLight())); } else { main.findViewById(R.id.dividerToDropDown).setVisibility(View.GONE); main.findViewById(R.id.RouteInfoControls).setVisibility(View.GONE); @@ -294,7 +294,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { ImageView viaIcon = (ImageView) parentView.findViewById(R.id.viaIcon); viaIcon.setImageDrawable(getIconOrig(R.drawable.list_intermediate)); - swapDirectionView.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_change_navigation_points, + swapDirectionView.setImageDrawable(mapActivity.getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_change_navigation_points, isLight() ? R.color.route_info_control_icon_color_light : R.color.route_info_control_icon_color_dark)); swapDirectionView.setOnClickListener(new View.OnClickListener() { @Override @@ -378,7 +378,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { updateToIcon(parentView); ImageView toDropDownIcon = (ImageView) parentView.findViewById(R.id.toDropDownIcon); - toDropDownIcon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, isLight())); + toDropDownIcon.setImageDrawable(mapActivity.getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, isLight())); } private void updateToIcon(View parentView) { @@ -448,7 +448,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { updateFromIcon(parentView); ImageView fromDropDownIcon = (ImageView) parentView.findViewById(R.id.fromDropDownIcon); - fromDropDownIcon.setImageDrawable(mapActivity.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, isLight())); + fromDropDownIcon.setImageDrawable(mapActivity.getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, isLight())); } public void updateFromIcon(View parentView) { @@ -520,7 +520,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { } private Drawable getIconOrig(int iconId) { - IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); + UiUtilities iconsCache = mapActivity.getMyApplication().getUIUtilities(); return iconsCache.getIcon(iconId, 0); } @@ -550,7 +550,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { mainView.findViewById(R.id.RouteInfoControls).setVisibility(View.VISIBLE); final OsmandApplication ctx = mapActivity.getMyApplication(); ImageView prev = (ImageView) mainView.findViewById(R.id.Prev); - prev.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_prev, isLight())); + prev.setImageDrawable(ctx.getUIUtilities().getIcon(R.drawable.ic_prev, isLight())); if (directionInfo >= 0) { prev.setVisibility(View.VISIBLE); prev.setOnClickListener(new View.OnClickListener() { @@ -578,7 +578,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { } ImageView next = (ImageView) mainView.findViewById(R.id.Next); next.setVisibility(View.VISIBLE); - next.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_next, isLight())); + next.setImageDrawable(ctx.getUIUtilities().getIcon(R.drawable.ic_next, isLight())); next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -614,9 +614,9 @@ public class MapRouteInfoMenu implements IRouteInformationListener { infoDurationView.setVisibility(View.GONE); textView.setVisibility(View.VISIBLE); } else { - infoIcon.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_action_route_distance, R.color.route_info_unchecked_mode_icon_color)); + infoIcon.setImageDrawable(ctx.getUIUtilities().getIcon(R.drawable.ic_action_route_distance, R.color.route_info_unchecked_mode_icon_color)); infoIcon.setVisibility(View.VISIBLE); - durationIcon.setImageDrawable(ctx.getIconsCache().getIcon(R.drawable.ic_action_time_span, R.color.route_info_unchecked_mode_icon_color)); + durationIcon.setImageDrawable(ctx.getUIUtilities().getIcon(R.drawable.ic_action_time_span, R.color.route_info_unchecked_mode_icon_color)); durationIcon.setVisibility(View.VISIBLE); infoDistanceView.setVisibility(View.VISIBLE); infoDurationView.setVisibility(View.VISIBLE); @@ -997,7 +997,7 @@ public class MapRouteInfoMenu implements IRouteInformationListener { if (row.icon != null) { icon = row.icon; } else if (row.iconId > 0) { - icon = mapActivity.getMyApplication().getIconsCache().getThemedIcon(row.iconId); + icon = mapActivity.getMyApplication().getUIUtilities().getThemedIcon(row.iconId); } label.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); label.setCompoundDrawablePadding(AndroidUtils.dpToPx(mapActivity, 16f)); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MultiSelectionArrayAdapter.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MultiSelectionArrayAdapter.java index d714caf0e2..0a0a2462c9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MultiSelectionArrayAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MultiSelectionArrayAdapter.java @@ -11,7 +11,7 @@ import android.widget.ImageView; import android.widget.TextView; import net.osmand.AndroidUtils; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.R; import java.util.List; @@ -50,7 +50,7 @@ public class MultiSelectionArrayAdapter extends ArrayAdapter implement nameTv.setText(names.get(position)); if (wrong) { - Drawable icon = app.getIconsCache().getPaintedIcon(R.drawable.ic_warning, app.getResources().getColor(R.color.color_warning)); + Drawable icon = app.getUIUtilities().getPaintedIcon(R.drawable.ic_warning, app.getResources().getColor(R.color.color_warning)); iconIv.setImageDrawable(icon); iconIv.setVisibility(View.VISIBLE); } diff --git a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java index 08241236e1..b64c8a620b 100644 --- a/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java +++ b/OsmAnd/src/net/osmand/plus/mapillary/MapillaryImageDialog.java @@ -32,7 +32,7 @@ import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; @@ -85,12 +85,12 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { private double fetchedTileLon = Double.NaN; private List sequenceImages = new ArrayList<>(); private AtomicInteger downloadRequestNumber = new AtomicInteger(); - private IconsCache ic; + private UiUtilities ic; public MapillaryImageDialog(@NonNull MapActivity mapActivity, @NonNull Bundle bundle) { super(mapActivity, CardDialogType.MAPILLARY); restoreFields(bundle); - this.ic = mapActivity.getMyApplication().getIconsCache(); + this.ic = mapActivity.getMyApplication().getUIUtilities(); } public MapillaryImageDialog(MapActivity mapActivity, String key, String sKey, String imageUrl, @@ -104,7 +104,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { this.viewerUrl = viewerUrl; this.latLon = latLon; this.ca = ca; - this.ic = mapActivity.getMyApplication().getIconsCache(); + this.ic = mapActivity.getMyApplication().getUIUtilities(); this.sync = sync; } @@ -204,7 +204,7 @@ public class MapillaryImageDialog extends ContextMenuCardDialog { @Override protected void createMenuItems(Menu menu) { MenuItem item = menu.add(R.string.open_mapillary) - .setIcon(getMapActivity().getMyApplication().getIconsCache().getThemedIcon( + .setIcon(getMapActivity().getMyApplication().getUIUtilities().getThemedIcon( R.drawable.ic_action_mapillary)); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 474b25b017..d75d50661a 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -47,7 +47,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; - import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.data.LatLon; @@ -58,6 +57,7 @@ import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.dashboard.DashLocationFragment; @@ -99,6 +99,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm private boolean locationUpdateStarted; private boolean compassUpdateAllowed = true; + public void setListener(OnMapMarkersSavedListener listener) { this.listener = listener; } @@ -497,7 +498,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm @Override public void onResume() { super.onResume(); - adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); + startLocationUpdate(); final View focusedView = getDialog().getCurrentFocus(); @@ -1020,7 +1021,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm } private Drawable getColoredIcon(@DrawableRes int resId, @ColorRes int colorResId) { - return getMyApplication().getIconsCache().getIcon(resId, colorResId); + return getMyApplication().getUIUtilities().getIcon(resId, colorResId); } private MapActivity getMapActivity() { @@ -1065,15 +1066,6 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm mapActivity.getMyApplication().runInUIThread(new Runnable() { @Override public void run() { - if (location == null) { - location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); - } - MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities(); - boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null); - - adapter.setUseCenter(useCenter); - adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude())); - adapter.setHeading(useCenter ? -mapActivity.getMapRotate() : heading != null ? heading : 99); adapter.notifyDataSetChanged(); } }); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java index bd036e77e5..b614901b98 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java @@ -36,11 +36,11 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment { private Float heading; private boolean useCenter; private boolean nightMode; - private int screenOrientation; private boolean target; private boolean intermediate; private OnMarkerSelectListener onClickListener; + private int screenOrientation; @Nullable @Override @@ -63,7 +63,7 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment { MapRouteInfoMenu routeInfoMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu(); onClickListener = routeInfoMenu.getOnMarkerSelectListener(); - screenOrientation = DashLocationFragment.getScreenOrientation(mapActivity); + screenOrientation = app.getUIUtilities().getScreenOrientation(mapActivity); MapViewTrackingUtilities trackingUtils = mapActivity.getMapViewTrackingUtilities(); if (trackingUtils != null) { @@ -84,7 +84,7 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment { View view = inflater.inflate(R.layout.map_marker_selection_fragment, container, false); ImageButton closeButton = (ImageButton) view.findViewById(R.id.closeButton); - closeButton.setImageDrawable(getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_mode_back)); + closeButton.setImageDrawable(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_mode_back)); closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java index d54054bf4e..38140fb307 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersActiveFragment.java @@ -147,7 +147,6 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL @Override public void onResume() { super.onResume(); - adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); startLocationUpdate(); } @@ -220,12 +219,6 @@ public class MapMarkersActiveFragment extends Fragment implements OsmAndCompassL if (location == null) { location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); } - MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities(); - boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null); - - adapter.setUseCenter(useCenter); - adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude())); - adapter.setHeading(useCenter ? -mapActivity.getMapRotate() : heading != null ? heading : 99); adapter.notifyDataSetChanged(); } }); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index 1546466953..bfae0e8886 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -147,7 +147,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.map_markers_toolbar); - toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back)); + toolbar.setNavigationIcon(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java index fb32c8dafe..2737b900bb 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroupsFragment.java @@ -1,5 +1,22 @@ package net.osmand.plus.mapmarkers; +import net.osmand.AndroidUtils; +import net.osmand.Location; +import net.osmand.data.Amenity; +import net.osmand.data.FavouritePoint; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; +import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapmarkers.SelectionMarkersGroupBottomSheetDialogFragment.AddMarkersGroupFragmentListener; +import net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder; +import net.osmand.plus.mapmarkers.adapters.MapMarkersGroupsAdapter; +import net.osmand.plus.widgets.EmptyStateRecyclerView; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -22,34 +39,11 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import net.osmand.AndroidUtils; -import net.osmand.Location; -import net.osmand.data.Amenity; -import net.osmand.data.FavouritePoint; -import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; -import net.osmand.plus.GPXUtilities.WptPt; -import net.osmand.plus.MapMarkersHelper.MapMarker; -import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; -import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.MapViewTrackingUtilities; -import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.plus.mapmarkers.SelectionMarkersGroupBottomSheetDialogFragment.AddMarkersGroupFragmentListener; -import net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder; -import net.osmand.plus.mapmarkers.adapters.MapMarkersGroupsAdapter; -import net.osmand.plus.widgets.EmptyStateRecyclerView; -import net.osmand.util.MapUtils; - public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassListener, OsmAndLocationListener { public static final String TAG = "MapMarkersGroupsFragment"; private MapMarkersGroupsAdapter adapter; - private Float heading; - private Location location; private boolean locationUpdateStarted; private Paint backgroundPaint = new Paint(); private Paint iconPaint = new Paint(); @@ -400,7 +394,6 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL @Override public void onResume() { super.onResume(); - adapter.setScreenOrientation(DashLocationFragment.getScreenOrientation(getActivity())); startLocationUpdate(); } @@ -442,27 +435,12 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL @Override public void updateLocation(Location location) { - boolean newLocation = this.location == null && location != null; - boolean locationChanged = this.location != null && location != null - && this.location.getLatitude() != location.getLatitude() - && this.location.getLongitude() != location.getLongitude(); - if (newLocation || locationChanged) { - this.location = location; - updateLocationUi(); - } + updateLocationUi(); } @Override public void updateCompassValue(float value) { - // 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction) - // on non-compass devices - float lastHeading = heading != null ? heading : 99; - heading = value; - if (Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) { - updateLocationUi(); - } else { - heading = lastHeading; - } + updateLocationUi(); } private OsmandApplication getMyApplication() { @@ -481,15 +459,6 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL mapActivity.getMyApplication().runInUIThread(new Runnable() { @Override public void run() { - if (location == null) { - location = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); - } - MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities(); - boolean useCenter = !(utilities.isMapLinkedToLocation() && location != null); - - adapter.setUseCenter(useCenter); - adapter.setLocation(useCenter ? mapActivity.getMapLocation() : new LatLon(location.getLatitude(), location.getLongitude())); - adapter.setHeading(useCenter ? -mapActivity.getMapRotate() : heading != null ? heading : 99); adapter.notifyDataSetChanged(); } }); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java index aa7a2a7e7e..b2508dcff9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java @@ -1,5 +1,13 @@ package net.osmand.plus.mapmarkers.adapters; +import java.util.List; + +import net.osmand.AndroidUtils; +import net.osmand.plus.MapMarkersHelper.MapMarker; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; +import net.osmand.plus.activities.MapActivity; import android.graphics.drawable.Drawable; import android.support.annotation.ColorInt; import android.support.annotation.ColorRes; @@ -10,51 +18,25 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import net.osmand.AndroidUtils; -import net.osmand.data.LatLon; -import net.osmand.plus.IconsCache; -import net.osmand.plus.MapMarkersHelper.MapMarker; -import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.dashboard.DashLocationFragment; - -import java.util.List; - public class CoordinateInputAdapter extends RecyclerView.Adapter { private MapActivity mapActivity; - private IconsCache iconsCache; + private UiUtilities iconsCache; private List mapMarkers; private boolean nightTheme; - - private LatLon location; - private Float heading; - private boolean useCenter; - private int screenOrientation; + private UpdateLocationViewCache updateViewCache; public CoordinateInputAdapter(MapActivity mapActivity, List mapMarkers) { this.mapActivity = mapActivity; - iconsCache = mapActivity.getMyApplication().getIconsCache(); + iconsCache = mapActivity.getMyApplication().getUIUtilities(); + updateViewCache = iconsCache.getUpdateLocationViewCache(mapActivity); this.mapMarkers = mapMarkers; nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent(); } - public void setLocation(LatLon location) { - this.location = location; - } - public void setHeading(Float heading) { - this.heading = heading; - } - public void setUseCenter(boolean useCenter) { - this.useCenter = useCenter; - } - - public void setScreenOrientation(int screenOrientation) { - this.screenOrientation = screenOrientation; - } @Override public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { @@ -98,11 +80,8 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter items = new ArrayList<>(); private boolean night; - private int screenOrientation; - private LatLon location; - private Float heading; - private boolean useCenter; private boolean showDirectionEnabled; private List showDirectionMarkers; private Snackbar snackbar; private MapMarkersGroupsAdapterListener listener; + private UpdateLocationViewCache updateLocationViewCache; public void setListener(MapMarkersGroupsAdapterListener listener) { this.listener = listener; @@ -77,6 +74,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter distanceSplit = new ArrayList<>(); private TIntArrayList timeSplit = new TIntArrayList(); private int selectedSplitInterval; - private IconsCache ic; + private UiUtilities ic; private int minMaxSpeedLayoutWidth; private Paint minMaxSpeedPaint; private Rect minMaxSpeedTextBounds; @@ -73,7 +73,7 @@ public class SplitSegmentDialogFragment extends DialogFragment { public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); app = getMyApplication(); - ic = app.getIconsCache(); + ic = app.getUIUtilities(); boolean isLightTheme = app.getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; int themeId = isLightTheme ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme; setStyle(STYLE_NO_FRAME, themeId); @@ -109,7 +109,7 @@ public class SplitSegmentDialogFragment extends DialogFragment { if (trackActivityActionBar != null) { titleTextView.setText(trackActivityActionBar.getTitle()); } - toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back)); + toolbar.setNavigationIcon(getMyApplication().getUIUtilities().getIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override @@ -254,7 +254,7 @@ public class SplitSegmentDialogFragment extends DialogFragment { int color = app.getResources().getColor(colorId); title.setTextColor(color); text.setTextColor(color); - img.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, colorId)); + img.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, colorId)); } private void updateSplitIntervalView(View view) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 5724d816d9..2947928d1b 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -493,7 +493,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { int color = app.getResources().getColor(colorId); title.setTextColor(color); text.setTextColor(color); - img.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_arrow_drop_down, colorId)); + img.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_arrow_drop_down, colorId)); } private void updateSplitIntervalView(View view) { @@ -523,9 +523,9 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { color = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor(renderer, prefColor.get()); } if (color == 0) { - colorImageView.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_circle)); + colorImageView.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle)); } else { - colorImageView.setImageDrawable(app.getIconsCache().getPaintedIcon(R.drawable.ic_action_circle, color)); + colorImageView.setImageDrawable(app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, color)); } TrackBitmapDrawer trackDrawer = getTrackBitmapDrawer(); if (trackDrawer != null) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 6ee6bed9fe..6de0b860ee 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -52,7 +52,7 @@ import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup; import net.osmand.plus.OsmandApplication; @@ -850,7 +850,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements public View getGroupView(final int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { View row = convertView; final GpxDisplayGroup group = getGroup(groupPosition); - IconsCache iconsCache = app.getIconsCache(); + UiUtilities iconsCache = app.getUIUtilities(); if (row == null) { LayoutInflater inflater = getLayoutInflater(); row = inflater.inflate(R.layout.wpt_list_item, parent, false); @@ -926,7 +926,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements if (groupColor == 0) { groupColor = ContextCompat.getColor(app, R.color.gpx_color_point); } - icon.setImageDrawable(app.getIconsCache().getPaintedIcon(R.drawable.ic_action_folder, groupColor | 0xff000000)); + icon.setImageDrawable(app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_folder, groupColor | 0xff000000)); options.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -1007,7 +1007,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { View row = convertView; - IconsCache iconsCache = getMyApplication().getIconsCache(); + UiUtilities iconsCache = getMyApplication().getUIUtilities(); if (row == null) { LayoutInflater inflater = getLayoutInflater(); row = inflater.inflate(R.layout.wpt_list_item, parent, false); @@ -1079,7 +1079,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements } else { description.setVisibility(View.GONE); } - icon.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_marker_dark)); + icon.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_marker_dark)); } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 47b4013e83..39850f31be 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -51,7 +51,7 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; @@ -676,7 +676,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit } }); - final IconsCache ic = app.getIconsCache(); + final UiUtilities ic = app.getUIUtilities(); switch (tabType) { case GPX_TAB_ITEM_GENERAL: if (analysis != null) { @@ -1063,7 +1063,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit ViewCompat.setAlpha(img, tabs.getTabTextSelectedAlpha()); break; case SOLID_COLOR: - img.setImageDrawable(app.getIconsCache().getPaintedIcon(imageId, tabs.getTextColor())); + img.setImageDrawable(app.getUIUtilities().getPaintedIcon(imageId, tabs.getTextColor())); break; } } @@ -1078,7 +1078,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit ViewCompat.setAlpha(img, tabs.getTabTextAlpha()); break; case SOLID_COLOR: - img.setImageDrawable(app.getIconsCache().getPaintedIcon(imageId, tabs.getTabInactiveTextColor())); + img.setImageDrawable(app.getUIUtilities().getPaintedIcon(imageId, tabs.getTabInactiveTextColor())); break; } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java index 9d6f3a25da..857a246b14 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java @@ -108,7 +108,7 @@ public class DashOsmEditsFragment extends DashBaseFragment OsmEditsFragment.getOsmEditView(view, point, getMyApplication()); ImageButton send = (ImageButton) view.findViewById(R.id.play); - send.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_export)); + send.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_export)); send.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java index 450a9ce993..0a14b1c76d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java @@ -203,7 +203,7 @@ public class OsmEditsAdapter extends ArrayAdapter { holder.selectCheckBox.setVisibility(View.GONE); } - holder.optionsImageButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_overflow_menu_white)); + holder.optionsImageButton.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_overflow_menu_white)); holder.optionsImageButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -281,9 +281,9 @@ public class OsmEditsAdapter extends ArrayAdapter { } else if (point.getAction() == OsmPoint.Action.REOPEN) { colorResId = R.color.color_osm_edit_modify; } - return app.getIconsCache().getIcon(iconResId, colorResId); + return app.getUIUtilities().getIcon(iconResId, colorResId); } else if (point.getGroup() == OsmPoint.Group.BUG) { - return app.getIconsCache().getIcon(R.drawable.ic_type_bug, R.color.color_distance); + return app.getUIUtilities().getIcon(R.drawable.ic_type_bug, R.color.color_distance); } return null; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 56415fd63e..22cca899ed 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -110,9 +110,9 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo String name = OsmEditingPlugin.getEditName(child); viewName.setText(name); if (child.getGroup() == Group.POI) { - icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_type_info, R.color.color_distance)); + icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_type_info, R.color.color_distance)); } else if (child.getGroup() == Group.BUG) { - icon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_type_bug, R.color.color_distance)); + icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_type_bug, R.color.color_distance)); } TextView descr = (TextView) v.findViewById(R.id.description); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java index 9cfa16e007..2d09804f5e 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsUploadListenerHelper.java @@ -23,7 +23,7 @@ import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -268,7 +268,7 @@ public class OsmEditsUploadListenerHelper implements OsmEditsUploadListener { PointWithPotentialError pointWrapper = data[position]; holder.pointNameTextView.setText(pointWrapper.point); - IconsCache cache = ((OsmandApplication) context.getApplication()).getIconsCache(); + UiUtilities cache = ((OsmandApplication) context.getApplication()).getUIUtilities(); holder.checkedUncheckedImageView.setImageDrawable(pointWrapper.hasError ? cache.getThemedIcon(R.drawable.ic_action_remove_dark) : cache.getThemedIcon(R.drawable.ic_action_done)); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java index 42124d947b..ebe5810a4a 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java @@ -20,7 +20,7 @@ import android.widget.EditText; import android.widget.ImageView; import android.widget.Toast; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -247,7 +247,7 @@ public class CreateEditActionDialog extends DialogFragment { return (OsmandApplication)(getContext().getApplicationContext()); } - private IconsCache getIconsCache(){ - return getApplication().getIconsCache(); + private UiUtilities getIconsCache(){ + return getApplication().getUIUtilities(); } } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index a0adce7a5c..6bd53dd8ac 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -109,7 +109,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick private void setUpToolbar(View view) { Toolbar toolbar = (Toolbar) view.findViewById(R.id.custom_toolbar); - Drawable back = getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back); + Drawable back = getMyApplication().getUIUtilities().getIcon(R.drawable.ic_arrow_back); back.setColorFilter(ContextCompat.getColor(getContext(), R.color.color_white), PorterDuff.Mode.MULTIPLY); toolbar.setNavigationIcon(back); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); @@ -161,7 +161,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(getContext(), R.style.OsmandLightTheme)); builder.setTitle(R.string.quick_actions_delete); builder.setMessage(getResources().getString(R.string.quick_actions_delete_text, itemName)); - builder.setIcon(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_delete_dark)); + builder.setIcon(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_delete_dark)); builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { adapter.deleteItem(itemPosition); @@ -216,7 +216,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick itemVH.title.setText(item.getName(getContext())); itemVH.subTitle.setText(getResources().getString(R.string.quick_action_item_action, getActionPosition(position))); - itemVH.icon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(item.getIconRes(getContext()))); + itemVH.icon.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(item.getIconRes(getContext()))); itemVH.handleView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { @@ -411,8 +411,8 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick closeBtn = (ImageView) itemView.findViewById(R.id.closeImageButton); container = itemView.findViewById(R.id.searchListItemLayout); - handleView.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_reorder)); - closeBtn.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark)); + handleView.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_reorder)); + closeBtn.setImageDrawable(getMyApplication().getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark)); } } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java index 944d8d3c1f..944740fa41 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java @@ -22,7 +22,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.helpers.AndroidUiHelper; @@ -317,7 +317,7 @@ public class QuickActionsWidget extends LinearLayout { return (OsmandApplication)(getContext().getApplicationContext()); } - private IconsCache getIconsCache(){ - return getApplication().getIconsCache(); + private UiUtilities getIconsCache(){ + return getApplication().getUIUtilities(); } } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/AddPOIAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/AddPOIAction.java index d264656730..c9fc22fdb8 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/AddPOIAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/AddPOIAction.java @@ -173,7 +173,7 @@ public class AddPOIAction extends QuickAction { .inflate(R.layout.quick_action_add_poi_layout, parent, false); final OsmandApplication application = activity.getMyApplication(); - Drawable deleteDrawable = application.getIconsCache().getPaintedIcon(R.drawable.ic_action_remove_dark, + Drawable deleteDrawable = application.getUIUtilities().getPaintedIcon(R.drawable.ic_action_remove_dark, activity.getResources().getColor(R.color.dash_search_icon_dark)); final LinearLayout editTagsLineaLayout = @@ -303,7 +303,7 @@ public class AddPOIAction extends QuickAction { boolean isLightTheme = activity.getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME; final int colorId = isLightTheme ? R.color.inactive_item_orange : R.color.dash_search_icon_dark; final int color = activity.getResources().getColor(colorId); - onlineDocumentationButton.setImageDrawable(activity.getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_help, color)); + onlineDocumentationButton.setImageDrawable(activity.getMyApplication().getUIUtilities().getPaintedIcon(R.drawable.ic_action_help, color)); // poiTypeEditText.setCompoundDrawables(null, null, activity.getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_arrow_drop_down, color), null); // Button addTypeButton = (Button) view.findViewById(R.id.addTypeButton); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java index 6c9df67456..6a389f5c22 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java @@ -314,7 +314,7 @@ public class ShowHidePoiAction extends QuickAction { @Override public void onShow(DialogInterface dialog) { Button neutralButton = alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL); - Drawable drawable = app.getIconsCache().getThemedIcon(R.drawable.ic_action_multiselect); + Drawable drawable = app.getUIUtilities().getThemedIcon(R.drawable.ic_action_multiselect); neutralButton.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } }); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java index 6214778c15..7f4ad2f277 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchCoordinatesFragment.java @@ -1,5 +1,24 @@ package net.osmand.plus.search; +import static android.text.InputType.TYPE_CLASS_PHONE; +import static android.text.InputType.TYPE_CLASS_TEXT; +import static android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; +import static android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; +import static android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; +import net.osmand.LocationConvert; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; +import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; +import net.osmand.plus.activities.MapActivity; +import net.osmand.util.Algorithms; +import net.osmand.util.MapUtils; import android.annotation.SuppressLint; import android.app.Dialog; import android.content.DialogInterface; @@ -27,28 +46,6 @@ import com.google.openlocationcode.OpenLocationCode; import com.jwetherell.openmap.common.LatLonPoint; import com.jwetherell.openmap.common.UTMPoint; -import net.osmand.Location; -import net.osmand.LocationConvert; -import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; -import net.osmand.plus.IconsCache; -import net.osmand.plus.OsmAndFormatter; -import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; -import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; -import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.util.Algorithms; -import net.osmand.util.MapUtils; - -import static android.text.InputType.TYPE_CLASS_PHONE; -import static android.text.InputType.TYPE_CLASS_TEXT; -import static android.text.InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; -import static android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS; -import static android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; - public class QuickSearchCoordinatesFragment extends DialogFragment implements OsmAndCompassListener, OsmAndLocationListener { public static final String TAG = "QuickSearchCoordinatesFragment"; @@ -60,7 +57,6 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os private static final String QUICK_SEARCH_COORDS_OLC_KEY = "quick_search_coords_olc_key"; private static final String QUICK_SEARCH_COORDS_OLC_INFO_KEY = "quick_search_coords_olc_info_key"; private static final String QUICK_SEARCH_COORDS_FORMAT_KEY = "quick_search_coords_format_key"; - private static final String QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY = "quick_search_coords_use_map_center_key"; private static final String QUICK_SEARCH_COORDS_TEXT_KEY = "quick_search_coords_text_key"; private static final String QUICK_SEARCH_COORDS_LATITUDE_KEY = "quick_search_coords_latitude_key"; @@ -80,11 +76,10 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os private int currentFormat = PointDescription.FORMAT_DEGREES; private net.osmand.Location myLocation = null; - private Float heading = null; - private boolean useMapCenter; + private float heading ; private boolean paused; - private int screenOrientation; private LatLon currentLatLon; + private UpdateLocationViewCache updateLocationViewCache; public QuickSearchCoordinatesFragment() { } @@ -113,7 +108,7 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os view = inflater.inflate(R.layout.search_advanced_coords, container, false); Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); - toolbar.setNavigationIcon(app.getIconsCache().getIcon(R.drawable.ic_arrow_back)); + toolbar.setNavigationIcon(app.getUIUtilities().getIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override @@ -121,8 +116,7 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os dismiss(); } }); - - screenOrientation = DashLocationFragment.getScreenOrientation(getActivity()); + updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(getActivity()); myLocation = app.getLocationProvider().getLastKnownLocation(); currentFormat = app.getSettings().COORDINATES_FORMAT.get(); @@ -175,11 +169,6 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os if (currentFormat == -1) currentFormat = app.getSettings().COORDINATES_FORMAT.get(); - if (savedInstanceState != null && savedInstanceState.containsKey(QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY)) - useMapCenter = savedInstanceState.getBoolean(QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY); - else if (getArguments().containsKey(QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY)) - useMapCenter = getArguments().getBoolean(QUICK_SEARCH_COORDS_USE_MAP_CENTER_KEY); - if (!coordinatesApplied) { latEdit.setText(latStr); latEdit.setSelection(latStr.length()); @@ -242,7 +231,7 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os zoneEdit.setOnEditorActionListener(doneListener); olcEdit.setOnEditorActionListener(doneListener); - IconsCache ic = app.getIconsCache(); + UiUtilities ic = app.getUIUtilities(); ((ImageView) view.findViewById(R.id.latitudeImage)) .setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_coordinates_latitude)); ((ImageView) view.findViewById(R.id.longitudeImage)) @@ -361,9 +350,7 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os @Override public void onResume() { super.onResume(); - if (!useMapCenter) { - startLocationUpdate(); - } + startLocationUpdate(); paused = false; } @@ -420,51 +407,35 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os public void updateCompassValue(final float value) { // 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction) // on non-compass devices - float lastHeading = heading != null ? heading : 99; - heading = value; - if (Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) { - final net.osmand.Location location = this.myLocation; + if (Math.abs(MapUtils.degreesDiff(value, heading)) > 5) { + heading = value; getMyApplication().runInUIThread(new Runnable() { @Override public void run() { - updateLocationUI(location, value); + updateLocationUI(); } }); - } else { - heading = lastHeading; } } @Override public void updateLocation(final net.osmand.Location location) { this.myLocation = location; - final Float heading = this.heading; getMyApplication().runInUIThread(new Runnable() { @Override public void run() { - updateLocationUI(location, heading); + updateLocationUI(); } }); } - private void updateLocationUI(net.osmand.Location location, Float heading) { - LatLon latLon = null; - if (location != null) { - latLon = new LatLon(location.getLatitude(), location.getLongitude()); - ((QuickSearchDialogFragment)getParentFragment()).getNavigationInfo().updateLocation(location); - } - updateLocationUI(latLon, heading); - } - private void updateLocationUI(LatLon latLon, Float heading) { - if (latLon != null && !paused) { + private void updateLocationUI() { + if (!paused) { QuickSearchDialogFragment dialogFragment = (QuickSearchDialogFragment) getParentFragment(); dialogFragment.getAccessibilityAssistant().lockEvents(); - updateCompassVisibility(coordsView, latLon, heading); + updateCompassVisibility(coordsView); dialogFragment.getAccessibilityAssistant().unlockEvents(); - if(heading != null) { - dialogFragment.getNavigationInfo().updateTargetDirection(currentLatLon, heading.floatValue()); - } } } @@ -629,18 +600,17 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, latLon); - updateLocationUI(latLon, heading); + updateLocationUI(); errorView.setVisibility(View.GONE); coordsView.setVisibility(View.VISIBLE); } } - private void updateCompassVisibility(View view, LatLon location, Float heading) { + private void updateCompassVisibility(View view) { View compassView = view.findViewById(R.id.compass_layout); - Location ll = getMyApplication().getLocationProvider().getLastKnownLocation(); - boolean showCompass = currentLatLon != null && location != null; - if (ll != null && showCompass) { - updateDistanceDirection(view, location, currentLatLon, heading); + boolean showCompass = currentLatLon != null; + if (showCompass) { + updateDistanceDirection(view, currentLatLon); compassView.setVisibility(View.VISIBLE); } else { if (!showCompass) { @@ -651,15 +621,10 @@ public class QuickSearchCoordinatesFragment extends DialogFragment implements Os } } - private void updateDistanceDirection(View view, LatLon myLatLon, LatLon location, Float heading) { + private void updateDistanceDirection(View view, LatLon location) { TextView distanceText = (TextView) view.findViewById(R.id.distance); ImageView direction = (ImageView) view.findViewById(R.id.direction); - - DashLocationFragment.updateLocationView(useMapCenter, myLatLon, - heading, direction, distanceText, - location.getLatitude(), - location.getLongitude(), - screenOrientation, getMyApplication()); + getMyApplication().getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, currentLatLon); } public static void showDialog(DialogFragment parentFragment, String text) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java index 0165d94a93..49b7fc8d40 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchCustomPoiFragment.java @@ -23,7 +23,7 @@ import android.widget.TextView; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiType; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -95,7 +95,7 @@ public class QuickSearchCustomPoiFragment extends DialogFragment { view = inflater.inflate(R.layout.search_custom_poi, container, false); Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); - toolbar.setNavigationIcon(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark)); + toolbar.setNavigationIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_remove_dark)); toolbar.setNavigationContentDescription(R.string.shared_string_close); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override @@ -227,7 +227,7 @@ public class QuickSearchCustomPoiFragment extends DialogFragment { SwitchCompat check = (SwitchCompat) row.findViewById(R.id.toggle_item); boolean categorySelected = filter.isTypeAccepted(category); - IconsCache ic = app.getIconsCache(); + UiUtilities ic = app.getUIUtilities(); int iconId = getIconId(category); if (iconId != 0) { if (categorySelected) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index d363aeded7..3818e4ce9a 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -284,9 +284,9 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC buttonToolbarView = view.findViewById(R.id.button_toolbar_layout); buttonToolbarImage = (ImageView) view.findViewById(R.id.buttonToolbarImage); - buttonToolbarImage.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_marker_dark)); + buttonToolbarImage.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_marker_dark)); buttonToolbarFilter = (ImageButton) view.findViewById(R.id.filterButton); - buttonToolbarFilter.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_filter)); + buttonToolbarFilter.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_filter)); buttonToolbarFilter.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { @@ -427,7 +427,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC if (!app.getSettings().isLightContent()) { toolbar.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.actionbar_dark_color)); } - toolbar.setNavigationIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_arrow_back)); + toolbar.setNavigationIcon(app.getUIUtilities().getThemedIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); toolbar.setNavigationOnClickListener( new OnClickListener() { @@ -441,7 +441,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC ); toolbarEdit = (Toolbar) view.findViewById(R.id.toolbar_edit); - toolbarEdit.setNavigationIcon(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark)); + toolbarEdit.setNavigationIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_remove_dark)); toolbarEdit.setNavigationContentDescription(R.string.shared_string_cancel); toolbarEdit.setNavigationOnClickListener( new OnClickListener() { @@ -588,7 +588,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC progressBar = (ProgressBar) view.findViewById(R.id.searchProgressBar); clearButton = (ImageButton) view.findViewById(R.id.clearButton); - clearButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark)); + clearButton.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark)); clearButton.setOnClickListener( new OnClickListener() { @Override @@ -842,10 +842,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC buttonToolbarFilter.setVisibility(filterButtonVisible ? View.VISIBLE : View.GONE); if (filterButtonVisible) { if (word.getResult().object instanceof PoiUIFilter) { - buttonToolbarFilter.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_filter, + buttonToolbarFilter.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_filter, app.getSettings().isLightContent() ? R.color.color_dialog_buttons_light : R.color.color_dialog_buttons_dark)); } else{ - buttonToolbarFilter.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_filter)); + buttonToolbarFilter.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_filter)); } } } @@ -1008,14 +1008,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC double d = MapUtils.getDistance(latLon, location.getLatitude(), location.getLongitude()); String dist = OsmAndFormatter.getFormattedDistance((float) d, app); searchEditText.setHint(getString(R.string.dist_away_from_my_location, dist)); - clearButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_get_my_location, R.color.color_myloc_distance)); + clearButton.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_get_my_location, R.color.color_myloc_distance)); } else { if (addressSearch) { searchEditText.setHint(R.string.type_address); } else { searchEditText.setHint(R.string.search_poi_category_hint); } - clearButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark)); + clearButton.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark)); } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java index 7ed14e61a0..48b8aa0d52 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListAdapter.java @@ -13,7 +13,6 @@ import android.widget.CheckBox; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; - import net.osmand.AndroidUtils; import net.osmand.CollatorStringMatcher; import net.osmand.Location; @@ -24,6 +23,7 @@ import net.osmand.osm.AbstractPoiType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.search.listitems.QuickSearchHeaderListItem; import net.osmand.plus.search.listitems.QuickSearchListItem; @@ -45,11 +45,8 @@ public class QuickSearchListAdapter extends ArrayAdapter { private Activity activity; private AccessibilityAssistant accessibilityAssistant; - private LatLon location; - private Float heading; private boolean useMapCenter; - private int screenOrientation; private int dp56; private int dp1; @@ -59,6 +56,7 @@ public class QuickSearchListAdapter extends ArrayAdapter { private boolean selectionMode; private boolean selectAll; private List selectedItems = new ArrayList<>(); + private UpdateLocationViewCache updateLocationViewCache; public interface OnSelectionListener { @@ -73,6 +71,7 @@ public class QuickSearchListAdapter extends ArrayAdapter { this.activity = activity; dp56 = AndroidUtils.dpToPx(app, 56f); dp1 = AndroidUtils.dpToPx(app, 1f); + updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(activity); } public void setAccessibilityAssistant(AccessibilityAssistant accessibilityAssistant) { @@ -87,30 +86,6 @@ public class QuickSearchListAdapter extends ArrayAdapter { this.selectionListener = selectionListener; } - public int getScreenOrientation() { - return screenOrientation; - } - - public void setScreenOrientation(int screenOrientation) { - this.screenOrientation = screenOrientation; - } - - public LatLon getLocation() { - return location; - } - - public void setLocation(LatLon location) { - this.location = location; - } - - public Float getHeading() { - return heading; - } - - public void setHeading(Float heading) { - this.heading = heading; - } - public boolean isUseMapCenter() { return useMapCenter; } @@ -425,7 +400,7 @@ public class QuickSearchListAdapter extends ArrayAdapter { int colorId = worksNow ? worksLater ? R.color.color_ok : R.color.color_intermediate : R.color.color_warning; timeLayout.setVisibility(View.VISIBLE); - timeIcon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_small_time, colorId)); + timeIcon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_small_time, colorId)); timeText.setTextColor(app.getResources().getColor(colorId)); String rt = rs.getCurrentRuleTime(inst); timeText.setText(rt == null ? "" : rt); @@ -497,17 +472,12 @@ public class QuickSearchListAdapter extends ArrayAdapter { private void updateCompassVisibility(View view, QuickSearchListItem listItem) { View compassView = view.findViewById(R.id.compass_layout); - Location ll = app.getLocationProvider().getLastKnownLocation(); - boolean showCompass = location != null && listItem.getSearchResult().location != null; - if ((ll != null || useMapCenter) && showCompass) { + boolean showCompass = listItem.getSearchResult().location != null; + if (showCompass) { updateDistanceDirection(view, listItem); compassView.setVisibility(View.VISIBLE); } else { - if (!showCompass) { - compassView.setVisibility(View.GONE); - } else { - compassView.setVisibility(View.INVISIBLE); - } + compassView.setVisibility(View.GONE); } } @@ -515,17 +485,11 @@ public class QuickSearchListAdapter extends ArrayAdapter { TextView distanceText = (TextView) view.findViewById(R.id.distance); ImageView direction = (ImageView) view.findViewById(R.id.direction); SearchPhrase phrase = listItem.getSearchResult().requiredSearchPhrase; - LatLon loc = location; + updateLocationViewCache.specialFrom = null; if(phrase != null && useMapCenter) { - LatLon ol = phrase.getSettings().getOriginalLocation(); - if(ol != null) { - loc = ol; - } + updateLocationViewCache.specialFrom = phrase.getSettings().getOriginalLocation(); } - DashLocationFragment.updateLocationView(useMapCenter, loc, - heading, direction, distanceText, - listItem.getSearchResult().location.getLatitude(), - listItem.getSearchResult().location.getLongitude(), - screenOrientation, app); + LatLon toloc = listItem.getSearchResult().location; + app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, toloc); } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index 96626656c7..df30d78ec8 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -192,8 +192,6 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { @Override public void onResume() { super.onResume(); - int screenOrientation = DashLocationFragment.getScreenOrientation(getActivity()); - listAdapter.setScreenOrientation(screenOrientation); dialogFragment.onSearchListFragmentResume(this); } @@ -336,8 +334,6 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { public void updateLocation(LatLon latLon, Float heading) { if (listAdapter != null && !touching && !scrolling) { - listAdapter.setLocation(latLon); - listAdapter.setHeading(heading); dialogFragment.getAccessibilityAssistant().lockEvents(); listAdapter.notifyDataSetChanged(); dialogFragment.getAccessibilityAssistant().unlockEvents(); @@ -346,7 +342,9 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { try { int position = getListView().getPositionForView(selected); if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) { - dialogFragment.getNavigationInfo().updateTargetDirection(listAdapter.getItem(position - getListView().getHeaderViewsCount()).getSearchResult().location, heading.floatValue()); + dialogFragment.getNavigationInfo().updateTargetDirection( + listAdapter.getItem(position - getListView().getHeaderViewsCount()).getSearchResult().location, + heading.floatValue()); } } catch (Exception e) { return; diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java index daaad406a3..5147ea3ad3 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchPoiFilterFragment.java @@ -34,7 +34,7 @@ import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -145,7 +145,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { description.setText(filter.getName()); Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar); - toolbar.setNavigationIcon(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark)); + toolbar.setNavigationIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_remove_dark)); toolbar.setNavigationContentDescription(R.string.shared_string_close); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override @@ -158,7 +158,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { moreButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - IconsCache iconsCache = app.getIconsCache(); + UiUtilities iconsCache = app.getUIUtilities(); final PopupMenu optionsMenu = new PopupMenu(getContext(), v); DirectionsDialogs.setupPopUpMenuIcon(optionsMenu); MenuItem item; @@ -235,7 +235,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { editText.setVisibility(View.VISIBLE); final ImageView textEditIcon = (ImageView) editTextView.findViewById(R.id.icon); - textEditIcon.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_search_dark)); + textEditIcon.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_search_dark)); textEditIcon.setVisibility(View.VISIBLE); editTextView.findViewById(R.id.titleBold).setVisibility(View.GONE); editTextView.findViewById(R.id.titleButton).setVisibility(View.GONE); @@ -804,7 +804,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { } if (item.iconId != 0) { - icon.setImageDrawable(app.getIconsCache().getIcon(item.iconId, + icon.setImageDrawable(app.getUIUtilities().getIcon(item.iconId, app.getSettings().isLightContent() ? R.color.icon_color : R.color.color_white)); icon.setVisibility(View.VISIBLE); } else { @@ -817,7 +817,7 @@ public class QuickSearchPoiFilterFragment extends DialogFragment { titleBold.setText(item.text); if (item.expandable) { expandItem.setImageDrawable(item.expanded ? - app.getIconsCache().getThemedIcon(R.drawable.ic_action_arrow_up) : app.getIconsCache().getThemedIcon(R.drawable.ic_action_arrow_down)); + app.getUIUtilities().getThemedIcon(R.drawable.ic_action_arrow_up) : app.getUIUtilities().getThemedIcon(R.drawable.ic_action_arrow_down)); expandItem.setVisibility(View.VISIBLE); } else { expandItem.setVisibility(View.GONE); diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchButtonListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchButtonListItem.java index 7899a1638f..45bebe2e88 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchButtonListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchButtonListItem.java @@ -41,7 +41,7 @@ public class QuickSearchButtonListItem extends QuickSearchListItem { @Override public Drawable getIcon() { if (iconId != 0) { - return app.getIconsCache().getIcon(iconId, colorId); + return app.getUIUtilities().getIcon(iconId, colorId); } else { return null; } diff --git a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java index 3a48ad161f..499e410190 100644 --- a/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java +++ b/OsmAnd/src/net/osmand/plus/search/listitems/QuickSearchListItem.java @@ -256,12 +256,12 @@ public class QuickSearchListItem { switch (searchResult.objectType) { case FAVORITE: case FAVORITE_GROUP: - return app.getIconsCache().getThemedIcon(R.drawable.ic_small_group); + return app.getUIUtilities().getThemedIcon(R.drawable.ic_small_group); case RECENT_OBJ: HistoryEntry historyEntry = (HistoryEntry) searchResult.object; String typeName = historyEntry.getName().getTypeName(); if (typeName != null && !typeName.isEmpty()) { - return app.getIconsCache().getThemedIcon(R.drawable.ic_small_group); + return app.getUIUtilities().getThemedIcon(R.drawable.ic_small_group); } else { return null; } @@ -359,7 +359,7 @@ public class QuickSearchListItem { case FAVORITE_GROUP: FavoriteGroup group = (FavoriteGroup) searchResult.object; int color = group.color == 0 || group.color == Color.BLACK ? app.getResources().getColor(R.color.color_favorite) : group.color; - return app.getIconsCache().getPaintedIcon(R.drawable.ic_action_fav_dark, color | 0xff000000); + return app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_fav_dark, color | 0xff000000); case REGION: return getIcon(app, R.drawable.ic_world_globe_dark); case RECENT_OBJ: @@ -390,7 +390,7 @@ public class QuickSearchListItem { } private static Drawable getIcon(OsmandApplication app, int iconId) { - return app.getIconsCache().getIcon(iconId, + return app.getUIUtilities().getIcon(iconId, app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark); } } diff --git a/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java b/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java index 40d9b9e342..43d061b7ea 100644 --- a/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java @@ -11,7 +11,7 @@ import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; import net.osmand.plus.GPXUtilities.GPXFile; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; @@ -28,7 +28,7 @@ public class AddGpxPointBottomSheetHelper implements OnDismissListener { private final MapActivity mapActivity; private final MapContextMenu contextMenu; private final ContextMenuLayer contextMenuLayer; - private final IconsCache iconsCache; + private final UiUtilities iconsCache; private String titleText; private boolean applyingPositionMode; private NewGpxPoint newGpxPoint; @@ -36,7 +36,7 @@ public class AddGpxPointBottomSheetHelper implements OnDismissListener { public AddGpxPointBottomSheetHelper(final MapActivity activity, ContextMenuLayer ctxMenuLayer) { this.contextMenuLayer = ctxMenuLayer; - iconsCache = activity.getMyApplication().getIconsCache(); + iconsCache = activity.getMyApplication().getUIUtilities(); mapActivity = activity; contextMenu = activity.getContextMenu(); view = activity.findViewById(R.id.add_gpx_point_bottom_sheet); diff --git a/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java b/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java index 38496c802f..50729d969a 100644 --- a/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java +++ b/OsmAnd/src/net/osmand/plus/views/DirectionDrawable.java @@ -1,6 +1,6 @@ package net.osmand.plus.views; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import android.content.Context; @@ -29,7 +29,7 @@ public class DirectionDrawable extends Drawable { public DirectionDrawable(OsmandApplication ctx, float width, float height, int resourceId, int clrId) { this(ctx, width, height); - IconsCache iconsCache = ctx.getIconsCache(); + UiUtilities iconsCache = ctx.getUIUtilities(); arrowImage = iconsCache.getIcon(resourceId, clrId); this.resourceId = resourceId; } @@ -45,14 +45,14 @@ public class DirectionDrawable extends Drawable { } public void setImage(int resourceId, int clrId) { - IconsCache iconsCache = app.getIconsCache(); + UiUtilities iconsCache = app.getUIUtilities(); arrowImage = iconsCache.getIcon(resourceId, clrId); this.resourceId = resourceId; onBoundsChange(getBounds()); } public void setImage(int resourceId) { - IconsCache iconsCache = app.getIconsCache(); + UiUtilities iconsCache = app.getUIUtilities(); arrowImage = iconsCache.getIcon(resourceId, 0); this.resourceId = resourceId; onBoundsChange(getBounds()); @@ -62,7 +62,7 @@ public class DirectionDrawable extends Drawable { public void setColorId(int clrId) { // R.color.color_ok, R.color.color_unknown, R.color.color_warning if(arrowImage != null) { - IconsCache iconsCache = app.getIconsCache(); + UiUtilities iconsCache = app.getUIUtilities(); arrowImage = iconsCache.getIcon(resourceId, clrId); } else { paintRouteDirection.setColor(app.getResources().getColor(clrId)); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 2517420d31..4c316989d0 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -294,7 +294,7 @@ public class MapControlsLayer extends OsmandMapLayer { public void updateRouteButtons(View main, boolean routeInfo) { boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); ImageView cancelRouteButton = (ImageView) main.findViewById(R.id.map_cancel_route_button); - cancelRouteButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.map_action_cancel, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light)); + cancelRouteButton.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.map_action_cancel, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light)); cancelRouteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -303,7 +303,7 @@ public class MapControlsLayer extends OsmandMapLayer { }); ImageView waypointsButton = (ImageView) main.findViewById(R.id.map_waypoints_route_button); - waypointsButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_intermediate_destination, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light)); + waypointsButton.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_intermediate_destination, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light)); waypointsButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -312,8 +312,8 @@ public class MapControlsLayer extends OsmandMapLayer { }); ImageView options = (ImageView) main.findViewById(R.id.map_options_route_button); - options.setImageDrawable(!routeInfo ? app.getIconsCache().getIcon(R.drawable.map_action_settings, - R.color.osmand_orange) : app.getIconsCache().getIcon(R.drawable.map_action_settings, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light)); + options.setImageDrawable(!routeInfo ? app.getUIUtilities().getIcon(R.drawable.map_action_settings, + R.color.osmand_orange) : app.getUIUtilities().getIcon(R.drawable.map_action_settings, nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light)); options.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -322,7 +322,7 @@ public class MapControlsLayer extends OsmandMapLayer { }); TextView routeGoButton = (TextView) main.findViewById(R.id.map_go_route_button); - routeGoButton.setCompoundDrawablesWithIntrinsicBounds(app.getIconsCache().getIcon(R.drawable.map_start_navigation, R.color.color_white), null, null, null); + routeGoButton.setCompoundDrawablesWithIntrinsicBounds(app.getUIUtilities().getIcon(R.drawable.map_start_navigation, R.color.color_white), null, null, null); routeGoButton.setText(mapActivity.getString(R.string.shared_string_go)); routeGoButton.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_white)); AndroidUtils.setBackground(mapActivity, routeGoButton, nightMode, R.drawable.route_info_go_btn_bg_light, R.drawable.route_info_go_btn_bg_dark); @@ -1189,11 +1189,11 @@ public class MapControlsLayer extends OsmandMapLayer { } Drawable d = null; if (resDarkId != 0 && nightMode) { - d = ctx.getIconsCache().getIcon(resDarkId); + d = ctx.getUIUtilities().getIcon(resDarkId); } else if (resLightId != 0 && !nightMode) { - d = ctx.getIconsCache().getIcon(resLightId); + d = ctx.getUIUtilities().getIcon(resLightId); } else if (resId != 0) { - d = ctx.getIconsCache().getIcon(resId, nightMode ? resClrDark : resClrLight); + d = ctx.getUIUtilities().getIcon(resId, nightMode ? resClrDark : resClrLight); } if (iv instanceof ImageView) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index bb96f035ec..348e4fea0c 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -271,7 +271,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe } private void updateQuickActionButton(boolean widgetVisible) { - quickActionButton.setImageDrawable(app.getIconsCache().getIcon( + quickActionButton.setImageDrawable(app.getUIUtilities().getIcon( !widgetVisible ? R.drawable.map_quick_action : R.drawable.map_action_cancel, !nightMode)); quickActionButton.setBackgroundResource( nightMode ? R.drawable.btn_circle_night : R.drawable.btn_circle_trans); diff --git a/OsmAnd/src/net/osmand/plus/views/MoveMarkerBottomSheetHelper.java b/OsmAnd/src/net/osmand/plus/views/MoveMarkerBottomSheetHelper.java index bcd3ea47b5..4e8c0b498d 100644 --- a/OsmAnd/src/net/osmand/plus/views/MoveMarkerBottomSheetHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/MoveMarkerBottomSheetHelper.java @@ -9,7 +9,7 @@ import android.widget.TextView; import net.osmand.data.RotatedTileBox; import net.osmand.data.PointDescription; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -27,7 +27,7 @@ public class MoveMarkerBottomSheetHelper { this.mDescription = (TextView) mView.findViewById(R.id.description); this.mContext = activity; - IconsCache iconsCache = activity.getMyApplication().getIconsCache(); + UiUtilities iconsCache = activity.getMyApplication().getUIUtilities(); icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_photo_dark, R.color.marker_green)); mView.findViewById(R.id.apply_button).setOnClickListener(new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 731534a28b..57dd52e656 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -305,7 +305,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon final Toolbar topBar = new Toolbar(ctx); topBar.setClickable(true); - Drawable back = app.getIconsCache().getIcon(R.drawable.ic_arrow_back); + Drawable back = app.getUIUtilities().getIcon(R.drawable.ic_arrow_back); topBar.setNavigationIcon(back); topBar.setNavigationContentDescription(R.string.access_shared_string_navigate_up); topBar.setTitle(title); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java index bc866ddf3a..523e2f3981 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapInfoWidgetsFactory.java @@ -600,17 +600,17 @@ public class MapInfoWidgetsFactory { if (controller.backBtnIconDarkId == 0) { backButton.setImageDrawable(null); } else { - backButton.setImageDrawable(app.getIconsCache().getIcon(controller.backBtnIconDarkId, controller.backBtnIconClrDarkId)); + backButton.setImageDrawable(app.getUIUtilities().getIcon(controller.backBtnIconDarkId, controller.backBtnIconClrDarkId)); } if (controller.closeBtnIconDarkId == 0) { closeButton.setImageDrawable(null); } else { - closeButton.setImageDrawable(app.getIconsCache().getIcon(controller.closeBtnIconDarkId, controller.closeBtnIconClrDarkId)); + closeButton.setImageDrawable(app.getUIUtilities().getIcon(controller.closeBtnIconDarkId, controller.closeBtnIconClrDarkId)); } if (controller.refreshBtnIconDarkId == 0) { refreshButton.setImageDrawable(null); } else { - refreshButton.setImageDrawable(app.getIconsCache().getIcon(controller.refreshBtnIconDarkId, controller.refreshBtnIconClrDarkId)); + refreshButton.setImageDrawable(app.getUIUtilities().getIcon(controller.refreshBtnIconDarkId, controller.refreshBtnIconClrDarkId)); } int titleColor = map.getResources().getColor(controller.titleTextClrDarkId); int descrColor = map.getResources().getColor(controller.descrTextClrDarkId); @@ -622,17 +622,17 @@ public class MapInfoWidgetsFactory { if (controller.backBtnIconLightId == 0) { backButton.setImageDrawable(null); } else { - backButton.setImageDrawable(app.getIconsCache().getIcon(controller.backBtnIconLightId, controller.backBtnIconClrLightId)); + backButton.setImageDrawable(app.getUIUtilities().getIcon(controller.backBtnIconLightId, controller.backBtnIconClrLightId)); } if (controller.closeBtnIconLightId == 0) { closeButton.setImageDrawable(null); } else { - closeButton.setImageDrawable(app.getIconsCache().getIcon(controller.closeBtnIconLightId, controller.closeBtnIconClrLightId)); + closeButton.setImageDrawable(app.getUIUtilities().getIcon(controller.closeBtnIconLightId, controller.closeBtnIconClrLightId)); } if (controller.refreshBtnIconLightId == 0) { refreshButton.setImageDrawable(null); } else { - refreshButton.setImageDrawable(app.getIconsCache().getIcon(controller.refreshBtnIconLightId, controller.refreshBtnIconClrLightId)); + refreshButton.setImageDrawable(app.getUIUtilities().getIcon(controller.refreshBtnIconLightId, controller.refreshBtnIconClrLightId)); } int titleColor = map.getResources().getColor(controller.titleTextClrLightId); int descrColor = map.getResources().getColor(controller.descrTextClrLightId); @@ -750,9 +750,9 @@ public class MapInfoWidgetsFactory { ImageView all = (ImageView) waypointInfoBar.findViewById(R.id.waypoint_more); ImageView remove = (ImageView) waypointInfoBar.findViewById(R.id.waypoint_close); - all.setImageDrawable(map.getMyApplication().getIconsCache() + all.setImageDrawable(map.getMyApplication().getUIUtilities() .getIcon(R.drawable.ic_overflow_menu_white, !nightMode)); - remove.setImageDrawable(map.getMyApplication().getIconsCache() + remove.setImageDrawable(map.getMyApplication().getUIUtilities() .getIcon(R.drawable.ic_action_remove_dark, !nightMode)); } @@ -847,7 +847,7 @@ public class MapInfoWidgetsFactory { addressText.setCompoundDrawables(turnDrawable, null, null, null); addressText.setCompoundDrawablePadding(4); } else if (showMarker) { - Drawable marker = map.getMyApplication().getIconsCache().getIcon(R.drawable.ic_action_start_navigation, R.color.color_myloc_distance); + Drawable marker = map.getMyApplication().getUIUtilities().getIcon(R.drawable.ic_action_start_navigation, R.color.color_myloc_distance); addressTextShadow.setCompoundDrawablesWithIntrinsicBounds(marker, null, null, null); addressTextShadow.setCompoundDrawablePadding(4); addressText.setCompoundDrawablesWithIntrinsicBounds(marker, null, null, null); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index fbaec120f0..0814cc49dd 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -8,7 +8,7 @@ import android.widget.TextView; import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndFormatter; @@ -60,7 +60,7 @@ public class MapMarkersWidgetsFactory { public MapMarkersWidgetsFactory(final MapActivity map) { this.map = map; helper = map.getMyApplication().getMapMarkersHelper(); - screenOrientation = DashLocationFragment.getScreenOrientation(map); + screenOrientation = map.getMyApplication().getUIUtilities().getScreenOrientation(map); portraitMode = AndroidUiHelper.isOrientationPortrait(map); addressTopBar = map.findViewById(R.id.map_top_bar); @@ -92,7 +92,7 @@ public class MapMarkersWidgetsFactory { } }); - IconsCache iconsCache = map.getMyApplication().getIconsCache(); + UiUtilities iconsCache = map.getMyApplication().getUIUtilities(); if (isLandscapeLayout() && helper.getMapMarkers().size() > 1 && !(map.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 1)) { moreButton.setVisibility(View.GONE); @@ -367,7 +367,7 @@ public class MapMarkersWidgetsFactory { if (marker.colorIndex != -1) { if (marker.colorIndex != cachedMarkerColorIndex || cachedNightMode == null || cachedNightMode != isNight()) { - setImageDrawable(map.getMyApplication().getIconsCache() + setImageDrawable(map.getMyApplication().getUIUtilities() .getIcon(isNight() ? R.drawable.widget_marker_night : R.drawable.widget_marker_day, R.drawable.widget_marker_triangle, MapMarker.getColorId(marker.colorIndex))); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index 961a75d1dd..7d4e43b4a0 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -14,7 +14,7 @@ import android.widget.LinearLayout; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.OsmandPreference; @@ -484,7 +484,7 @@ public class MapWidgetRegistry { MenuInflater inflater = popup.getMenuInflater(); final Menu menu = popup.getMenu(); inflater.inflate(R.menu.widget_visibility_menu, menu); - IconsCache ic = mapActivity.getMyApplication().getIconsCache(); + UiUtilities ic = mapActivity.getMyApplication().getUIUtilities(); menu.findItem(R.id.action_show).setIcon(ic.getThemedIcon(R.drawable.ic_action_view)); menu.findItem(R.id.action_hide).setIcon(ic.getThemedIcon(R.drawable.ic_action_hide)); menu.findItem(R.id.action_collapse).setIcon(ic.getThemedIcon(R.drawable.ic_action_widget_collapse)); diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/TextInfoWidget.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/TextInfoWidget.java index 16f983e92b..2bce2af1cf 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/TextInfoWidget.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/TextInfoWidget.java @@ -62,7 +62,7 @@ public class TextInfoWidget { } public void setImageDrawable(int res) { - setImageDrawable(app.getIconsCache().getIcon(res, 0), false); + setImageDrawable(app.getUIUtilities().getIcon(res, 0), false); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java index 9c0c0ed779..a07fe37927 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/SavedArticlesRvAdapter.java @@ -17,7 +17,7 @@ import com.squareup.picasso.RequestCreator; import net.osmand.AndroidUtils; import net.osmand.PicassoUtils; -import net.osmand.plus.IconsCache; +import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; @@ -56,7 +56,7 @@ public class SavedArticlesRvAdapter extends RecyclerView.Adapter Date: Thu, 24 May 2018 10:03:23 +0200 Subject: [PATCH 2/4] Fix crashes --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 13 +++++---- .../activities/search/SearchPOIActivity.java | 28 ++++++------------- .../plus/dashboard/DashLocationFragment.java | 2 -- .../MapContextMenuFragment.java | 1 + 4 files changed, 17 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 036f632891..0304b10188 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -122,10 +122,10 @@ public class UiUtilities { LatLon toLoc) { float[] mes = new float[2]; boolean stale = false; - LatLon fromLoc = cache.specialFrom; - boolean useCenter = cache.specialFrom != null; + LatLon fromLoc = cache == null ? null : cache.specialFrom; + boolean useCenter = fromLoc != null; Float h = null; - if (cache.specialFrom == null) { + if (fromLoc == null) { Location loc = app.getLocationProvider().getLastKnownLocation(); h = app.getLocationProvider().getHeading(); if (loc == null) { @@ -150,7 +150,7 @@ public class UiUtilities { if (arrow != null) { boolean newImage = false; - int arrowResId = cache.arrowResId; + int arrowResId = cache == null ? 0 : cache.arrowResId; if (arrowResId == 0) { arrowResId = R.drawable.ic_direction_arrow; } @@ -161,7 +161,7 @@ public class UiUtilities { } else { dd = (DirectionDrawable) arrow.getDrawable(); } - int imgColorSet = cache.arrowColor; + int imgColorSet = cache == null ? 0 : cache.arrowColor; if (imgColorSet == 0) { imgColorSet = useCenter ? R.color.color_distance : R.color.color_myloc_distance; if (stale) { @@ -172,7 +172,8 @@ public class UiUtilities { if (fromLoc == null || h == null || toLoc == null) { dd.setAngle(0); } else { - dd.setAngle(mes[1] - h + 180 + cache.screenOrientation); + float orientation = (cache == null ? 0 : cache.screenOrientation) * 90; + dd.setAngle(mes[1] - h + 180 + orientation); } if (newImage) { arrow.setImageDrawable(dd); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 7d8e02e032..ea8baa460b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -30,6 +30,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.R.color; import net.osmand.plus.UiUtilities; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.activities.EditPOIFilterActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.OsmandListActivity; @@ -716,10 +717,11 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa class AmenityAdapter extends ArrayAdapter { private AmenityFilter listFilter; private List originalAmenityList; - private int screenOrientation; + private UpdateLocationViewCache updateLocationViewCache; AmenityAdapter(List list) { super(SearchPOIActivity.this, R.layout.searchpoi_list, list); + updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(SearchPOIActivity.this); originalAmenityList = new ArrayList(list); this.setNotifyOnChange(false); } @@ -730,7 +732,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa public void setNewModel(List amenityList) { setNotifyOnChange(false); - screenOrientation = getMyApplication().getUIUtilities().getScreenOrientation(SearchPOIActivity.this); + updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(SearchPOIActivity.this); originalAmenityList = new ArrayList(amenityList); clear(); for (Amenity obj : amenityList) { @@ -789,19 +791,12 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa direction.setImageDrawable(draw); } net.osmand.Location loc = location; - if (loc != null) { - mes = new float[2]; - LatLon l = amenity.getLocation(); - net.osmand.Location.distanceBetween(l.getLatitude(), l.getLongitude(), loc.getLatitude(), - loc.getLongitude(), mes); + if(searchNearBy) { + updateLocationViewCache.specialFrom = null; + } else if(loc != null) { + updateLocationViewCache.specialFrom = new LatLon(loc.getLatitude(), loc.getLongitude()); } - if (loc != null) { - float a = heading != null ? heading : 0; - draw.setAngle(mes[1] - a + 180 + screenOrientation); - } else { - draw.setAngle(0); - } - draw.setColorId(searchNearBy ? color.color_myloc_distance : color.color_distance); + getMyApplication().getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, amenity.getLocation()); direction.setImageDrawable(draw); PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType()); if (st != null) { @@ -816,15 +811,10 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa icon.setImageDrawable(null); } - String distance = " "; - if (mes != null) { - distance = " " + OsmAndFormatter.getFormattedDistance((int) mes[0], getMyApplication()) + " "; //$NON-NLS-1$ - } String poiType = OsmAndFormatter.getPoiStringWithoutType(amenity, app.getSettings().MAP_PREFERRED_LOCALE.get(), app.getSettings().MAP_TRANSLITERATE_NAMES.get()); label.setText(poiType); - distanceText.setText(distance); ViewCompat.setAccessibilityDelegate(row, accessibilityAssistant); return (row); } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java index db1b8511ad..0ff8965496 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java @@ -18,7 +18,6 @@ import android.widget.TextView; public abstract class DashLocationFragment extends DashBaseFragment { protected List distances = new ArrayList(); - private int screenOrientation; public static class DashLocationView { public ImageView arrow; @@ -39,7 +38,6 @@ 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 = UiUtilities.getScreenOrientation(getActivity()); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 16efb55e97..243913f2c6 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -142,6 +142,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo processScreenHeight(container); menu = getMapActivity().getContextMenu(); + updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(getMapActivity()); markerPaddingPx = dpToPx(MARKER_PADDING_DP); markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP); From f6859d5ed04b23ebae8032933012fb06ea56168e Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 24 May 2018 10:11:37 +0200 Subject: [PATCH 3/4] Small issues --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 4 +- .../plus/mapcontextmenu/MapContextMenu.java | 39 +++++++------------ 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 0304b10188..4f04e72d30 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -137,7 +137,7 @@ public class UiUtilities { } else { useCenter = true; fromLoc = app.getMapViewTrackingUtilities().getMapLocation(); - h = app.getMapViewTrackingUtilities().getHeading(); + h = app.getMapViewTrackingUtilities().getMapRotate(); if(h != null) { h = -h; } @@ -172,7 +172,7 @@ public class UiUtilities { if (fromLoc == null || h == null || toLoc == null) { dd.setAngle(0); } else { - float orientation = (cache == null ? 0 : cache.screenOrientation) * 90; + float orientation = (cache == null ? 0 : -cache.screenOrientation) * 90; dd.setAngle(mes[1] - h + 180 + orientation); } if (newImage) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 45e61fe30f..a1eaf2b0f3 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -1,15 +1,8 @@ package net.osmand.plus.mapcontextmenu; -import android.app.Dialog; -import android.app.ProgressDialog; -import android.content.DialogInterface; -import android.graphics.drawable.Drawable; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.app.AlertDialog; -import android.view.View; -import android.widget.LinearLayout; +import java.lang.ref.WeakReference; +import java.util.LinkedList; +import java.util.List; import net.osmand.CallbackWithObject; import net.osmand.Location; @@ -56,11 +49,16 @@ import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.util.Algorithms; -import net.osmand.util.MapUtils; - -import java.lang.ref.WeakReference; -import java.util.LinkedList; -import java.util.List; +import android.app.Dialog; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.graphics.drawable.Drawable; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v7.app.AlertDialog; +import android.view.View; +import android.widget.LinearLayout; public class MapContextMenu extends MenuTitleController implements StateChangedListener, MapMarkerChangedListener, TargetPointChangedListener { @@ -84,9 +82,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL private boolean centerMarker; private int mapZoom; - private LatLon myLocation; private boolean inLocationUpdate = false; - private boolean cachedMyLocation; private boolean appModeChanged; private boolean appModeListenerAdded; private boolean autoHide; @@ -293,9 +289,6 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL boolean update, boolean restorePrevious) { OsmandApplication app = mapActivity.getMyApplication(); - if (myLocation == null) { - updateMyLocation(app.getLocationProvider().getLastKnownLocation(), false); - } if (!update && isVisible()) { if (this.object == null || !this.object.equals(object)) { @@ -422,7 +415,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } public void onFragmentResume() { - if (active && displayDistanceDirection() && myLocation != null) { + if (active && displayDistanceDirection()) { updateLocation(false, true, false); } } @@ -1252,12 +1245,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL private void updateMyLocation(Location location, boolean updateLocationUi) { if (location == null) { location = getMapActivity().getMyApplication().getLocationProvider().getLastStaleKnownLocation(); - cachedMyLocation = location != null; - } else { - cachedMyLocation = false; } if (location != null) { - myLocation = new LatLon(location.getLatitude(), location.getLongitude()); if (updateLocationUi) { updateLocation(false, true, false); } From 83915a44ab266c95a269f16af0816cfd3a131944 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 24 May 2018 10:25:06 +0200 Subject: [PATCH 4/4] Remove unnecessary method --- OsmAnd/src/net/osmand/plus/UiUtilities.java | 12 +++++----- .../activities/FavoritesListFragment.java | 2 +- .../search/SearchHistoryFragment.java | 2 +- .../activities/search/SearchPOIActivity.java | 4 ++-- .../plus/dashboard/DashLocationFragment.java | 2 +- .../MapContextMenuFragment.java | 4 ++-- .../other/FavouritesAdapter.java | 23 ++++++++----------- .../FavouritesBottomSheetMenuFragment.java | 2 +- .../MapMarkerSelectionFragment.java | 2 +- .../adapters/CoordinateInputAdapter.java | 2 +- .../adapters/MapMarkersActiveAdapter.java | 2 +- .../adapters/MapMarkersGroupsAdapter.java | 2 +- .../QuickSearchCoordinatesFragment.java | 2 +- .../plus/search/QuickSearchListAdapter.java | 2 +- .../mapwidgets/MapMarkersWidgetsFactory.java | 2 +- 15 files changed, 30 insertions(+), 35 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 4f04e72d30..de1d8abc25 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -99,9 +99,9 @@ public class UiUtilities { } - public UpdateLocationViewCache getUpdateLocationViewCache(Activity a){ + public UpdateLocationViewCache getUpdateLocationViewCache(){ UpdateLocationViewCache uvc = new UpdateLocationViewCache(); - uvc.screenOrientation = getScreenOrientation(a); + uvc.screenOrientation = getScreenOrientation(); return uvc; } @@ -172,7 +172,7 @@ public class UiUtilities { if (fromLoc == null || h == null || toLoc == null) { dd.setAngle(0); } else { - float orientation = (cache == null ? 0 : -cache.screenOrientation) * 90; + float orientation = (cache == null ? 0 : -cache.screenOrientation) ; dd.setAngle(mes[1] - h + 180 + orientation); } if (newImage) { @@ -199,8 +199,8 @@ public class UiUtilities { } } - public static int getScreenOrientation(Activity a) { - int screenOrientation = ((WindowManager) a.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); + public int getScreenOrientation() { + int screenOrientation = ((WindowManager) app.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); switch (screenOrientation) { case ORIENTATION_0: // Device default (normally portrait) screenOrientation = 0; @@ -216,7 +216,7 @@ public class UiUtilities { break; } //Looks like screenOrientation correction must not be applied for devices without compass? - Sensor compass = ((SensorManager) a.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); + Sensor compass = ((SensorManager) app.getSystemService(Context.SENSOR_SERVICE)).getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); if (compass == null) { screenOrientation = 0; } diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java index 6f1b283c78..27fc4c3907 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java @@ -166,7 +166,7 @@ public class FavoritesListFragment extends OsmAndListFragment implements SearchA this.activity = activity; this.app = ((OsmandApplication) activity.getApplication()); this.shouldShowMenuButton = shouldShowMenuButton; - cache = app.getUIUtilities().getUpdateLocationViewCache(activity); + cache = app.getUIUtilities().getUpdateLocationViewCache(); } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java index 83191ef1da..e3258b7c68 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryFragment.java @@ -124,7 +124,7 @@ public class SearchHistoryFragment extends OsmAndListFragment implements SearchA //Hardy: onResume() code is needed so that search origin is properly reflected in tab contents when origin has been changed on one tab, then tab is changed to another one. location = null; FragmentActivity activity = getActivity(); - updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(getActivity()); + updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(); Intent intent = activity.getIntent(); if (intent != null) { double lat = intent.getDoubleExtra(SEARCH_LAT, 0); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index ea8baa460b..22e38384a9 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -721,7 +721,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa AmenityAdapter(List list) { super(SearchPOIActivity.this, R.layout.searchpoi_list, list); - updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(SearchPOIActivity.this); + updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(); originalAmenityList = new ArrayList(list); this.setNotifyOnChange(false); } @@ -732,7 +732,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa public void setNewModel(List amenityList) { setNotifyOnChange(false); - updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(SearchPOIActivity.this); + updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(); originalAmenityList = new ArrayList(amenityList); clear(); for (Amenity obj : amenityList) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java index 0ff8965496..4387bb4cfa 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashLocationFragment.java @@ -55,7 +55,7 @@ public abstract class DashLocationFragment extends DashBaseFragment { return; } UiUtilities ic = getMyApplication().getUIUtilities(); - UpdateLocationViewCache cache = ic.getUpdateLocationViewCache(getActivity()); + UpdateLocationViewCache cache = ic.getUpdateLocationViewCache(); for (DashLocationView lv : distances) { cache.arrowResId = lv.arrowResId; cache.paintTxt = lv.paint; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 243913f2c6..91e8ce13b5 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -142,7 +142,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo processScreenHeight(container); menu = getMapActivity().getContextMenu(); - updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(getMapActivity()); + updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(); markerPaddingPx = dpToPx(MARKER_PADDING_DP); markerPaddingXPx = dpToPx(MARKER_PADDING_X_DP); @@ -1173,7 +1173,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo dismissMenu(); return; } - updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(getMapActivity()); + updateLocationViewCache = getMyApplication().getUIUtilities().getUpdateLocationViewCache(); getMapActivity().getMapViewTrackingUtilities().setContextMenu(menu); getMapActivity().getMapViewTrackingUtilities().setMapLinkedToLocation(false); wasDrawerDisabled = getMapActivity().isDrawerDisabled(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java index 98cfe4b180..83460e028c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesAdapter.java @@ -1,5 +1,12 @@ package net.osmand.plus.mapcontextmenu.other; +import java.util.List; + +import net.osmand.data.FavouritePoint; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities.UpdateLocationViewCache; +import net.osmand.plus.base.FavoriteImageDrawable; import android.app.Activity; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; @@ -7,18 +14,6 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import net.osmand.data.FavouritePoint; -import net.osmand.data.LatLon; -import net.osmand.plus.UiUtilities; -import net.osmand.plus.OsmAndFormatter; -import net.osmand.plus.OsmandApplication; -import net.osmand.plus.R; -import net.osmand.plus.UiUtilities.UpdateLocationViewCache; -import net.osmand.plus.base.FavoriteImageDrawable; -import net.osmand.plus.dashboard.DashLocationFragment; -import net.osmand.util.MapUtils; - -import java.util.List; public class FavouritesAdapter extends RecyclerView.Adapter { @@ -29,10 +24,10 @@ public class FavouritesAdapter extends RecyclerView.Adapter FavouritePoints) { + public FavouritesAdapter(OsmandApplication app, List FavouritePoints) { this.app = app; this.favouritePoints = FavouritePoints; - cache = app.getUIUtilities().getUpdateLocationViewCache(a); + cache = app.getUIUtilities().getUpdateLocationViewCache(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java index 07cfe2bc34..3c014bb30e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/FavouritesBottomSheetMenuFragment.java @@ -64,7 +64,7 @@ public class FavouritesBottomSheetMenuFragment extends MenuBottomSheetDialogFrag recyclerView = (RecyclerView) View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.recyclerview, null); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); - adapter = new FavouritesAdapter(getMyApplication(), getActivity(), favouritePoints); + adapter = new FavouritesAdapter(getMyApplication(), favouritePoints); sortFavourites(); final BottomSheetItemTitleWithDescrAndButton[] title = new BottomSheetItemTitleWithDescrAndButton[1]; title[0] = (BottomSheetItemTitleWithDescrAndButton) new BottomSheetItemTitleWithDescrAndButton.Builder() diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java index b614901b98..20d127a2ca 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkerSelectionFragment.java @@ -63,7 +63,7 @@ public class MapMarkerSelectionFragment extends BaseOsmAndDialogFragment { MapRouteInfoMenu routeInfoMenu = mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu(); onClickListener = routeInfoMenu.getOnMarkerSelectListener(); - screenOrientation = app.getUIUtilities().getScreenOrientation(mapActivity); + screenOrientation = app.getUIUtilities().getScreenOrientation(); MapViewTrackingUtilities trackingUtils = mapActivity.getMapViewTrackingUtilities(); if (trackingUtils != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java index b2508dcff9..66286e9065 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/CoordinateInputAdapter.java @@ -30,7 +30,7 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter mapMarkers) { this.mapActivity = mapActivity; iconsCache = mapActivity.getMyApplication().getUIUtilities(); - updateViewCache = iconsCache.getUpdateLocationViewCache(mapActivity); + updateViewCache = iconsCache.getUpdateLocationViewCache(); this.mapMarkers = mapMarkers; nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java index 30b2d76eb2..7c554c4c4e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersActiveAdapter.java @@ -44,7 +44,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter { this.activity = activity; dp56 = AndroidUtils.dpToPx(app, 56f); dp1 = AndroidUtils.dpToPx(app, 1f); - updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(activity); + updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(); } public void setAccessibilityAssistant(AccessibilityAssistant accessibilityAssistant) { diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java index 0814cc49dd..d09e8e0b97 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapMarkersWidgetsFactory.java @@ -60,7 +60,7 @@ public class MapMarkersWidgetsFactory { public MapMarkersWidgetsFactory(final MapActivity map) { this.map = map; helper = map.getMyApplication().getMapMarkersHelper(); - screenOrientation = map.getMyApplication().getUIUtilities().getScreenOrientation(map); + screenOrientation = map.getMyApplication().getUIUtilities().getScreenOrientation(); portraitMode = AndroidUiHelper.isOrientationPortrait(map); addressTopBar = map.findViewById(R.id.map_top_bar);