use of net.osmand.plus.views.controls.DynamicListView 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);
}
Aggregations