Added ContextMenuAdapter for waypoints
This commit is contained in:
parent
37859475e6
commit
4a50d2c3eb
7 changed files with 433 additions and 207 deletions
36
OsmAnd/res/layout/drawer_list_poi_header.xml
Normal file
36
OsmAnd/res/layout/drawer_list_poi_header.xml
Normal 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>
|
24
OsmAnd/res/layout/drawer_list_waypoint.xml
Normal file
24
OsmAnd/res/layout/drawer_list_waypoint.xml
Normal 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>
|
8
OsmAnd/res/layout/drawer_list_waypoint_sub_header.xml
Normal file
8
OsmAnd/res/layout/drawer_list_waypoint_sub_header.xml
Normal 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>
|
|
@ -15,6 +15,18 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
|
|||
|
||||
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 {
|
||||
//boolean return type needed to desribe if drawer needed to be close or not
|
||||
public boolean onContextMenuClick(int itemId, int pos, boolean isChecked);
|
||||
|
@ -24,6 +36,7 @@ public class ContextMenuAdapter {
|
|||
private View anchor;
|
||||
private int defaultLayoutId = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ?
|
||||
R.layout.list_menu_item : R.layout.list_menu_item_native;
|
||||
private ArrayAdapter listAdapter;
|
||||
final TIntArrayList items = new TIntArrayList();
|
||||
final TIntArrayList isCategory = new TIntArrayList();
|
||||
final ArrayList<String> itemNames = new ArrayList<String>();
|
||||
|
@ -70,6 +83,12 @@ public class ContextMenuAdapter {
|
|||
itemNames.set(pos, str);
|
||||
}
|
||||
|
||||
public void notifyDataSetChanged(){
|
||||
if (listAdapter != null){
|
||||
listAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemDescription(int pos, String str) {
|
||||
itemDescription.set(pos, str);
|
||||
}
|
||||
|
@ -127,6 +146,7 @@ public class ContextMenuAdapter {
|
|||
int pos = -1;
|
||||
String description = "";
|
||||
private OnContextMenuClick listener;
|
||||
boolean enabled = false;
|
||||
|
||||
private Item() {
|
||||
}
|
||||
|
@ -188,6 +208,10 @@ public class ContextMenuAdapter {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Item enabled(boolean checked) {
|
||||
this.enabled = checked;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public String[] getItemNames() {
|
||||
|
@ -217,7 +241,7 @@ public class ContextMenuAdapter {
|
|||
public ListAdapter createListAdapter(final Activity activity, final boolean holoLight) {
|
||||
final int padding = (int) (12 * activity.getResources().getDisplayMetrics().density + 0.5f);
|
||||
final int layoutId = defaultLayoutId;
|
||||
ListAdapter listadapter = new ArrayAdapter<String>(activity, layoutId, R.id.title,
|
||||
listAdapter = new ArrayAdapter<String>(activity, layoutId, R.id.title,
|
||||
getItemNames()) {
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
|
@ -246,7 +270,9 @@ public class ContextMenuAdapter {
|
|||
tv.setTypeface(null);
|
||||
}
|
||||
|
||||
if (v.findViewById(R.id.check_item) instanceof CheckBox){
|
||||
final CheckBox ch = ((CheckBox) v.findViewById(R.id.check_item));
|
||||
|
||||
if(selectedList.get(position) != -1) {
|
||||
ch.setOnCheckedChangeListener(null);
|
||||
ch.setVisibility(View.VISIBLE);
|
||||
|
@ -265,6 +291,29 @@ public class ContextMenuAdapter {
|
|||
} else if (ch != null) {
|
||||
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);
|
||||
if (v.findViewById(R.id.descr) != null){
|
||||
|
@ -273,7 +322,7 @@ public class ContextMenuAdapter {
|
|||
return v;
|
||||
}
|
||||
};
|
||||
return listadapter;
|
||||
return listAdapter;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -898,8 +898,8 @@ public class MapActivityActions implements DialogProvider {
|
|||
if (getMyApplication().getWaypointHelper().isRouteCalculated()) {
|
||||
|
||||
final List<WaypointHelper.LocationPointWrapper> deletedPoints = new ArrayList<WaypointHelper.LocationPointWrapper>();
|
||||
ArrayAdapter<Object> adapter = waypointDialogHelper.getWaypointsAdapter(app.getMapActivity(), deletedPoints);
|
||||
mDrawerList.setAdapter(adapter);
|
||||
ContextMenuAdapter cm = waypointDialogHelper.setListAdapter(app.getMapActivity(), mDrawerList, deletedPoints);
|
||||
|
||||
return false;
|
||||
} else {
|
||||
openIntermediatePointsDialog();
|
||||
|
|
|
@ -6,12 +6,8 @@ import java.util.List;
|
|||
import net.osmand.Location;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.*;
|
||||
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.helpers.WaypointHelper.LocationPointWrapper;
|
||||
import net.osmand.plus.views.AnimateDraggingMapThread;
|
||||
|
@ -36,7 +32,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
|
@ -140,7 +135,6 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
|
|||
});
|
||||
TextView textDist = (TextView) localView.findViewById(R.id.waypoint_dist);
|
||||
((ImageView) localView.findViewById(R.id.waypoint_icon)).setImageDrawable(ps.getDrawable(ctx));
|
||||
// Location lastKnownMapLocation = app.getLocationProvider().getLastKnownLocation();
|
||||
int dist = wh.getRouteDistance(ps);
|
||||
String dd = OsmAndFormatter.getFormattedDistance(dist, app);
|
||||
if (ps.deviationDistance > 0) {
|
||||
|
@ -148,9 +142,6 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
|
|||
}
|
||||
textDist.setText(dd);
|
||||
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() {
|
||||
|
@ -330,156 +321,158 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
|
|||
}
|
||||
}
|
||||
|
||||
public ArrayAdapter<Object> getWaypointsAdapter(final Activity ctx, final List<LocationPointWrapper> deletedPoints){
|
||||
final List<Object> points = getPoints();
|
||||
final int[] running = new int[]{-1};
|
||||
return new ArrayAdapter<Object>(ctx,
|
||||
R.layout.waypoint_reached, R.id.title, points) {
|
||||
|
||||
@Override
|
||||
public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
// User super class to create the View
|
||||
View v = convertView;
|
||||
final ArrayAdapter<Object> thisAdapter = this;
|
||||
boolean labelView = (getItem(position) instanceof Integer);
|
||||
boolean viewText = v != null && v.findViewById(R.id.info_close) == null;
|
||||
if (v == null || viewText != labelView) {
|
||||
v = ctx.getLayoutInflater().inflate(labelView ? R.layout.waypoint_header : R.layout.waypoint_reached, null);
|
||||
}
|
||||
if (getItem(position) instanceof String && getItem(position).equals(POI_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);
|
||||
final TextView radius = (TextView) v.findViewById(R.id.radius);
|
||||
radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getPoiSearchDeviationRadius(), app));
|
||||
radius.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
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] = position;
|
||||
thisAdapter.notifyDataSetInvalidated();
|
||||
waypointHelper.setPoiSearchDeviationRadius(value);
|
||||
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();
|
||||
}
|
||||
});
|
||||
} 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);
|
||||
final TextView radius = (TextView) v.findViewById(R.id.radius);
|
||||
radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getSearchDeviationRadius(), app));
|
||||
radius.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
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] = position;
|
||||
thisAdapter.notifyDataSetInvalidated();
|
||||
waypointHelper.setSearchDeviationRadius(value);
|
||||
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();
|
||||
}
|
||||
});
|
||||
} else if (labelView) {
|
||||
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_header, null);
|
||||
final int type = (Integer) getItem(position);
|
||||
ImageView sort = (ImageView) v.findViewById(R.id.sort);
|
||||
//sort button in Destination header
|
||||
if (type == 0 && sort != null){
|
||||
sort.setVisibility(View.VISIBLE);
|
||||
if (app.getSettings().isLightContent()){
|
||||
sort.setImageResource(R.drawable.ic_sort_waypoint_white);
|
||||
} else {
|
||||
sort.setImageResource(R.drawable.ic_sort_waypoint_dark);
|
||||
}
|
||||
sort.setOnClickListener(new View.OnClickListener() {
|
||||
@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 boolean checked = waypointHelper.isTypeEnabled(type);
|
||||
btn.setChecked(checked);
|
||||
btn.setEnabled(running[0] == -1);
|
||||
v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
|
||||
btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
running[0] = position;
|
||||
thisAdapter.notifyDataSetInvalidated();
|
||||
if (type == WaypointHelper.POI && 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 {
|
||||
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
|
||||
updatePointInfoView(app, ctx, v, (LocationPointWrapper) getItem(position), null);
|
||||
View remove = v.findViewById(R.id.info_close);
|
||||
((ImageButton) remove).setImageDrawable(ctx.getResources().getDrawable(
|
||||
app.getSettings().isLightContent() ? R.drawable.ic_action_gremove_light
|
||||
: R.drawable.ic_action_gremove_dark));
|
||||
remove.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
LocationPointWrapper point = (LocationPointWrapper) points.get(position);
|
||||
remove(point);
|
||||
deletedPoints.add(point);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
return v;
|
||||
}
|
||||
};
|
||||
public ContextMenuAdapter setListAdapter(final Activity ctx, ListView mDrawerList, final List<LocationPointWrapper> deletedPoints){
|
||||
final ContextMenuAdapter adapter = new ContextMenuAdapter(ctx);
|
||||
registerPoints(adapter, ctx, mDrawerList);
|
||||
mDrawerList.setAdapter(adapter.createListAdapter(mapActivity, mapActivity.getMyApplication().getSettings().isLightContentMenu()));
|
||||
return adapter;
|
||||
// return new ArrayAdapter<Object>(ctx,
|
||||
// R.layout.waypoint_reached, R.id.title, points) {
|
||||
//
|
||||
// @Override
|
||||
// public View getView(final int position, View convertView, ViewGroup parent) {
|
||||
// // User super class to create the View
|
||||
// View v = convertView;
|
||||
// final ArrayAdapter<Object> thisAdapter = this;
|
||||
// boolean labelView = (getItem(position) instanceof Integer);
|
||||
// boolean viewText = v != null && v.findViewById(R.id.info_close) == null;
|
||||
// if (v == null || viewText != labelView) {
|
||||
// v = ctx.getLayoutInflater().inflate(labelView ? R.layout.waypoint_header : R.layout.waypoint_reached, null);
|
||||
// }
|
||||
// if (getItem(position) instanceof String && getItem(position).equals(POI_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);
|
||||
// final TextView radius = (TextView) v.findViewById(R.id.radius);
|
||||
// radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getPoiSearchDeviationRadius(), app));
|
||||
// radius.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// 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] = position;
|
||||
// thisAdapter.notifyDataSetInvalidated();
|
||||
// waypointHelper.setPoiSearchDeviationRadius(value);
|
||||
// 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();
|
||||
// }
|
||||
// });
|
||||
// } 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);
|
||||
// final TextView radius = (TextView) v.findViewById(R.id.radius);
|
||||
// radius.setText(OsmAndFormatter.getFormattedDistance(waypointHelper.getSearchDeviationRadius(), app));
|
||||
// radius.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// 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] = position;
|
||||
// thisAdapter.notifyDataSetInvalidated();
|
||||
// waypointHelper.setSearchDeviationRadius(value);
|
||||
// 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();
|
||||
// }
|
||||
// });
|
||||
// } else if (labelView) {
|
||||
// v = ctx.getLayoutInflater().inflate(R.layout.waypoint_header, null);
|
||||
// final int type = (Integer) getItem(position);
|
||||
// ImageView sort = (ImageView) v.findViewById(R.id.sort);
|
||||
// //sort button in Destination header
|
||||
// if (type == 0 && sort != null){
|
||||
// sort.setVisibility(View.VISIBLE);
|
||||
// if (app.getSettings().isLightContent()){
|
||||
// sort.setImageResource(R.drawable.ic_sort_waypoint_white);
|
||||
// } else {
|
||||
// sort.setImageResource(R.drawable.ic_sort_waypoint_dark);
|
||||
// }
|
||||
// sort.setOnClickListener(new View.OnClickListener() {
|
||||
// @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 boolean checked = waypointHelper.isTypeEnabled(type);
|
||||
// btn.setChecked(checked);
|
||||
// btn.setEnabled(running[0] == -1);
|
||||
// v.findViewById(R.id.ProgressBar).setVisibility(position == running[0] ? View.VISIBLE : View.GONE);
|
||||
// btn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
// running[0] = position;
|
||||
// thisAdapter.notifyDataSetInvalidated();
|
||||
// if (type == WaypointHelper.POI && 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 {
|
||||
// v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
|
||||
// updatePointInfoView(app, ctx, v, (LocationPointWrapper) getItem(position), null);
|
||||
// View remove = v.findViewById(R.id.info_close);
|
||||
// ((ImageButton) remove).setImageDrawable(ctx.getResources().getDrawable(
|
||||
// app.getSettings().isLightContent() ? R.drawable.ic_action_gremove_light
|
||||
// : R.drawable.ic_action_gremove_dark));
|
||||
// remove.setOnClickListener(new View.OnClickListener() {
|
||||
// @Override
|
||||
// public void onClick(View view) {
|
||||
// LocationPointWrapper point = (LocationPointWrapper) points.get(position);
|
||||
// remove(point);
|
||||
// deletedPoints.add(point);
|
||||
// notifyDataSetChanged();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// return v;
|
||||
// }
|
||||
// };
|
||||
}
|
||||
|
||||
protected String getHeader(Activity ctx, int type, boolean checked) {
|
||||
|
@ -505,8 +498,8 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
|
|||
return str;
|
||||
}
|
||||
|
||||
private void selectPoi(final int[] running, final ArrayAdapter<Object> listAdapter, final int type,
|
||||
final boolean enable, MapActivity map) {
|
||||
private void selectPoi(final int[] running, final ContextMenuAdapter menuAdapter, final int type,
|
||||
final boolean enable, MapActivity map, final ListView drawerlist) {
|
||||
if (!PoiFilter.CUSTOM_FILTER_ID.equals(app.getSettings().getPoiFilterForMap())) {
|
||||
final PoiFilter[] selected = new PoiFilter[1];
|
||||
AlertDialog dlg = map.getMapLayers().selectPOIFilterLayer(map.getMapView(), selected);
|
||||
|
@ -515,16 +508,16 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
|
|||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (selected != null) {
|
||||
enableType(running, listAdapter, type, enable);
|
||||
enableType(running, menuAdapter, type, enable, drawerlist);
|
||||
}
|
||||
}
|
||||
});
|
||||
} 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>() {
|
||||
|
||||
@Override
|
||||
|
@ -535,36 +528,118 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
|
|||
|
||||
protected void onPostExecute(Void result) {
|
||||
running[0] = -1;
|
||||
listAdapter.clear();
|
||||
for (Object point : getPoints()) {
|
||||
listAdapter.add(point);
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
menuAdapter.clearAll();
|
||||
registerPoints(menuAdapter, mapActivity, mDrawerList);
|
||||
|
||||
}
|
||||
}.execute((Void) null);
|
||||
}
|
||||
|
||||
protected List<Object> getPoints() {
|
||||
final List<Object> points = new ArrayList<Object>();
|
||||
protected void registerPoints(final ContextMenuAdapter adapter, final Activity ctx, final ListView drawerList) {
|
||||
final int[] running = new int[]{-1};
|
||||
for (int i = 0; i < WaypointHelper.MAX; i++) {
|
||||
List<LocationPointWrapper> tp = waypointHelper.getWaypoints(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)){
|
||||
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)){
|
||||
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) {
|
||||
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,
|
||||
final boolean enable) {
|
||||
private void enableType(final int[] running, final ContextMenuAdapter menuAdapter, final int type,
|
||||
final boolean enable, final ListView drawerList) {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
|
||||
@Override
|
||||
|
@ -575,11 +650,13 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
|
|||
|
||||
protected void onPostExecute(Void result) {
|
||||
running[0] = -1;
|
||||
listAdapter.clear();
|
||||
for (Object point : getPoints()) {
|
||||
listAdapter.add(point);
|
||||
}
|
||||
listAdapter.notifyDataSetChanged();
|
||||
menuAdapter.clearAll();
|
||||
registerPoints(menuAdapter, mapActivity, drawerList);
|
||||
// menuAdapter.clear();
|
||||
// for (Object point : registerPoints()) {
|
||||
// menuAdapter.add(point);
|
||||
// }
|
||||
// menuAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}.execute((Void) null);
|
||||
}
|
||||
|
|
|
@ -651,6 +651,38 @@ public class WaypointHelper {
|
|||
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) {
|
||||
if(type == POI) {
|
||||
Amenity amenity = ((AmenityLocationPoint) point).a;
|
||||
|
|
Loading…
Reference in a new issue