add search POI draft
git-svn-id: https://osmand.googlecode.com/svn/trunk@103 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
parent
b726918d38
commit
6867c31a2d
13 changed files with 268 additions and 56 deletions
|
@ -14,9 +14,11 @@
|
|||
</activity>
|
||||
<activity android:name=".activities.SettingsActivity"
|
||||
android:label="@string/settings_activity"></activity>
|
||||
<activity android:name=".activities.SearchActivity"
|
||||
android:label="@string/search_activity"></activity>
|
||||
<activity android:label="@string/search_activity" android:name=".activities.search.SearchActivity"></activity>
|
||||
|
||||
<activity android:name=".activities.search.SearchPOIActivity" android:label="@string/searchpoi_activity"></activity>
|
||||
<activity android:name=".activities.search.SearchPOIListActivity"></activity>
|
||||
<activity android:name=".activities.search.SearchAddress"></activity>
|
||||
</application>
|
||||
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This file is at /res/layout/list.xml -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
|
||||
android:layout_height="0dip" android:layout_weight="1"
|
||||
android:stackFromBottom="true" android:transcriptMode="normal" />
|
||||
android:layout_width="fill_parent" android:orientation="vertical"
|
||||
android:layout_height="fill_parent" android:background="@color/menu_background">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
6
OsmAnd/res/layout/searchaddress.xml
Normal file
6
OsmAnd/res/layout/searchaddress.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
</LinearLayout>
|
11
OsmAnd/res/layout/searchpoi.xml
Normal file
11
OsmAnd/res/layout/searchpoi.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This file is at /res/layout/list.xml -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/search_POI_level_btn" android:id="@+id/SearchPOILevelButton"></Button><ListView android:id="@android:id/list" android:layout_width="fill_parent"
|
||||
android:layout_height="0dip" android:layout_weight="1"
|
||||
android:stackFromBottom="true" android:transcriptMode="normal" ></ListView>
|
||||
|
||||
|
||||
</LinearLayout>
|
16
OsmAnd/res/layout/searchpoi_list.xml
Normal file
16
OsmAnd/res/layout/searchpoi_list.xml
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView android:id="@+id/poi_icon" android:layout_width="25px"
|
||||
android:paddingLeft="2px" android:paddingRight="2px"
|
||||
android:paddingTop="2px" android:layout_height="fill_parent" />
|
||||
|
||||
<TextView android:id="@+id/poidistance_label"
|
||||
android:layout_width="wrap_content" android:layout_height="wrap_content"
|
||||
android:textSize="25px" />
|
||||
<TextView android:id="@+id/poi_label" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:textSize="25px" />
|
||||
|
||||
</LinearLayout>
|
|
@ -1,9 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
|
||||
<ImageView android:id="@+id/icon" android:layout_width="25px"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView android:id="@+id/folder_icon" android:layout_width="25px"
|
||||
android:paddingLeft="2px" android:paddingRight="2px"
|
||||
android:paddingTop="2px" android:layout_height="fill_parent"/>
|
||||
<TextView android:id="@+id/label" android:layout_width="wrap_content"
|
||||
android:paddingTop="2px" android:layout_height="fill_parent" />
|
||||
<TextView android:id="@+id/folder_label" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:textSize="25px" />
|
||||
</LinearLayout>
|
11
OsmAnd/res/layout/searchpoilist.xml
Normal file
11
OsmAnd/res/layout/searchpoilist.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This file is at /res/layout/list.xml -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
|
||||
android:layout_height="0dip" android:layout_weight="1"
|
||||
android:stackFromBottom="true" android:transcriptMode="normal" ></ListView>
|
||||
|
||||
|
||||
</LinearLayout>
|
|
@ -33,4 +33,6 @@
|
|||
<string name="search_activity">search</string>
|
||||
<color name="color_white">#FFFFFF</color>
|
||||
<color name="color_red">#FF0000</color>
|
||||
<string name="searchpoi_activity">searchpoi_activity</string>
|
||||
<string name="search_POI_level_btn">Find more</string>
|
||||
</resources>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
41
OsmAnd/src/com/osmand/activities/search/SearchActivity.java
Normal file
41
OsmAnd/src/com/osmand/activities/search/SearchActivity.java
Normal file
|
@ -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)));
|
||||
}
|
||||
|
||||
}
|
16
OsmAnd/src/com/osmand/activities/search/SearchAddress.java
Normal file
16
OsmAnd/src/com/osmand/activities/search/SearchAddress.java
Normal file
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<String> amenityList = new ArrayList<String>();
|
||||
Map<AmenityType, List<Amenity>> filter;
|
||||
|
||||
private List<Amenity> 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<Amenity> 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<AmenityType, List<Amenity>>();
|
||||
LatLon lastKnownMapLocation = OsmandSettings.getLastKnownMapLocation(this);
|
||||
List<Amenity> 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
|
||||
|
@ -118,24 +126,25 @@ public class SearchActivity extends ListActivity {
|
|||
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);
|
|
@ -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<String> amenityList = new ArrayList<String>();
|
||||
Map<AmenityType, List<Amenity>> 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));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue