Search in sources :

Example 6 with StableArrayAdapter

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

the class DashboardOnMap method createDashboardView.

public void createDashboardView() {
    baseColor = ContextCompat.getColor(mapActivity, R.color.osmand_orange) & 0x00ffffff;
    waypointDialogHelper = new WaypointDialogHelper(mapActivity);
    waypointDialogHelper.setHelperCallbacks(this);
    landscape = !AndroidUiHelper.isOrientationPortrait(mapActivity);
    dashboardView = (FrameLayout) mapActivity.findViewById(R.id.dashboard);
    AndroidUtils.addStatusBarPadding21v(mapActivity, dashboardView);
    final View.OnClickListener listener = new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hideDashboard();
        }
    };
    toolbar = ((Toolbar) dashboardView.findViewById(R.id.toolbar));
    ObservableScrollView scrollView = ((ObservableScrollView) dashboardView.findViewById(R.id.main_scroll));
    listView = (DynamicListView) dashboardView.findViewById(R.id.dash_list_view);
    // listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setDrawSelectorOnTop(true);
    listView.setDynamicListViewCallbacks(this);
    listEmptyTextView = (TextView) dashboardView.findViewById(R.id.emptyTextView);
    // Create a ListView-specific touch listener. ListViews are given special treatment because
    // by default they handle touches for their list items... i.e. they're in charge of drawing
    // the pressed state (the list selector), handling list item clicks, etc.
    swipeDismissListener = new SwipeDismissListViewTouchListener(mapActivity, listView, new DismissCallbacks() {

        @Override
        public boolean canDismiss(int position) {
            if (listAdapter instanceof StableArrayAdapter && (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT)) {
                List<Object> activeObjects = ((StableArrayAdapter) listAdapter).getActiveObjects();
                Object obj = listAdapter.getItem(position);
                if (obj instanceof LocationPointWrapper) {
                    LocationPointWrapper w = (LocationPointWrapper) obj;
                    if (w.getPoint() instanceof TargetPoint) {
                        return !((TargetPoint) w.getPoint()).start;
                    }
                }
                return activeObjects.contains(obj);
            }
            return false;
        }

        @Override
        public Undoable onDismiss(final int position) {
            final Object item;
            final StableArrayAdapter stableAdapter;
            final int activeObjPos;
            if (listAdapter instanceof StableArrayAdapter) {
                stableAdapter = (StableArrayAdapter) listAdapter;
                item = stableAdapter.getItem(position);
                stableAdapter.setNotifyOnChange(false);
                stableAdapter.remove(item);
                stableAdapter.getObjects().remove(item);
                activeObjPos = stableAdapter.getActiveObjects().indexOf(item);
                stableAdapter.getActiveObjects().remove(item);
                stableAdapter.refreshData();
                stableAdapter.notifyDataSetChanged();
            } else {
                item = null;
                stableAdapter = null;
                activeObjPos = 0;
            }
            return new Undoable() {

                @Override
                public void undo() {
                    if (item != null) {
                        stableAdapter.setNotifyOnChange(false);
                        stableAdapter.insert(item, position);
                        stableAdapter.getObjects().add(position, item);
                        stableAdapter.getActiveObjects().add(activeObjPos, item);
                        stableAdapter.refreshData();
                        if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) {
                            onItemsSwapped(stableAdapter.getActiveObjects());
                        }
                    }
                }

                @Override
                public String getTitle() {
                    List<Object> activeObjects;
                    if ((visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) && (getMyApplication().getRoutingHelper().isRoutePlanningMode() || getMyApplication().getRoutingHelper().isFollowingMode()) && item != null && ((activeObjects = stableAdapter.getActiveObjects()).isEmpty() || isContainsOnlyStart(activeObjects))) {
                        return mapActivity.getResources().getString(R.string.cancel_navigation);
                    } else {
                        return null;
                    }
                }
            };
        }

        @Override
        public void onHidePopup() {
            if (listAdapter instanceof StableArrayAdapter) {
                StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter;
                stableAdapter.refreshData();
                if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) {
                    onItemsSwapped(stableAdapter.getActiveObjects());
                }
                List<Object> activeObjects = stableAdapter.getActiveObjects();
                if (activeObjects.isEmpty() || isContainsOnlyStart(activeObjects)) {
                    hideDashboard();
                    if (visibleType == DashboardType.WAYPOINTS || visibleType == DashboardType.WAYPOINTS_FLAT) {
                        mapActivity.getMapActions().stopNavigationWithoutConfirm();
                        getMyApplication().getTargetPointsHelper().removeAllWayPoints(false, true);
                        mapActivity.getMapLayers().getMapControlsLayer().getMapRouteInfoMenu().hide();
                    }
                }
            }
        }

        private boolean isContainsOnlyStart(List<Object> items) {
            if (items.size() == 1) {
                Object item = items.get(0);
                if (item instanceof LocationPointWrapper) {
                    LocationPointWrapper w = (LocationPointWrapper) item;
                    if (w.getPoint() instanceof TargetPoint) {
                        return ((TargetPoint) w.getPoint()).start;
                    }
                }
            }
            return false;
        }
    });
    gradientToolbar = ContextCompat.getDrawable(mapActivity, R.drawable.gradient_toolbar).mutate();
    if (AndroidUiHelper.isOrientationPortrait(mapActivity)) {
        this.portrait = true;
        scrollView.setScrollViewCallbacks(this);
        listView.setScrollViewCallbacks(this);
        mFlexibleSpaceImageHeight = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_map_top_padding);
        mFlexibleBlurSpaceHeight = mapActivity.getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar);
        // Set padding view for ListView. This is the flexible space.
        paddingView = new FrameLayout(mapActivity);
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, mFlexibleSpaceImageHeight);
        paddingView.setLayoutParams(lp);
        // This is required to disable header's list selector effect
        paddingView.setClickable(true);
        paddingView.setOnClickListener(listener);
        FrameLayout shadowContainer = new FrameLayout(mapActivity);
        FrameLayout.LayoutParams fl = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
        fl.gravity = Gravity.BOTTOM;
        shadowContainer.setLayoutParams(fl);
        ImageView shadow = new ImageView(mapActivity);
        shadow.setImageDrawable(ContextCompat.getDrawable(mapActivity, R.drawable.bg_shadow_onmap));
        shadow.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM));
        shadow.setScaleType(ScaleType.FIT_XY);
        shadowContainer.addView(shadow);
        ((FrameLayout) paddingView).addView(shadowContainer);
        listView.addHeaderView(paddingView);
        listBackgroundView = mapActivity.findViewById(R.id.dash_list_background);
    }
    dashboardView.findViewById(R.id.animateContent).setOnClickListener(listener);
    dashboardView.findViewById(R.id.map_part_dashboard).setOnClickListener(listener);
    initActionButtons();
    dashboardView.addView(actionButton);
}
Also used : Undoable(net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.Undoable) StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) WaypointDialogHelper(net.osmand.plus.helpers.WaypointDialogHelper) LocationPointWrapper(net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper) AbsListView(android.widget.AbsListView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) ImageView(android.widget.ImageView) DynamicListView(net.osmand.plus.views.controls.DynamicListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ScrollView(android.widget.ScrollView) ObservableScrollView(com.github.ksoichiro.android.observablescrollview.ObservableScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) SuppressLint(android.annotation.SuppressLint) SwipeDismissListViewTouchListener(net.osmand.plus.views.controls.SwipeDismissListViewTouchListener) FrameLayout(android.widget.FrameLayout) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) ImageView(android.widget.ImageView) DismissCallbacks(net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.DismissCallbacks) Toolbar(android.support.v7.widget.Toolbar)

Example 7 with StableArrayAdapter

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

the class DashboardOnMap method reloadAdapter.

@Override
public void reloadAdapter() {
    if (listAdapter != null && listAdapter instanceof StableArrayAdapter) {
        StableArrayAdapter stableAdapter = (StableArrayAdapter) listAdapter;
        if (DashboardType.WAYPOINTS == visibleType || DashboardType.WAYPOINTS_FLAT == visibleType) {
            waypointDialogHelper.reloadListAdapter(stableAdapter);
        }
        setDynamicListItems(listView, stableAdapter);
    }
}
Also used : StableArrayAdapter(net.osmand.plus.views.controls.StableArrayAdapter)

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