From 8e03bb33fe6898cd17691851f9935ddf39e232c9 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 11 Sep 2011 17:16:43 +0200 Subject: [PATCH] Improving search UI --- .../plus/activities/DownloadFileHelper.java | 3 -- .../osmand/plus/activities/MapActivity.java | 13 +++++- .../activities/NavigatePointActivity.java | 26 ++++++++++- .../osmand/plus/activities/RoutingHelper.java | 3 -- .../activities/ShowRouteInfoActivity.java | 1 - .../activities/search/SearchActivity.java | 46 +++++++++++++++---- .../search/SearchHistoryActivity.java | 15 +++++- .../activities/search/SearchPOIActivity.java | 5 +- .../search/SearchPoiFilterActivity.java | 4 +- .../search/SearchTransportActivity.java | 22 +++++---- .../net/osmand/plus/views/MapTileAdapter.java | 1 - 11 files changed, 102 insertions(+), 37 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java b/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java index 9d17c586e7..860f82aaea 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadFileHelper.java @@ -15,9 +15,6 @@ import java.util.zip.ZipInputStream; import org.apache.commons.logging.Log; import android.app.Activity; -import android.graphics.drawable.Drawable.Callback; -import android.os.AsyncTask; -import android.widget.Toast; import net.osmand.IProgress; import net.osmand.LogUtil; diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 163fc19b91..9c569190ba 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -454,6 +454,9 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso @Override public void onClick(View v) { final Intent search = new Intent(MapActivity.this, SearchActivity.class); + LatLon loc = getMapLocation(); + search.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude()); + search.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude()); search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); MapActivity.this.startActivity(search); dlg.dismiss(); @@ -478,6 +481,9 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) { Intent newIntent = new Intent(MapActivity.this, SearchActivity.class); newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + LatLon loc = getMapLocation(); + newIntent.putExtra(SearchActivity.SEARCH_LAT, loc.getLatitude()); + newIntent.putExtra(SearchActivity.SEARCH_LON, loc.getLongitude()); startActivity(newIntent); return true; } else if (!routingHelper.isFollowingMode()) { @@ -1012,6 +1018,9 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso Intent newIntent = new Intent(MapActivity.this, SearchActivity.class); newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); newIntent.putExtra(SearchActivity.TAB_INDEX_EXTRA, SearchActivity.LOCATION_TAB_INDEX); + LatLon mapLoc = getMapLocation(); + newIntent.putExtra(SearchActivity.SEARCH_LAT, mapLoc.getLatitude()); + newIntent.putExtra(SearchActivity.SEARCH_LON, mapLoc.getLongitude()); startActivity(newIntent); return true; case R.id.map_mute: @@ -1151,8 +1160,8 @@ public class MapActivity extends Activity implements IMapLocationListener, Senso startActivity(intent); } else if(standardId == R.string.context_menu_item_search_transport){ Intent intent = new Intent(MapActivity.this, SearchTransportActivity.class); - intent.putExtra(SearchTransportActivity.LAT_KEY, latitude); - intent.putExtra(SearchTransportActivity.LON_KEY, longitude); + intent.putExtra(SearchTransportActivity.SEARCH_LAT, latitude); + intent.putExtra(SearchTransportActivity.SEARCH_LON, longitude); startActivity(intent); } else if(standardId == R.string.context_menu_item_add_favorite){ mapActions.addFavouritePoint(latitude, longitude); diff --git a/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java b/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java index 6867f6d7f3..cc5d4894ad 100644 --- a/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/NavigatePointActivity.java @@ -11,9 +11,11 @@ import net.osmand.osm.LatLon; import net.osmand.osm.MapUtils; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.activities.search.SearchActivity; import net.osmand.plus.views.OsmandMapTileView; import android.app.Activity; import android.app.Dialog; +import android.content.Intent; import android.location.Location; import android.os.Bundle; import android.util.Log; @@ -28,6 +30,9 @@ public class NavigatePointActivity extends Activity { MapActivity activity; int currentFormat = Location.FORMAT_DEGREES; + public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; + public static final String SEARCH_LON = SearchActivity.SEARCH_LON; + // dialog constructor public NavigatePointActivity(MapActivity activity){ this.activity = activity; @@ -48,13 +53,30 @@ public class NavigatePointActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - LatLon loc = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); + setContentView(R.layout.navigate_point); setTitle(R.string.map_specify_point); - initUI(loc.getLatitude(), loc.getLongitude()); ((Button) findViewById(R.id.Cancel)).setText(getString(R.string.navigate_to)); } + @Override + protected void onResume() { + super.onResume(); + LatLon loc = null; + Intent intent = getIntent(); + if(intent != null){ + float lat = intent.getFloatExtra(SEARCH_LAT, 0); + float lon = intent.getFloatExtra(SEARCH_LON, 0); + if(lat != 0 || lon != 0){ + loc = new LatLon(lat, lon); + } + } + if (loc == null) { + loc = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); + } + initUI(loc.getLatitude(), loc.getLongitude()); + } + @Override public View findViewById(int id) { if(dlg != null){ diff --git a/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java index 7da3f7ddee..b666f1aea2 100644 --- a/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java +++ b/OsmAnd/src/net/osmand/plus/activities/RoutingHelper.java @@ -7,9 +7,6 @@ import java.util.List; import net.osmand.LogUtil; import net.osmand.OsmAndFormatter; import net.osmand.GPXUtilities.GPXFile; -import net.osmand.GPXUtilities.Track; -import net.osmand.GPXUtilities.TrkSegment; -import net.osmand.GPXUtilities.WptPt; import net.osmand.osm.LatLon; import net.osmand.osm.MapUtils; import net.osmand.plus.OsmandSettings; diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java index c44a753b2a..1cd8605024 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoActivity.java @@ -13,7 +13,6 @@ import net.osmand.plus.activities.RoutingHelper.RouteDirectionInfo; import net.osmand.plus.activities.RoutingHelper.TurnType; import net.osmand.plus.views.MapInfoLayer; import android.app.ListActivity; -import android.content.Intent; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java index cb7347eddf..40d75b76c4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchActivity.java @@ -3,6 +3,7 @@ package net.osmand.plus.activities.search; import net.osmand.osm.LatLon; import net.osmand.plus.R; import net.osmand.plus.activities.NavigatePointActivity; +import android.app.Activity; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; @@ -18,9 +19,13 @@ public class SearchActivity extends TabActivity { public static final int TRANSPORT_TAB_INDEX = 3; public static final int HISTORY_TAB_INDEX = 4; public static final String TAB_INDEX_EXTRA = "TAB_INDEX_EXTRA"; + + public static final String SEARCH_LAT = "net.osmand.search_lat"; //$NON-NLS-1$ + public static final String SEARCH_LON = "net.osmand.search_lon"; //$NON-NLS-1$ Button searchPOIButton; private TabSpec addressSpec; + private LatLon searchPoint = null; private static boolean searchOnLine = false; @@ -28,45 +33,66 @@ public class SearchActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + } + + @Override + protected void onResume() { + super.onResume(); Intent intent = getIntent(); -// LatLon latLon = null; int tabIndex = 0; if(intent != null){ tabIndex = intent.getIntExtra(TAB_INDEX_EXTRA, POI_TAB_INDEX); + float lat = intent.getFloatExtra(SEARCH_LAT, 0); + float lon = intent.getFloatExtra(SEARCH_LON, 0); + if(lat != 0 || lon != 0){ + searchPoint = new LatLon(lat, lon); + } } TabHost host = getTabHost(); + // TODO investigate proper intent with lat/lon ? host.addTab(host.newTabSpec("Search_POI").setIndicator(getString(R.string.poi)).setContent(new Intent(this, SearchPoiFilterActivity.class))); //$NON-NLS-1$ addressSpec = host.newTabSpec("Search_Address").setIndicator(getString(R.string.address)); - setAddressSpecContent(); + setAddressSpecContent(searchPoint); host.addTab(addressSpec); - host.addTab(host.newTabSpec("Search_Location").setIndicator(getString(R.string.search_tabs_location)).setContent(new Intent(this, NavigatePointActivity.class))); //$NON-NLS-1$ -// host.addTab(host.newTabSpec("Search_Transport").setIndicator(getString(R.string.transport)).setContent(new Intent(this, SearchTransportActivity.class))); //$NON-NLS-1$ - host.addTab(host.newTabSpec("Search_History").setIndicator(getString(R.string.history)).setContent(new Intent(this, SearchHistoryActivity.class))); //$NON-NLS-1$ + host.addTab(host.newTabSpec("Search_Location").setIndicator(getString(R.string.search_tabs_location)).setContent(createIntent(NavigatePointActivity.class))); //$NON-NLS-1$ + if (searchPoint != null) { + host.addTab(host.newTabSpec("Search_Transport").setIndicator(getString(R.string.transport)).setContent(createIntent(SearchTransportActivity.class))); //$NON-NLS-1$ + } + host.addTab(host.newTabSpec("Search_History").setIndicator(getString(R.string.history)).setContent(createIntent(SearchHistoryActivity.class))); //$NON-NLS-1$ host.setCurrentTab(tabIndex); } + private Intent createIntent(Class cl){ + Intent intent = new Intent(this, cl); + if(searchPoint != null){ + intent.putExtra(SearchActivity.SEARCH_LAT, searchPoint.getLatitude()); + intent.putExtra(SearchActivity.SEARCH_LON, searchPoint.getLongitude()); + } + return intent; + } + public void startSearchAddressOffline(){ searchOnLine = false; getTabHost().setCurrentTab(0); - setAddressSpecContent(); + setAddressSpecContent(searchPoint); getTabHost().setCurrentTab(1); } public void startSearchAddressOnline(){ searchOnLine = true; getTabHost().setCurrentTab(0); - setAddressSpecContent(); + setAddressSpecContent(searchPoint); getTabHost().setCurrentTab(1); } - public void setAddressSpecContent() { + public void setAddressSpecContent(LatLon latLon) { if (searchOnLine) { - addressSpec.setContent(new Intent(this, SearchAddressOnlineActivity.class)); + addressSpec.setContent(createIntent(SearchAddressOnlineActivity.class)); } else { - addressSpec.setContent(new Intent(this, SearchAddressActivity.class)); + addressSpec.setContent(createIntent(SearchAddressOnlineActivity.class)); } } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java index 16fd1c26cf..f0ce656a81 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchHistoryActivity.java @@ -1,5 +1,6 @@ package net.osmand.plus.activities.search; + import java.util.List; import net.osmand.OsmAndFormatter; @@ -28,6 +29,8 @@ public class SearchHistoryActivity extends ListActivity { private LatLon location; private SearchHistoryHelper helper; private Button clearButton; + public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; + public static final String SEARCH_LON = SearchActivity.SEARCH_LON; @Override protected void onCreate(Bundle savedInstanceState) { @@ -36,7 +39,17 @@ public class SearchHistoryActivity extends ListActivity { lv.setId(android.R.id.list); setContentView(lv); - location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); + Intent intent = getIntent(); + if(intent != null){ + float lat = intent.getFloatExtra(SEARCH_LAT, 0); + float lon = intent.getFloatExtra(SEARCH_LON, 0); + if(lat != 0 || lon != 0){ + location = new LatLon(lat, lon); + } + } + if (location == null) { + location = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); + } helper = SearchHistoryHelper.getInstance(); diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 494643c506..45678e8858 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -24,7 +24,6 @@ import net.osmand.plus.activities.OsmandApplication; import android.app.AlertDialog; import android.app.ListActivity; import android.content.DialogInterface; -import android.content.Intent; import android.content.pm.ActivityInfo; import android.graphics.Canvas; import android.graphics.Color; @@ -71,8 +70,8 @@ import android.widget.Toast; public class SearchPOIActivity extends ListActivity implements SensorEventListener { public static final String AMENITY_FILTER = "net.osmand.amenity_filter"; //$NON-NLS-1$ - public static final String SEARCH_LAT = "net.osmand.am_search_lat"; //$NON-NLS-1$ - public static final String SEARCH_LON = "net.osmand.am_search_lon"; //$NON-NLS-1$ + public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; //$NON-NLS-1$ + public static final String SEARCH_LON = SearchActivity.SEARCH_LON; //$NON-NLS-1$ private static final int GPS_TIMEOUT_REQUEST = 1000; private static final int GPS_DIST_REQUEST = 5; private static final int MIN_DISTANCE_TO_RESEARCH = 70; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterActivity.java index 131f479f2f..0431ecfe56 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPoiFilterActivity.java @@ -36,8 +36,8 @@ import android.widget.TextView; public class SearchPoiFilterActivity extends ListActivity { private Typeface typeFace; - public final static String SEARCH_LAT = "search_lat"; //$NON-NLS-1$ - public final static String SEARCH_LON = "search_lon"; //$NON-NLS-1$ + public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; + public static final String SEARCH_LON = SearchActivity.SEARCH_LON; private boolean searchNearBy = true; private double latitude = 0; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java index 82ee554c36..2180d51cf2 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchTransportActivity.java @@ -23,6 +23,7 @@ import android.app.AlertDialog; import android.app.ListActivity; import android.app.AlertDialog.Builder; import android.content.DialogInterface; +import android.content.Intent; import android.graphics.Typeface; import android.os.Bundle; import android.view.LayoutInflater; @@ -43,8 +44,8 @@ import android.widget.TextView; */ public class SearchTransportActivity extends ListActivity { - public static final String LAT_KEY = "lat"; //$NON-NLS-1$ - public static final String LON_KEY = "lon"; //$NON-NLS-1$ + public static final String SEARCH_LAT = SearchActivity.SEARCH_LAT; + public static final String SEARCH_LON = SearchActivity.SEARCH_LON; private Button searchTransportLevel; @@ -68,17 +69,20 @@ public class SearchTransportActivity extends ListActivity { private OsmandSettings settings; - - @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); settings = OsmandSettings.getOsmandSettings(this); - Bundle extras = getIntent().getExtras(); - if(extras != null && extras.containsKey(LAT_KEY) && extras.containsKey(LON_KEY)){ - lastKnownMapLocation = new LatLon(extras.getDouble(LAT_KEY), extras.getDouble(LON_KEY)); - } else { - lastKnownMapLocation = settings.getLastKnownMapLocation(); + Intent intent = getIntent(); + if(intent != null){ + float lat = intent.getFloatExtra(SEARCH_LAT, 0); + float lon = intent.getFloatExtra(SEARCH_LON, 0); + if(lat != 0 || lon != 0){ + lastKnownMapLocation = new LatLon(lat, lon); + } + } + if (lastKnownMapLocation == null) { + lastKnownMapLocation = OsmandSettings.getOsmandSettings(this).getLastKnownMapLocation(); } setContentView(R.layout.search_transport); searchTransportLevel = (Button) findViewById(R.id.SearchTransportLevelButton); diff --git a/OsmAnd/src/net/osmand/plus/views/MapTileAdapter.java b/OsmAnd/src/net/osmand/plus/views/MapTileAdapter.java index d08e6c4139..c305a77071 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapTileAdapter.java +++ b/OsmAnd/src/net/osmand/plus/views/MapTileAdapter.java @@ -2,7 +2,6 @@ package net.osmand.plus.views; import android.graphics.Canvas; import android.graphics.RectF; -import net.osmand.map.ITileSource; /** * This class is designed to represent adapter for specific map sources