Small changes

This commit is contained in:
Victor Shcherb 2015-03-02 10:36:57 +02:00
parent 2d1a8b34c5
commit 705863a23b
5 changed files with 203 additions and 10 deletions

View file

@ -46,6 +46,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<fragment
android:id="@+id/RecentsFragment"
android:name="net.osmand.plus.dashboard.DashRecentsFragment"
android:layout_marginTop="@dimen/dashCardMargin"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<fragment
android:id="@+id/FavoritesFragment"
android:name="net.osmand.plus.dashboard.DashFavoritesFragment"

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="recents">RECENTS</string>
<string name="selected_tracks">Selected</string>
<string name="turn_off_all">Turn_off_all</string>
<string name="showed_on_map">Showed on map</string>
@ -49,7 +50,6 @@
<string name="tracks">Tracks</string>
<string name="my_location">My location</string>
<string name="osm_editing_manage">Manage</string>
<string name="recents">RECENTS</string>
<string name="navigation_over_track">Start navigation over track?</string>
<string name="avoid_roads_msg">You can trigger an alternative route by selecting roads to avoid</string>
<string name="rendering_value__name">Default</string>

View file

@ -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<GpxInfo> 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<GpxInfo> result, LoadGpxTask loadTask,
List<GpxInfo> 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<GpxInfo>) results.values)) {
allGpxAdapter.addLocalIndexInfo(i);
}
allGpxAdapter.addSelected();
allGpxAdapter.refreshSelected();
}
allGpxAdapter.notifyDataSetChanged();
if (constraint != null && constraint.length() > 3) {

View file

@ -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();

View file

@ -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<ImageView> arrows = new ArrayList<ImageView>();
List<HistoryEntry> points = new ArrayList<HistoryEntry>();
@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();
}
}