Add update dashboard method

This commit is contained in:
Victor Shcherb 2015-03-08 15:20:53 +01:00
parent 9882da1594
commit 7fb1bee03a
16 changed files with 161 additions and 186 deletions

View file

@ -1,8 +1,6 @@
package net.osmand.plus; package net.osmand.plus;
import java.io.File; import java.io.File;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -11,22 +9,15 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; 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.PlatformUtil;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import android.app.AlertDialog;
import android.content.Context;
public class FavouritesDbHelper { public class FavouritesDbHelper {
@ -34,7 +25,6 @@ public class FavouritesDbHelper {
void updateFavourites(); void updateFavourites();
} }
private List<FavoritesUpdatedListener> favoritesUpdatedListeners = new ArrayList<FavoritesUpdatedListener>();
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(FavouritesDbHelper.class); private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(FavouritesDbHelper.class);
@ -93,20 +83,8 @@ public class FavouritesDbHelper {
} }
private void favouritesUpdated(){ 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<String, FavouritePoint> source, Map<String, FavouritePoint> destination) { private boolean merge(Map<String, FavouritePoint> source, Map<String, FavouritePoint> destination) {
boolean changed = false; boolean changed = false;

View file

@ -58,19 +58,13 @@ public class DashAudioVideoNotesFragment extends DashBaseFragment {
} }
@Override @Override
public void onOpenUpdate() { public void onOpenDash() {
if (plugin == null) { if (plugin == null) {
plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class); plugin = OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class);
} }
setupNotes(); setupNotes();
} }
@Override
public void onPause() {
super.onPause();
}
public void setupNotes() { public void setupNotes() {
View mainView = getView(); View mainView = getView();
if (plugin == null){ if (plugin == null){

View file

@ -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) { public void onLocationCompassChanged(Location l, double compassValue) {

View file

@ -64,7 +64,7 @@ public class DashDownloadMapsFragment extends DashBaseFragment {
} }
@Override @Override
public void onOpenUpdate() { public void onOpenDash() {
refreshData(); refreshData();
} }

View file

@ -84,6 +84,6 @@ public class DashErrorFragment extends DashBaseFragment {
} }
@Override @Override
public void onOpenUpdate() { public void onOpenDash() {
} }
} }

View file

@ -13,11 +13,11 @@ import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
@ -33,8 +33,7 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
/** /**
* Created by Denis * Created by Denis on 24.11.2014.
* on 24.11.2014.
*/ */
public class DashFavoritesFragment extends DashLocationFragment implements FavouritesDbHelper.FavoritesUpdatedListener { public class DashFavoritesFragment extends DashLocationFragment implements FavouritesDbHelper.FavoritesUpdatedListener {
public static final String TAG = "DASH_FAVORITES_FRAGMENT"; public static final String TAG = "DASH_FAVORITES_FRAGMENT";
@ -63,38 +62,29 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou
}); });
return view; return view;
} }
@Override @Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
} }
@Override @Override
public void onResume() { public void onOpenDash() {
super.onResume(); // This is used as origin for both Fav-list and direction arrows
//This is used as origin for both Fav-list and direction arrows
if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { if (getMyApplication().getSettings().getLastKnownMapLocation() != null) {
loc = getMyApplication().getSettings().getLastKnownMapLocation(); loc = getMyApplication().getSettings().getLastKnownMapLocation();
} else { } else {
loc = new LatLon(0f, 0f); loc = new LatLon(0f, 0f);
} }
getMyApplication().getFavorites().addFavoritesUpdatedListener(this);
setupFavorites(); setupFavorites();
} }
@Override public void setupFavorites() {
public void onPause() {
super.onPause();
getMyApplication().getFavorites().removeFavoritesUpdatedListener(this);
}
public void setupFavorites(){
View mainView = getView(); View mainView = getView();
final FavouritesDbHelper helper = getMyApplication().getFavorites(); final FavouritesDbHelper helper = getMyApplication().getFavorites();
points = new ArrayList<FavouritePoint>(helper.getFavouritePoints()); points = new ArrayList<FavouritePoint>(helper.getFavouritePoints());
arrows.clear(); arrows.clear();
if (points.size() == 0){ if (points.size() == 0) {
(mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE); (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
return; return;
} else { } else {
@ -104,18 +94,18 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou
Collections.sort(points, new Comparator<FavouritePoint>() { Collections.sort(points, new Comparator<FavouritePoint>() {
@Override @Override
public int compare(FavouritePoint point, FavouritePoint point2) { public int compare(FavouritePoint point, FavouritePoint point2) {
//LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); // LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), loc.getLatitude(),
loc.getLatitude(), loc.getLongitude())); loc.getLongitude()));
int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(), int dist2 = (int) (MapUtils.getDistance(point2.getLatitude(), point2.getLongitude(), loc.getLatitude(),
loc.getLatitude(), loc.getLongitude())); loc.getLongitude()));
return (dist - dist2); return (dist - dist2);
} }
}); });
LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items); LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items);
favorites.removeAllViews(); favorites.removeAllViews();
if (points.size() > 3){ if (points.size() > 3) {
while (points.size() != 3){ while (points.size() != 3) {
points.remove(3); points.remove(3);
} }
} }
@ -132,27 +122,27 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou
view.findViewById(R.id.group_image).setVisibility(View.GONE); 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)). if (loc != null) {
setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), point.getColor()));
if(loc != null){
direction.setVisibility(View.VISIBLE); direction.setVisibility(View.VISIBLE);
updateArrow(getActivity(), loc, new LatLon(point.getLatitude(), point.getLongitude()), direction, updateArrow(getActivity(), loc, new LatLon(point.getLatitude(), point.getLongitude()), direction, 10,
10, R.drawable.ic_destination_arrow, heading); R.drawable.ic_destination_arrow, heading);
} }
arrows.add(direction); arrows.add(direction);
name.setText(point.getName()); name.setText(point.getName());
//LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); // LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation();
int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), int dist = (int) (MapUtils.getDistance(point.getLatitude(), point.getLongitude(), loc.getLatitude(),
loc.getLatitude(), loc.getLongitude())); loc.getLongitude()));
String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " "; String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " ";
view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE); view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE);
view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() { view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { 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())); new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()));
} }
}); });
@ -161,8 +151,8 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou
view.setOnClickListener(new View.OnClickListener() { view.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(), 15, getMyApplication().getSettings().setMapLocationToShow(point.getLatitude(), point.getLongitude(),
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), true, 15, new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), true,
point); //$NON-NLS-1$ point); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} }
@ -186,7 +176,7 @@ public class DashFavoritesFragment extends DashLocationFragment implements Favou
@Override @Override
public boolean updateCompassValue(float value) { public boolean updateCompassValue(float value) {
if (super.updateCompassValue(value)){ if (super.updateCompassValue(value)) {
updateArrows(); updateArrows();
} }
return true; return true;

View file

@ -60,6 +60,13 @@ public class DashMapFragment extends DashBaseFragment implements IMapDownloaderC
protected void startMapActivity() { protected void startMapActivity() {
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} }
@Override
public void onOpenDash() {
if (!getMyApplication().isApplicationInitializing()) {
updateMapImage();
}
}
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 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 @Override
public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) { public void onViewCreated(final View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);

View file

@ -87,10 +87,9 @@ public class DashPluginsFragment extends DashBaseFragment {
return contentView; return contentView;
} }
@Override
public void onResume() {
super.onResume();
@Override
public void onOpenDash() {
View contentView = getView(); View contentView = getView();
if (contentView == null) { if (contentView == null) {
return; return;
@ -99,9 +98,9 @@ public class DashPluginsFragment extends DashBaseFragment {
for (int pluginIndex = 0; pluginIndex < plugins.size(); pluginIndex++) { for (int pluginIndex = 0; pluginIndex < plugins.size(); pluginIndex++) {
View pluginView = pluginsContainer.getChildAt(pluginIndex); View pluginView = pluginsContainer.getChildAt(pluginIndex);
updatePluginState(pluginView, plugins.get(pluginIndex)); updatePluginState(pluginView, plugins.get(pluginIndex));
} }
} }
private void updatePluginState(View pluginView, OsmandPlugin plugin) { private void updatePluginState(View pluginView, OsmandPlugin plugin) {
CompoundButton enableDisableButton = (CompoundButton) pluginView.findViewById(R.id.plugin_enable_disable); CompoundButton enableDisableButton = (CompoundButton) pluginView.findViewById(R.id.plugin_enable_disable);
Button getButton = (Button) pluginView.findViewById(R.id.get_plugin); Button getButton = (Button) pluginView.findViewById(R.id.get_plugin);

View file

@ -32,8 +32,7 @@ import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
/** /**
* Created by Denis * Created by Denis on 24.11.2014.
* on 24.11.2014.
*/ */
public class DashRecentsFragment extends DashLocationFragment { public class DashRecentsFragment extends DashLocationFragment {
public static final String TAG = "DASH_RECENTS_FRAGMENT"; 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); View view = getActivity().getLayoutInflater().inflate(R.layout.dash_common_fragment, container, false);
Typeface typeface = FontCache.getRobotoMedium(getActivity()); Typeface typeface = FontCache.getRobotoMedium(getActivity());
((TextView) view.findViewById(R.id.fav_text)).setTypeface(typeface); ((TextView) view.findViewById(R.id.fav_text)).setTypeface(typeface);
((TextView) view.findViewById(R.id.fav_text)).setText( ((TextView) view.findViewById(R.id.fav_text)).setText(Algorithms
Algorithms.capitalizeFirstLetterAndLowercase(getString(R.string.recents))); .capitalizeFirstLetterAndLowercase(getString(R.string.recents)));
((Button) view.findViewById(R.id.show_all)).setTypeface(typeface); ((Button) view.findViewById(R.id.show_all)).setTypeface(typeface);
(view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() { (view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() {
@ -56,9 +55,9 @@ public class DashRecentsFragment extends DashLocationFragment {
public void onClick(View view) { public void onClick(View view) {
Activity activity = getActivity(); Activity activity = getActivity();
OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization(); OsmAndAppCustomization appCustomization = getMyApplication().getAppCustomization();
final Intent search = new Intent(activity, appCustomization.getSearchActivity()); 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); search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.HISTORY_TAB_INDEX); getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.HISTORY_TAB_INDEX);
activity.startActivity(search); activity.startActivity(search);
@ -71,12 +70,10 @@ public class DashRecentsFragment extends DashLocationFragment {
} }
return view; return view;
} }
@Override @Override
public void onResume() { public void onOpenDash() {
super.onResume(); // This is used as origin for both Fav-list and direction arrows
//This is used as origin for both Fav-list and direction arrows
if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { if (getMyApplication().getSettings().getLastKnownMapLocation() != null) {
loc = getMyApplication().getSettings().getLastKnownMapLocation(); loc = getMyApplication().getSettings().getLastKnownMapLocation();
} else { } else {
@ -85,17 +82,13 @@ public class DashRecentsFragment extends DashLocationFragment {
setupRecents(); setupRecents();
} }
@Override public void setupRecents() {
public void onPause() {
super.onPause();
}
public void setupRecents(){
View mainView = getView(); View mainView = getView();
SearchHistoryHelper helper = SearchHistoryHelper.getInstance((OsmandApplication) getActivity().getApplicationContext()); SearchHistoryHelper helper = SearchHistoryHelper.getInstance((OsmandApplication) getActivity()
.getApplicationContext());
points = helper.getHistoryEntries(); points = helper.getHistoryEntries();
arrows.clear(); arrows.clear();
if (points.size() == 0){ if (points.size() == 0) {
(mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE); (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
return; return;
} else { } else {
@ -104,28 +97,26 @@ public class DashRecentsFragment extends DashLocationFragment {
LinearLayout recents = (LinearLayout) mainView.findViewById(R.id.items); LinearLayout recents = (LinearLayout) mainView.findViewById(R.id.items);
recents.removeAllViews(); recents.removeAllViews();
if (points.size() > 3){ if (points.size() > 3) {
points = points.subList(0, 3); points = points.subList(0, 3);
} }
for (final HistoryEntry historyEntry : points) { for (final HistoryEntry historyEntry : points) {
LayoutInflater inflater = getActivity().getLayoutInflater(); LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.search_history_list_item, null, false); View view = inflater.inflate(R.layout.search_history_list_item, null, false);
SearchHistoryFragment.udpateHistoryItem(historyEntry, view, SearchHistoryFragment.udpateHistoryItem(historyEntry, view, loc, getActivity(), getMyApplication());
loc, getActivity(), getMyApplication());
view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE); view.findViewById(R.id.navigate_to).setVisibility(View.VISIBLE);
view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() { view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), historyEntry.getLat(), historyEntry.getLon(), DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), historyEntry.getLat(),
historyEntry.getName()); historyEntry.getLon(), historyEntry.getName());
} }
}); });
view.setOnClickListener(new View.OnClickListener() { view.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
getMyApplication().getSettings().setMapLocationToShow(historyEntry.getLat(), historyEntry.getLon(), 15, getMyApplication().getSettings().setMapLocationToShow(historyEntry.getLat(), historyEntry.getLon(),
historyEntry.getName(), true, 15, historyEntry.getName(), true, historyEntry); //$NON-NLS-1$
historyEntry); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} }
}); });
@ -140,14 +131,14 @@ public class DashRecentsFragment extends DashLocationFragment {
for (int i = 0; i < arrows.size(); i++) { for (int i = 0; i < arrows.size(); i++) {
arrows.get(i).setVisibility(View.VISIBLE); arrows.get(i).setVisibility(View.VISIBLE);
updateArrow(getActivity(), loc, new LatLon(points.get(i).getLat(), points.get(i).getLon()), updateArrow(getActivity(), loc, new LatLon(points.get(i).getLat(), points.get(i).getLon()), arrows.get(i),
arrows.get(i), 10, R.drawable.ic_destination_arrow, heading); 10, R.drawable.ic_destination_arrow, heading);
} }
} }
@Override @Override
public boolean updateCompassValue(float value) { public boolean updateCompassValue(float value) {
if (super.updateCompassValue(value)){ if (super.updateCompassValue(value)) {
updateArrows(); updateArrows();
} }
return true; return true;

View file

@ -32,11 +32,6 @@ public class DashSearchFragment extends DashBaseFragment {
return view; return view;
} }
@Override
public void onResume() {
super.onResume();
}
protected void searchActivity(final Activity activity, final OsmAndAppCustomization appCustomization, int tab) { protected void searchActivity(final Activity activity, final OsmAndAppCustomization appCustomization, int tab) {
final Intent search = new Intent(activity, appCustomization.getSearchActivity()); final Intent search = new Intent(activity, appCustomization.getSearchActivity());
@ -78,4 +73,9 @@ public class DashSearchFragment extends DashBaseFragment {
} }
}); });
} }
@Override
public void onOpenDash() {
}
} }

View file

@ -5,26 +5,29 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import android.graphics.Typeface;
import android.widget.*;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.download.BaseDownloadActivity; import net.osmand.plus.download.BaseDownloadActivity;
import net.osmand.plus.download.DownloadActivity; import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.DatabaseHelper;
import net.osmand.plus.helpers.FontCache;
import android.content.Intent; import android.content.Intent;
import android.graphics.Typeface;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import net.osmand.plus.helpers.DatabaseHelper; import android.widget.Button;
import net.osmand.plus.helpers.FontCache; import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
/** /**
* Created by Denis * Created by Denis on 21.11.2014.
* on 21.11.2014.
*/ */
public class DashUpdatesFragment extends DashBaseFragment { public class DashUpdatesFragment extends DashBaseFragment {
@ -47,9 +50,10 @@ public class DashUpdatesFragment extends DashBaseFragment {
showAll.setOnClickListener(new View.OnClickListener() { showAll.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { 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.TAB_TO_OPEN, DownloadActivity.UPDATES_TAB);
//intent.putExtra(DownloadActivity.SINGLE_TAB, true); // intent.putExtra(DownloadActivity.SINGLE_TAB, true);
getActivity().startActivity(intent); getActivity().startActivity(intent);
} }
}); });
@ -57,13 +61,7 @@ public class DashUpdatesFragment extends DashBaseFragment {
} }
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onOpenDash() {
super.onCreate(savedInstanceState);
}
@Override
public void onResume() {
super.onResume();
downloadQueue.clear(); downloadQueue.clear();
if (BaseDownloadActivity.downloadListIndexThread != null) { if (BaseDownloadActivity.downloadListIndexThread != null) {
currentProgress = null; currentProgress = null;
@ -79,19 +77,20 @@ public class DashUpdatesFragment extends DashBaseFragment {
@Override @Override
public int compare(IndexItem indexItem, IndexItem t1) { public int compare(IndexItem indexItem, IndexItem t1) {
DatabaseHelper helper = BaseDownloadActivity.downloadListIndexThread.getDbHelper(); DatabaseHelper helper = BaseDownloadActivity.downloadListIndexThread.getDbHelper();
return (int)(helper.getCount(t1.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY) - return (int) (helper.getCount(t1.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY) - helper.getCount(
helper.getCount(indexItem.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY)); indexItem.getBasename(), DatabaseHelper.DOWNLOAD_ENTRY));
} }
}); });
View mainView = getView(); 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) { if (mainView == null) {
return; return;
} }
progressBars.clear(); progressBars.clear();
baseNames.clear(); baseNames.clear();
downloadButtons.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); LinearLayout updates = (LinearLayout) mainView.findViewById(R.id.updates_items);
updates.removeAllViews(); updates.removeAllViews();
@ -110,8 +109,10 @@ public class DashUpdatesFragment extends DashBaseFragment {
} }
LayoutInflater inflater = getActivity().getLayoutInflater(); LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dash_updates_item, null, false); View view = inflater.inflate(R.layout.dash_updates_item, null, false);
String name = item.getVisibleName(getMyApplication(), getMyApplication().getResourceManager().getOsmandRegions()); String name = item.getVisibleName(getMyApplication(), getMyApplication().getResourceManager()
String d = item.getDate(getMyApplication().getResourceManager().getDateFormat()) + ", " + item.getSizeDescription(getMyApplication()); .getOsmandRegions());
String d = item.getDate(getMyApplication().getResourceManager().getDateFormat()) + ", "
+ item.getSizeDescription(getMyApplication());
String eName = name.replace("\n", " "); String eName = name.replace("\n", " ");
((TextView) view.findViewById(R.id.map_name)).setText(eName); ((TextView) view.findViewById(R.id.map_name)).setText(eName);
((TextView) view.findViewById(R.id.map_descr)).setText(d); ((TextView) view.findViewById(R.id.map_descr)).setText(d);
@ -122,9 +123,9 @@ public class DashUpdatesFragment extends DashBaseFragment {
public void onClick(View view) { public void onClick(View view) {
if (getDownloadActivity().isInQueue(item)) { if (getDownloadActivity().isInQueue(item)) {
getDownloadActivity().removeFromQueue(item); getDownloadActivity().removeFromQueue(item);
((ImageButton)view).setImageResource(R.drawable.download_button); ((ImageButton) view).setImageResource(R.drawable.download_button);
} else if (!getDownloadActivity().startDownload(item)) { } 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) { if (basicProgressAsyncTask == null) {
return; return;
} }
//needed when rotation is performed and progress can be null // needed when rotation is performed and progress can be null
if (!updateOnlyProgress) { if (!updateOnlyProgress) {
getProgressIfPossible(basicProgressAsyncTask.getDescription()); getProgressIfPossible(basicProgressAsyncTask.getDescription());
} }
@ -163,9 +164,8 @@ public class DashUpdatesFragment extends DashBaseFragment {
return; return;
} }
cancelButton.setImageResource(R.drawable.cancel_button); cancelButton.setImageResource(R.drawable.cancel_button);
View view = (View)cancelButton.getParent(); View view = (View) cancelButton.getParent();
if (view != null && if (view != null && view.findViewById(R.id.map_descr) != null) {
view.findViewById(R.id.map_descr) != null){
view.findViewById(R.id.map_descr).setVisibility(View.GONE); view.findViewById(R.id.map_descr).setVisibility(View.GONE);
} }
cancelButton.setOnClickListener(new View.OnClickListener() { cancelButton.setOnClickListener(new View.OnClickListener() {
@ -183,7 +183,7 @@ public class DashUpdatesFragment extends DashBaseFragment {
} }
private void getProgressIfPossible(String message) { private void getProgressIfPossible(String message) {
if (getActivity() == null){ if (getActivity() == null) {
return; return;
} }
for (int i = 0; i < baseNames.size(); i++) { for (int i = 0; i < baseNames.size(); i++) {

View file

@ -123,6 +123,12 @@ public class DashboardOnMap {
mapActivity.findViewById(R.id.MapInfoControls).setVisibility(View.VISIBLE); mapActivity.findViewById(R.id.MapInfoControls).setVisibility(View.VISIBLE);
mapActivity.findViewById(R.id.MapButtons).setVisibility(View.VISIBLE); mapActivity.findViewById(R.id.MapButtons).setVisibility(View.VISIBLE);
fabButton.hideFloatingActionButton(); fabButton.hideFloatingActionButton();
for (WeakReference<DashBaseFragment> df : fragList) {
if (df.get() != null) {
df.get().onCloseDash();
}
}
} }
} }
@ -221,6 +227,15 @@ public class DashboardOnMap {
private void addOrUpdateDashboardFragments() { private void addOrUpdateDashboardFragments() {
Iterator<WeakReference<DashBaseFragment>> it = fragList.iterator();
while(it.hasNext()) {
WeakReference<DashBaseFragment> df = it.next();
if(df.get() != null) {
df.get().onOpenDash();
} else {
it.remove();
}
}
FragmentManager manager = mapActivity.getSupportFragmentManager(); FragmentManager manager = mapActivity.getSupportFragmentManager();
FragmentTransaction fragmentTransaction = manager.beginTransaction(); FragmentTransaction fragmentTransaction = manager.beginTransaction();
showFragment(manager, fragmentTransaction, DashErrorFragment.TAG, DashErrorFragment.class, showFragment(manager, fragmentTransaction, DashErrorFragment.TAG, DashErrorFragment.class,

View file

@ -8,25 +8,20 @@ import net.osmand.IndexConstants;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; 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.MapActivity;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.dashboard.DashBaseFragment; import net.osmand.plus.dashboard.DashBaseFragment;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.myplaces.AvailableGPXFragment;
import net.osmand.plus.myplaces.FavoritesActivity;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -71,19 +66,20 @@ public class DashTrackFragment extends DashBaseFragment {
}); });
return view; return view;
} }
@Override @Override
public void onResume() { public void onOpenDash() {
super.onResume();
updateEnable = true; updateEnable = true;
setupGpxFiles(); setupGpxFiles();
} }
@Override @Override
public void onPause() { public void onCloseDash() {
super.onPause();
updateEnable = false; updateEnable = false;
} }

View file

@ -37,22 +37,19 @@ public class DashOsmEditsFragment extends DashBaseFragment {
@Override @Override
public void onResume() { public void onOpenDash() {
super.onResume();
if (plugin == null) { if (plugin == null) {
plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class); plugin = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class);
} }
setupEditings();
setupEditings();
} }
private void setupEditings() { private void setupEditings() {
View mainView = getView(); View mainView = getView();
if (plugin == null){ if (plugin == null){
mainView.setVisibility(View.GONE); mainView.setVisibility(View.GONE);
return; return;
} }
} }
} }

View file

@ -31,4 +31,9 @@ public class DashOsmoFragment extends DashBaseFragment {
return view; return view;
} }
@Override
public void onOpenDash() {
plugin = OsmandPlugin.getEnabledPlugin(OsMoPlugin.class);
}
} }

View file

@ -20,8 +20,7 @@ import net.osmand.plus.helpers.FontCache;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
/** /**
* Created by Denis on * Created by Denis on 26.01.2015.
* 26.01.2015.
*/ */
public class DashParkingFragment extends DashLocationFragment { public class DashParkingFragment extends DashLocationFragment {
ParkingPositionPlugin plugin; ParkingPositionPlugin plugin;
@ -49,24 +48,19 @@ public class DashParkingFragment extends DashLocationFragment {
} }
@Override @Override
public void onResume() { public void onOpenDash() {
super.onResume();
plugin = OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class); plugin = OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class);
if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { if (getMyApplication().getSettings().getLastKnownMapLocation() != null) {
loc = getMyApplication().getSettings().getLastKnownMapLocation(); loc = getMyApplication().getSettings().getLastKnownMapLocation();
} else { } else {
loc = new LatLon(0f, 0f); loc = new LatLon(0f, 0f);
} }
updateParkingPosition(); updateParkingPosition();
} }
private void updateParkingPosition() { private void updateParkingPosition() {
View mainView = getView(); View mainView = getView();
if (plugin == null || plugin.getParkingPosition() == null){ if (plugin == null || plugin.getParkingPosition() == null) {
mainView.setVisibility(View.GONE); mainView.setVisibility(View.GONE);
return; return;
} else { } else {
@ -75,16 +69,16 @@ public class DashParkingFragment extends DashLocationFragment {
LatLon position = plugin.getParkingPosition(); LatLon position = plugin.getParkingPosition();
int dist = (int) (MapUtils.getDistance(position.getLatitude(), position.getLongitude(), int dist = (int) (MapUtils.getDistance(position.getLatitude(), position.getLongitude(), loc.getLatitude(),
loc.getLatitude(), loc.getLongitude())); loc.getLongitude()));
String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()); String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication());
((TextView) mainView.findViewById(R.id.distance)).setText(distance); ((TextView) mainView.findViewById(R.id.distance)).setText(distance);
//TODO add parking time // TODO add parking time
String parking_name = plugin.getParkingType() ? String parking_name = plugin.getParkingType() ? getString(R.string.parking_place)
getString(R.string.parking_place) : getString(R.string.parking_place); : getString(R.string.parking_place);
((TextView) mainView.findViewById(R.id.name)).setText(parking_name); ((TextView) mainView.findViewById(R.id.name)).setText(parking_name);
ImageView direction = (ImageView) mainView.findViewById(R.id.direction_icon); ImageView direction = (ImageView) mainView.findViewById(R.id.direction_icon);
if (loc != null){ if (loc != null) {
direction.setVisibility(View.VISIBLE); direction.setVisibility(View.VISIBLE);
updateArrow(getActivity(), loc, position, direction, 10, R.drawable.ic_destination_arrow, heading); updateArrow(getActivity(), loc, position, direction, 10, R.drawable.ic_destination_arrow, heading);
} }
@ -92,10 +86,10 @@ public class DashParkingFragment extends DashLocationFragment {
@Override @Override
public boolean updateCompassValue(float value) { public boolean updateCompassValue(float value) {
if (plugin == null){ if (plugin == null) {
return true; return true;
} }
if (super.updateCompassValue(value)){ if (super.updateCompassValue(value)) {
updateParkingPosition(); updateParkingPosition();
} }
return true; return true;
@ -104,8 +98,7 @@ public class DashParkingFragment extends DashLocationFragment {
@Override @Override
public void updateLocation(Location location) { public void updateLocation(Location location) {
super.updateLocation(location); super.updateLocation(location);
if (plugin == null) {
if (plugin == null){
return; return;
} }
updateParkingPosition(); updateParkingPosition();