diff --git a/OsmAnd/AndroidManifest.xml b/OsmAnd/AndroidManifest.xml index 6535820da9..2afc0d9c41 100644 --- a/OsmAnd/AndroidManifest.xml +++ b/OsmAnd/AndroidManifest.xml @@ -14,9 +14,11 @@ - + + + + diff --git a/OsmAnd/res/layout/search.xml b/OsmAnd/res/layout/search.xml index 04134a0189..aefec27c8c 100644 --- a/OsmAnd/res/layout/search.xml +++ b/OsmAnd/res/layout/search.xml @@ -1,10 +1,12 @@ - - + android:layout_width="fill_parent" android:orientation="vertical" + android:layout_height="fill_parent" android:background="@color/menu_background"> + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/searchaddress.xml b/OsmAnd/res/layout/searchaddress.xml new file mode 100644 index 0000000000..fe20d9d7ce --- /dev/null +++ b/OsmAnd/res/layout/searchaddress.xml @@ -0,0 +1,6 @@ + + + diff --git a/OsmAnd/res/layout/searchpoi.xml b/OsmAnd/res/layout/searchpoi.xml new file mode 100644 index 0000000000..f4238a877e --- /dev/null +++ b/OsmAnd/res/layout/searchpoi.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/searchpoi_list.xml b/OsmAnd/res/layout/searchpoi_list.xml new file mode 100644 index 0000000000..67f3dd7bc7 --- /dev/null +++ b/OsmAnd/res/layout/searchpoi_list.xml @@ -0,0 +1,16 @@ + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/searchlist.xml b/OsmAnd/res/layout/searchpoifolder_list.xml similarity index 52% rename from OsmAnd/res/layout/searchlist.xml rename to OsmAnd/res/layout/searchpoifolder_list.xml index 7aa243025b..609edee28d 100644 --- a/OsmAnd/res/layout/searchlist.xml +++ b/OsmAnd/res/layout/searchpoifolder_list.xml @@ -1,9 +1,11 @@ - + + - + - \ No newline at end of file + diff --git a/OsmAnd/res/layout/searchpoilist.xml b/OsmAnd/res/layout/searchpoilist.xml new file mode 100644 index 0000000000..15ba603a6f --- /dev/null +++ b/OsmAnd/res/layout/searchpoilist.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index c1bb1c9f3d..6efb660846 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -33,4 +33,6 @@ search #FFFFFF #FF0000 +searchpoi_activity +Find more diff --git a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java index 787dc3d576..68467f93c4 100644 --- a/OsmAnd/src/com/osmand/activities/MainMenuActivity.java +++ b/OsmAnd/src/com/osmand/activities/MainMenuActivity.java @@ -28,6 +28,7 @@ import com.osmand.LogUtil; import com.osmand.ProgressDialogImplementation; import com.osmand.R; import com.osmand.ResourceManager; +import com.osmand.activities.search.SearchActivity; public class MainMenuActivity extends Activity { @@ -126,11 +127,9 @@ public class MainMenuActivity extends Activity { searchButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - Bundle bundle = new Bundle(); - bundle.putString(SearchActivity.ANENITY_TYPE, null); final Intent search = new Intent(MainMenuActivity.this, SearchActivity.class); - search.putExtras(bundle); +// search.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(search); } }); diff --git a/OsmAnd/src/com/osmand/activities/search/SearchActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java new file mode 100644 index 0000000000..9c43b07708 --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/search/SearchActivity.java @@ -0,0 +1,41 @@ +/** + * + */ +package com.osmand.activities.search; + +import android.app.TabActivity; +import android.content.Intent; +import android.os.Bundle; +import android.widget.Button; +import android.widget.TabHost; + +/** + * @author Maxim Frolov + * + */ +public class SearchActivity extends TabActivity { + + Button searchPOIButton; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); +// +// setContentView(R.layout.search); +// +// searchPOIButton = (Button) findViewById(R.id.SearchPOIButton); +// searchPOIButton.setOnClickListener(new OnClickListener() { +// @Override +// public void onClick(View v) { +// final Intent search = new Intent(SearchActivity.this, SearchPOIListActivity.class); +// search.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); +// startActivity(search); +// +// } +// }); + TabHost host = getTabHost(); + host.addTab(host.newTabSpec("Search_POI").setIndicator("Search POI").setContent(new Intent(this, SearchPOIListActivity.class))); + host.addTab(host.newTabSpec("Search_Adress").setIndicator("Search Address").setContent(new Intent(this, SearchAddress.class))); + } + +} diff --git a/OsmAnd/src/com/osmand/activities/search/SearchAddress.java b/OsmAnd/src/com/osmand/activities/search/SearchAddress.java new file mode 100644 index 0000000000..e666526366 --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/search/SearchAddress.java @@ -0,0 +1,16 @@ +package com.osmand.activities.search; + + +import com.osmand.R; + +import android.app.Activity; +import android.os.Bundle; + +public class SearchAddress extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.searchaddress); + } +} diff --git a/OsmAnd/src/com/osmand/activities/SearchActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java similarity index 57% rename from OsmAnd/src/com/osmand/activities/SearchActivity.java rename to OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java index 8a8a3feff3..a393da095d 100644 --- a/OsmAnd/src/com/osmand/activities/SearchActivity.java +++ b/OsmAnd/src/com/osmand/activities/search/SearchPOIActivity.java @@ -1,7 +1,7 @@ /** * */ -package com.osmand.activities; +package com.osmand.activities.search; import java.util.ArrayList; import java.util.List; @@ -10,11 +10,14 @@ import java.util.TreeMap; import android.app.ListActivity; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.View.OnClickListener; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; @@ -23,6 +26,7 @@ import com.osmand.Algoritms; import com.osmand.OsmandSettings; import com.osmand.R; import com.osmand.ResourceManager; +import com.osmand.activities.MapActivity; import com.osmand.data.Amenity; import com.osmand.data.Amenity.AmenityType; import com.osmand.osm.LatLon; @@ -32,45 +36,53 @@ import com.osmand.osm.MapUtils; * @author Maxim Frolov * */ -public class SearchActivity extends ListActivity { +public class SearchPOIActivity extends ListActivity { public static final String ANENITY_TYPE = "amenity_type"; - List amenityList = new ArrayList(); Map> filter; + private List amenityList; + + private Button searchPOILevel; + private int zoom = 12; + + private AmenityType amenityType; + + private AmenityAdapter amenityAdapter; + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); - setContentView(R.layout.search); - createAmenityTypeList(); + setContentView(R.layout.searchpoi); + searchPOILevel = (Button) findViewById(R.id.SearchPOILevelButton); + searchPOILevel.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + + } + }); Bundle bundle = this.getIntent().getExtras(); String anemity = bundle.getString(ANENITY_TYPE); if (anemity != null) { - AmenityType amenityType = findAmenityType(anemity); - createAmenityFilter(); - List list = filter.get(amenityType); - if(list != null) { - setListAdapter(new AmenityAdapter(filter.get(amenityType))); + amenityType = findAmenityType(anemity); + createAmenityFilter(zoom); + amenityList = filter.get(amenityType); + if(amenityList != null) { + amenityAdapter = new AmenityAdapter(amenityList); + setListAdapter(amenityAdapter); } - } else { - setListAdapter(new AmenityAdapter(amenityList)); - } + } } - private void createAmenityTypeList() { - for (AmenityType type : AmenityType.values()) { - amenityList.add(Algoritms.capitalizeFirstLetterAndLowercase(type.toString())); - } - } - private void createAmenityFilter() { + private void createAmenityFilter(int zoom) { ResourceManager resourceManager = ResourceManager.getResourceManager(); filter = new TreeMap>(); LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this); List closestAmenities = resourceManager.searchAmenities(lastKnownMapLocation.getLatitude(), - lastKnownMapLocation.getLongitude(), 12, 500); + lastKnownMapLocation.getLongitude(), zoom, 500); MapUtils.sortListOfMapObject(closestAmenities, lastKnownMapLocation.getLatitude(), lastKnownMapLocation.getLongitude()); for (Amenity n : closestAmenities) { AmenityType type = n.getType(); @@ -83,16 +95,12 @@ public class SearchActivity extends ListActivity { } public void onListItemClick(ListView parent, View v, int position, long id) { - AmenityType amenityType = findAmenityType(amenityList.get(position)); - // folder selected - if (amenityType != null) { - Bundle bundle = new Bundle(); - bundle.putString(ANENITY_TYPE, amenityList.get(position)); - Intent newIntent = new Intent(this.getApplicationContext(), SearchActivity.class); - newIntent.putExtras(bundle); - startActivityForResult(newIntent, 0); - } else { - // poi selected + SharedPreferences prefs = getSharedPreferences(OsmandSettings.SHARED_PREFERENCES_NAME, MODE_WORLD_READABLE); + if(prefs != null ){ + Amenity amenity = amenityList.get(position); + OsmandSettings.setLastKnownMapLocation(this,amenity.getLocation().getLatitude(),amenity.getLocation().getLongitude()); + Intent newIntent = new Intent(this.getApplicationContext(), MapActivity.class); + startActivity(newIntent); } } @@ -109,7 +117,7 @@ public class SearchActivity extends ListActivity { @SuppressWarnings("unchecked") class AmenityAdapter extends ArrayAdapter { AmenityAdapter(Object list) { - super(SearchActivity.this, R.layout.searchlist, (List) list); + super(SearchPOIActivity.this, R.layout.searchpoi_list, (List) list); } @Override @@ -117,25 +125,26 @@ public class SearchActivity extends ListActivity { int c = super.getCount(); return c > 20 ? 20 : c; } + + public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = getLayoutInflater(); - View row = inflater.inflate(R.layout.searchlist, parent, false); - TextView label = (TextView) row.findViewById(R.id.label); - ImageView icon = (ImageView) row.findViewById(R.id.icon); + View row = inflater.inflate(R.layout.searchpoi_list, parent, false); + TextView label = (TextView) row.findViewById(R.id.poi_label); + TextView distanceLabel = (TextView) row.findViewById(R.id.poidistance_label); + ImageView icon = (ImageView) row.findViewById(R.id.poi_icon); Object model = getModel(position); - if (model instanceof String) { - label.setText((String) model); - icon.setImageResource(R.drawable.folder); - } else if (model instanceof Amenity) { + if (model instanceof Amenity) { Amenity anemity = (Amenity) model; if (anemity != null) { - LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(SearchActivity.this); + LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(SearchPOIActivity.this); int dist = (int) (MapUtils.getDistance(anemity.getLocation(), lastKnownMapLocation.getLatitude(), lastKnownMapLocation .getLongitude())); - String str = anemity.getStringWithoutType() + " [" + dist + " m ]"; + String str = anemity.getStringWithoutType(); label.setText(str); icon.setImageResource(R.drawable.poi); + distanceLabel.setText(" " +dist + " m "); } } return (row); diff --git a/OsmAnd/src/com/osmand/activities/search/SearchPOIListActivity.java b/OsmAnd/src/com/osmand/activities/search/SearchPOIListActivity.java new file mode 100644 index 0000000000..9a50594165 --- /dev/null +++ b/OsmAnd/src/com/osmand/activities/search/SearchPOIListActivity.java @@ -0,0 +1,95 @@ +/** + * + */ +package com.osmand.activities.search; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import android.app.ListActivity; +import android.content.Intent; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.ListView; +import android.widget.TextView; + +import com.osmand.Algoritms; +import com.osmand.R; +import com.osmand.data.Amenity; +import com.osmand.data.Amenity.AmenityType; + +/** + * @author Maxim Frolov + * + */ +public class SearchPOIListActivity extends ListActivity { + + + List amenityList = new ArrayList(); + Map> filter; + + @Override + public void onCreate(Bundle icicle) { + super.onCreate(icicle); + setContentView(R.layout.searchpoilist); + createAmenityTypeList(); + setListAdapter(new AmenityAdapter(amenityList)); + + } + + private void createAmenityTypeList() { + for (AmenityType type : AmenityType.values()) { + amenityList.add(Algoritms.capitalizeFirstLetterAndLowercase(type.toString())); + } + + } + + public void onListItemClick(ListView parent, View v, int position, long id) { + AmenityType amenityType = findAmenityType(amenityList.get(position)); + // folder selected + if (amenityType != null) { + Bundle bundle = new Bundle(); + bundle.putString(SearchPOIActivity.ANENITY_TYPE, amenityList.get(position)); + Intent newIntent = new Intent(this.getApplicationContext(), SearchPOIActivity.class); + newIntent.putExtras(bundle); + startActivityForResult(newIntent, 0); + } + } + + private AmenityType findAmenityType(String string) { + for (AmenityType type : AmenityType.values()) { + if (string.equals(Algoritms.capitalizeFirstLetterAndLowercase(type.toString()))) { + return type; + } + } + return null; + + } + + @SuppressWarnings("unchecked") + class AmenityAdapter extends ArrayAdapter { + AmenityAdapter(Object list) { + super(SearchPOIListActivity.this, R.layout.searchpoi_list, (List) list); + } + + public View getView(int position, View convertView, ViewGroup parent) { + LayoutInflater inflater = getLayoutInflater(); + View row = inflater.inflate(R.layout.searchpoifolder_list, parent, false); + TextView label = (TextView) row.findViewById(R.id.folder_label); + ImageView icon = (ImageView) row.findViewById(R.id.folder_icon); + Object model = getModel(position); + label.setText((String) model); + icon.setImageResource(R.drawable.folder); + return (row); + } + + private Object getModel(int position) { + return (((AmenityAdapter) getListAdapter()).getItem(position)); + } + } +}