Added ContextMenuAdapter for waypoints

This commit is contained in:
Denis 2014-10-24 18:26:39 +03:00
parent 37859475e6
commit 4a50d2c3eb
7 changed files with 433 additions and 207 deletions

View file

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginRight="3dp">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:id="@+id/ProgressBar"
android:layout_marginLeft="4dp"/>
<TextView android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:singleLine="true"
android:ellipsize="end"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:textSize="20sp"/>
<include layout="@layout/check_item_rel"/>
<ImageView
android:id="@+id/sort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"/>
</LinearLayout>

View file

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/descr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/title"
android:textSize="18sp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageButton android:id="@+id/remove"
android:focusable="false"
android:layout_marginLeft="11dp"
android:layout_marginRight="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>

View file

@ -15,6 +15,18 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
public class ContextMenuAdapter { public class ContextMenuAdapter {
public void clearAll() {
items.clear();
isCategory.clear();
itemNames.clear();
listeners.clear();
selectedList.clear();
layoutIds.clear();
iconList.clear();
iconListLight.clear();
itemDescription.clear();
}
public interface OnContextMenuClick { public interface OnContextMenuClick {
//boolean return type needed to desribe if drawer needed to be close or not //boolean return type needed to desribe if drawer needed to be close or not
public boolean onContextMenuClick(int itemId, int pos, boolean isChecked); public boolean onContextMenuClick(int itemId, int pos, boolean isChecked);
@ -24,6 +36,7 @@ public class ContextMenuAdapter {
private View anchor; private View anchor;
private int defaultLayoutId = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? private int defaultLayoutId = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ?
R.layout.list_menu_item : R.layout.list_menu_item_native; R.layout.list_menu_item : R.layout.list_menu_item_native;
private ArrayAdapter listAdapter;
final TIntArrayList items = new TIntArrayList(); final TIntArrayList items = new TIntArrayList();
final TIntArrayList isCategory = new TIntArrayList(); final TIntArrayList isCategory = new TIntArrayList();
final ArrayList<String> itemNames = new ArrayList<String>(); final ArrayList<String> itemNames = new ArrayList<String>();
@ -70,6 +83,12 @@ public class ContextMenuAdapter {
itemNames.set(pos, str); itemNames.set(pos, str);
} }
public void notifyDataSetChanged(){
if (listAdapter != null){
listAdapter.notifyDataSetChanged();
}
}
public void setItemDescription(int pos, String str) { public void setItemDescription(int pos, String str) {
itemDescription.set(pos, str); itemDescription.set(pos, str);
} }
@ -127,6 +146,7 @@ public class ContextMenuAdapter {
int pos = -1; int pos = -1;
String description = ""; String description = "";
private OnContextMenuClick listener; private OnContextMenuClick listener;
boolean enabled = false;
private Item() { private Item() {
} }
@ -188,6 +208,10 @@ public class ContextMenuAdapter {
return this; return this;
} }
public Item enabled(boolean checked) {
this.enabled = checked;
return this;
}
} }
public String[] getItemNames() { public String[] getItemNames() {
@ -217,7 +241,7 @@ public class ContextMenuAdapter {
public ListAdapter createListAdapter(final Activity activity, final boolean holoLight) { public ListAdapter createListAdapter(final Activity activity, final boolean holoLight) {
final int padding = (int) (12 * activity.getResources().getDisplayMetrics().density + 0.5f); final int padding = (int) (12 * activity.getResources().getDisplayMetrics().density + 0.5f);
final int layoutId = defaultLayoutId; final int layoutId = defaultLayoutId;
ListAdapter listadapter = new ArrayAdapter<String>(activity, layoutId, R.id.title, listAdapter = new ArrayAdapter<String>(activity, layoutId, R.id.title,
getItemNames()) { getItemNames()) {
@Override @Override
public View getView(final int position, View convertView, ViewGroup parent) { public View getView(final int position, View convertView, ViewGroup parent) {
@ -246,7 +270,9 @@ public class ContextMenuAdapter {
tv.setTypeface(null); tv.setTypeface(null);
} }
if (v.findViewById(R.id.check_item) instanceof CheckBox){
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item)); final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
if(selectedList.get(position) != -1) { if(selectedList.get(position) != -1) {
ch.setOnCheckedChangeListener(null); ch.setOnCheckedChangeListener(null);
ch.setVisibility(View.VISIBLE); ch.setVisibility(View.VISIBLE);
@ -265,6 +291,29 @@ public class ContextMenuAdapter {
} else if (ch != null) { } else if (ch != null) {
ch.setVisibility(View.GONE); ch.setVisibility(View.GONE);
} }
} else if (v.findViewById(R.id.check_item) instanceof Switch) {
final Switch ch = (Switch) v.findViewById(R.id.check_item);
if(selectedList.get(position) != -1) {
ch.setOnCheckedChangeListener(null);
ch.setVisibility(View.VISIBLE);
ch.setChecked(selectedList.get(position) > 0);
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
OnContextMenuClick ca = getClickAdapter(position);
if(ca != null) {
ca.onContextMenuClick(getElementId(position), position, isChecked);
}
}
});
ch.setVisibility(View.VISIBLE);
} else if (ch != null) {
ch.setVisibility(View.GONE);
}
}
String itemDescr = getItemDescr(position); String itemDescr = getItemDescr(position);
if (v.findViewById(R.id.descr) != null){ if (v.findViewById(R.id.descr) != null){
@ -273,7 +322,7 @@ public class ContextMenuAdapter {
return v; return v;
} }
}; };
return listadapter; return listAdapter;
} }

View file

@ -898,8 +898,8 @@ public class MapActivityActions implements DialogProvider {
if (getMyApplication().getWaypointHelper().isRouteCalculated()) { if (getMyApplication().getWaypointHelper().isRouteCalculated()) {
final List<WaypointHelper.LocationPointWrapper> deletedPoints = new ArrayList<WaypointHelper.LocationPointWrapper>(); final List<WaypointHelper.LocationPointWrapper> deletedPoints = new ArrayList<WaypointHelper.LocationPointWrapper>();
ArrayAdapter<Object> adapter = waypointDialogHelper.getWaypointsAdapter(app.getMapActivity(), deletedPoints); ContextMenuAdapter cm = waypointDialogHelper.setListAdapter(app.getMapActivity(), mDrawerList, deletedPoints);
mDrawerList.setAdapter(adapter);
return false; return false;
} else { } else {
openIntermediatePointsDialog(); openIntermediatePointsDialog();

View file

@ -6,12 +6,8 @@ import java.util.List;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint; import net.osmand.data.LocationPoint;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.*;
import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.PoiFilter;
import net.osmand.plus.R;
import net.osmand.plus.activities.IntermediatePointsDialog;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.AnimateDraggingMapThread;
@ -36,7 +32,6 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
@ -140,7 +135,6 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
}); });
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist); TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(ctx)); ((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(ctx));
// Location lastKnownMapLocation = app.getLocationProvider().getLastKnownLocation();
int dist = wh.getRouteDistance(ps); int dist = wh.getRouteDistance(ps);
String dd = OsmAndFormatter.getFormattedDistance(dist, app); String dd = OsmAndFormatter.getFormattedDistance(dist, app);
if (ps.deviationDistance > 0) { if (ps.deviationDistance > 0) {
@ -148,9 +142,6 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
} }
textDist.setText(dd); textDist.setText(dd);
text.setText(point.getName(app)); text.setText(point.getName(app));
// ((Spannable) text.getText()).setSpan(
// new ForegroundColorSpan(ctx.getResources().getColor(R.color.color_distance)), 0, distance.length() - 1,
// 0);
} }
public void removeDialog() { public void removeDialog() {
@ -330,156 +321,158 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
} }
} }
public ArrayAdapter<Object> getWaypointsAdapter(final Activity ctx, final List<LocationPointWrapper> deletedPoints){ public ContextMenuAdapter setListAdapter(final Activity ctx, ListView mDrawerList, final List<LocationPointWrapper> deletedPoints){
final List<Object> points = getPoints(); final ContextMenuAdapter adapter = new ContextMenuAdapter(ctx);
final int[] running = new int[]{-1}; registerPoints(adapter, ctx, mDrawerList);
return new ArrayAdapter<Object>(ctx, mDrawerList.setAdapter(adapter.createListAdapter(mapActivity, mapActivity.getMyApplication().getSettings().isLightContentMenu()));
R.layout.waypoint_reached, R.id.title, points) { return adapter;
// return new ArrayAdapter<Object>(ctx,
@Override // R.layout.waypoint_reached, R.id.title, points) {
public View getView(final int position, View convertView, ViewGroup parent) { //
// User super class to create the View // @Override
View v = convertView; // public View getView(final int position, View convertView, ViewGroup parent) {
final ArrayAdapter<Object> thisAdapter = this; // // User super class to create the View
boolean labelView = (getItem(position) instanceof Integer); // View v = convertView;
boolean viewText = v != null && v.findViewById(R.id.info_close) == null; // final ArrayAdapter<Object> thisAdapter = this;
if (v == null || viewText != labelView) { // boolean labelView = (getItem(position) instanceof Integer);
v = ctx.getLayoutInflater().inflate(labelView ? R.layout.waypoint_header : R.layout.waypoint_reached, null); // boolean viewText = v != null && v.findViewById(R.id.info_close) == null;
} // if (v == null || viewText != labelView) {
if (getItem(position) instanceof String && getItem(position).equals(POI_RADIUS)){ // v = ctx.getLayoutInflater().inflate(labelView ? R.layout.waypoint_header : R.layout.waypoint_reached, null);
v = ctx.getLayoutInflater().inflate(R.layout.radius_search_list_element, null); // }
v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE); // if (getItem(position) instanceof String && getItem(position).equals(POI_RADIUS)){
final TextView radius = (TextView) v.findViewById(R.id.radius); // v = ctx.getLayoutInflater().inflate(R.layout.radius_search_list_element, null);
radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getPoiSearchDeviationRadius(), app)); // v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
radius.setOnClickListener(new View.OnClickListener() { // final TextView radius = (TextView) v.findViewById(R.id.radius);
@Override // radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getPoiSearchDeviationRadius(), app));
public void onClick(View view) { // radius.setOnClickListener(new View.OnClickListener() {
int length = WaypointHelper.SEARCH_RADIUS_VALUES.length; // @Override
String[] names = new String[length]; // public void onClick(View view) {
int selected = 0; // int length = WaypointHelper.SEARCH_RADIUS_VALUES.length;
for (int i = 0; i < length; i++) { // String[] names = new String[length];
names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app); // int selected = 0;
if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getPoiSearchDeviationRadius()){ // for (int i = 0; i < length; i++) {
selected = i; // names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app);
} // if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getPoiSearchDeviationRadius()){
} // selected = i;
new AlertDialog.Builder(ctx) // }
.setSingleChoiceItems(names, selected, new OnClickListener() { // }
@Override // new AlertDialog.Builder(ctx)
public void onClick(DialogInterface dialogInterface, int i) { // .setSingleChoiceItems(names, selected, new OnClickListener() {
int value = WaypointHelper.SEARCH_RADIUS_VALUES[i]; // @Override
if (waypointHelper.getPoiSearchDeviationRadius() != value){ // public void onClick(DialogInterface dialogInterface, int i) {
running[0] = position; // int value = WaypointHelper.SEARCH_RADIUS_VALUES[i];
thisAdapter.notifyDataSetInvalidated(); // if (waypointHelper.getPoiSearchDeviationRadius() != value){
waypointHelper.setPoiSearchDeviationRadius(value); // running[0] = position;
radius.setText(OsmAndFormatter.getFormattedDistance(value, app)); // thisAdapter.notifyDataSetInvalidated();
recalculatePoints(running, thisAdapter, WaypointHelper.POI); // waypointHelper.setPoiSearchDeviationRadius(value);
dialogInterface.dismiss(); // radius.setText(OsmAndFormatter.getFormattedDistance(value, app));
} // recalculatePoints(running, thisAdapter, WaypointHelper.POI);
} // dialogInterface.dismiss();
}).setTitle(app.getString(R.string.search_radius_proximity)+ " " + app.getString(R.string.poi)) // }
.setNegativeButton(R.string.default_buttons_cancel, null) // }
.show(); // }).setTitle(app.getString(R.string.search_radius_proximity)+ " " + app.getString(R.string.poi))
} // .setNegativeButton(R.string.default_buttons_cancel, null)
}); // .show();
} else if (getItem(position) instanceof String && getItem(position).equals(SEARCH_RADIUS)){ // }
v = ctx.getLayoutInflater().inflate(R.layout.radius_search_list_element, null); // });
v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE); // } else if (getItem(position) instanceof String && getItem(position).equals(SEARCH_RADIUS)){
final TextView radius = (TextView) v.findViewById(R.id.radius); // v = ctx.getLayoutInflater().inflate(R.layout.radius_search_list_element, null);
radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getSearchDeviationRadius(), app)); // v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
radius.setOnClickListener(new View.OnClickListener() { // final TextView radius = (TextView) v.findViewById(R.id.radius);
@Override // radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getSearchDeviationRadius(), app));
public void onClick(View view) { // radius.setOnClickListener(new View.OnClickListener() {
int length = WaypointHelper.SEARCH_RADIUS_VALUES.length; // @Override
String[] names = new String[length]; // public void onClick(View view) {
int selected = 0; // int length = WaypointHelper.SEARCH_RADIUS_VALUES.length;
for (int i = 0; i < length; i++) { // String[] names = new String[length];
names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app); // int selected = 0;
if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getSearchDeviationRadius()){ // for (int i = 0; i < length; i++) {
selected = i; // names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app);
} // if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getSearchDeviationRadius()){
} // selected = i;
new AlertDialog.Builder(ctx) // }
.setSingleChoiceItems(names, selected, new OnClickListener() { // }
@Override // new AlertDialog.Builder(ctx)
public void onClick(DialogInterface dialogInterface, int i) { // .setSingleChoiceItems(names, selected, new OnClickListener() {
int value = WaypointHelper.SEARCH_RADIUS_VALUES[i]; // @Override
if (waypointHelper.getSearchDeviationRadius() != value){ // public void onClick(DialogInterface dialogInterface, int i) {
running[0] = position; // int value = WaypointHelper.SEARCH_RADIUS_VALUES[i];
thisAdapter.notifyDataSetInvalidated(); // if (waypointHelper.getSearchDeviationRadius() != value){
waypointHelper.setSearchDeviationRadius(value); // running[0] = position;
radius.setText(OsmAndFormatter.getFormattedDistance(value, app)); // thisAdapter.notifyDataSetInvalidated();
recalculatePoints(running, thisAdapter, -1); // waypointHelper.setSearchDeviationRadius(value);
dialogInterface.dismiss(); // radius.setText(OsmAndFormatter.getFormattedDistance(value, app));
} // recalculatePoints(running, thisAdapter, -1);
} // dialogInterface.dismiss();
}).setTitle(app.getString(R.string.search_radius_proximity)) // }
.setNegativeButton(R.string.default_buttons_cancel, null) // }
.show(); // }).setTitle(app.getString(R.string.search_radius_proximity))
} // .setNegativeButton(R.string.default_buttons_cancel, null)
}); // .show();
} else if (labelView) { // }
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_header, null); // });
final int type = (Integer) getItem(position); // } else if (labelView) {
ImageView sort = (ImageView) v.findViewById(R.id.sort); // v = ctx.getLayoutInflater().inflate(R.layout.waypoint_header, null);
//sort button in Destination header // final int type = (Integer) getItem(position);
if (type == 0 && sort != null){ // ImageView sort = (ImageView) v.findViewById(R.id.sort);
sort.setVisibility(View.VISIBLE); // //sort button in Destination header
if (app.getSettings().isLightContent()){ // if (type == 0 && sort != null){
sort.setImageResource(R.drawable.ic_sort_waypoint_white); // sort.setVisibility(View.VISIBLE);
} else { // if (app.getSettings().isLightContent()){
sort.setImageResource(R.drawable.ic_sort_waypoint_dark); // sort.setImageResource(R.drawable.ic_sort_waypoint_white);
} // } else {
sort.setOnClickListener(new View.OnClickListener() { // sort.setImageResource(R.drawable.ic_sort_waypoint_dark);
@Override // }
public void onClick(View view) { // sort.setOnClickListener(new View.OnClickListener() {
IntermediatePointsDialog.openIntermediatePointsDialog(ctx, app, true); // @Override
} // public void onClick(View view) {
}); // IntermediatePointsDialog.openIntermediatePointsDialog(ctx, app, true);
} // }
final CompoundButton btn = (CompoundButton) v.findViewById(R.id.check_item); // });
btn.setVisibility(waypointHelper.isTypeConfigurable(type) ? View.VISIBLE : View.GONE); // }
btn.setOnCheckedChangeListener(null); // final CompoundButton btn = (CompoundButton) v.findViewById(R.id.check_item);
final boolean checked = waypointHelper.isTypeEnabled(type); // btn.setVisibility(waypointHelper.isTypeConfigurable(type) ? View.VISIBLE : View.GONE);
btn.setChecked(checked); // btn.setOnCheckedChangeListener(null);
btn.setEnabled(running[0] == -1); // final boolean checked = waypointHelper.isTypeEnabled(type);
v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE); // btn.setChecked(checked);
btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // btn.setEnabled(running[0] == -1);
// v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
@Override // btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { //
running[0] = position; // @Override
thisAdapter.notifyDataSetInvalidated(); // public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (type == WaypointHelper.POI && isChecked) { // running[0] = position;
selectPoi(running, thisAdapter, type, isChecked, mapActivity); // thisAdapter.notifyDataSetInvalidated();
} else { // if (type == WaypointHelper.POI && isChecked) {
enableType(running, thisAdapter, type, isChecked); // selectPoi(running, thisAdapter, type, isChecked, mapActivity);
} // } else {
} // enableType(running, thisAdapter, type, isChecked);
// }
}); // }
TextView tv = (TextView) v.findViewById(R.id.header_text); //
tv.setText(getHeader(ctx, type, checked)); // });
} else { // TextView tv = (TextView) v.findViewById(R.id.header_text);
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null); // tv.setText(getHeader(ctx, type, checked));
updatePointInfoView(app, ctx, v, (LocationPointWrapper) getItem(position), null); // } else {
View remove = v.findViewById(R.id.info_close); // v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
((ImageButton) remove).setImageDrawable(ctx.getResources().getDrawable( // updatePointInfoView(app, ctx, v, (LocationPointWrapper) getItem(position), null);
app.getSettings().isLightContent() ? R.drawable.ic_action_gremove_light // View remove = v.findViewById(R.id.info_close);
: R.drawable.ic_action_gremove_dark)); // ((ImageButton) remove).setImageDrawable(ctx.getResources().getDrawable(
remove.setOnClickListener(new View.OnClickListener() { // app.getSettings().isLightContent() ? R.drawable.ic_action_gremove_light
@Override // : R.drawable.ic_action_gremove_dark));
public void onClick(View view) { // remove.setOnClickListener(new View.OnClickListener() {
LocationPointWrapper point = (LocationPointWrapper) points.get(position); // @Override
remove(point); // public void onClick(View view) {
deletedPoints.add(point); // LocationPointWrapper point = (LocationPointWrapper) points.get(position);
notifyDataSetChanged(); // remove(point);
} // deletedPoints.add(point);
}); // notifyDataSetChanged();
} // }
return v; // });
} // }
}; // return v;
// }
// };
} }
protected String getHeader(Activity ctx, int type, boolean checked) { protected String getHeader(Activity ctx, int type, boolean checked) {
@ -505,8 +498,8 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
return str; return str;
} }
private void selectPoi(final int[] running, final ArrayAdapter<Object> listAdapter, final int type, private void selectPoi(final int[] running, final ContextMenuAdapter menuAdapter, final int type,
final boolean enable, MapActivity map) { final boolean enable, MapActivity map, final ListView drawerlist) {
if (!PoiFilter.CUSTOM_FILTER_ID.equals(app.getSettings().getPoiFilterForMap())) { if (!PoiFilter.CUSTOM_FILTER_ID.equals(app.getSettings().getPoiFilterForMap())) {
final PoiFilter[] selected = new PoiFilter[1]; final PoiFilter[] selected = new PoiFilter[1];
AlertDialog dlg = map.getMapLayers().selectPOIFilterLayer(map.getMapView(), selected); AlertDialog dlg = map.getMapLayers().selectPOIFilterLayer(map.getMapView(), selected);
@ -515,16 +508,16 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
if (selected != null) { if (selected != null) {
enableType(running, listAdapter, type, enable); enableType(running, menuAdapter, type, enable, drawerlist);
} }
} }
}); });
} else { } else {
enableType(running, listAdapter, type, enable); enableType(running, menuAdapter, type, enable, drawerlist);
} }
} }
private void recalculatePoints(final int[] running, final ArrayAdapter<Object> listAdapter, final int type){ private void recalculatePoints(final int[] running, final ContextMenuAdapter menuAdapter, final int type, final ListView mDrawerList){
new AsyncTask<Void, Void, Void>() { new AsyncTask<Void, Void, Void>() {
@Override @Override
@ -535,36 +528,118 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
protected void onPostExecute(Void result) { protected void onPostExecute(Void result) {
running[0] = -1; running[0] = -1;
listAdapter.clear(); menuAdapter.clearAll();
for (Object point : getPoints()) { registerPoints(menuAdapter, mapActivity, mDrawerList);
listAdapter.add(point);
}
listAdapter.notifyDataSetChanged();
} }
}.execute((Void) null); }.execute((Void) null);
} }
protected List<Object> getPoints() { protected void registerPoints(final ContextMenuAdapter adapter, final Activity ctx, final ListView drawerList) {
final List<Object> points = new ArrayList<Object>(); final int[] running = new int[]{-1};
for (int i = 0; i < WaypointHelper.MAX; i++) { for (int i = 0; i < WaypointHelper.MAX; i++) {
List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i); List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i);
if (waypointHelper.isTypeVisible(i)) { if (waypointHelper.isTypeVisible(i)) {
points.add(new Integer(i)); final boolean checked = waypointHelper.isTypeEnabled(i);
final int type = i;
adapter.item(getHeader(ctx, i, checked)).enabled(checked).layout(R.layout.drawer_list_poi_header).listen(new ContextMenuAdapter.OnContextMenuClick() {
@Override
public boolean onContextMenuClick(int itemId, int pos, boolean isChecked) {
running[0] = pos;
adapter.notifyDataSetChanged();
if (type == WaypointHelper.POI && isChecked) {
selectPoi(running, adapter, type, isChecked, mapActivity, drawerList);
} else {
enableType(running, adapter, type, isChecked, drawerList);
}
return false;
}
}).reg();
if (i == WaypointHelper.POI && waypointHelper.isTypeEnabled(WaypointHelper.POI)){ if (i == WaypointHelper.POI && waypointHelper.isTypeEnabled(WaypointHelper.POI)){
points.add(POI_RADIUS); adapter.item(ctx.getString(R.string.search_radius_proximity)).listen(new ContextMenuAdapter.OnContextMenuClick() {
@Override
public boolean onContextMenuClick(int itemId, final int pos, boolean isChecked) {
int length = WaypointHelper.SEARCH_RADIUS_VALUES.length;
String[] names = new String[length];
int selected = 0;
for (int i = 0; i < length; i++) {
names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app);
if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getPoiSearchDeviationRadius()) {
selected = i;
}
}
new AlertDialog.Builder(ctx)
.setSingleChoiceItems(names, selected, new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int value = WaypointHelper.SEARCH_RADIUS_VALUES[i];
if (waypointHelper.getPoiSearchDeviationRadius() != value) {
running[0] = pos;
adapter.notifyDataSetChanged();
waypointHelper.setPoiSearchDeviationRadius(value);
//radius.setText(OsmAndFormatter.getFormattedDistance(value, app));
recalculatePoints(running, adapter, WaypointHelper.POI, drawerList);
dialogInterface.dismiss();
}
}
}).setTitle(app.getString(R.string.search_radius_proximity) + " " + app.getString(R.string.poi))
.setNegativeButton(R.string.default_buttons_cancel, null)
.show();
return false;
}
}).reg();
} else if (i == WaypointHelper.FAVORITES && waypointHelper.isTypeEnabled(WaypointHelper.FAVORITES)){ } else if (i == WaypointHelper.FAVORITES && waypointHelper.isTypeEnabled(WaypointHelper.FAVORITES)){
points.add(SEARCH_RADIUS); adapter.item(ctx.getString(R.string.search_radius_proximity)).listen(new ContextMenuAdapter.OnContextMenuClick() {
@Override
public boolean onContextMenuClick(int itemId, final int pos, boolean isChecked) {
int length = WaypointHelper.SEARCH_RADIUS_VALUES.length;
String[] names = new String[length];
int selected = 0;
for (int i = 0; i < length; i++) {
names[i] = OsmAndFormatter.getFormattedDistance(WaypointHelper.SEARCH_RADIUS_VALUES[i], app);
if (WaypointHelper.SEARCH_RADIUS_VALUES[i] == waypointHelper.getSearchDeviationRadius()){
selected = i;
}
}
new AlertDialog.Builder(ctx)
.setSingleChoiceItems(names, selected, new OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
int value = WaypointHelper.SEARCH_RADIUS_VALUES[i];
if (waypointHelper.getSearchDeviationRadius() != value){
running[0] = pos;
waypointHelper.setSearchDeviationRadius(value);
//radius.setText(OsmAndFormatter.getFormattedDistance(value, app));
recalculatePoints(running, adapter, -1, drawerList);
dialogInterface.dismiss();
}
}
}).setTitle(app.getString(R.string.search_radius_proximity))
.setNegativeButton(R.string.default_buttons_cancel, null)
.show();
return false;
}
}).reg();
} }
if (tp != null && tp.size() > 0) { if (tp != null && tp.size() > 0) {
points.addAll(tp); for (LocationPointWrapper p : tp){
WaypointHelper wh =app.getWaypointHelper();
int dist = wh.getRouteDistance(p);
String dd = OsmAndFormatter.getFormattedDistance(dist, app);
if (p.deviationDistance > 0) {
dd += "\n+" + OsmAndFormatter.getFormattedDistance(p.deviationDistance, app);
}
adapter.item(p.getPoint().getName(ctx)).icon(p.getDrawableId(ctx)).description(dd).layout(R.layout.drawer_list_waypoint).reg();
}
//points.addAll(tp);
} }
} }
} }
return points;
} }
private void enableType(final int[] running, final ArrayAdapter<Object> listAdapter, final int type, private void enableType(final int[] running, final ContextMenuAdapter menuAdapter, final int type,
final boolean enable) { final boolean enable, final ListView drawerList) {
new AsyncTask<Void, Void, Void>() { new AsyncTask<Void, Void, Void>() {
@Override @Override
@ -575,11 +650,13 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
protected void onPostExecute(Void result) { protected void onPostExecute(Void result) {
running[0] = -1; running[0] = -1;
listAdapter.clear(); menuAdapter.clearAll();
for (Object point : getPoints()) { registerPoints(menuAdapter, mapActivity, drawerList);
listAdapter.add(point); // menuAdapter.clear();
} // for (Object point : registerPoints()) {
listAdapter.notifyDataSetChanged(); // menuAdapter.add(point);
// }
// menuAdapter.notifyDataSetChanged();
} }
}.execute((Void) null); }.execute((Void) null);
} }

View file

@ -651,6 +651,38 @@ public class WaypointHelper {
return point; return point;
} }
public int getDrawableId(Context uiCtx) {
if(type == POI) {
Amenity amenity = ((AmenityLocationPoint) point).a;
StringBuilder tag = new StringBuilder();
StringBuilder value = new StringBuilder();
MapRenderingTypes.getDefault().getAmenityTagValue(amenity.getType(), amenity.getSubType(),
tag, value);
if(RenderingIcons.containsBigIcon(tag + "_" + value)) {
return RenderingIcons.getBigIconResourceId(tag + "_" + value);
} else if(RenderingIcons.containsBigIcon(value.toString())) {
return RenderingIcons.getBigIconResourceId(value.toString());
}
return 0;
} else if(type == TARGETS) {
return !((TargetPoint)point).intermediate? R.drawable.list_destination:
R.drawable.list_intermediate;
} else if(type == FAVORITES || type == WAYPOINTS) {
//return FavoriteImageDrawable.getOrCreate(uiCtx, point.getColor());
return 0;
} else if(type == ALARMS) {
//TODO: Looks like this does not work yet, not sure why:
if(RenderingIcons.containsBigIcon("list_" + ((AlarmInfo) point).getType().toString().toLowerCase())) {
return RenderingIcons.getBigIconResourceId("list_" + ((AlarmInfo) point).getType().toString().toLowerCase());
} else {
return 0;
}
} else {
return 0;
}
}
public Drawable getDrawable(Context uiCtx) { public Drawable getDrawable(Context uiCtx) {
if(type == POI) { if(type == POI) {
Amenity amenity = ((AmenityLocationPoint) point).a; Amenity amenity = ((AmenityLocationPoint) point).a;