diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 0cbb9ec1b5..a2451ab9cf 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -27,6 +27,7 @@ + diff --git a/OsmAnd/res/layout/favourites_list_item.xml b/OsmAnd/res/layout/favourites_list_item.xml index 411e4dff76..c88d27b087 100644 --- a/OsmAnd/res/layout/favourites_list_item.xml +++ b/OsmAnd/res/layout/favourites_list_item.xml @@ -13,7 +13,7 @@ + android:textSize="23sp" android:maxWidth="150dp" android:minWidth="90dp"/> diff --git a/OsmAnd/res/menu/map_menu.xml b/OsmAnd/res/menu/map_menu.xml index 0ae5106ffa..2fa2b87f62 100644 --- a/OsmAnd/res/menu/map_menu.xml +++ b/OsmAnd/res/menu/map_menu.xml @@ -13,7 +13,7 @@ - + diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index da4b01c065..21674bbedb 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -46,7 +46,7 @@ Нет объектов, чтобы %1$s Вы собириаетесь %1$s %2$s объектов. Вы уверены? Менеджер офлайн данных: - Офлайн данные доступные на SD карточке. Вы можете загрузить новые, архивировать и удалить данные. + Офлайн данные доступные на SD карточке. Вы можете загрузить новые, архивировать и удалить данные. Доступно %1$s. Восстановить Архив Удалить diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 8cc2390d0a..ba7b9b85ff 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -1,5 +1,6 @@ + Download new, or move to backup or delete existing data. \nCurrent offline data on device (%1$s is available): Search location... Location [Found] Address... @@ -10,7 +11,7 @@ Last map view Search around : - Search around + Search Recent changes for 0.6.7 : \n\t- Offline data manager (download, delete, backup offline data directly in Osmand) \n\t- Favorite points and groups (categorize, delete, manage favorites) @@ -57,7 +58,7 @@ No items to %1$s You are about to %1$s %2$s item(s). Continue? Offline Data Manager: - Download new, or move to backup or delete existing data.\nCurrent offline data on device: + Restore... Backup... Delete... diff --git a/OsmAnd/src/net/osmand/FavouritePoint.java b/OsmAnd/src/net/osmand/FavouritePoint.java index 258d7f35bf..be2fd262e9 100644 --- a/OsmAnd/src/net/osmand/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/FavouritePoint.java @@ -1,6 +1,9 @@ package net.osmand; -public class FavouritePoint { +import java.io.Serializable; + +public class FavouritePoint implements Serializable { + private static final long serialVersionUID = 729654300829771466L; private String name; private String category = ""; private double latitude; diff --git a/OsmAnd/src/net/osmand/plus/activities/FavouritesListActivity.java b/OsmAnd/src/net/osmand/plus/activities/FavouritesListActivity.java new file mode 100644 index 0000000000..b28e8cda9f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/activities/FavouritesListActivity.java @@ -0,0 +1,203 @@ +/** + * + */ +package net.osmand.plus.activities; + +import java.util.Comparator; +import java.util.List; + +import net.osmand.FavouritePoint; +import net.osmand.OsmAndFormatter; +import net.osmand.osm.LatLon; +import net.osmand.osm.MapUtils; +import net.osmand.plus.OsmandSettings; +import net.osmand.plus.R; +import net.osmand.plus.activities.search.SearchActivity; +import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild; +import android.app.AlertDialog; +import android.app.ListActivity; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.DialogInterface.OnClickListener; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.CheckBox; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; + +/** + * + */ +public class FavouritesListActivity extends ListActivity implements SearchActivityChild { + + public static final String SELECT_FAVORITE_POINT_INTENT_KEY = "SELECT_FAVORITE_POINT_INTENT_KEY"; + public static final int SELECT_FAVORITE_POINT_RESULT_OK = 1; + + private FavouritesAdapter favouritesAdapter; + private LatLon location; + + private boolean selectFavoriteMode; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + ListView lv = new ListView(this); + lv.setId(android.R.id.list); + setContentView(lv); + + favouritesAdapter = new FavouritesAdapter(((OsmandApplication) getApplication()).getFavorites().getFavouritePoints()); + setListAdapter(favouritesAdapter); + } + + + @Override + protected void onResume() { + super.onResume(); + Intent intent = getIntent(); + if (intent != null) { + selectFavoriteMode = intent.hasExtra(SELECT_FAVORITE_POINT_INTENT_KEY); + if (intent.hasExtra(SearchActivity.SEARCH_LAT) && intent.hasExtra(SearchActivity.SEARCH_LON)) { + double lat = intent.getDoubleExtra(SearchActivity.SEARCH_LAT, 0); + double lon = intent.getDoubleExtra(SearchActivity.SEARCH_LON, 0); + if (lat != 0 || lon != 0) { + location = new LatLon(lat, lon); + } + } + } + if (!isSelectFavoriteMode()) { + if (location == null && getParent() instanceof SearchActivity) { + location = ((SearchActivity) getParent()).getSearchPoint(); + } + if (location == null) { + location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); + } + } + locationUpdate(location); + + if (!isSelectFavoriteMode()) { + getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { + return FavouritesListActivity.this.onItemLongClick(position); + } + }); + } + } + + @Override + public void locationUpdate(LatLon l) { + location = l; + favouritesAdapter.sort(new Comparator() { + @Override + public int compare(FavouritePoint object1, FavouritePoint object2) { + if (location != null) { + double d1 = MapUtils.getDistance(location, object1.getLatitude(), object1.getLongitude()); + double d2 = MapUtils.getDistance(location, object2.getLatitude(), object2.getLongitude()); + if (d1 == d2) { + return 0; + } else if (d1 > d2) { + return 1; + } + return -1; + } else { + return favouritesAdapter.getName(object1).compareTo(favouritesAdapter.getName(object2)); + } + } + }); + } + + public boolean isSelectFavoriteMode(){ + return selectFavoriteMode; + } + + + private boolean onItemLongClick(int pos) { + final FavouritePoint entry = favouritesAdapter.getItem(pos); + AlertDialog.Builder builder = new AlertDialog.Builder(FavouritesListActivity.this); + builder.setTitle(entry.getName()); + OnClickListener onClickListener = new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (which == 0) { + OsmandSettings.getOsmandSettings(FavouritesListActivity.this).setMapLocationToShow(entry.getLatitude(), + entry.getLongitude()); + } else if (which == 1) { + OsmandSettings.getOsmandSettings(FavouritesListActivity.this).setPointToNavigate(entry.getLatitude(), + entry.getLongitude(), getString(R.string.favorite) + " : " + entry.getName()); + } + MapActivity.launchMapActivityMoveToTop(FavouritesListActivity.this); + } + }; + builder.setItems(new String[] { getString(R.string.show_poi_on_map), getString(R.string.navigate_to) }, onClickListener); + builder.show(); + return true; + } + + @Override + protected void onListItemClick(ListView l, View v, int position, long id) { + if(!isSelectFavoriteMode()) { + FavouritePoint point = favouritesAdapter.getItem(position); + OsmandSettings.getOsmandSettings(this).SHOW_FAVORITES.set( true); + OsmandSettings.getOsmandSettings(this).setMapLocationToShow(point.getLatitude(), point.getLongitude(), getString(R.string.favorite)+" : " + point.getName()); //$NON-NLS-1$ + MapActivity.launchMapActivityMoveToTop(FavouritesListActivity.this); + } else { + Intent intent = getIntent(); + intent.putExtra(SELECT_FAVORITE_POINT_INTENT_KEY, favouritesAdapter.getItem(position)); + setResult(SELECT_FAVORITE_POINT_RESULT_OK, intent); + finish(); + } + } + + class FavouritesAdapter extends ArrayAdapter { + + + public FavouritesAdapter(List list) { + super(FavouritesListActivity.this, R.layout.favourites_list_item, list); + } + + public String getName(FavouritePoint model){ + return model.getCategory() + " : " + model.getName(); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + View row = convertView; + if (row == null) { + LayoutInflater inflater = getLayoutInflater(); + row = inflater.inflate(R.layout.favourites_list_item, parent, false); + } + + TextView label = (TextView) row.findViewById(R.id.favourite_label); + TextView distanceLabel = (TextView) row.findViewById(R.id.favouritedistance_label); + ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon); + final FavouritePoint model = getItem(position); + if (model.isStored()) { + icon.setImageResource(R.drawable.favorites); + } else { + icon.setImageResource(R.drawable.opened_poi); + } + if (location != null) { + int dist = (int) (MapUtils.getDistance(model.getLatitude(), model.getLongitude(), location.getLatitude(), location + .getLongitude())); + distanceLabel.setText(OsmAndFormatter.getFormattedDistance(dist, FavouritesListActivity.this)); + distanceLabel.setVisibility(View.VISIBLE); + } else { + distanceLabel.setVisibility(View.GONE); + } + + label.setText(getName(model)); + final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item); + row.findViewById(R.id.favourite_icon).setVisibility(View.VISIBLE); + ch.setVisibility(View.GONE); + return row; + } + + } + + +} diff --git a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java index b53d1b5f27..43fa2c4420 100644 --- a/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/LocalIndexesActivity.java @@ -30,6 +30,7 @@ import android.graphics.Color; import android.graphics.Typeface; import android.os.AsyncTask; import android.os.Bundle; +import android.os.StatFs; import android.os.AsyncTask.Status; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -62,7 +63,10 @@ public class LocalIndexesActivity extends ExpandableListActivity { protected static int DELETE_OPERATION = 1; protected static int BACKUP_OPERATION = 2; protected static int RESTORE_OPERATION = 3; - + + MessageFormat formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US); + MessageFormat formatGb = new MessageFormat("{0, number,#.##} GB", Locale.US); + @SuppressWarnings("unchecked") @Override protected void onCreate(Bundle savedInstanceState) { @@ -110,6 +114,7 @@ public class LocalIndexesActivity extends ExpandableListActivity { }); setListAdapter(listAdapter); + updateDescriptionTextWithSize(); } public class LoadLocalIndexTask extends AsyncTask> { @@ -515,6 +520,17 @@ public class LocalIndexesActivity extends ExpandableListActivity { listAdapter.notifyDataSetChanged(); } + private void updateDescriptionTextWithSize(){ + File dir = OsmandSettings.getOsmandSettings(this).extendOsmandPath(""); + String size = formatGb.format(new Object[]{0}); + if(dir.canRead()){ + StatFs fs = new StatFs(dir.getAbsolutePath()); + size = formatGb.format(new Object[]{(float) (fs.getAvailableBlocks()) * fs.getBlockSize() / (1 << 30) }); + } + ((TextView) findViewById(R.id.DescriptionText)).setText( + getString(R.string.local_index_description, size)); + } + private void closeSelectionMode(){ selectionMode = false; findViewById(R.id.DownloadButton).setVisibility(View.VISIBLE); @@ -524,7 +540,10 @@ public class LocalIndexesActivity extends ExpandableListActivity { findViewById(R.id.CancelButton).setVisibility(View.GONE); findViewById(R.id.ActionButton).setVisibility(View.GONE); ((TextView) findViewById(R.id.DescriptionTextTop)).setVisibility(View.GONE); - ((TextView) findViewById(R.id.DescriptionText)).setText(R.string.local_index_description); + + + ; + updateDescriptionTextWithSize(); listAdapter.cancelFilter(); collapseAllGroups(); listAdapter.notifyDataSetChanged(); @@ -596,10 +615,8 @@ public class LocalIndexesActivity extends ExpandableListActivity { List category = new ArrayList(); List filterCategory = null; - private MessageFormat formatMb; public LocalIndexesAdapter() { - formatMb = new MessageFormat("{0, number,##.#} MB", Locale.US); } public void clear() { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index a8e7227067..39896aa78e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -21,7 +21,6 @@ import net.osmand.plus.R; import net.osmand.plus.ResourceManager; import net.osmand.plus.activities.RouteProvider.GPXRouteParams; import net.osmand.plus.activities.search.SearchActivity; -import net.osmand.plus.activities.search.SearchPoiFilterActivity; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.OsmandMapTileView; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java index 101e6ac451..9e4137f5fa 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java @@ -1,13 +1,16 @@ package net.osmand.plus.activities.search; +import java.io.Serializable; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Locale; +import net.osmand.FavouritePoint; import net.osmand.osm.LatLon; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.activities.FavouritesListActivity; import net.osmand.plus.activities.NavigatePointActivity; import android.app.Activity; import android.app.TabActivity; @@ -36,13 +39,15 @@ public class SearchActivity extends TabActivity { protected static final int POSITION_CURRENT_LOCATION = 1; protected static final int POSITION_LAST_MAP_VIEW = 2; - protected static final int POSITION_ADDRESS = 3; - protected static final int POSITION_FAVORITES = 4; + protected static final int POSITION_FAVORITES = 3; + protected static final int POSITION_ADDRESS = 4; private static final int GPS_TIMEOUT_REQUEST = 1000; private static final int GPS_DIST_REQUEST = 5; private static final int GPS_ACCURACY = 50; + private static final int REQUEST_FAVORITE_SELECT = 1; + public static final String SEARCH_LAT = "net.osmand.search_lat"; //$NON-NLS-1$ public static final String SEARCH_LON = "net.osmand.search_lon"; //$NON-NLS-1$ @@ -76,7 +81,8 @@ public class SearchActivity extends TabActivity { getString(R.string.search_position_current_location), getString(R.string.search_position_map_view), getString(R.string.search_position_favorites), - getString(R.string.search_position_address) + // Address is not yet implemented + // getString(R.string.search_position_address) })) ); @@ -90,9 +96,8 @@ public class SearchActivity extends TabActivity { host.addTab(addressSpec); host.addTab(host.newTabSpec("Search_Location").setIndicator(getString(R.string.search_tabs_location)).setContent(createIntent(NavigatePointActivity.class))); //$NON-NLS-1$ TabSpec transportTab = host.newTabSpec("Search_Transport").setIndicator(getString(R.string.transport)).setContent(createIntent(SearchTransportActivity.class)); - //if (searchPoint != null) { - host.addTab(transportTab); //$NON-NLS-1$ - //} + host.addTab(transportTab); //$NON-NLS-1$ + host.addTab(host.newTabSpec("Search_Favorites").setIndicator(getString(R.string.favorite)).setContent(createIntent(FavouritesListActivity.class))); //$NON-NLS-1$ host.addTab(host.newTabSpec("Search_History").setIndicator(getString(R.string.history)).setContent(createIntent(SearchHistoryActivity.class))); //$NON-NLS-1$ host.setCurrentTab(POI_TAB_INDEX); @@ -112,6 +117,11 @@ public class SearchActivity extends TabActivity { if (position == POSITION_LAST_MAP_VIEW) { OsmandSettings settings = OsmandSettings.getOsmandSettings(SearchActivity.this); updateSearchPoint(settings.getLastKnownMapLocation(), getString(R.string.search_position_fixed), true); + } else if (position == POSITION_FAVORITES) { + Intent intent = new Intent(SearchActivity.this, FavouritesListActivity.class); + intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + intent.putExtra(FavouritesListActivity.SELECT_FAVORITE_POINT_INTENT_KEY, (Serializable) null); + startActivityForResult(intent, REQUEST_FAVORITE_SELECT); } } } @@ -123,6 +133,18 @@ public class SearchActivity extends TabActivity { }); } + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if(requestCode == REQUEST_FAVORITE_SELECT && resultCode == FavouritesListActivity.SELECT_FAVORITE_POINT_RESULT_OK){ + FavouritePoint p = (FavouritePoint) data.getSerializableExtra(FavouritesListActivity.SELECT_FAVORITE_POINT_INTENT_KEY); + if (p != null) { + LatLon latLon = new LatLon(p.getLatitude(), p.getLongitude()); + updateSearchPoint(latLon, p.getName(), false); + } + } + } + public void startSearchCurrentLocation(){ @@ -177,10 +199,13 @@ public class SearchActivity extends TabActivity { double lat = intent.getDoubleExtra(SEARCH_LAT, 0); double lon = intent.getDoubleExtra(SEARCH_LON, 0); if (lat != 0 || lon != 0) { - LatLon searchPoint = new LatLon(lat, lon); - updateSearchPoint(searchPoint, getString(R.string.search_position_fixed), true); + updateSearchPoint(new LatLon(lat, lon), getString(R.string.search_position_fixed), true); } } + if(searchPoint == null){ + LatLon last = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); + updateSearchPoint(last, getString(R.string.search_position_fixed), true); + } } @Override @@ -189,12 +214,16 @@ public class SearchActivity extends TabActivity { endSearchCurrentLocation(); } + private String formatLatLon(LatLon searchPoint){ + MessageFormat format = new MessageFormat(" ({0,number,#.##};{1,number,#.##})", Locale.US); + return format.format(new Object[]{searchPoint.getLatitude(), searchPoint.getLongitude()}); + } + public void updateSearchPoint(LatLon searchPoint, String message, boolean showLoc){ spinnerAdapter.remove(spinnerAdapter.getItem(0)); String suffix = ""; if(showLoc && searchPoint != null){ - MessageFormat format = new MessageFormat(" ({0,number,#.##};{1,number,#.##})", Locale.US); - suffix = format.format(new Object[]{searchPoint.getLatitude(), searchPoint.getLongitude()}); + suffix = formatLatLon(searchPoint); } spinnerAdapter.insert(message + suffix, 0); this.searchPoint = searchPoint; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java index 01f6359762..62c1c3d82a 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java @@ -104,13 +104,13 @@ public class SearchHistoryActivity extends ListActivity implements SearchActivit @Override public void onClick(DialogInterface dialog, int which) { if (which == 0) { - OsmandSettings.getOsmandSettings(SearchHistoryActivity.this).setMapLocationToShow(entry.getLat(), entry.getLon()); + OsmandSettings.getOsmandSettings(SearchHistoryActivity.this).setMapLocationToShow(entry.getLat(), + entry.getLon()); } else if (which == 1) { - OsmandSettings.getOsmandSettings(SearchHistoryActivity.this).setPointToNavigate(entry.getLat(), entry.getLon(), null); + OsmandSettings.getOsmandSettings(SearchHistoryActivity.this).setPointToNavigate(entry.getLat(), entry.getLon(), + null); } - MapActivity.launchMapActivityMoveToTop(SearchHistoryActivity.this); - } }); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 53e687ae5d..d31a0028aa 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -48,8 +48,6 @@ import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener;