Search in sources :

Example 1 with StableArrayAdapter

use of net.osmand.plus.views.controls.StableArrayAdapter in project Osmand by osmandapp.

the class DashboardOnMap method exchangeWaypoints.

@Override
public void exchangeWaypoints(int pos1, int pos2) {
    if (swipeDismissListener != null) {
        swipeDismissListener.discardUndo();
    }
    if (pos1 != -1 && pos2 != -1) {
        StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter;
        Object item1 = stableAdapter.getActiveObjects().get(pos1);
        Object item2 = stableAdapter.getActiveObjects().get(pos2);
        stableAdapter.getActiveObjects().set(pos1, item2);
        stableAdapter.getActiveObjects().set(pos2, item1);
        stableAdapter.refreshData();
        onItemsSwapped(stableAdapter.getActiveObjects());
    }
}
Also used : StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter)

Example 2 with StableArrayAdapter

use of net.osmand.plus.views.controls.StableArrayAdapter in project Osmand by osmandapp.

the class DashboardOnMap method updateListAdapter.

private void updateListAdapter() {
    listEmptyTextView.setVisibility(View.GONE);
    listView.setEmptyView(null);
    ContextMenuAdapter cm = null;
    if (DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType) {
        StableArrayAdapter listAdapter = waypointDialogHelper.getWaypointsDrawerAdapter(true, deletedPoints, mapActivity, running, DashboardType.WAYPOINTS_FLAT == visibleType, nightMode);
        OnItemClickListener listener = waypointDialogHelper.getDrawerItemClickListener(mapActivity, running, listAdapter);
        setDynamicListItems(listView, listAdapter);
        updateListAdapter(listAdapter, listener);
        if (listAdapter.getObjects().size() == 0) {
            listEmptyTextView.setText(mapActivity.getString(R.string.no_waypoints_found));
            if (landscape) {
                listView.setEmptyView(listEmptyTextView);
            } else {
                listEmptyTextView.setVisibility(View.VISIBLE);
            }
        }
    } else {
        if (visibleType == DashboardType.CONFIGURE_SCREEN) {
            cm = mapActivity.getMapLayers().getMapWidgetRegistry().getViewConfigureMenuAdapter(mapActivity);
        } else if (visibleType == DashboardType.CONFIGURE_MAP) {
            cm = new ConfigureMapMenu().createListAdapter(mapActivity);
        } else if (visibleType == DashboardType.LIST_MENU) {
            cm = mapActivity.getMapActions().createMainOptionsMenu();
        } else if (visibleType == DashboardType.ROUTE_PREFERENCES) {
            RoutePreferencesMenu routePreferencesMenu = new RoutePreferencesMenu(mapActivity);
            ArrayAdapter<LocalRoutingParameter> listAdapter = routePreferencesMenu.getRoutePreferencesDrawerAdapter(nightMode);
            OnItemClickListener listener = routePreferencesMenu.getItemClickListener(listAdapter);
            updateListAdapter(listAdapter, listener);
        } else if (visibleType == DashboardType.UNDERLAY_MAP) {
            cm = RasterMapMenu.createListAdapter(mapActivity, OsmandRasterMapsPlugin.RasterMapType.UNDERLAY);
        } else if (visibleType == DashboardType.OVERLAY_MAP) {
            cm = RasterMapMenu.createListAdapter(mapActivity, OsmandRasterMapsPlugin.RasterMapType.OVERLAY);
        } else if (visibleType == DashboardType.CONTOUR_LINES) {
            cm = ContourLinesMenu.createListAdapter(mapActivity);
        } else if (visibleType == DashboardType.HILLSHADE) {
            cm = HillshadeMenu.createListAdapter(mapActivity);
        } else if (visibleType == DashboardType.OSM_NOTES) {
            cm = OsmNotesMenu.createListAdapter(mapActivity);
        }
        if (cm != null) {
            updateListAdapter(cm);
        }
    }
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) ConfigureMapMenu(net.osmand.plus.dialogs.ConfigureMapMenu) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) RoutePreferencesMenu(net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu) ArrayAdapter(android.widget.ArrayAdapter) StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter)

Example 3 with StableArrayAdapter

use of net.osmand.plus.views.controls.StableArrayAdapter in project Osmand by osmandapp.

the class WaypointDialogHelper method getWaypointsDrawerAdapter.

public StableArrayAdapter getWaypointsDrawerAdapter(final boolean edit, final List<LocationPointWrapper> deletedPoints, final MapActivity ctx, final int[] running, final boolean flat, final boolean nightMode) {
    this.flat = flat;
    this.deletedPoints = deletedPoints;
    final List<Object> points = getPoints();
    List<Object> activePoints = getActivePoints(points);
    final WaypointDialogHelper helper = this;
    final StableArrayAdapter listAdapter = new StableArrayAdapter(ctx, R.layout.waypoint_reached, R.id.title, points, activePoints) {

        @Override
        public void buildDividers() {
            dividers = getCustomDividers(ctx, getObjects(), nightMode);
        }

        @Override
        public boolean isEnabled(int position) {
            Object obj = getItem(position);
            boolean labelView = (obj instanceof Integer);
            boolean topDividerView = (obj instanceof Boolean) && ((Boolean) obj);
            boolean bottomDividerView = (obj instanceof Boolean) && !((Boolean) obj);
            boolean enabled = !labelView && !topDividerView && !bottomDividerView;
            if (enabled && obj instanceof RadiusItem) {
                int type = ((RadiusItem) obj).type;
                enabled = type != WaypointHelper.POI;
            }
            return enabled;
        }

        @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;
            Object obj = getItem(position);
            boolean labelView = (obj instanceof Integer);
            boolean topDividerView = (obj instanceof Boolean) && ((Boolean) obj);
            boolean bottomDividerView = (obj instanceof Boolean) && !((Boolean) obj);
            if (obj instanceof RadiusItem) {
                final int type = ((RadiusItem) obj).type;
                v = createItemForRadiusProximity(ctx, type, running, position, thisAdapter, nightMode);
                // Drawable d = new ColorDrawable(mapActivity.getResources().getColor(R.color.dashboard_divider_light));
                AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
            } else if (labelView) {
                v = createItemForCategory(ctx, (Integer) obj, running, position, thisAdapter, nightMode, helper);
                AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
            } else if (topDividerView) {
                v = ctx.getLayoutInflater().inflate(R.layout.card_top_divider, null);
                AndroidUtils.setListBackground(mapActivity, v, nightMode);
            } else if (bottomDividerView) {
                v = ctx.getLayoutInflater().inflate(R.layout.card_bottom_divider, null);
                AndroidUtils.setListBackground(mapActivity, v, nightMode);
            } else if (obj instanceof LocationPointWrapper) {
                LocationPointWrapper point = (LocationPointWrapper) obj;
                v = updateWaypointItemView(edit, deletedPoints, app, ctx, helper, v, point, this, nightMode, flat);
                AndroidUtils.setListItemBackground(mapActivity, v, nightMode);
            }
            return v;
        }
    };
    for (Object p : points) {
        if (p instanceof LocationPointWrapper) {
            LocationPointWrapper w = (LocationPointWrapper) p;
            if (w.type == WaypointHelper.TARGETS) {
                final TargetPoint t = (TargetPoint) w.point;
                if (t.getOriginalPointDescription() != null && t.getOriginalPointDescription().isSearchingAddress(mapActivity)) {
                    GeocodingLookupService.AddressLookupRequest lookupRequest = new GeocodingLookupService.AddressLookupRequest(t.point, new GeocodingLookupService.OnAddressLookupResult() {

                        @Override
                        public void geocodingDone(String address) {
                            if (helperCallbacks != null) {
                                helperCallbacks.reloadAdapter();
                            } else {
                                reloadListAdapter(listAdapter);
                            }
                        // updateRouteInfoMenu(ctx);
                        }
                    }, null);
                    app.getGeocodingLookupService().lookupAddress(lookupRequest);
                }
            }
        }
    }
    return listAdapter;
}
Also used : StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) GeocodingLookupService(net.osmand.plus.GeocodingLookupService) ViewGroup(android.view.ViewGroup) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) SuppressLint(android.annotation.SuppressLint) FavouritePoint(net.osmand.data.FavouritePoint)

Example 4 with StableArrayAdapter

use of net.osmand.plus.views.controls.StableArrayAdapter in project Osmand by osmandapp.

the class WaypointDialogHelper method createItemForCategory.

protected View createItemForCategory(final FragmentActivity ctx, final int type, final int[] running, final int position, final ArrayAdapter<Object> thisAdapter, boolean nightMode, final WaypointDialogHelper helper) {
    View v;
    v = ctx.getLayoutInflater().inflate(R.layout.waypoint_header, null);
    final CompoundButton btn = (CompoundButton) v.findViewById(R.id.toggle_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, ctx);
            } else {
                enableType(running, thisAdapter, type, isChecked);
            }
        }
    });
    final TextViewEx optionsButton = (TextViewEx) v.findViewById(R.id.text_button);
    if (type == WaypointHelper.TARGETS) {
        optionsButton.setVisibility(View.VISIBLE);
        optionsButton.setTextColor(ContextCompat.getColor(ctx, nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light));
        optionsButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                boolean hasActivePoints = false;
                if (thisAdapter instanceof StableArrayAdapter) {
                    List<Object> items = ((StableArrayAdapter) thisAdapter).getActiveObjects();
                    if (items.size() > 0) {
                        if (items.size() > 1) {
                            hasActivePoints = true;
                        } else {
                            Object item = items.get(0);
                            if (item instanceof LocationPointWrapper) {
                                LocationPointWrapper w = (LocationPointWrapper) item;
                                if (w.getPoint() instanceof TargetPoint) {
                                    hasActivePoints = !((TargetPoint) w.point).start;
                                }
                            } else {
                                hasActivePoints = true;
                            }
                        }
                    }
                }
                if (hasActivePoints) {
                    TargetOptionsBottomSheetDialogFragment fragment = new TargetOptionsBottomSheetDialogFragment();
                    fragment.setUsedOnMap(true);
                    fragment.show(ctx.getSupportFragmentManager(), TargetOptionsBottomSheetDialogFragment.TAG);
                }
            }
        });
    } else {
        optionsButton.setVisibility(View.GONE);
    }
    TextView tv = (TextView) v.findViewById(R.id.header_text);
    AndroidUtils.setTextPrimaryColor(mapActivity, tv, nightMode);
    tv.setText(getHeader(type, checked, ctx));
    return v;
}
Also used : StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) TextViewEx(net.osmand.plus.widgets.TextViewEx) List(java.util.List) ArrayList(java.util.ArrayList) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 5 with StableArrayAdapter

use of net.osmand.plus.views.controls.StableArrayAdapter in project Osmand by osmandapp.

the class WaypointDialogHelper method deletePoint.

public static void deletePoint(final OsmandApplication app, Activity ctx, final ArrayAdapter adapter, final WaypointDialogHelper helper, final Object item, final List<LocationPointWrapper> deletedPoints, final boolean needCallback) {
    if (item instanceof LocationPointWrapper && adapter != null) {
        LocationPointWrapper point = (LocationPointWrapper) item;
        if (point.type == WaypointHelper.TARGETS && adapter instanceof StableArrayAdapter) {
            StableArrayAdapter stableAdapter = (StableArrayAdapter) adapter;
            if (helper != null && helper.helperCallbacks != null && needCallback) {
                helper.helperCallbacks.deleteWaypoint(stableAdapter.getPosition(item));
            }
            updateRouteInfoMenu(ctx);
        } else {
            ArrayList<LocationPointWrapper> arr = new ArrayList<>();
            arr.add(point);
            app.getWaypointHelper().removeVisibleLocationPoint(arr);
            deletedPoints.add(point);
            adapter.setNotifyOnChange(false);
            adapter.remove(point);
            if (adapter instanceof StableArrayAdapter) {
                StableArrayAdapter stableAdapter = (StableArrayAdapter) adapter;
                stableAdapter.getObjects().remove(item);
                stableAdapter.refreshData();
            }
            adapter.notifyDataSetChanged();
        }
    }
}
Also used : StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) ArrayList(java.util.ArrayList)

Aggregations

StableArrayAdapter (net.osmand.plus.views.controls.StableArrayAdapter)7 LocationPointWrapper (net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper)4 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 ArrayList (java.util.ArrayList)3 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)3 SuppressLint (android.annotation.SuppressLint)2 List (java.util.List)2 Toolbar (android.support.v7.widget.Toolbar)1 ViewGroup (android.view.ViewGroup)1 AbsListView (android.widget.AbsListView)1 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)1 ArrayAdapter (android.widget.ArrayAdapter)1 CompoundButton (android.widget.CompoundButton)1 FrameLayout (android.widget.FrameLayout)1 ListView (android.widget.ListView)1 ScrollView (android.widget.ScrollView)1 ObservableScrollView (com.github.ksoichiro.android.observablescrollview.ObservableScrollView)1