Implemented search radius for POI in waypoints dialog

This commit is contained in:
Denis 2014-10-15 19:09:16 +03:00
parent f540b3e6fd
commit 4604ec38dc
11 changed files with 142 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -0,0 +1,34 @@
<?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="wrap_content"
android:layout_marginTop="3dp"
android:layout_marginBottom="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/header"
android:text="@string/search_radius"
android:layout_width="0dp"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:textSize="20sp"/>
<TextView android:id="@+id/radius"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="@color/sherpafy_selection"
android:layout_gravity="center_vertical"
android:layout_marginRight="8dp"/>
</LinearLayout>

View file

@ -8,11 +8,11 @@
android:layout_marginBottom="3dp"
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"/>
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/header_text"
android:layout_width="0dp"
@ -25,4 +25,12 @@
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

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="search_radius">Search radius</string>
<string name="osmo_device_not_found">Device not found</string>
<string name="osmo_no_connection_msg">OsMo service is not available:\n- check the connection;\n- check the settings;\n- check out our Twitter: https://twitter.com/OsMomobi</string>
<string name="anonymous_user_hint">An anonymous user can not:\n- create groups;\n- synchronize groups and devices with the server;\n- manage groups and devices in a private office.</string>

View file

@ -13,6 +13,7 @@ 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;
@ -44,6 +45,8 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
private LinearLayout mainLayout;
private WaypointHelper waypointHelper;
private final static String POI_RADIUS = "poi_radius";
public final static boolean OVERLAP_LAYOUT = true; // only true is supported
private View closePointDialog;
private List<LocationPointWrapper> many = new ArrayList<WaypointHelper.LocationPointWrapper>();
@ -245,15 +248,30 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
}
}
private void recalculatePoints(final int[] running, final ArrayAdapter<Object> listAdapter, final int type){
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
app.getWaypointHelper().recalculatePoints(type);
return null;
}
protected void onPostExecute(Void result) {
running[0] = -1;
listAdapter.clear();
for (Object point : getPoints()) {
listAdapter.add(point);
}
listAdapter.notifyDataSetChanged();
}
}.execute((Void) null);
}
private void enableType(final int[] running, final ArrayAdapter<Object> listAdapter, final int type,
final boolean enable) {
new AsyncTask<Void, Void, Void>() {
protected void onPreExecute() {
}
;
@Override
protected Void doInBackground(Void... params) {
app.getWaypointHelper().enableWaypointType(type, enable);
@ -356,6 +374,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
final int[] running = new int[]{-1};
final ArrayAdapter<Object> listAdapter = 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
@ -366,8 +385,60 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
if (v == null || viewText != labelView) {
v = ctx.getLayoutInflater().inflate(labelView ? R.layout.waypoint_header : R.layout.waypoint_reached, null);
}
if (labelView) {
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.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(getActivity())
.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;
waypointHelper.setSearchDeviationRadius(value);
radius.setText(OsmAndFormatter.getFormattedDistance(value, app));
recalculatePoints(running, thisAdapter, WaypointHelper.POI);
dialogInterface.dismiss();
}
}
}).setTitle(app.getString(R.string.search_radius)+ " " + app.getString(R.string.poi))
.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);
@ -392,6 +463,7 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
TextView tv = (TextView) v.findViewById(R.id.header_text);
tv.setText(getHeader(type, checked));
} else {
v = ctx.getLayoutInflater().inflate(R.layout.waypoint_reached, null);
updatePointInfoView(app, ctx, v, (LocationPointWrapper) getItem(position), WaypointDialogFragment.this);
View remove = v.findViewById(R.id.info_close);
((ImageButton) remove).setImageDrawable(ctx.getResources().getDrawable(
@ -448,6 +520,9 @@ public class WaypointDialogHelper implements OsmAndLocationListener {
List<LocationPointWrapper> tp = waypointHelper.getWaypoints(i);
if (waypointHelper.isTypeVisible(i)) {
points.add(new Integer(i));
if (i == WaypointHelper.POI && waypointHelper.isTypeEnabled(WaypointHelper.POI)){
points.add(POI_RADIUS);
}
if (tp != null && tp.size() > 0) {
points.addAll(tp);
}

View file

@ -56,6 +56,7 @@ public class WaypointHelper {
public static final int FAVORITES = 3;
public static final int ALARMS = 4;
public static final int MAX = 5;
public static final int[] SEARCH_RADIUS_VALUES = {50, 100, 250, 500, 1000, 1500};
private List<List<LocationPointWrapper>> locationPoints = new ArrayList<List<LocationPointWrapper>>();
private ConcurrentHashMap<LocationPoint, Integer> locationPointsStates = new ConcurrentHashMap<LocationPoint, Integer>();
@ -210,7 +211,9 @@ public class WaypointHelper {
recalculatePoints(route, type, locationPoints);
}
public void recalculatePoints(int type){
recalculatePoints(route, type, locationPoints);
}
public boolean isTypeConfigurable(int waypointType) {
@ -706,6 +709,14 @@ public class WaypointHelper {
}
public int getSearchDeviationRadius(){
return searchDeviationRadius;
}
public void setSearchDeviationRadius(int radius){
this.searchDeviationRadius = radius;
}
private class AmenityLocationPoint implements LocationPoint {
Amenity a;