Experiments with address search
This commit is contained in:
parent
96a71caa26
commit
ea60891ce8
4 changed files with 96 additions and 9 deletions
|
@ -3,11 +3,17 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" android:orientation="vertical">
|
||||
<TextView android:text="" android:id="@+id/Label" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center"></TextView>
|
||||
<LinearLayout android:id="@+id/LinearLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="3dp" android:layout_marginRight="5dp"
|
||||
android:orientation="horizontal">
|
||||
<TextView android:text="" android:id="@+id/Label" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center"></TextView>
|
||||
<Button android:id="@+id/EndingButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minWidth="7dp"
|
||||
android:text="..."></Button>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="3dp" android:layout_marginRight="3dp">
|
||||
<LinearLayout android:id="@+id/LinearLayout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginTop="1dp" android:layout_marginRight="3dp">
|
||||
<ProgressBar android:id="@+id/ProgressBar" android:layout_width="wrap_content" android:layout_height="wrap_content"></ProgressBar>
|
||||
<EditText android:text="" android:id="@+id/SearchText" android:layout_weight="1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType="textFilter"></EditText>
|
||||
|
||||
<Button android:id="@+id/ResetButton" android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:layout_weight="0" android:text="@string/default_buttons_reset"></Button>
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import net.londatiga.android.QuickAction;
|
||||
import net.osmand.Algoritms;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.OsmAndFormatter;
|
||||
|
@ -18,7 +19,7 @@ import net.osmand.osm.MapUtils;
|
|||
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.activities.MapActivityActions;
|
||||
import net.osmand.plus.activities.OsmandListActivity;
|
||||
import net.osmand.plus.activities.search.SearchActivity.SearchActivityChild;
|
||||
|
||||
|
@ -214,9 +215,11 @@ public class SearchAddressOnlineActivity extends OsmandListActivity implements S
|
|||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||
super.onListItemClick(l, v, position, id);
|
||||
Place item = ((PlacesAdapter) getListAdapter()).getItem(position);
|
||||
settings.setMapLocationToShow(item.lat, item.lon,
|
||||
Math.max(15, settings.getLastKnownMapZoom()), getString(R.string.address)+ " : " + item.displayName); //$NON-NLS-1$
|
||||
MapActivity.launchMapActivityMoveToTop(this);
|
||||
QuickAction qa = new QuickAction(v);
|
||||
MapActivityActions.createDirectionsActions(qa, new LatLon(item.lat, item.lon), item,
|
||||
getString(R.string.address)+ " : " + item.displayName, Math.max(15, settings.getLastKnownMapZoom()),
|
||||
this, true, null);
|
||||
qa.show();
|
||||
}
|
||||
|
||||
private static class Place {
|
||||
|
|
|
@ -5,21 +5,28 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import net.londatiga.android.QuickAction;
|
||||
import net.osmand.CollatorStringMatcher;
|
||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.data.MapObject;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.CustomTitleBar;
|
||||
import net.osmand.plus.activities.MapActivityActions;
|
||||
import net.osmand.plus.activities.OsmandListActivity;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.AsyncTask.Status;
|
||||
import android.os.Bundle;
|
||||
|
@ -29,12 +36,15 @@ import android.text.Editable;
|
|||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filter.FilterListener;
|
||||
import android.widget.ListView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
@ -56,19 +66,23 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
|||
protected Collator collator;
|
||||
protected NamesFilter namesFilter;
|
||||
private String currentFilter = "";
|
||||
private Button endingButton;
|
||||
private Set<String> endingSet = new HashSet<String>();
|
||||
private T endingObject;
|
||||
private static final Log log = LogUtil.getLog(SearchByNameAbstractActivity.class);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
settings = ((OsmandApplication) getApplication()).getSettings();
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
CustomTitleBar titleBar = new CustomTitleBar(this, R.string.search_activity, R.drawable.tab_search_address_icon);
|
||||
setContentView(R.layout.search_by_name);
|
||||
titleBar.afterSetContentView();
|
||||
|
||||
initializeTask = getInitializeTask();
|
||||
uiHandler = new UIUpdateHandler();
|
||||
namesFilter = new NamesFilter();
|
||||
NamesAdapter namesAdapter = new NamesAdapter(new ArrayList<T>(),createComparator()); //$NON-NLS-1$
|
||||
final NamesAdapter namesAdapter = new NamesAdapter(new ArrayList<T>(), createComparator()); //$NON-NLS-1$
|
||||
setListAdapter(namesAdapter);
|
||||
|
||||
collator = Collator.getInstance(Locale.US);
|
||||
|
@ -76,6 +90,24 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
|||
|
||||
|
||||
progress = (ProgressBar) findViewById(R.id.ProgressBar);
|
||||
endingButton = (Button) findViewById(R.id.EndingButton);
|
||||
endingButton.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
T obj = endingObject;
|
||||
LatLon loc = getLocation(obj);
|
||||
if (obj != null && loc != null) {
|
||||
QuickAction qa = new QuickAction(v);
|
||||
// TODO more granular description and text message!
|
||||
MapActivityActions.createDirectionsActions(qa, loc,
|
||||
obj, getText(obj), getZoomToDisplay(endingObject),
|
||||
SearchByNameAbstractActivity.this, true, null);
|
||||
qa.show();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
searchText = (EditText) findViewById(R.id.SearchText);
|
||||
searchText.addTextChangedListener(new TextWatcher(){
|
||||
|
||||
|
@ -98,7 +130,6 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
|||
public void onClick(View v) {
|
||||
searchText.setText("");
|
||||
}
|
||||
|
||||
});
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
if(initializeTask != null){
|
||||
|
@ -106,6 +137,17 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
|||
}
|
||||
}
|
||||
|
||||
protected int getZoomToDisplay(T item){
|
||||
return 15;
|
||||
}
|
||||
|
||||
protected LatLon getLocation(T item) {
|
||||
if (item instanceof MapObject) {
|
||||
return ((MapObject) item).getLocation();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public AsyncTask<Object, ?, ?> getInitializeTask(){
|
||||
return null;
|
||||
|
@ -120,11 +162,41 @@ public abstract class SearchByNameAbstractActivity<T> extends OsmandListActivity
|
|||
}
|
||||
|
||||
|
||||
private int MAX_THRESHOLD_UI = 70;
|
||||
private int MAX_VISIBLE_NAME = 20;
|
||||
public void querySearch(final String filter) {
|
||||
currentFilter = filter;
|
||||
progress.setVisibility(View.VISIBLE);
|
||||
namesFilter.cancelPreviousFilter(filter);
|
||||
namesFilter.filter(filter);
|
||||
NamesAdapter listAdapter = getListAdapter();
|
||||
int i = 0;
|
||||
boolean empty = filter.length() == 0;
|
||||
if (!empty) {
|
||||
while (i < listAdapter.getCount() && i < MAX_THRESHOLD_UI) {
|
||||
T item = listAdapter.getItem(i);
|
||||
String text = getText(item);
|
||||
if (endingSet.add(text)) {
|
||||
if (text.length() > MAX_VISIBLE_NAME) {
|
||||
text = text.substring(0, MAX_VISIBLE_NAME);
|
||||
}
|
||||
endingButton.setText(text + "..");
|
||||
endingObject = item;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (i >= listAdapter.getCount() || i == MAX_THRESHOLD_UI) {
|
||||
endingButton.setText("...");
|
||||
endingObject = null;
|
||||
}
|
||||
} else {
|
||||
endingButton.setText("...");
|
||||
endingObject = null;
|
||||
endingSet.clear();
|
||||
}
|
||||
|
||||
endingButton.forceLayout();
|
||||
|
||||
}
|
||||
|
||||
protected void addObjectToInitialList(T initial){
|
||||
|
|
|
@ -5,9 +5,11 @@ import java.util.ArrayList;
|
|||
import java.util.Comparator;
|
||||
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.RegionAddressRepository;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -27,6 +29,10 @@ public class SearchRegionByNameActivity extends SearchByNameAbstractActivity<Reg
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LatLon getLocation(RegionAddressRepository item) {
|
||||
return item.getEstimatedRegionCenter();
|
||||
}
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
Loading…
Reference in a new issue