diff --git a/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java index a9e85e0996..d5d2e2b7b5 100644 --- a/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/activities/DownloadIndexActivity.java @@ -85,7 +85,10 @@ public class DownloadIndexActivity extends ListActivity { public void onTextChanged(CharSequence s, int start, int before, int count) { - ((DownloadIndexAdapter)getListAdapter()).getFilter().filter(s); + DownloadIndexAdapter adapter = ((DownloadIndexAdapter)getListAdapter()); + if(adapter != null){ + adapter.getFilter().filter(s); + } } }; diff --git a/OsmAnd/src/net/osmand/activities/RoutingHelper.java b/OsmAnd/src/net/osmand/activities/RoutingHelper.java index d83e3a7460..cca64c4eda 100644 --- a/OsmAnd/src/net/osmand/activities/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/activities/RoutingHelper.java @@ -494,7 +494,9 @@ public class RoutingHelper { uiActivity.runOnUiThread(new Runnable() { @Override public void run() { - Toast.makeText(uiActivity, msg, Toast.LENGTH_SHORT).show(); + if(uiActivity != null){ + Toast.makeText(uiActivity, msg, Toast.LENGTH_SHORT).show(); + } } }); } diff --git a/OsmAnd/src/net/osmand/activities/search/SearchHistoryActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchHistoryActivity.java index a6b8b9aec8..705b21cbc4 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchHistoryActivity.java +++ b/OsmAnd/src/net/osmand/activities/search/SearchHistoryActivity.java @@ -8,12 +8,15 @@ import net.osmand.activities.MapActivity; import net.osmand.activities.search.SearchHistoryHelper.HistoryEntry; import net.osmand.osm.LatLon; import net.osmand.osm.MapUtils; +import android.app.AlertDialog; import android.app.ListActivity; +import android.content.DialogInterface; import android.content.Intent; 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.Button; import android.widget.ImageButton; @@ -45,6 +48,13 @@ public class SearchHistoryActivity extends ListActivity { setListAdapter(new HistoryAdapter(helper.getHistoryEntries(SearchHistoryActivity.this))); } }); + lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView av, View v, int pos, long id) { + return SearchHistoryActivity.this.onItemLongClick(pos); + } + + }); } @Override protected void onResume() { @@ -58,6 +68,32 @@ public class SearchHistoryActivity extends ListActivity { setListAdapter(new HistoryAdapter(historyEntries)); } + private boolean onItemLongClick(int pos) { + final HistoryEntry entry = ((HistoryAdapter) getListAdapter()).getItem(pos); + AlertDialog.Builder builder = new AlertDialog.Builder(SearchHistoryActivity.this); + builder.setTitle(entry.getName()); + builder.setItems(new String[] { getString(R.string.show_poi_on_map), getString(R.string.navigate_to) }, + new DialogInterface.OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + if (which == 0) { + OsmandSettings.setMapLocationToShow(SearchHistoryActivity.this, entry.getLat(), entry.getLon()); + } else if (which == 1) { + OsmandSettings.setPointToNavigate(SearchHistoryActivity.this, entry.getLat(), entry.getLon()); + } + + Intent newIntent = new Intent(SearchHistoryActivity.this, MapActivity.class); + startActivity(newIntent); + + } + + }); + builder.show(); + return true; + } + + @Override protected void onListItemClick(ListView l, View v, int position, long id) { HistoryEntry model = ((HistoryAdapter)getListAdapter()).getItem(position); @@ -78,7 +114,7 @@ public class SearchHistoryActivity extends ListActivity { } @Override - public View getView(int position, View convertView, ViewGroup parent) { + public View getView(final int position, View convertView, ViewGroup parent) { View row = convertView; if (row == null) { LayoutInflater inflater = getLayoutInflater(); @@ -108,8 +144,16 @@ public class SearchHistoryActivity extends ListActivity { public void onClick(View v) { selectModel(model); } - }; + + View.OnLongClickListener longClickListener = new View.OnLongClickListener() { + @Override + public boolean onLongClick(View v) { + return onItemLongClick(position); + } + }; + distanceLabel.setOnLongClickListener(longClickListener); + label.setOnLongClickListener(longClickListener); distanceLabel.setOnClickListener(clickListener); label.setOnClickListener(clickListener); return row; diff --git a/OsmAnd/src/net/osmand/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/activities/search/SearchPOIActivity.java index 5bf0337749..420f8d59e8 100644 --- a/OsmAnd/src/net/osmand/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/activities/search/SearchPOIActivity.java @@ -210,7 +210,6 @@ public class SearchPOIActivity extends ListActivity implements SensorEventListen // ListActivity has a ListView, which you can get with: ListView lv = getListView(); - // Then you can create a listener like so: lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView av, View v, int pos, long id) {