add edit filter activity draft

git-svn-id: https://osmand.googlecode.com/svn/trunk@191 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
frolovmo 2010-06-21 16:00:22 +00:00
parent 643d3230e9
commit 864efadc42
7 changed files with 171 additions and 0 deletions

View file

@ -25,6 +25,7 @@
<activity android:name=".activities.search.SearchStreet2ByNameActivity"></activity> <activity android:name=".activities.search.SearchStreet2ByNameActivity"></activity>
<activity android:name=".activities.search.SearchBuildingByNameActivity"></activity> <activity android:name=".activities.search.SearchBuildingByNameActivity"></activity>
<activity android:name=".activities.EditPOIFilterActivity"></activity>
</application> </application>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_weight="1" android:text="@string/filter_current_poiButton" android:id="@+id/filter_currentButton"></Button>
<TextView android:layout_width="wrap_content" android:text="" android:id="@+id/SearchAreaText" android:layout_height="wrap_content"/>
</LinearLayout>
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:choiceMode="multipleChoice"
android:layout_height="fill_parent"></ListView>
</LinearLayout>

View file

@ -0,0 +1,15 @@
<?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">
<CheckBox android:id="@+id/filter_poi_check"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="25px"></CheckBox>
<TextView android:id="@+id/filter_poi_label"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textSize="25px"></TextView>
</LinearLayout>

View file

@ -211,4 +211,5 @@
<string name="poi_context_menu_delete">Удалить</string> <string name="poi_context_menu_delete">Удалить</string>
<string name="default_buttons_commit">Сохранить</string> <string name="default_buttons_commit">Сохранить</string>
<string name="default_buttons_reset">Сброс</string> <string name="default_buttons_reset">Сброс</string>
<string name="filter_current_poiButton">Фильтровать</string>
</resources> </resources>

View file

@ -213,4 +213,5 @@
<string name="poi_context_menu_delete">Delete</string> <string name="poi_context_menu_delete">Delete</string>
<string name="default_buttons_commit">Commit</string> <string name="default_buttons_commit">Commit</string>
<string name="default_buttons_reset">Reset</string> <string name="default_buttons_reset">Reset</string>
<string name="filter_current_poiButton">Filter</string>
</resources> </resources>

View file

@ -0,0 +1,119 @@
/**
*
*/
package com.osmand.activities;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
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.CheckBox;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import com.osmand.PoiFilter;
import com.osmand.PoiFiltersHelper;
import com.osmand.R;
import com.osmand.activities.search.SearchPOIActivity;
import com.osmand.data.AmenityType;
/**
* @author Frolov
*
*/
public class EditPOIFilterActivity extends ListActivity {
private Button filterLevel;
private PoiFilter filter;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.editing_poi_filter);
filterLevel = (Button) findViewById(R.id.filter_currentButton);
filterLevel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO
}
});
Bundle bundle = this.getIntent().getExtras();
String filterId = bundle.getString(SearchPOIActivity.AMENITY_FILTER);
filter = PoiFiltersHelper.getFilterById(this, filterId);
setListAdapter(new AmenityAdapter(AmenityType.getCategories()));
}
private void showDialog(AmenityType amenity) {
Builder builder = new AlertDialog.Builder(this);
ScrollView scroll = new ScrollView(this);
ListView listView = new ListView(this);
scroll.addView(listView);
builder.setView(scroll);
builder.setNegativeButton("Close", null);
builder.setNeutralButton("Select all", null);
builder.setMultiChoiceItems(AmenityType.getSubCategories(amenity).toArray(new String[0]), null, null);
builder.show();
}
class AmenityAdapter extends ArrayAdapter<AmenityType> {
AmenityAdapter(AmenityType[] amenityTypes) {
super(EditPOIFilterActivity.this, R.layout.editing_poi_filter_list, amenityTypes);
}
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = convertView;
if (row == null) {
row = inflater.inflate(R.layout.editing_poi_filter_list, parent, false);
}
AmenityType model = getItem(position);
CheckBox check = (CheckBox) row.findViewById(R.id.filter_poi_check);
check.setChecked(filter.isTypeAccepted(model));
TextView text = (TextView) row.findViewById(R.id.filter_poi_label);
text.setText(AmenityType.toPublicString(model));
addRowListener(model, text, check);
return (row);
}
private void addRowListener(final AmenityType model,final TextView text, final CheckBox check) {
text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(model);
}
});
check.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(check.isChecked()) {
showDialog(model);
} else {
filter.setTypeToAccept(model,false);
}
}
});
}
}
}

View file

@ -13,6 +13,7 @@ import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView; import android.widget.ListView;
@ -22,6 +23,7 @@ import com.osmand.OsmandSettings;
import com.osmand.PoiFilter; import com.osmand.PoiFilter;
import com.osmand.PoiFiltersHelper; import com.osmand.PoiFiltersHelper;
import com.osmand.R; import com.osmand.R;
import com.osmand.activities.EditPOIFilterActivity;
/** /**
* @author Maxim Frolov * @author Maxim Frolov
@ -42,6 +44,26 @@ public class SearchPoiFilterActivity extends ListActivity {
filters.addAll(PoiFiltersHelper.getOsmDefinedPoiFilters(this)); filters.addAll(PoiFiltersHelper.getOsmDefinedPoiFilters(this));
setListAdapter(new AmenityAdapter(filters)); setListAdapter(new AmenityAdapter(filters));
typeFace = Typeface.create((String)null, Typeface.ITALIC); typeFace = Typeface.create((String)null, Typeface.ITALIC);
// 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) {
PoiFilter poi = ((AmenityAdapter) getListAdapter()).getItem(pos);
if(!poi.isStandardFilter()) {
Bundle bundle = new Bundle();
Intent newIntent = new Intent(SearchPoiFilterActivity.this, EditPOIFilterActivity.class);
// folder selected
bundle.putString(SearchPOIActivity.AMENITY_FILTER, poi.getFilterId());
newIntent.putExtras(bundle);
startActivityForResult(newIntent, 0);
}
return true;
}
});
} }