diff --git a/OsmAnd/res/layout-land/fragment_plan_route.xml b/OsmAnd/res/layout-land/fragment_plan_route.xml index 7123151125..ff21237f2e 100644 --- a/OsmAnd/res/layout-land/fragment_plan_route.xml +++ b/OsmAnd/res/layout-land/fragment_plan_route.xml @@ -143,7 +143,7 @@ android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:background="@null" - tools:src="@drawable/ic_sort_waypoint_dark"/> + tools:src="@drawable/ic_action_list_sort"/> + tools:src="@drawable/ic_action_list_sort"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index dd5c0206ed..c338c21cf8 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -36,6 +36,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MapViewTrackingUtilities; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.mapmarkers.PlanRouteSortByBottomSheetDialogFragment.PlanRouteSortByFragmentListener; import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback; import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter; import net.osmand.plus.measurementtool.RecyclerViewFragment; @@ -92,6 +93,10 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene if (snapToRoadFragment != null) { ((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener()); } + Fragment sortByFragment = fragmentManager.findFragmentByTag(PlanRouteSortByBottomSheetDialogFragment.TAG); + if (sortByFragment != null) { + ((PlanRouteSortByBottomSheetDialogFragment) sortByFragment).setListener(createSortByFragmentListener()); + } // If rotate the screen from landscape to portrait when the list of markers is displayed then // the RecyclerViewFragment will exist without view. This is necessary to remove it. if (!portrait) { @@ -125,7 +130,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene upDownIconIv = (ImageView) mainView.findViewById(R.id.up_down_icon); upDownIconIv.setImageDrawable(getContentIcon(R.drawable.ic_action_arrow_up)); - ((ImageView) mainView.findViewById(R.id.sort_icon)).setImageDrawable(getContentIcon(R.drawable.ic_sort_waypoint_dark)); + ((ImageView) mainView.findViewById(R.id.sort_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_list_sort)); mainView.findViewById(R.id.up_down_row).setOnClickListener(new View.OnClickListener() { @Override @@ -162,7 +167,9 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene mainView.findViewById(R.id.sort_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Toast.makeText(mapActivity, "Sort", Toast.LENGTH_SHORT).show(); + PlanRouteSortByBottomSheetDialogFragment fragment = new PlanRouteSortByBottomSheetDialogFragment(); + fragment.setListener(createSortByFragmentListener()); + fragment.show(mapActivity.getSupportFragmentManager(), PlanRouteSortByBottomSheetDialogFragment.TAG); } }); @@ -345,6 +352,27 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene }; } + private PlanRouteSortByFragmentListener createSortByFragmentListener() { + return new PlanRouteSortByFragmentListener() { + + private MapActivity mapActivity = getMapActivity(); + + @Override + public void doorByDoorOnClick() { + if (mapActivity != null) { + Toast.makeText(mapActivity, "Door to Door", Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void reverseOrderOnClick() { + if (mapActivity != null) { + Toast.makeText(mapActivity, "Reverse order", Toast.LENGTH_SHORT).show(); + } + } + }; + } + private void enterPlanRouteMode() { final MapActivity mapActivity = getMapActivity(); MapMarkersLayer markersLayer = getMapMarkersLayer(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java new file mode 100644 index 0000000000..9008068b4f --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteSortByBottomSheetDialogFragment.java @@ -0,0 +1,142 @@ +package net.osmand.plus.mapmarkers; + +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.DrawableRes; +import android.support.annotation.Nullable; +import android.support.v4.content.ContextCompat; +import android.view.ContextThemeWrapper; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.ViewTreeObserver; +import android.view.Window; +import android.view.WindowManager; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.AndroidUtils; +import net.osmand.plus.R; +import net.osmand.plus.base.BottomSheetDialogFragment; +import net.osmand.plus.helpers.AndroidUiHelper; + +public class PlanRouteSortByBottomSheetDialogFragment extends BottomSheetDialogFragment { + + public final static String TAG = "PlanRouteSortByBottomSheetDialogFragment"; + + private boolean portrait; + private boolean night; + private PlanRouteSortByFragmentListener listener; + + public void setListener(PlanRouteSortByFragmentListener listener) { + this.listener = listener; + } + + @Nullable + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + night = getMyApplication().getDaynightHelper().isNightModeForMapControls(); + final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + + final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_plan_route_sort_by_bottom_sheet_dialog, container); + if (portrait) { + AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); + } + + if (night) { + ((TextView) mainView.findViewById(R.id.title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); + } + + ((ImageView) mainView.findViewById(R.id.door_to_door_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_door_to_door)); + ((ImageView) mainView.findViewById(R.id.reverse_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_reverse_order)); + + mainView.findViewById(R.id.door_to_door_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.doorByDoorOnClick(); + dismiss(); + } + } + }); + mainView.findViewById(R.id.reverse_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.reverseOrderOnClick(); + dismiss(); + } + } + }); + + mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + dismiss(); + } + }); + + final int screenHeight = AndroidUtils.getScreenHeight(getActivity()); + final int statusBarHeight = AndroidUtils.getStatusBarHeight(getActivity()); + final int navBarHeight = AndroidUtils.getNavBarHeight(getActivity()); + + mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + final View scrollView = mainView.findViewById(R.id.sort_by_scroll_view); + int scrollViewHeight = scrollView.getHeight(); + int dividerHeight = AndroidUtils.dpToPx(getContext(), 1); + int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); + int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight; + if (scrollViewHeight > spaceForScrollView) { + scrollView.getLayoutParams().height = spaceForScrollView; + scrollView.requestLayout(); + } + + if (!portrait) { + if (screenHeight - statusBarHeight - mainView.getHeight() >= AndroidUtils.dpToPx(getActivity(), 8)) { + AndroidUtils.setBackground(getActivity(), mainView, false, + R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); + } else { + AndroidUtils.setBackground(getActivity(), mainView, false, + R.drawable.bg_bottom_sheet_sides_landscape_light, R.drawable.bg_bottom_sheet_sides_landscape_dark); + } + } + + ViewTreeObserver obs = mainView.getViewTreeObserver(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + obs.removeOnGlobalLayoutListener(this); + } else { + obs.removeGlobalOnLayoutListener(this); + } + } + }); + + return mainView; + } + + @Override + public void onStart() { + super.onStart(); + if (!portrait) { + final Window window = getDialog().getWindow(); + WindowManager.LayoutParams params = window.getAttributes(); + params.width = getActivity().getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width); + window.setAttributes(params); + } + } + + @Override + protected Drawable getContentIcon(@DrawableRes int id) { + return getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); + } + + interface PlanRouteSortByFragmentListener { + + void doorByDoorOnClick(); + + void reverseOrderOnClick(); + } +}