Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-07-25 19:51:51 +02:00
commit 15d4a29070
11 changed files with 250 additions and 316 deletions

View file

@ -43,7 +43,7 @@
android:id="@+id/searchProgressBar" android:id="@+id/searchProgressBar"
android:layout_width="32dp" android:layout_width="32dp"
android:layout_height="32dp" android:layout_height="32dp"
android:layout_marginRight="16dp" android:layout_marginRight="8dp"
android:indeterminate="true" android:indeterminate="true"
android:visibility="gone"/> android:visibility="gone"/>

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). 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 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="confirmation_to_delete_history_items">Do you want to delete selected history items?</string>
<string name="show_something_on_map">Show %1$s on the map</string> <string name="show_something_on_map">Show %1$s on the map</string>
<string name="release_2_4"> <string name="release_2_4">
\u2022 New very powerful free text search. \n\n \u2022 New very powerful free text search. \n\n
@ -17,7 +18,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="dist_away_from_my_location">Search %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

@ -1182,137 +1182,6 @@ public class GPXUtilities {
return res; return res;
} }
public static GPXFile loadWptPt(Context ctx, File f) {
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
GPXFile file = loadWptPt(ctx, fis);
file.path = f.getAbsolutePath();
try {
fis.close();
} catch (IOException e) {
}
return file;
} catch (FileNotFoundException e) {
GPXFile res = new GPXFile();
res.path = f.getAbsolutePath();
log.error("Error reading gpx", e); //$NON-NLS-1$
res.warning = ctx.getString(R.string.error_reading_gpx);
return res;
} finally {
try {
if (fis != null)
fis.close();
} catch (IOException ignore) {
// ignore
}
}
}
public static GPXFile loadWptPt(Context ctx, InputStream f) {
GPXFile res = new GPXFile();
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
try {
XmlPullParser parser = PlatformUtil.newXMLPullParser();
parser.setInput(getUTF8Reader(f)); //$NON-NLS-1$
Stack<GPXExtensions> parserState = new Stack<GPXExtensions>();
boolean extensionReadMode = false;
parserState.push(res);
int tok;
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (tok == XmlPullParser.START_TAG) {
Object parse = parserState.peek();
String tag = parser.getName();
if (extensionReadMode && parse instanceof GPXExtensions) {
String value = readText(parser, tag);
if (value != null) {
((GPXExtensions) parse).getExtensionsToWrite().put(tag, value);
if (tag.equals("speed") && parse instanceof WptPt) {
try {
((WptPt) parse).speed = Float.parseFloat(value);
} catch (NumberFormatException e) {
}
}
}
} else if (parse instanceof GPXExtensions && tag.equals("extensions")) {
extensionReadMode = true;
} else {
if (parse instanceof GPXFile) {
if (parser.getName().equals("wpt")) {
WptPt wptPt = parseWptAttributes(parser);
((GPXFile) parse).points.add(wptPt);
parserState.push(wptPt);
}
} else if (parse instanceof WptPt) {
if (parser.getName().equals("name")) {
((WptPt) parse).name = readText(parser, "name");
} else if (parser.getName().equals("desc")) {
((WptPt) parse).desc = readText(parser, "desc");
} else if (parser.getName().equals("link")) {
((WptPt) parse).link = parser.getAttributeValue("", "href");
} else if (tag.equals("category")) {
((WptPt) parse).category = readText(parser, "category");
} else if (tag.equals("type")) {
if (((WptPt) parse).category == null) {
((WptPt) parse).category = readText(parser, "type");
}
} else if (parser.getName().equals("ele")) {
String text = readText(parser, "ele");
if (text != null) {
try {
((WptPt) parse).ele = Float.parseFloat(text);
} catch (NumberFormatException e) {
}
}
} else if (parser.getName().equals("hdop")) {
String text = readText(parser, "hdop");
if (text != null) {
try {
((WptPt) parse).hdop = Float.parseFloat(text);
} catch (NumberFormatException e) {
}
}
} else if (parser.getName().equals("time")) {
String text = readText(parser, "time");
if (text != null) {
try {
((WptPt) parse).time = format.parse(text).getTime();
} catch (ParseException e) {
}
}
}
}
}
} else if (tok == XmlPullParser.END_TAG) {
Object parse = parserState.peek();
String tag = parser.getName();
if (parse instanceof GPXExtensions && tag.equals("extensions")) {
extensionReadMode = false;
}
if (tag.equals("wpt")) {
Object pop = parserState.pop();
assert pop instanceof WptPt;
}
}
}
} catch (RuntimeException e) {
log.error("Error reading gpx", e); //$NON-NLS-1$
res.warning = ctx.getString(R.string.error_reading_gpx) + " " + e.getMessage();
} catch (XmlPullParserException e) {
log.error("Error reading gpx", e); //$NON-NLS-1$
res.warning = ctx.getString(R.string.error_reading_gpx) + " " + e.getMessage();
} catch (IOException e) {
log.error("Error reading gpx", e); //$NON-NLS-1$
res.warning = ctx.getString(R.string.error_reading_gpx) + " " + e.getMessage();
}
return res;
}
private static Reader getUTF8Reader(InputStream f) throws IOException { private static Reader getUTF8Reader(InputStream f) throws IOException {
BufferedInputStream bis = new BufferedInputStream(f); BufferedInputStream bis = new BufferedInputStream(f);
assert bis.markSupported(); assert bis.markSupported();

View file

@ -168,7 +168,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean permissionGranted; private boolean permissionGranted;
private boolean mIsDestroyed = false; private boolean mIsDestroyed = false;
private boolean quickSearchActive = false; private boolean quickSearchTopbarActive = false;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -1381,11 +1381,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return fragment!= null && !fragment.isDetached() && !fragment.isRemoving() ? (QuickSearchDialogFragment) fragment : null; return fragment!= null && !fragment.isDetached() && !fragment.isRemoving() ? (QuickSearchDialogFragment) fragment : null;
} }
public boolean isQuickSearchDialogActive() { public boolean isQuickSearchTopbarActive() {
return quickSearchActive && getQuickSearchDialogFragment() != null; return quickSearchTopbarActive && getQuickSearchDialogFragment() != null;
} }
public void setQuickSearchActive(boolean quickSearchActive) { public void setQuickSearchTopbarActive(boolean quickSearchTopbarActive) {
this.quickSearchActive = quickSearchActive; this.quickSearchTopbarActive = quickSearchTopbarActive;
} }
} }

View file

@ -15,6 +15,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -130,15 +131,29 @@ public abstract class PointEditorFragment extends Fragment {
descriptionEdit.setText(getDescriptionInitValue()); descriptionEdit.setText(getDescriptionInitValue());
} }
view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { if (Build.VERSION.SDK_INT >= 11) {
@Override view.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) { @Override
if (descriptionEdit.isFocused()) { public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
ScrollView scrollView = (ScrollView) view.findViewById(R.id.editor_scroll_view); if (descriptionEdit.isFocused()) {
scrollView.scrollTo(0, bottom); ScrollView scrollView = (ScrollView) view.findViewById(R.id.editor_scroll_view);
scrollView.scrollTo(0, bottom);
}
} }
} });
}); } else {
ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (descriptionEdit.isFocused()) {
ScrollView scrollView = (ScrollView) view.findViewById(R.id.editor_scroll_view);
scrollView.scrollTo(0, view.getBottom());
}
}
});
}
ImageView nameImage = (ImageView) view.findViewById(R.id.name_image); ImageView nameImage = (ImageView) view.findViewById(R.id.name_image);
nameImage.setImageDrawable(getNameIcon()); nameImage.setImageDrawable(getNameIcon());

View file

@ -1,11 +1,14 @@
package net.osmand.plus.search; package net.osmand.plus.search;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
@ -13,6 +16,7 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.FileProvider; import android.support.v4.content.FileProvider;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -28,28 +32,29 @@ 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.Location; import net.osmand.Location;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.osm.AbstractPoiType; import net.osmand.osm.AbstractPoiType;
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.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.LockableViewPager; import net.osmand.plus.LockableViewPager;
import net.osmand.plus.OsmAndFormatter;
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;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.resources.RegionAddressRepository; import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.search.SearchUICore; import net.osmand.search.SearchUICore;
@ -69,7 +74,6 @@ import net.osmand.util.MapUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -105,6 +109,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private net.osmand.Location location = null; private net.osmand.Location location = null;
private Float heading = null; private Float heading = null;
private boolean useMapCenter;
private boolean paused;
public static final int SEARCH_FAVORITE_API_PRIORITY = 2; public static final int SEARCH_FAVORITE_API_PRIORITY = 2;
public static final int SEARCH_FAVORITE_OBJECT_PRIORITY = 10; public static final int SEARCH_FAVORITE_OBJECT_PRIORITY = 10;
@ -152,11 +158,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
view.findViewById(R.id.buttonToolbar).setOnClickListener(new OnClickListener() { view.findViewById(R.id.buttonToolbar).setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
OsmandSettings settings = app.getSettings();
SearchPhrase searchPhrase = searchUICore.getPhrase(); SearchPhrase searchPhrase = searchUICore.getPhrase();
if (searchPhrase.isLastWord(ObjectType.POI_TYPE)) { if (searchPhrase.isNoSelectedType() || searchPhrase.isLastWord(ObjectType.POI_TYPE)) {
OsmandSettings settings = app.getSettings(); PoiUIFilter filter;
AbstractPoiType abstractPoiType = (AbstractPoiType) searchPhrase.getLastSelectedWord().getResult().object; if (searchPhrase.isNoSelectedType()) {
PoiUIFilter filter = new PoiUIFilter(abstractPoiType, app, ""); filter = new PoiUIFilter(null, app, "");
} else {
AbstractPoiType abstractPoiType = (AbstractPoiType) searchPhrase.getLastSelectedWord().getResult().object;
filter = new PoiUIFilter(abstractPoiType, app, "");
}
if (!Algorithms.isEmpty(searchPhrase.getUnknownSearchWord())) { if (!Algorithms.isEmpty(searchPhrase.getUnknownSearchWord())) {
filter.setFilterByName(searchPhrase.getUnknownSearchWord()); filter.setFilterByName(searchPhrase.getUnknownSearchWord());
} }
@ -165,8 +176,28 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (location != null) { if (location != null) {
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), 15); settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), 15);
} }
getMapActivity().setQuickSearchTopbarActive(searchPhrase.isNoSelectedType());
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
hide(); if (searchPhrase.isNoSelectedType()) {
hide();
} else {
dismiss();
}
} else {
SearchWord word = searchPhrase.getLastSelectedWord();
if (word != null && word.getLocation() != null) {
SearchResult searchResult = word.getResult();
String name = QuickSearchListItem.getName(app, searchResult);
String typeName = QuickSearchListItem.getTypeName(app, searchResult);
PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeName, name);
getMyApplication().getSettings().setMapLocationToShow(
searchResult.location.getLatitude(), searchResult.location.getLongitude(),
searchResult.preferredZoom, pointDescription, true, searchResult.object);
getMapActivity().setQuickSearchTopbarActive(true);
MapActivity.launchMapActivityMoveToTop(getActivity());
hide();
}
} }
} }
}); });
@ -210,14 +241,30 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
view.findViewById(R.id.deleteButton).setOnClickListener(new OnClickListener() { view.findViewById(R.id.deleteButton).setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
SearchHistoryHelper helper = SearchHistoryHelper.getInstance(app);
List<QuickSearchListItem> selectedItems = historySearchFragment.getListAdapter().getSelectedItems(); new DialogFragment() {
for (QuickSearchListItem searchListItem : selectedItems) { @NonNull
HistoryEntry historyEntry = (HistoryEntry) searchListItem.getSearchResult().object; @Override
helper.remove(historyEntry); public Dialog onCreateDialog(Bundle savedInstanceState) {
} AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
reloadHistory(); builder.setTitle(R.string.confirmation_to_delete_history_items)
enableSelectionMode(false, -1); .setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
SearchHistoryHelper helper = SearchHistoryHelper.getInstance(app);
List<QuickSearchListItem> selectedItems = historySearchFragment.getListAdapter().getSelectedItems();
for (QuickSearchListItem searchListItem : selectedItems) {
HistoryEntry historyEntry = (HistoryEntry) searchListItem.getSearchResult().object;
helper.remove(historyEntry);
}
reloadHistory();
enableSelectionMode(false, -1);
}
})
.setNegativeButton(R.string.shared_string_no, null);
return builder.create();
}
}.show(getChildFragmentManager(), "DeleteHistoryConfirmationFragment");
} }
}); });
@ -241,6 +288,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
String newQueryText = s.toString(); String newQueryText = s.toString();
updateClearButtonAndHint();
updateClearButtonVisibility(newQueryText.length() > 0); updateClearButtonVisibility(newQueryText.length() > 0);
updateTabbarVisibility(newQueryText.length() == 0); updateTabbarVisibility(newQueryText.length() == 0);
if (!searchQuery.equalsIgnoreCase(newQueryText)) { if (!searchQuery.equalsIgnoreCase(newQueryText)) {
@ -266,21 +314,22 @@ 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 { } else if (useMapCenter && location != null) {
searchEditText.setHint(R.string.search_poi_category_hint); useMapCenter = false;
clearButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark)); updateUseMapCenterUI();
if(location != null && searchUICore != null) { startLocationUpdate();
LatLon centerLatLon = new LatLon(location.getLatitude(), location.getLongitude()); LatLon centerLatLon = new LatLon(location.getLatitude(), location.getLongitude());
SearchSettings ss = searchUICore.getSearchSettings().setOriginalLocation( SearchSettings ss = searchUICore.getSearchSettings().setOriginalLocation(
new LatLon(centerLatLon.getLatitude(), centerLatLon.getLongitude())); new LatLon(centerLatLon.getLatitude(), centerLatLon.getLongitude()));
searchUICore.updateSettings(ss); searchUICore.updateSettings(ss);
} updateClearButtonAndHint();
}
}
} }
}); });
setupSearch(mapActivity); setupSearch(mapActivity);
updateClearButtonAndHint();
addMainSearchFragment(); addMainSearchFragment();
searchEditText.requestFocus(); searchEditText.requestFocus();
@ -294,6 +343,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
public void show() { public void show() {
getMapActivity().setQuickSearchTopbarActive(false);
if (useMapCenter) {
LatLon mapCenter = getMapActivity().getMapView().getCurrentRotatedTileBox().getCenterLatLon();
SearchSettings ss = searchUICore.getSearchSettings().setOriginalLocation(
new LatLon(mapCenter.getLatitude(), mapCenter.getLongitude()));
searchUICore.updateSettings(ss);
updateLocationUI(mapCenter, null);
}
getDialog().show(); getDialog().show();
} }
@ -331,37 +388,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
searchUICore = new SearchUICore(app.getPoiTypes(), locale, binaryMapIndexReaderArray); searchUICore = new SearchUICore(app.getPoiTypes(), locale, binaryMapIndexReaderArray);
/* location = app.getLocationProvider().getLastKnownLocation();
List<BinaryMapIndexReader> files = new ArrayList<>();
File file = new File(Environment.getExternalStorageDirectory() + "/osmand");
if (file.exists() && file.listFiles() != null) {
for (File obf : file.listFiles()) {
if (!obf.isDirectory() && obf.getName().endsWith(".obf")) {
try {
BinaryMapIndexReader bmir = new BinaryMapIndexReader(new RandomAccessFile(obf, "r"), obf);
files.add(bmir);
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
}
searchUICore = new SearchUICore(app.getPoiTypes(), locale, files.toArray(new BinaryMapIndexReader[files.size()]));
*/
LatLon clt = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon(); LatLon clt = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
LatLon centerLatLon = clt; LatLon centerLatLon = clt;
searchEditText.setHint(R.string.search_poi_category_hint); searchEditText.setHint(R.string.search_poi_category_hint);
if (location != null) { if (location != null) {
double d = MapUtils.getDistance(clt, location.getLatitude(), location.getLongitude()); double d = MapUtils.getDistance(clt, location.getLatitude(), location.getLongitude());
if(d < DISTANCE_THRESHOLD) { if (d < DISTANCE_THRESHOLD) {
centerLatLon = new LatLon(location.getLatitude(), location.getLongitude()); centerLatLon = new LatLon(location.getLatitude(), location.getLongitude());
} else { } else {
String n = getString(R.string.search_poi_category_hint); useMapCenter = true;
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(
@ -399,6 +435,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
resultMatcher.publish(sr); resultMatcher.publish(sr);
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) { } else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
resultMatcher.publish(sr); resultMatcher.publish(sr);
} else if (point.getCategory() != null && phrase.getNameStringMatcher().matches(point.getCategory())) {
resultMatcher.publish(sr);
} }
} }
return true; return true;
@ -431,31 +469,48 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
OsmandApplication app = getMyApplication(); if (!useMapCenter) {
app.getLocationProvider().addCompassListener(this); startLocationUpdate();
app.getLocationProvider().addLocationListener(this); }
location = app.getLocationProvider().getLastKnownLocation(); paused = false;
updateLocation(location);
getMapActivity().setQuickSearchActive(true);
} }
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
OsmandApplication app = getMyApplication(); paused = true;
getMapActivity().setQuickSearchActive(false); stopLocationUpdate();
}
@Override
public void onDismiss(DialogInterface dialog) {
getMapActivity().setQuickSearchTopbarActive(false);
getChildFragmentManager().popBackStack(); getChildFragmentManager().popBackStack();
app.getLocationProvider().removeLocationListener(this); super.onDismiss(dialog);
app.getLocationProvider().removeCompassListener(this);
mainSearchFragment = null;
historySearchFragment = null;
categoriesSearchFragment = null;
} }
public Toolbar getToolbar() { public Toolbar getToolbar() {
return toolbar; return toolbar;
} }
public boolean isUseMapCenter() {
return useMapCenter;
}
private void startLocationUpdate() {
OsmandApplication app = getMyApplication();
app.getLocationProvider().addCompassListener(this);
app.getLocationProvider().addLocationListener(this);
location = app.getLocationProvider().getLastKnownLocation();
updateLocation(location);
}
private void stopLocationUpdate() {
OsmandApplication app = getMyApplication();
app.getLocationProvider().removeLocationListener(this);
app.getLocationProvider().removeCompassListener(this);
}
private void showProgressBar() { private void showProgressBar() {
updateClearButtonVisibility(false); updateClearButtonVisibility(false);
progressBar.setVisibility(View.VISIBLE); progressBar.setVisibility(View.VISIBLE);
@ -466,9 +521,23 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} }
private void updateClearButtonAndHint() {
OsmandApplication app = getMyApplication();
if (useMapCenter && searchEditText.length() == 0) {
LatLon latLon = searchUICore.getSearchSettings().getOriginalLocation();
double d = MapUtils.getDistance(latLon, location.getLatitude(), location.getLongitude());
String dist = OsmAndFormatter.getFormattedDistance((float) d, app);
searchEditText.setHint(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));
} else {
searchEditText.setHint(R.string.search_poi_category_hint);
clearButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
}
}
private void updateClearButtonVisibility(boolean show) { private void updateClearButtonVisibility(boolean show) {
if (show) { if (show) {
clearButton.setVisibility(searchEditText.length() > 0 ? View.VISIBLE : View.GONE); clearButton.setVisibility(searchEditText.length() > 0 || useMapCenter ? View.VISIBLE : View.GONE);
} else { } else {
clearButton.setVisibility(View.GONE); clearButton.setVisibility(View.GONE);
} }
@ -489,7 +558,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
public void onSearchListFragmentResume(QuickSearchListFragment searchListFragment) { public void onSearchListFragmentResume(QuickSearchListFragment searchListFragment) {
SearchPhrase sp;
switch (searchListFragment.getType()) { switch (searchListFragment.getType()) {
case HISTORY: case HISTORY:
historySearchFragment = (QuickSearchHistoryListFragment) searchListFragment; historySearchFragment = (QuickSearchHistoryListFragment) searchListFragment;
@ -510,6 +578,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
break; break;
} }
LatLon mapCenter = getMapActivity().getMapView().getCurrentRotatedTileBox().getCenterLatLon();
if (useMapCenter) {
searchListFragment.updateLocation(mapCenter, null);
}
} }
private void reloadCategories() { private void reloadCategories() {
@ -597,7 +669,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
public boolean publish(SearchResult object) { public boolean publish(SearchResult object) {
if (mainSearchFragment == null) { if (paused) {
return false; return false;
} }
@ -673,7 +745,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return mainSearchFragment == null; return paused;
} }
}); });
} }
@ -703,7 +775,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
}); });
if (mainSearchFragment != null) { if (!paused && mainSearchFragment != null) {
mainSearchFragment.addListItem(moreListItem); mainSearchFragment.addListItem(moreListItem);
} }
} }
@ -711,15 +783,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private void updateSearchResult(SearchResultCollection res, boolean appended) { private void updateSearchResult(SearchResultCollection res, boolean appended) {
OsmandApplication app = getMyApplication(); if (!paused && mainSearchFragment != null) {
OsmandApplication app = getMyApplication();
List<QuickSearchListItem> rows = new ArrayList<>(); List<QuickSearchListItem> rows = new ArrayList<>();
if (res.getCurrentSearchResults().size() > 0) { if (res.getCurrentSearchResults().size() > 0) {
for (final SearchResult sr : res.getCurrentSearchResults()) { for (final SearchResult sr : res.getCurrentSearchResults()) {
rows.add(new QuickSearchListItem(app, sr)); rows.add(new QuickSearchListItem(app, sr));
}
} }
}
if (mainSearchFragment != null) {
mainSearchFragment.updateListAdapter(rows, appended); mainSearchFragment.updateListAdapter(rows, appended);
} }
} }
@ -828,14 +899,34 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (location != null) { if (location != null) {
latLon = new LatLon(location.getLatitude(), location.getLongitude()); latLon = new LatLon(location.getLatitude(), location.getLongitude());
} }
if (mainSearchFragment != null) { updateLocationUI(latLon, heading);
mainSearchFragment.updateLocation(latLon, heading); }
private void updateLocationUI(LatLon latLon, Float heading) {
if (latLon != null && !paused) {
if (mainSearchFragment != null) {
mainSearchFragment.updateLocation(latLon, heading);
}
if (historySearchFragment != null) {
historySearchFragment.updateLocation(latLon, heading);
}
if (categoriesSearchFragment != null) {
categoriesSearchFragment.updateLocation(latLon, heading);
}
} }
if (historySearchFragment != null) { }
historySearchFragment.updateLocation(latLon, heading);
} private void updateUseMapCenterUI() {
if (categoriesSearchFragment != null) { if (!paused) {
categoriesSearchFragment.updateLocation(latLon, heading); if (mainSearchFragment != null) {
mainSearchFragment.getListAdapter().setUseMapCenter(useMapCenter);
}
if (historySearchFragment != null) {
historySearchFragment.getListAdapter().setUseMapCenter(useMapCenter);
}
if (categoriesSearchFragment != null) {
categoriesSearchFragment.getListAdapter().setUseMapCenter(useMapCenter);
}
} }
} }
@ -1053,35 +1144,36 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
public static class SearchWptAPI extends SearchBaseAPI { public static class SearchWptAPI extends SearchBaseAPI {
private OsmandApplication app; private OsmandApplication app;
private LoadGpxTask asyncLoader = new LoadGpxTask();
public SearchWptAPI(OsmandApplication app) { public SearchWptAPI(OsmandApplication app) {
this.app = app; this.app = app;
asyncLoader.execute();
} }
@Override @Override
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) { public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) {
if (asyncLoader.getResult() == null) {
if (phrase.isEmpty()) {
return false; return false;
} }
List<GpxInfo> infos = asyncLoader.getResult(); List<SelectedGpxFile> list = app.getSelectedGpxHelper().getSelectedGPXFiles();
for (GpxInfo info : infos) { for (SelectedGpxFile selectedGpx : list) {
for (WptPt point : info.gpx.points) { if (selectedGpx != null) {
SearchResult sr = new SearchResult(phrase); for (WptPt point : selectedGpx.getGpxFile().points) {
sr.localeName = point.getPointDescription(app).getName(); SearchResult sr = new SearchResult(phrase);
sr.object = point; sr.localeName = point.getPointDescription(app).getName();
sr.priority = SEARCH_WPT_OBJECT_PRIORITY; sr.object = point;
sr.objectType = ObjectType.WPT; sr.priority = SEARCH_WPT_OBJECT_PRIORITY;
sr.location = new LatLon(point.getLatitude(), point.getLongitude()); sr.objectType = ObjectType.WPT;
sr.localeRelatedObjectName = app.getRegions().getCountryName(sr.location); sr.location = new LatLon(point.getLatitude(), point.getLongitude());
sr.relatedObject = info; sr.localeRelatedObjectName = app.getRegions().getCountryName(sr.location);
sr.preferredZoom = 17; sr.relatedObject = selectedGpx.getGpxFile();
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) { sr.preferredZoom = 17;
resultMatcher.publish(sr); if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) { resultMatcher.publish(sr);
resultMatcher.publish(sr); } else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
resultMatcher.publish(sr);
}
} }
} }
} }
@ -1095,59 +1187,5 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} }
return SEARCH_WPT_API_PRIORITY; return SEARCH_WPT_API_PRIORITY;
} }
public class LoadGpxTask extends AsyncTask<Void, Void, List<GpxInfo>> {
private List<GpxInfo> result;
@Override
protected List<GpxInfo> doInBackground(Void... params) {
List<GpxInfo> result = new ArrayList<>();
loadGPXData(app.getAppPath(IndexConstants.GPX_INDEX_DIR), result, this);
return result;
}
@Override
protected void onPostExecute(List<GpxInfo> result) {
this.result = result;
}
private File[] listFilesSorted(File dir) {
File[] listFiles = dir.listFiles();
if (listFiles == null) {
return new File[0];
}
Arrays.sort(listFiles);
return listFiles;
}
private void loadGPXData(File mapPath, List<GpxInfo> result, LoadGpxTask loadTask) {
if (mapPath.canRead()) {
loadGPXFolder(mapPath, result, loadTask, "");
}
}
private void loadGPXFolder(File mapPath, List<GpxInfo> result, LoadGpxTask loadTask,
String gpxSubfolder) {
for (File gpxFile : listFilesSorted(mapPath)) {
if (gpxFile.isDirectory()) {
String sub = gpxSubfolder.length() == 0 ? gpxFile.getName() : gpxSubfolder + "/"
+ gpxFile.getName();
loadGPXFolder(gpxFile, result, loadTask, sub);
} else if (gpxFile.isFile() && gpxFile.getName().toLowerCase().endsWith(".gpx")) {
GpxInfo info = new GpxInfo();
info.subfolder = gpxSubfolder;
info.file = gpxFile;
info.gpx = GPXUtilities.loadWptPt(app, gpxFile);
result.add(info);
}
}
}
public List<GpxInfo> getResult() {
return result;
}
}
} }
} }

View file

@ -33,6 +33,7 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
private LatLon location; private LatLon location;
private Float heading; private Float heading;
private boolean useMapCenter;
private int searchMoreItemPosition; private int searchMoreItemPosition;
private int selectAllItemPosition; private int selectAllItemPosition;
@ -97,6 +98,14 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
this.heading = heading; this.heading = heading;
} }
public boolean isUseMapCenter() {
return useMapCenter;
}
public void setUseMapCenter(boolean useMapCenter) {
this.useMapCenter = useMapCenter;
}
public boolean isSelectionMode() { public boolean isSelectionMode() {
return selectionMode; return selectionMode;
} }
@ -376,9 +385,8 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
TextView distanceText = (TextView) view.findViewById(R.id.distance); TextView distanceText = (TextView) view.findViewById(R.id.distance);
ImageView direction = (ImageView) view.findViewById(R.id.direction); ImageView direction = (ImageView) view.findViewById(R.id.direction);
float myHeading = heading == null ? 0f : heading; DashLocationFragment.updateLocationView(useMapCenter, location,
DashLocationFragment.updateLocationView(false, location, heading, direction, distanceText,
myHeading, direction, distanceText,
listItem.getSearchResult().location.getLatitude(), listItem.getSearchResult().location.getLatitude(),
listItem.getSearchResult().location.getLongitude(), listItem.getSearchResult().location.getLongitude(),
screenOrientation, app, activity); screenOrientation, app, activity);

View file

@ -87,6 +87,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
dialogFragment = (QuickSearchDialogFragment) getParentFragment(); dialogFragment = (QuickSearchDialogFragment) getParentFragment();
listAdapter = new QuickSearchListAdapter(getMyApplication(), getActivity()); listAdapter = new QuickSearchListAdapter(getMyApplication(), getActivity());
listAdapter.setUseMapCenter(dialogFragment.isUseMapCenter());
setListAdapter(listAdapter); setListAdapter(listAdapter);
ListView listView = getListView(); ListView listView = getListView();
listView.setBackgroundColor(getResources().getColor( listView.setBackgroundColor(getResources().getColor(

View file

@ -15,18 +15,22 @@ import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiFilter;
import net.osmand.osm.PoiType; import net.osmand.osm.PoiType;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.search.SearchHistoryFragment; import net.osmand.plus.activities.search.SearchHistoryFragment;
import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry; import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; import net.osmand.plus.myplaces.AvailableGPXFragment;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
import net.osmand.search.core.SearchResult; import net.osmand.search.core.SearchResult;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.io.File;
public class QuickSearchListItem { public class QuickSearchListItem {
protected OsmandApplication app; protected OsmandApplication app;
@ -207,16 +211,15 @@ public class QuickSearchListItem {
} }
case WPT: case WPT:
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
WptPt wpt = (WptPt) searchResult.object; GPXFile gpx = (GPXFile) searchResult.relatedObject;
GpxInfo gpxInfo = (GpxInfo) searchResult.relatedObject;
if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) { if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
sb.append(searchResult.localeRelatedObjectName); sb.append(searchResult.localeRelatedObjectName);
} }
if (gpxInfo != null && !Algorithms.isEmpty(gpxInfo.getFileName())) { if (gpx != null && !Algorithms.isEmpty(gpx.path)) {
if (sb.length() > 0) { if (sb.length() > 0) {
sb.append(", "); sb.append(", ");
} }
sb.append(gpxInfo.getFileName()); sb.append(new File(gpx.path).getName());
} }
return sb.toString(); return sb.toString();
case UNKNOWN_NAME_FILTER: case UNKNOWN_NAME_FILTER:

View file

@ -15,7 +15,6 @@ import android.widget.TextView;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.ValueHolder; import net.osmand.ValueHolder;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.NavigationService; import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
@ -210,7 +209,7 @@ public class MapInfoWidgetsFactory {
} }
public void updateInfo() { public void updateInfo() {
boolean isQuickSearchActive = map.isQuickSearchDialogActive(); boolean isQuickSearchActive = map.isQuickSearchTopbarActive();
if (isQuickSearchActive) { if (isQuickSearchActive) {
QuickSearchDialogFragment fragment = map.getQuickSearchDialogFragment(); QuickSearchDialogFragment fragment = map.getQuickSearchDialogFragment();
if (fragment != null) { if (fragment != null) {
@ -335,7 +334,7 @@ public class MapInfoWidgetsFactory {
text = "\u2316+ " + text; text = "\u2316+ " + text;
} }
} }
if (map.isQuickSearchDialogActive()) { if (map.isQuickSearchTopbarActive()) {
updateVisibility(false); updateVisibility(false);
} else if (!showNextTurn && updateWaypoint()) { } else if (!showNextTurn && updateWaypoint()) {
updateVisibility(true); updateVisibility(true);

View file

@ -203,7 +203,7 @@ public class MapMarkersWidgetsFactory {
|| map.getMyApplication().getRoutingHelper().isRoutePlanningMode() || map.getMyApplication().getRoutingHelper().isRoutePlanningMode()
|| map.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().isVisible() || map.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().isVisible()
|| addressTopBar.getVisibility() == View.VISIBLE || addressTopBar.getVisibility() == View.VISIBLE
|| map.isQuickSearchDialogActive()) { || map.isQuickSearchTopbarActive()) {
updateVisibility(false); updateVisibility(false);
return; return;
} }