From 705863a23b96defde7c18d36e3dbdfe93483bba1 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 2 Mar 2015 10:36:57 +0200 Subject: [PATCH] Small changes --- OsmAnd/res/layout/dashboard.xml | 8 + OsmAnd/res/values/strings.xml | 2 +- .../plus/activities/AvailableGPXFragment.java | 14 +- .../plus/activities/FavoritesActivity.java | 3 - .../plus/dashboard/DashRecentsFragment.java | 186 ++++++++++++++++++ 5 files changed, 203 insertions(+), 10 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java diff --git a/OsmAnd/res/layout/dashboard.xml b/OsmAnd/res/layout/dashboard.xml index f7d2a148e9..f9a47129c9 100644 --- a/OsmAnd/res/layout/dashboard.xml +++ b/OsmAnd/res/layout/dashboard.xml @@ -46,6 +46,14 @@ android:layout_width="match_parent" android:layout_height="wrap_content"/> + + + + RECENTS Selected Turn_off_all Showed on map @@ -49,7 +50,6 @@ Tracks My location Manage - RECENTS Start navigation over track? You can trigger an alternative route by selecting roads to avoid Default diff --git a/OsmAnd/src/net/osmand/plus/activities/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/activities/AvailableGPXFragment.java index 9e1997de94..ae45358df0 100644 --- a/OsmAnd/src/net/osmand/plus/activities/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/AvailableGPXFragment.java @@ -136,7 +136,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { asyncLoader = new LoadGpxTask(); asyncLoader.execute(getActivity()); } else { - allGpxAdapter.addSelected(); + allGpxAdapter.refreshSelected(); allGpxAdapter.notifyDataSetChanged();; } @@ -444,6 +444,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { public boolean onActionItemClicked(ActionMode mode, MenuItem item) { runSelection(false); actionMode.finish(); + allGpxAdapter.refreshSelected(); allGpxAdapter.notifyDataSetChanged(); return true; } @@ -619,7 +620,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { for (GpxInfo v : result) { allGpxAdapter.addLocalIndexInfo(v); } - allGpxAdapter.addSelected(); + allGpxAdapter.refreshSelected(); allGpxAdapter.notifyDataSetChanged(); onPostExecute(result); } @@ -628,7 +629,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { @Override protected void onPostExecute(List result) { this.result = result; - allGpxAdapter.addSelected(); + allGpxAdapter.refreshSelected(); if (getActivity() != null) { ((ActionBarActivity) getActivity()).setSupportProgressBarIndeterminateVisibility(false); } @@ -658,7 +659,6 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { private void loadGPXFolder(File mapPath, List result, LoadGpxTask loadTask, List progress, String gpxSubfolder) { - GpxSelectionHelper sgpx = app.getSelectedGpxHelper(); for (File gpxFile : listFilesSorted(mapPath)) { if (gpxFile.isDirectory()) { String sub = gpxSubfolder.length() == 0 ? gpxFile.getName() : gpxSubfolder + "/" + gpxFile.getName(); @@ -703,7 +703,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { ta.recycle(); } - public void addSelected() { + public void refreshSelected() { selected.clear(); selected.addAll(getSelectedGpx()); } @@ -1144,6 +1144,8 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { protected void onPostExecute(String result) { selectedGpxHelper.runUiListeners(); getActivity().setProgressBarIndeterminateVisibility(false); + allGpxAdapter.refreshSelected(); + allGpxAdapter.notifyDataSetChanged(); if (showOnMap && toShow != null) { getMyApplication().getSettings().setMapLocationToShow(toShow.lat, toShow.lon, getMyApplication().getSettings().getLastKnownMapZoom()); @@ -1225,7 +1227,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { for (GpxInfo i : ((List) results.values)) { allGpxAdapter.addLocalIndexInfo(i); } - allGpxAdapter.addSelected(); + allGpxAdapter.refreshSelected(); } allGpxAdapter.notifyDataSetChanged(); if (constraint != null && constraint.length() > 3) { diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java index 6d570f592a..35c4e9d52f 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesActivity.java @@ -94,9 +94,6 @@ public class FavoritesActivity extends TabActivity { if (tab > mTabs.size() - 1){ tab = 0; } - if(tab > 0) { - tab ++; - } mViewPager.setCurrentItem(tab ); updateSelectedTracks(); // setupHomeButton(); diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java new file mode 100644 index 0000000000..5f0d7601f5 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashRecentsFragment.java @@ -0,0 +1,186 @@ +package net.osmand.plus.dashboard; + +import java.util.ArrayList; +import java.util.List; + +import net.osmand.Location; +import net.osmand.data.LatLon; +import net.osmand.plus.OsmAndAppCustomization; +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.search.SearchActivity; +import net.osmand.plus.base.FavoriteImageDrawable; +import net.osmand.plus.dialogs.DirectionsDialogs; +import net.osmand.plus.helpers.FontCache; +import net.osmand.plus.helpers.SearchHistoryHelper; +import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; +import net.osmand.util.Algorithms; +import net.osmand.util.MapUtils; +import android.app.Activity; +import android.content.Intent; +import android.graphics.Color; +import android.graphics.Typeface; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +/** + * Created by Denis + * on 24.11.2014. + */ +public class DashRecentsFragment extends DashLocationFragment { + public static final String TAG = "DASH_RECENTS_FRAGMENT"; + private net.osmand.Location location = null; + + private List arrows = new ArrayList(); + List points = new ArrayList(); + + @Override + public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + 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))); + ((Button) view.findViewById(R.id.show_all)).setTypeface(typeface); + + (view.findViewById(R.id.show_all)).setOnClickListener(new View.OnClickListener() { + @Override + 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.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.HISTORY_TAB_INDEX); + activity.startActivity(search); + } + }); + 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 + if (getMyApplication().getSettings().getLastKnownMapLocation() != null) { + loc = getMyApplication().getSettings().getLastKnownMapLocation(); + } else { + loc = new LatLon(0f, 0f); + } + setupFavorites(); + } + + @Override + public void onPause() { + super.onPause(); + } + + public void setupFavorites(){ + View mainView = getView(); + SearchHistoryHelper helper = SearchHistoryHelper.getInstance((OsmandApplication) getActivity().getApplicationContext()); + points = helper.getHistoryEntries(); + arrows.clear(); + if (points.size() == 0){ + (mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE); + return; + } else { + (mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE); + } + + LinearLayout favorites = (LinearLayout) mainView.findViewById(R.id.items); + favorites.removeAllViews(); + if (points.size() > 3){ + points = points.subList(0, 3); + } + for (final HistoryEntry point : points) { + LayoutInflater inflater = getActivity().getLayoutInflater(); + View view = inflater.inflate(R.layout.dash_favorites_item, null, false); + TextView name = (TextView) view.findViewById(R.id.name); + TextView label = (TextView) view.findViewById(R.id.distance); + ImageView direction = (ImageView) view.findViewById(R.id.direction); +// if (point.getCategory().length() > 0) { +// ((TextView) view.findViewById(R.id.group_name)).setText(point.getCategory()); +// } else { + view.findViewById(R.id.group_image).setVisibility(View.GONE); +// } + + + ((ImageView) view.findViewById(R.id.icon)). + setImageDrawable(FavoriteImageDrawable.getOrCreate(getActivity(), Color.BLUE)); + + if(loc != null){ + direction.setVisibility(View.VISIBLE); + updateArrow(getActivity(), loc, new LatLon(point.getLat(), point.getLon()), direction, + 10, R.drawable.ic_destination_arrow, heading); + } + arrows.add(direction); + name.setText(point.getName().getName()); + + //LatLon lastKnownMapLocation = getMyApplication().getSettings().getLastKnownMapLocation(); + int dist = (int) (MapUtils.getDistance(point.getLat(), point.getLon(), + loc.getLatitude(), loc.getLongitude())); + String distance = OsmAndFormatter.getFormattedDistance(dist, getMyApplication()) + " "; + view.findViewById(R.id.navigate_to).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DirectionsDialogs.directionsToDialogAndLaunchMap(getActivity(), point.getLat(), point.getLon(), + point.getName()); + } + }); + label.setText(distance, TextView.BufferType.SPANNABLE); + view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + getMyApplication().getSettings().setMapLocationToShow(point.getLat(), point.getLon(), 15, + point.getName(), true, + point); //$NON-NLS-1$ + MapActivity.launchMapActivityMoveToTop(getActivity()); + } + }); + favorites.addView(view); + } + updateLocation(location); + } + + private void updateArrows() { + if (loc == null) { + return; + } + + for (int i = 0; i < arrows.size(); i++) { + arrows.get(i).setVisibility(View.VISIBLE); + updateArrow(getActivity(), loc, new LatLon(points.get(i).getLat(), points.get(i).getLon()), + arrows.get(i), 10, R.drawable.ic_destination_arrow, heading); + } + } + + @Override + public boolean updateCompassValue(float value) { + if (super.updateCompassValue(value)){ + updateArrows(); + } + return true; + } + + @Override + public void updateLocation(Location location) { + super.updateLocation(location); + updateArrows(); + } + +}