use of net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper 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;
}
use of net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper 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();
}
}
}
use of net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper 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