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:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginRight="16dp"
android:layout_marginRight="8dp"
android:indeterminate="true"
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).
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="release_2_4">
\u2022 New very powerful free text search. \n\n
@ -17,7 +18,7 @@
\u2022 Many other improvements and bug fixes.\n\n
and more…
</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="share_history_subject"> shared via OsmAnd</string>
<string name="search_categories">Categories</string>

View file

@ -1182,137 +1182,6 @@ public class GPXUtilities {
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 {
BufferedInputStream bis = new BufferedInputStream(f);
assert bis.markSupported();

View file

@ -168,7 +168,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private boolean permissionGranted;
private boolean mIsDestroyed = false;
private boolean quickSearchActive = false;
private boolean quickSearchTopbarActive = false;
@Override
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;
}
public boolean isQuickSearchDialogActive() {
return quickSearchActive && getQuickSearchDialogFragment() != null;
public boolean isQuickSearchTopbarActive() {
return quickSearchTopbarActive && getQuickSearchDialogFragment() != null;
}
public void setQuickSearchActive(boolean quickSearchActive) {
this.quickSearchActive = quickSearchActive;
public void setQuickSearchTopbarActive(boolean quickSearchTopbarActive) {
this.quickSearchTopbarActive = quickSearchTopbarActive;
}
}

View file

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

View file

@ -1,11 +1,14 @@
package net.osmand.plus.search;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout;
import android.support.v4.app.DialogFragment;
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.FragmentTransaction;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
@ -28,28 +32,29 @@ import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.Location;
import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.osm.AbstractPoiType;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.LockableViewPager;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.resources.RegionAddressRepository;
import net.osmand.search.SearchUICore;
@ -69,7 +74,6 @@ import net.osmand.util.MapUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@ -105,6 +109,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private net.osmand.Location location = 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_OBJECT_PRIORITY = 10;
@ -152,11 +158,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
view.findViewById(R.id.buttonToolbar).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
OsmandSettings settings = app.getSettings();
SearchPhrase searchPhrase = searchUICore.getPhrase();
if (searchPhrase.isLastWord(ObjectType.POI_TYPE)) {
OsmandSettings settings = app.getSettings();
AbstractPoiType abstractPoiType = (AbstractPoiType) searchPhrase.getLastSelectedWord().getResult().object;
PoiUIFilter filter = new PoiUIFilter(abstractPoiType, app, "");
if (searchPhrase.isNoSelectedType() || searchPhrase.isLastWord(ObjectType.POI_TYPE)) {
PoiUIFilter filter;
if (searchPhrase.isNoSelectedType()) {
filter = new PoiUIFilter(null, app, "");
} else {
AbstractPoiType abstractPoiType = (AbstractPoiType) searchPhrase.getLastSelectedWord().getResult().object;
filter = new PoiUIFilter(abstractPoiType, app, "");
}
if (!Algorithms.isEmpty(searchPhrase.getUnknownSearchWord())) {
filter.setFilterByName(searchPhrase.getUnknownSearchWord());
}
@ -165,8 +176,28 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (location != null) {
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), 15);
}
getMapActivity().setQuickSearchTopbarActive(searchPhrase.isNoSelectedType());
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() {
@Override
public void onClick(View v) {
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);
new DialogFragment() {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.confirmation_to_delete_history_items)
.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
public void afterTextChanged(Editable s) {
String newQueryText = s.toString();
updateClearButtonAndHint();
updateClearButtonVisibility(newQueryText.length() > 0);
updateTabbarVisibility(newQueryText.length() == 0);
if (!searchQuery.equalsIgnoreCase(newQueryText)) {
@ -266,21 +314,22 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} else {
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);
}
}
} else if (useMapCenter && location != null) {
useMapCenter = false;
updateUseMapCenterUI();
startLocationUpdate();
LatLon centerLatLon = new LatLon(location.getLatitude(), location.getLongitude());
SearchSettings ss = searchUICore.getSearchSettings().setOriginalLocation(
new LatLon(centerLatLon.getLatitude(), centerLatLon.getLongitude()));
searchUICore.updateSettings(ss);
updateClearButtonAndHint();
}
}
});
setupSearch(mapActivity);
updateClearButtonAndHint();
addMainSearchFragment();
searchEditText.requestFocus();
@ -294,6 +343,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
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();
}
@ -331,37 +388,16 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
searchUICore = new SearchUICore(app.getPoiTypes(), locale, binaryMapIndexReaderArray);
/*
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()]));
*/
location = app.getLocationProvider().getLastKnownLocation();
LatLon clt = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
LatLon centerLatLon = clt;
searchEditText.setHint(R.string.search_poi_category_hint);
if (location != null) {
double d = MapUtils.getDistance(clt, location.getLatitude(), location.getLongitude());
if(d < DISTANCE_THRESHOLD) {
if (d < DISTANCE_THRESHOLD) {
centerLatLon = new LatLon(location.getLatitude(), location.getLongitude());
} else {
String n = getString(R.string.search_poi_category_hint);
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));
useMapCenter = true;
}
}
SearchSettings settings = searchUICore.getPhrase().getSettings().setOriginalLocation(
@ -399,6 +435,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
resultMatcher.publish(sr);
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
resultMatcher.publish(sr);
} else if (point.getCategory() != null && phrase.getNameStringMatcher().matches(point.getCategory())) {
resultMatcher.publish(sr);
}
}
return true;
@ -431,31 +469,48 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override
public void onResume() {
super.onResume();
OsmandApplication app = getMyApplication();
app.getLocationProvider().addCompassListener(this);
app.getLocationProvider().addLocationListener(this);
location = app.getLocationProvider().getLastKnownLocation();
updateLocation(location);
getMapActivity().setQuickSearchActive(true);
if (!useMapCenter) {
startLocationUpdate();
}
paused = false;
}
@Override
public void onPause() {
super.onPause();
OsmandApplication app = getMyApplication();
getMapActivity().setQuickSearchActive(false);
paused = true;
stopLocationUpdate();
}
@Override
public void onDismiss(DialogInterface dialog) {
getMapActivity().setQuickSearchTopbarActive(false);
getChildFragmentManager().popBackStack();
app.getLocationProvider().removeLocationListener(this);
app.getLocationProvider().removeCompassListener(this);
mainSearchFragment = null;
historySearchFragment = null;
categoriesSearchFragment = null;
super.onDismiss(dialog);
}
public Toolbar getToolbar() {
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() {
updateClearButtonVisibility(false);
progressBar.setVisibility(View.VISIBLE);
@ -466,9 +521,23 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
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) {
if (show) {
clearButton.setVisibility(searchEditText.length() > 0 ? View.VISIBLE : View.GONE);
clearButton.setVisibility(searchEditText.length() > 0 || useMapCenter ? View.VISIBLE : View.GONE);
} else {
clearButton.setVisibility(View.GONE);
}
@ -489,7 +558,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
public void onSearchListFragmentResume(QuickSearchListFragment searchListFragment) {
SearchPhrase sp;
switch (searchListFragment.getType()) {
case HISTORY:
historySearchFragment = (QuickSearchHistoryListFragment) searchListFragment;
@ -510,6 +578,10 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
}
break;
}
LatLon mapCenter = getMapActivity().getMapView().getCurrentRotatedTileBox().getCenterLatLon();
if (useMapCenter) {
searchListFragment.updateLocation(mapCenter, null);
}
}
private void reloadCategories() {
@ -597,7 +669,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override
public boolean publish(SearchResult object) {
if (mainSearchFragment == null) {
if (paused) {
return false;
}
@ -673,7 +745,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override
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);
}
}
@ -711,15 +783,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
private void updateSearchResult(SearchResultCollection res, boolean appended) {
OsmandApplication app = getMyApplication();
List<QuickSearchListItem> rows = new ArrayList<>();
if (res.getCurrentSearchResults().size() > 0) {
for (final SearchResult sr : res.getCurrentSearchResults()) {
rows.add(new QuickSearchListItem(app, sr));
if (!paused && mainSearchFragment != null) {
OsmandApplication app = getMyApplication();
List<QuickSearchListItem> rows = new ArrayList<>();
if (res.getCurrentSearchResults().size() > 0) {
for (final SearchResult sr : res.getCurrentSearchResults()) {
rows.add(new QuickSearchListItem(app, sr));
}
}
}
if (mainSearchFragment != null) {
mainSearchFragment.updateListAdapter(rows, appended);
}
}
@ -828,14 +899,34 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (location != null) {
latLon = new LatLon(location.getLatitude(), location.getLongitude());
}
if (mainSearchFragment != null) {
mainSearchFragment.updateLocation(latLon, heading);
updateLocationUI(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);
}
if (categoriesSearchFragment != null) {
categoriesSearchFragment.updateLocation(latLon, heading);
}
private void updateUseMapCenterUI() {
if (!paused) {
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 {
private OsmandApplication app;
private LoadGpxTask asyncLoader = new LoadGpxTask();
public SearchWptAPI(OsmandApplication app) {
this.app = app;
asyncLoader.execute();
}
@Override
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) {
if (asyncLoader.getResult() == null) {
if (phrase.isEmpty()) {
return false;
}
List<GpxInfo> infos = asyncLoader.getResult();
for (GpxInfo info : infos) {
for (WptPt point : info.gpx.points) {
SearchResult sr = new SearchResult(phrase);
sr.localeName = point.getPointDescription(app).getName();
sr.object = point;
sr.priority = SEARCH_WPT_OBJECT_PRIORITY;
sr.objectType = ObjectType.WPT;
sr.location = new LatLon(point.getLatitude(), point.getLongitude());
sr.localeRelatedObjectName = app.getRegions().getCountryName(sr.location);
sr.relatedObject = info;
sr.preferredZoom = 17;
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
resultMatcher.publish(sr);
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
resultMatcher.publish(sr);
List<SelectedGpxFile> list = app.getSelectedGpxHelper().getSelectedGPXFiles();
for (SelectedGpxFile selectedGpx : list) {
if (selectedGpx != null) {
for (WptPt point : selectedGpx.getGpxFile().points) {
SearchResult sr = new SearchResult(phrase);
sr.localeName = point.getPointDescription(app).getName();
sr.object = point;
sr.priority = SEARCH_WPT_OBJECT_PRIORITY;
sr.objectType = ObjectType.WPT;
sr.location = new LatLon(point.getLatitude(), point.getLongitude());
sr.localeRelatedObjectName = app.getRegions().getCountryName(sr.location);
sr.relatedObject = selectedGpx.getGpxFile();
sr.preferredZoom = 17;
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
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;
}
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 Float heading;
private boolean useMapCenter;
private int searchMoreItemPosition;
private int selectAllItemPosition;
@ -97,6 +98,14 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
this.heading = heading;
}
public boolean isUseMapCenter() {
return useMapCenter;
}
public void setUseMapCenter(boolean useMapCenter) {
this.useMapCenter = useMapCenter;
}
public boolean isSelectionMode() {
return selectionMode;
}
@ -376,9 +385,8 @@ public class QuickSearchListAdapter extends ArrayAdapter<QuickSearchListItem> {
TextView distanceText = (TextView) view.findViewById(R.id.distance);
ImageView direction = (ImageView) view.findViewById(R.id.direction);
float myHeading = heading == null ? 0f : heading;
DashLocationFragment.updateLocationView(false, location,
myHeading, direction, distanceText,
DashLocationFragment.updateLocationView(useMapCenter, location,
heading, direction, distanceText,
listItem.getSearchResult().location.getLatitude(),
listItem.getSearchResult().location.getLongitude(),
screenOrientation, app, activity);

View file

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

View file

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

View file

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

View file

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