Add title 10km away

This commit is contained in:
Victor Shcherb 2016-07-25 10:07:51 +02:00
parent 5ab723f0ef
commit da4a27195e
3 changed files with 29 additions and 11 deletions

View file

@ -17,6 +17,7 @@
\u2022 Many other improvements and bug fixes.\n\n \u2022 Many other improvements and bug fixes.\n\n
and more… and more…
</string> </string>
<string name="dist_away_from_my_location">%1$s away</string>
<string name="show_on_map">Show on the map</string> <string name="show_on_map">Show on the map</string>
<string name="share_history_subject"> shared via OsmAnd</string> <string name="share_history_subject"> shared via OsmAnd</string>
<string name="search_categories">Categories</string> <string name="search_categories">Categories</string>

View file

@ -28,7 +28,6 @@ import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.Location; import net.osmand.Location;
@ -43,6 +42,7 @@ import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.LockableViewPager; import net.osmand.plus.LockableViewPager;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -112,6 +112,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
public static final int SEARCH_WPT_OBJECT_PRIORITY = 10; public static final int SEARCH_WPT_OBJECT_PRIORITY = 10;
public static final int SEARCH_HISTORY_API_PRIORITY = 3; public static final int SEARCH_HISTORY_API_PRIORITY = 3;
public static final int SEARCH_HISTORY_OBJECT_PRIORITY = 10; public static final int SEARCH_HISTORY_OBJECT_PRIORITY = 10;
private static final double DISTANCE_THRESHOLD = 70000; // 70km
@Override @Override
@ -220,8 +221,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
}); });
setupSearch(mapActivity);
viewPager = (LockableViewPager) view.findViewById(R.id.pager); viewPager = (LockableViewPager) view.findViewById(R.id.pager);
pagerAdapter = new SearchFragmentPagerAdapter(getChildFragmentManager(), getResources()); pagerAdapter = new SearchFragmentPagerAdapter(getChildFragmentManager(), getResources());
viewPager.setAdapter(pagerAdapter); viewPager.setAdapter(pagerAdapter);
@ -267,9 +266,20 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} else { } else {
buttonToolbarText.setText(app.getString(R.string.show_on_map).toUpperCase()); buttonToolbarText.setText(app.getString(R.string.show_on_map).toUpperCase());
} }
} else {
searchEditText.setHint(R.string.search_poi_category_hint);
clearButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
if(location != null && searchUICore != null) {
LatLon centerLatLon = new LatLon(location.getLatitude(), location.getLongitude());
SearchSettings ss = searchUICore.getSearchSettings().setOriginalLocation(
new LatLon(centerLatLon.getLatitude(), centerLatLon.getLongitude()));
searchUICore.updateSettings(ss);
}
} }
} }
}); });
setupSearch(mapActivity);
addMainSearchFragment(); addMainSearchFragment();
@ -340,11 +350,18 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
searchUICore = new SearchUICore(app.getPoiTypes(), locale, files.toArray(new BinaryMapIndexReader[files.size()])); searchUICore = new SearchUICore(app.getPoiTypes(), locale, files.toArray(new BinaryMapIndexReader[files.size()]));
*/ */
LatLon centerLatLon; LatLon clt = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
LatLon centerLatLon = clt;
searchEditText.setHint(R.string.search_poi_category_hint);
if (location != null) { if (location != null) {
double d = MapUtils.getDistance(clt, location.getLatitude(), location.getLongitude());
if(MapUtils.getDistance(clt, location.getLatitude(), location.getLongitude()) < DISTANCE_THRESHOLD) {
centerLatLon = new LatLon(location.getLatitude(), location.getLongitude()); centerLatLon = new LatLon(location.getLatitude(), location.getLongitude());
} else { String n = getString(R.string.search_poi_category_hint);
centerLatLon = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon(); String dist = OsmAndFormatter.getFormattedDistance((float) d, mapActivity.getMyApplication());
searchEditText.setHint(n +", " + getString(R.string.dist_away_from_my_location, dist));
clearButton.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_action_get_my_location, R.color.color_myloc_distance));
}
} }
SearchSettings settings = searchUICore.getPhrase().getSettings().setOriginalLocation( SearchSettings settings = searchUICore.getPhrase().getSettings().setOriginalLocation(
new LatLon(centerLatLon.getLatitude(), centerLatLon.getLongitude())); new LatLon(centerLatLon.getLatitude(), centerLatLon.getLongitude()));