diff --git a/OsmAnd/res/layout/fragment_snap_to_road_bottom_sheet_dialog.xml b/OsmAnd/res/layout/fragment_snap_to_road_bottom_sheet_dialog.xml
index 15eabef32f..86e1ad62e5 100644
--- a/OsmAnd/res/layout/fragment_snap_to_road_bottom_sheet_dialog.xml
+++ b/OsmAnd/res/layout/fragment_snap_to_road_bottom_sheet_dialog.xml
@@ -1,15 +1,15 @@
-
+ android:background="@drawable/bg_bottom_menu_dark">
-
+ android:layout_height="wrap_content"
+ android:background="?attr/bg_color"
+ android:orientation="vertical">
-
+
-
+
-
+
+
-
-
+
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java
index f1adb4ac87..9b8084ad99 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/SnapToRoadBottomSheetDialogFragment.java
@@ -1,32 +1,33 @@
package net.osmand.plus.measurementtool;
+import android.app.Dialog;
+import android.content.DialogInterface;
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.design.widget.BottomSheetBehavior;
+import android.support.design.widget.BottomSheetDialog;
+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.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
+import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
-import net.osmand.plus.base.BottomSheetDialogFragment;
+import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import java.util.ArrayList;
import java.util.List;
-public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragment {
+public class SnapToRoadBottomSheetDialogFragment extends android.support.design.widget.BottomSheetDialogFragment {
public static final String TAG = "SnapToRoadBottomSheetDialogFragment";
@@ -39,18 +40,20 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
this.listener = listener;
}
- @Nullable
@Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ public void setupDialog(Dialog dialog, int style) {
+ super.setupDialog(dialog, style);
+
nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
final OsmandSettings settings = getMyApplication().getSettings();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
- final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_snap_to_road_bottom_sheet_dialog, container);
- if (portrait) {
- AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
- }
+ final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_snap_to_road_bottom_sheet_dialog, null);
+
+ AndroidUtils.setBackground(getActivity(), mainView, nightMode,
+ portrait ? R.drawable.bg_bottom_menu_light : R.drawable.bg_bottom_sheet_topsides_landscape_light,
+ portrait ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_sheet_topsides_landscape_dark);
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
@Override
@@ -58,13 +61,16 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
dismiss();
}
});
+
if (nightMode) {
- ((TextView) mainView.findViewById(R.id.choose_navigation_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark));
+ ((TextView) mainView.findViewById(R.id.choose_navigation_title))
+ .setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark));
}
- LinearLayout navContainer = (LinearLayout) mainView.findViewById(R.id.navigation_types_container);
+ LinearLayout container = (LinearLayout) mainView.findViewById(R.id.navigation_types_container);
final List modes = new ArrayList<>(ApplicationMode.values(settings));
modes.remove(ApplicationMode.DEFAULT);
+
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
@@ -75,6 +81,7 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
dismiss();
}
};
+
for (int i = 0; i < modes.size(); i++) {
ApplicationMode mode = modes.get(i);
View row = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.list_item_icon_and_title, null);
@@ -82,47 +89,22 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
((TextView) row.findViewById(R.id.title)).setText(mode.toHumanString(getContext()));
row.setOnClickListener(onClickListener);
row.setTag(i);
- navContainer.addView(row);
+ container.addView(row);
}
- 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.navigation_types_scroll_view);
- int scrollViewHeight = scrollView.getHeight();
- int dividerHeight = AndroidUtils.dpToPx(getContext(), 1);
- int cancelButtonHeight = getContext().getResources().getDimensionPixelSize(R.dimen.measure_distance_bottom_sheet_cancel_button_height);
- int spaceForScrollView = screenHeight - statusBarHeight - navBarHeight - dividerHeight - cancelButtonHeight;
- if (scrollViewHeight > spaceForScrollView) {
- scrollView.getLayoutParams().height = spaceForScrollView;
- scrollView.requestLayout();
+ if (!portrait) {
+ dialog.setOnShowListener(new DialogInterface.OnShowListener() {
+ @Override
+ public void onShow(DialogInterface dialogInterface) {
+ BottomSheetDialog dialog = (BottomSheetDialog) dialogInterface;
+ FrameLayout bottomSheet = (FrameLayout) dialog.findViewById(android.support.design.R.id.design_bottom_sheet);
+ BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
}
+ });
+ }
- if (!portrait) {
- if (screenHeight - statusBarHeight - mainView.getHeight()
- >= AndroidUtils.dpToPx(getActivity(), 8)) {
- AndroidUtils.setBackground(getActivity(), mainView, nightMode,
- R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark);
- } else {
- AndroidUtils.setBackground(getActivity(), mainView, nightMode,
- 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;
+ dialog.setContentView(mainView);
+ ((View) mainView.getParent()).setBackgroundResource(0);
}
@Override
@@ -144,9 +126,13 @@ public class SnapToRoadBottomSheetDialogFragment extends BottomSheetDialogFragme
super.onDestroyView();
}
- @Override
- protected Drawable getContentIcon(@DrawableRes int id) {
- return getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
+ private OsmandApplication getMyApplication() {
+ return ((MapActivity) getActivity()).getMyApplication();
+ }
+
+ private Drawable getContentIcon(@DrawableRes int id) {
+ return getMyApplication().getIconsCache()
+ .getIcon(id, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color);
}
interface SnapToRoadFragmentListener {