diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 4f6342da9c..f414d7bb96 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -1,8 +1,6 @@ package net.osmand.plus; import java.io.File; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Array; import java.text.Collator; import java.util.ArrayList; import java.util.Collections; @@ -11,22 +9,15 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import android.app.AlertDialog; -import android.content.ActivityNotFoundException; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.net.Uri; -import android.widget.Toast; import net.osmand.PlatformUtil; import net.osmand.data.FavouritePoint; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; +import android.app.AlertDialog; +import android.content.Context; public class FavouritesDbHelper { @@ -34,7 +25,6 @@ public class FavouritesDbHelper { void updateFavourites(); } - private List favoritesUpdatedListeners = new ArrayList(); private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(FavouritesDbHelper.class); @@ -93,20 +83,8 @@ public class FavouritesDbHelper { } private void favouritesUpdated(){ - for (FavoritesUpdatedListener listener : favoritesUpdatedListeners){ - listener.updateFavourites(); - } } - public void addFavoritesUpdatedListener(FavoritesUpdatedListener listener){ - if (!favoritesUpdatedListeners.contains(listener)){ - favoritesUpdatedListeners.add(listener); - } - } - - public void removeFavoritesUpdatedListener(FavoritesUpdatedListener listener){ - favoritesUpdatedListeners.remove(listener); - } private boolean merge(Map source, Map destination) { boolean changed = false; diff --git a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java index ad9d451d46..12de9be350 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/DashAudioVideoNotesFragment.java @@ -58,19 +58,13 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment { } @Override - public void onOpenUpdate() { + public void onOpenDash() { if (plugin == null) { plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class); } setupNotes(); } - - @Override - public void onPause() { - super.onPause(); - } - public void setupNotes() { View mainView = getView(); if (plugin == null){ diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java index 6c9fdf5a8f..13bc27cf22 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashBaseFragment.java @@ -29,7 +29,26 @@ public abstract class DashBaseFragment extends Fragment { } } - public void onOpenUpdate() {} + public abstract void onOpenDash() ; + + public void onCloseDash() { + } + + @Override + public final void onPause() { + // use on close + super.onPause(); + onCloseDash(); + } + + @Override + public final void onResume() { + // use on open update + super.onResume(); + if(dashboard != null && dashboard.isVisible()) { + onOpenDash(); + } + } public void onLocationCompassChanged(Location l, double compassValue) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashDownloadMapsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashDownloadMapsFragment.java index fc41443b91..048c7a8b84 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashDownloadMapsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashDownloadMapsFragment.java @@ -64,7 +64,7 @@ public class DashDownloadMapsFragment extends DashBaseFragment { } @Override - public void onOpenUpdate() { + public void onOpenDash() { refreshData(); } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java index c8fdab5a09..d429985dea 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashErrorFragment.java @@ -84,6 +84,6 @@ public class DashErrorFragment extends DashBaseFragment { } @Override - public void onOpenUpdate() { + public void onOpenDash() { } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java index 4826cc3f3a..3fdad84b56 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashFavoritesFragment.java @@ -13,11 +13,11 @@ import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; -import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.helpers.FontCache; +import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.util.MapUtils; import android.app.Activity; import android.content.Intent; @@ -33,8 +33,7 @@ import android.widget.LinearLayout; import android.widget.TextView; /** - * Created by Denis - * on 24.11.2014. + * Created by Denis on 24.11.2014. */ public class DashFavoritesFragment extends DashLocationFragment implements FavouritesDbHelper.FavoritesUpdatedListener { public static final String TAG = "DASH_FAVORITES_FRAGMENT"; @@ -63,38 +62,29 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou }); return view; } - + @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); } @Override - public void onResume() { - super.onResume(); - //This is used as origin for both Fav-list and direction arrows + public void onOpenDash() { + // This is used as origin for both Fav-list and direction arrows if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { loc = getMyApplication().getSettings().getLastKnownMapLocation(); } else { loc = new LatLon(0f, 0f); } - - getMyApplication().getFavorites().addFavoritesUpdatedListener(this); setupFavorites(); } - @Override - public void onPause() { - super.onPause(); - getMyApplication().getFavorites().removeFavoritesUpdatedListener(this); - } - - public void setupFavorites(){ + public void setupFavorites() { View mainView = getView(); final FavouritesDbHelper helper = getMyApplication().getFavorites(); points = new ArrayList(helper.getFavouritePoints()); arrows.clear(); - if (points.size() == 0){ + if (points.size() == 0) { (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE); return; } else { @@ -104,18 +94,18 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou Collections.sort(points, new Comparator() { @Override public int compare(FavouritePoint point, FavouritePoint point2) { - //LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); - int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), - loc.getLatitude(), loc.getLongitude())); - int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(), - loc.getLatitude(), loc.getLongitude())); + // LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); + int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), loc.getLatitude(), + loc.getLongitude())); + int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(), loc.getLatitude(), + loc.getLongitude())); return (dist - dist2); } }); LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items); favorites.removeAllViews(); - if (points.size() > 3){ - while (points.size() != 3){ + if (points.size() > 3) { + while (points.size() != 3) { points.remove(3); } } @@ -132,27 +122,27 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou view.findViewById(R.id.group_image).setVisibility(View.GONE); } + ((ImageView) view.findViewById(R.id.favourite_icon)).setImageDrawable(FavoriteImageDrawable.getOrCreate( + getActivity(), point.getColor())); - ((ImageView) view.findViewById(R.id.favourite_icon)). - setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), point.getColor())); - - if(loc != null){ + if (loc != null) { direction.setVisibility(View.VISIBLE); - updateArrow(getActivity(), loc, new LatLon(point.getLatitude(), point.getLongitude()), direction, - 10, R.drawable.ic_destination_arrow, heading); + updateArrow(getActivity(), loc, new LatLon(point.getLatitude(), point.getLongitude()), direction, 10, + R.drawable.ic_destination_arrow, heading); } arrows.add(direction); name.setText(point.getName()); - //LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); - int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), - loc.getLatitude(), loc.getLongitude())); + // LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); + int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), loc.getLatitude(), + loc.getLongitude())); String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " "; view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE); view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), point.getLatitude(), point.getLongitude(), + DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), point.getLatitude(), + point.getLongitude(), new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName())); } }); @@ -161,8 +151,8 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(), 15, - new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), true, + getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(), + 15, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), true, point); //$NON-NLS-1$ MapActivity.launchMapActivityMoveToTop(getActivity()); } @@ -186,7 +176,7 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou @Override public boolean updateCompassValue(float value) { - if (super.updateCompassValue(value)){ + if (super.updateCompassValue(value)) { updateArrows(); } return true; diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashMapFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashMapFragment.java index a6ee66c04d..15b0077c62 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashMapFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashMapFragment.java @@ -60,6 +60,13 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloaderC protected void startMapActivity() { MapActivity.launchMapActivityMoveToTop(getActivity()); } + + @Override + public void onOpenDash() { + if (!getMyApplication().isApplicationInitializing()) { + updateMapImage(); + } + } @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -112,15 +119,6 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloaderC } - @Override - public void onResume() { - super.onResume(); - if (!getMyApplication().isApplicationInitializing()) { - updateMapImage(); - } - - } - @Override public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java index e1a3b1fd43..6ab5da6f5c 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashPluginsFragment.java @@ -87,10 +87,9 @@ public class DashPluginsFragment extends DashBaseFragment { return contentView; } - @Override - public void onResume() { - super.onResume(); + @Override + public void onOpenDash() { View contentView = getView(); if (contentView == null) { return; @@ -99,9 +98,9 @@ public class DashPluginsFragment extends DashBaseFragment { for (int pluginIndex = 0; pluginIndex < plugins.size(); pluginIndex++) { View pluginView = pluginsContainer.getChildAt(pluginIndex); updatePluginState(pluginView, plugins.get(pluginIndex)); - } + } } - + private void updatePluginState(View pluginView, OsmandPlugin plugin) { CompoundButton enableDisableButton = (CompoundButton) pluginView.findViewById(R.id.plugin_enable_disable); Button getButton = (Button) pluginView.findViewById(R.id.get_plugin); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java index 56231db466..1cce8ebb6a 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java @@ -32,8 +32,7 @@ import android.widget.LinearLayout; import android.widget.TextView; /** - * Created by Denis - * on 24.11.2014. + * Created by Denis on 24.11.2014. */ public class DashRecentsFragment extends DashLocationFragment { public static final String TAG = "DASH_RECENTS_FRAGMENT"; @@ -47,8 +46,8 @@ public class DashRecentsFragment extends DashLocationFragment { View view = getActivity().getLayoutInflater().inflate(R.layout.dash_common_fragment, container, false); Typeface typeface = FontCache.getRobotoMedium(getActivity()); ((TextView) view.findViewById(R.id.fav_text)).setTypeface(typeface); - ((TextView) view.findViewById(R.id.fav_text)).setText( - Algorithms.capitalizeFirstLetterAndLowercase(getString(R.string.recents))); + ((TextView) view.findViewById(R.id.fav_text)).setText(Algorithms + .capitalizeFirstLetterAndLowercase(getString(R.string.recents))); ((Button) view.findViewById(R.id.show_all)).setTypeface(typeface); (view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() { @@ -56,9 +55,9 @@ public class DashRecentsFragment extends DashLocationFragment { public void onClick(View view) { Activity activity = getActivity(); OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization(); - + final Intent search = new Intent(activity, appCustomization.getSearchActivity()); - //search.putExtra(SearchActivity.SHOW_ONLY_ONE_TAB, true); + // search.putExtra(SearchActivity.SHOW_ONLY_ONE_TAB, true); search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.HISTORY_TAB_INDEX); activity.startActivity(search); @@ -71,12 +70,10 @@ public class DashRecentsFragment extends DashLocationFragment { } return view; } - @Override - public void onResume() { - super.onResume(); - //This is used as origin for both Fav-list and direction arrows + public void onOpenDash() { + // This is used as origin for both Fav-list and direction arrows if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { loc = getMyApplication().getSettings().getLastKnownMapLocation(); } else { @@ -85,17 +82,13 @@ public class DashRecentsFragment extends DashLocationFragment { setupRecents(); } - @Override - public void onPause() { - super.onPause(); - } - - public void setupRecents(){ + public void setupRecents() { View mainView = getView(); - SearchHistoryHelper helper = SearchHistoryHelper.getInstance((OsmandApplication) getActivity().getApplicationContext()); + SearchHistoryHelper helper = SearchHistoryHelper.getInstance((OsmandApplication) getActivity() + .getApplicationContext()); points = helper.getHistoryEntries(); arrows.clear(); - if (points.size() == 0){ + if (points.size() == 0) { (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE); return; } else { @@ -104,28 +97,26 @@ public class DashRecentsFragment extends DashLocationFragment { LinearLayout recents = (LinearLayout) mainView.findViewById(R.id.items); recents.removeAllViews(); - if (points.size() > 3){ + if (points.size() > 3) { points = points.subList(0, 3); } for (final HistoryEntry historyEntry : points) { LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.search_history_list_item, null, false); - SearchHistoryFragment.udpateHistoryItem(historyEntry, view, - loc, getActivity(), getMyApplication()); + SearchHistoryFragment.udpateHistoryItem(historyEntry, view, loc, getActivity(), getMyApplication()); view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE); view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), historyEntry.getLat(), historyEntry.getLon(), - historyEntry.getName()); + DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), historyEntry.getLat(), + historyEntry.getLon(), historyEntry.getName()); } }); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - getMyApplication().getSettings().setMapLocationToShow(historyEntry.getLat(), historyEntry.getLon(), 15, - historyEntry.getName(), true, - historyEntry); //$NON-NLS-1$ + getMyApplication().getSettings().setMapLocationToShow(historyEntry.getLat(), historyEntry.getLon(), + 15, historyEntry.getName(), true, historyEntry); //$NON-NLS-1$ MapActivity.launchMapActivityMoveToTop(getActivity()); } }); @@ -140,14 +131,14 @@ public class DashRecentsFragment extends DashLocationFragment { for (int i = 0; i < arrows.size(); i++) { arrows.get(i).setVisibility(View.VISIBLE); - updateArrow(getActivity(), loc, new LatLon(points.get(i).getLat(), points.get(i).getLon()), - arrows.get(i), 10, R.drawable.ic_destination_arrow, heading); + updateArrow(getActivity(), loc, new LatLon(points.get(i).getLat(), points.get(i).getLon()), arrows.get(i), + 10, R.drawable.ic_destination_arrow, heading); } } @Override public boolean updateCompassValue(float value) { - if (super.updateCompassValue(value)){ + if (super.updateCompassValue(value)) { updateArrows(); } return true; diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashSearchFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashSearchFragment.java index 447eb61102..869ba45d76 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashSearchFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashSearchFragment.java @@ -32,11 +32,6 @@ public class DashSearchFragment extends DashBaseFragment { return view; } - @Override - public void onResume() { - super.onResume(); - - } protected void searchActivity(final Activity activity, final OsmAndAppCustomization appCustomization, int tab) { final Intent search = new Intent(activity, appCustomization.getSearchActivity()); @@ -78,4 +73,9 @@ public class DashSearchFragment extends DashBaseFragment { } }); } + + @Override + public void onOpenDash() { + + } } diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashUpdatesFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashUpdatesFragment.java index f1905c8e99..e3189da8cb 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashUpdatesFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashUpdatesFragment.java @@ -5,26 +5,29 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; -import android.graphics.Typeface; -import android.widget.*; import net.osmand.plus.R; import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.download.BaseDownloadActivity; import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.IndexItem; +import net.osmand.plus.helpers.DatabaseHelper; +import net.osmand.plus.helpers.FontCache; import android.content.Intent; +import android.graphics.Typeface; import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.Nullable; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import net.osmand.plus.helpers.DatabaseHelper; -import net.osmand.plus.helpers.FontCache; +import android.widget.Button; +import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.ProgressBar; +import android.widget.TextView; /** - * Created by Denis - * on 21.11.2014. + * Created by Denis on 21.11.2014. */ public class DashUpdatesFragment extends DashBaseFragment { @@ -47,9 +50,10 @@ public class DashUpdatesFragment extends DashBaseFragment { showAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - final Intent intent = new Intent(view.getContext(), getMyApplication().getAppCustomization().getDownloadIndexActivity()); + final Intent intent = new Intent(view.getContext(), getMyApplication().getAppCustomization() + .getDownloadIndexActivity()); intent.putExtra(DownloadActivity.TAB_TO_OPEN, DownloadActivity.UPDATES_TAB); - //intent.putExtra(DownloadActivity.SINGLE_TAB, true); + // intent.putExtra(DownloadActivity.SINGLE_TAB, true); getActivity().startActivity(intent); } }); @@ -57,13 +61,7 @@ public class DashUpdatesFragment extends DashBaseFragment { } @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } - - @Override - public void onResume() { - super.onResume(); + public void onOpenDash() { downloadQueue.clear(); if (BaseDownloadActivity.downloadListIndexThread != null) { currentProgress = null; @@ -79,19 +77,20 @@ public class DashUpdatesFragment extends DashBaseFragment { @Override public int compare(IndexItem indexItem, IndexItem t1) { DatabaseHelper helper = BaseDownloadActivity.downloadListIndexThread.getDbHelper(); - return (int)(helper.getCount(t1.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY) - - helper.getCount(indexItem.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY)); + return (int) (helper.getCount(t1.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY) - helper.getCount( + indexItem.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY)); } }); View mainView = getView(); - //it may be null because download index thread is async + // it may be null because download index thread is async if (mainView == null) { return; } progressBars.clear(); baseNames.clear(); downloadButtons.clear(); - ((TextView) mainView.findViewById(R.id.header)).setText(getString(R.string.map_update ,String.valueOf(list.size()))); + ((TextView) mainView.findViewById(R.id.header)).setText(getString(R.string.map_update, + String.valueOf(list.size()))); LinearLayout updates = (LinearLayout) mainView.findViewById(R.id.updates_items); updates.removeAllViews(); @@ -110,8 +109,10 @@ public class DashUpdatesFragment extends DashBaseFragment { } LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.dash_updates_item, null, false); - String name = item.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions()); - String d = item.getDate(getMyApplication().getResourceManager().getDateFormat()) + ", " + item.getSizeDescription(getMyApplication()); + String name = item.getVisibleName(getMyApplication(), getMyApplication().getResourceManager() + .getOsmandRegions()); + String d = item.getDate(getMyApplication().getResourceManager().getDateFormat()) + ", " + + item.getSizeDescription(getMyApplication()); String eName = name.replace("\n", " "); ((TextView) view.findViewById(R.id.map_name)).setText(eName); ((TextView) view.findViewById(R.id.map_descr)).setText(d); @@ -122,9 +123,9 @@ public class DashUpdatesFragment extends DashBaseFragment { public void onClick(View view) { if (getDownloadActivity().isInQueue(item)) { getDownloadActivity().removeFromQueue(item); - ((ImageButton)view).setImageResource(R.drawable.download_button); + ((ImageButton) view).setImageResource(R.drawable.download_button); } else if (!getDownloadActivity().startDownload(item)) { - ((ImageButton)view).setImageResource(R.drawable.cancel_button); + ((ImageButton) view).setImageResource(R.drawable.cancel_button); } } }); @@ -144,7 +145,7 @@ public class DashUpdatesFragment extends DashBaseFragment { if (basicProgressAsyncTask == null) { return; } - //needed when rotation is performed and progress can be null + // needed when rotation is performed and progress can be null if (!updateOnlyProgress) { getProgressIfPossible(basicProgressAsyncTask.getDescription()); } @@ -163,9 +164,8 @@ public class DashUpdatesFragment extends DashBaseFragment { return; } cancelButton.setImageResource(R.drawable.cancel_button); - View view = (View)cancelButton.getParent(); - if (view != null && - view.findViewById(R.id.map_descr) != null){ + View view = (View) cancelButton.getParent(); + if (view != null && view.findViewById(R.id.map_descr) != null) { view.findViewById(R.id.map_descr).setVisibility(View.GONE); } cancelButton.setOnClickListener(new View.OnClickListener() { @@ -183,7 +183,7 @@ public class DashUpdatesFragment extends DashBaseFragment { } private void getProgressIfPossible(String message) { - if (getActivity() == null){ + if (getActivity() == null) { return; } for (int i = 0; i < baseNames.size(); i++) { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java index c3b9dbc165..507d9e1949 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashboardOnMap.java @@ -123,6 +123,12 @@ public class DashboardOnMap { mapActivity.findViewById(R.id.MapInfoControls).setVisibility(View.VISIBLE); mapActivity.findViewById(R.id.MapButtons).setVisibility(View.VISIBLE); fabButton.hideFloatingActionButton(); + for (WeakReference df : fragList) { + if (df.get() != null) { + df.get().onCloseDash(); + } + } + } } @@ -221,6 +227,15 @@ public class DashboardOnMap { private void addOrUpdateDashboardFragments() { + Iterator> it = fragList.iterator(); + while(it.hasNext()) { + WeakReference df = it.next(); + if(df.get() != null) { + df.get().onOpenDash(); + } else { + it.remove(); + } + } FragmentManager manager = mapActivity.getSupportFragmentManager(); FragmentTransaction fragmentTransaction = manager.beginTransaction(); showFragment(manager, fragmentTransaction, DashErrorFragment.TAG, DashErrorFragment.class, diff --git a/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java b/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java index d0d4e3a51b..a9df508575 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/DashTrackFragment.java @@ -8,25 +8,20 @@ import net.osmand.IndexConstants; import net.osmand.access.AccessibleToast; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; -import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.myplaces.AvailableGPXFragment; -import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.dashboard.DashBaseFragment; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.GpxUiHelper; +import net.osmand.plus.myplaces.AvailableGPXFragment; +import net.osmand.plus.myplaces.FavoritesActivity; import android.app.Activity; import android.content.Intent; -import android.graphics.Color; -import android.graphics.PorterDuff; import android.graphics.Typeface; -import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.Handler; import android.view.LayoutInflater; @@ -71,19 +66,20 @@ public class DashTrackFragment extends DashBaseFragment { }); return view; } - + @Override - public void onResume() { - super.onResume(); + public void onOpenDash() { updateEnable = true; setupGpxFiles(); } + @Override - public void onPause() { - super.onPause(); + public void onCloseDash() { updateEnable = false; } + + diff --git a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java index eed1878bdf..c92065fd5d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/DashOsmEditsFragment.java @@ -37,22 +37,19 @@ public class DashOsmEditsFragment extends DashBaseFragment { @Override - public void onResume() { - super.onResume(); + public void onOpenDash() { if (plugin == null) { plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class); } - - setupEditings(); + setupEditings(); } - + + private void setupEditings() { View mainView = getView(); if (plugin == null){ mainView.setVisibility(View.GONE); return; } - - } } diff --git a/OsmAnd/src/net/osmand/plus/osmo/DashOsmoFragment.java b/OsmAnd/src/net/osmand/plus/osmo/DashOsmoFragment.java index 9ccf1e7c42..165b6a55f8 100644 --- a/OsmAnd/src/net/osmand/plus/osmo/DashOsmoFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmo/DashOsmoFragment.java @@ -31,4 +31,9 @@ public class DashOsmoFragment extends DashBaseFragment { return view; } + + @Override + public void onOpenDash() { + plugin = OsmandPlugin.getEnabledPlugin(OsMoPlugin.class); + } } diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java b/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java index 9a706542bb..55f42810c7 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/DashParkingFragment.java @@ -20,8 +20,7 @@ import net.osmand.plus.helpers.FontCache; import net.osmand.util.MapUtils; /** - * Created by Denis on - * 26.01.2015. + * Created by Denis on 26.01.2015. */ public class DashParkingFragment extends DashLocationFragment { ParkingPositionPlugin plugin; @@ -49,24 +48,19 @@ public class DashParkingFragment extends DashLocationFragment { } @Override - public void onResume() { - super.onResume(); + public void onOpenDash() { plugin = OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class); - - - if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { loc = getMyApplication().getSettings().getLastKnownMapLocation(); } else { loc = new LatLon(0f, 0f); } - updateParkingPosition(); } private void updateParkingPosition() { View mainView = getView(); - if (plugin == null || plugin.getParkingPosition() == null){ + if (plugin == null || plugin.getParkingPosition() == null) { mainView.setVisibility(View.GONE); return; } else { @@ -75,16 +69,16 @@ public class DashParkingFragment extends DashLocationFragment { LatLon position = plugin.getParkingPosition(); - int dist = (int) (MapUtils.getDistance(position.getLatitude(), position.getLongitude(), - loc.getLatitude(), loc.getLongitude())); + int dist = (int) (MapUtils.getDistance(position.getLatitude(), position.getLongitude(), loc.getLatitude(), + loc.getLongitude())); String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()); ((TextView) mainView.findViewById(R.id.distance)).setText(distance); - //TODO add parking time - String parking_name = plugin.getParkingType() ? - getString(R.string.parking_place) : getString(R.string.parking_place); + // TODO add parking time + String parking_name = plugin.getParkingType() ? getString(R.string.parking_place) + : getString(R.string.parking_place); ((TextView) mainView.findViewById(R.id.name)).setText(parking_name); ImageView direction = (ImageView) mainView.findViewById(R.id.direction_icon); - if (loc != null){ + if (loc != null) { direction.setVisibility(View.VISIBLE); updateArrow(getActivity(), loc, position, direction, 10, R.drawable.ic_destination_arrow, heading); } @@ -92,10 +86,10 @@ public class DashParkingFragment extends DashLocationFragment { @Override public boolean updateCompassValue(float value) { - if (plugin == null){ + if (plugin == null) { return true; } - if (super.updateCompassValue(value)){ + if (super.updateCompassValue(value)) { updateParkingPosition(); } return true; @@ -104,8 +98,7 @@ public class DashParkingFragment extends DashLocationFragment { @Override public void updateLocation(Location location) { super.updateLocation(location); - - if (plugin == null){ + if (plugin == null) { return; } updateParkingPosition();