From f88b55470940bbb97e95a144482401e5823dcfc0 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 30 Oct 2017 11:25:09 +0200 Subject: [PATCH] Create base class for menus --- .../base/MenuBottomSheetDialogFragment.java | 81 +++++++++++++++++ .../osmand/plus/helpers/GpxImportHelper.java | 70 ++------------- ...rdinateInputBottomSheetDialogFragment.java | 72 ++-------------- ...ryMarkerMenuBottomSheetDialogFragment.java | 66 ++------------ .../OptionsBottomSheetDialogFragment.java | 86 +++---------------- .../OrderByBottomSheetDialogFragment.java | 86 +++---------------- ...RouteOptionsBottomSheetDialogFragment.java | 71 ++------------- ...howDirectionBottomSheetDialogFragment.java | 71 ++------------- .../OptionsBottomSheetDialogFragment.java | 76 ++-------------- ...veAsNewTrackBottomSheetDialogFragment.java | 78 ++--------------- ...electedPointBottomSheetDialogFragment.java | 77 ++--------------- 11 files changed, 157 insertions(+), 677 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java new file mode 100644 index 0000000000..5ee1b9a6be --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -0,0 +1,81 @@ +package net.osmand.plus.base; + +import android.app.Activity; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.support.annotation.DrawableRes; +import android.view.View; +import android.view.ViewTreeObserver; +import android.view.Window; +import android.view.WindowManager; + +import net.osmand.AndroidUtils; +import net.osmand.plus.R; +import net.osmand.plus.helpers.AndroidUiHelper; + +public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFragment { + + @Override + public void onStart() { + super.onStart(); + if (!AndroidUiHelper.isOrientationPortrait(getActivity())) { + 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, isNightMode() ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); + } + + protected Drawable getActiveIcon(@DrawableRes int id) { + return getIcon(id, isNightMode() ? R.color.osmand_orange : R.color.color_myloc_distance); + } + + protected void setupHeightAndBackground(final View mainView, final int scrollViewId) { + final Activity activity = getActivity(); + final boolean night = isNightMode(); + final int screenHeight = AndroidUtils.getScreenHeight(activity); + final int statusBarHeight = AndroidUtils.getStatusBarHeight(activity); + final int navBarHeight = AndroidUtils.getNavBarHeight(activity); + + mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + final View scrollView = mainView.findViewById(scrollViewId); + 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 (AndroidUiHelper.isOrientationPortrait(activity)) { + AndroidUtils.setBackground(activity, mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); + } else { + if (screenHeight - statusBarHeight - mainView.getHeight() >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) { + AndroidUtils.setBackground(activity, mainView, night, + R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); + } else { + AndroidUtils.setBackground(activity, mainView, night, + 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); + } + } + }); + } + + protected abstract boolean isNightMode(); +} diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java index 3d2ade1e96..4697fc7406 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java @@ -4,15 +4,12 @@ import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.provider.OpenableColumns; import android.provider.Settings; -import android.support.annotation.DrawableRes; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.support.v7.app.AlertDialog; @@ -24,14 +21,10 @@ 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 android.widget.Toast; -import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.data.FavouritePoint; import net.osmand.plus.FavouritesDbHelper; @@ -40,7 +33,7 @@ import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.BottomSheetDialogFragment; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.views.OsmandMapTileView; @@ -605,13 +598,11 @@ public class GpxImportHelper { return false; } - public static class ImportGpxBottomSheetDialogFragment extends BottomSheetDialogFragment { + public static class ImportGpxBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public static final String TAG = "ImportGpxBottomSheetDialogFragment"; private GpxImportHelper gpxImportHelper; - private boolean portrait; - private boolean night; private GPXFile gpxFile; private String fileName; @@ -641,14 +632,10 @@ public class GpxImportHelper { @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - night = getMyApplication().getDaynightHelper().isNightModeForMapControls(); + boolean night = isNightMode(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_import_gpx_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.import_gpx_title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); @@ -687,59 +674,14 @@ public class GpxImportHelper { } }); - 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.import_gpx_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() >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) { - AndroidUtils.setBackground(getActivity(), mainView, night, - R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); - } else { - AndroidUtils.setBackground(getActivity(), mainView, night, - 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); - } - } - }); + setupHeightAndBackground(mainView, R.id.import_gpx_scroll_view); 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); + protected boolean isNightMode() { + return getMyApplication().getDaynightHelper().isNightModeForMapControls(); } } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java index 3721a6f52d..d10e7fb311 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -1,36 +1,27 @@ package net.osmand.plus.mapmarkers; 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.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.CompoundButton; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.TextView; -import net.osmand.AndroidUtils; import net.osmand.data.PointDescription; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.BottomSheetDialogFragment; -import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; -public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogFragment { +public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "CoordinateInputBottomSheetDialogFragment"; - private boolean portrait; private View mainView; private boolean night; private int coordinateFormat = -1; @@ -58,15 +49,11 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final MapActivity mapActivity = (MapActivity) getActivity(); - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - night = !mapActivity.getMyApplication().getSettings().isLightContent(); + night = isNightMode(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), coordinateFormat == -1 ? R.layout.fragment_marker_coordinate_input_bottom_sheet_dialog : R.layout.fragment_marker_coordinate_input_options_bottom_sheet_helper, 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.coordinate_input_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); @@ -162,57 +149,11 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF } }); - 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.marker_coordinate_input_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, night, - R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); - } else { - AndroidUtils.setBackground(getActivity(), mainView, night, - 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); - } - } - }); + setupHeightAndBackground(mainView, R.id.marker_coordinate_input_scroll_view); 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 public void onCancel(DialogInterface dialog) { super.onCancel(dialog); @@ -222,8 +163,8 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF } @Override - protected Drawable getContentIcon(@DrawableRes int id) { - return getIcon(id, night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); + protected boolean isNightMode() { + return !getMyApplication().getSettings().isLightContent(); } private void highlightSelectedItem(boolean check) { @@ -255,6 +196,5 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF void onKeyboardChanged(boolean useOsmandKeyboard); void onCancel(); - } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index c6b8d359be..2b5c153f08 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -1,29 +1,23 @@ package net.osmand.plus.mapmarkers; -import android.os.Build; import android.os.Bundle; import android.support.annotation.Nullable; 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.MapMarkersHelper.MapMarker; import net.osmand.plus.R; -import net.osmand.plus.base.BottomSheetDialogFragment; -import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; -public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialogFragment { +public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "HistoryMarkerMenuBottomSheetDialogFragment"; @@ -33,7 +27,6 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo public static final String MARKER_VISITED_DATE = "marker_visited_date"; private HistoryMarkerMenuFragmentListener listener; - private boolean portrait; public void setListener(HistoryMarkerMenuFragmentListener listener) { this.listener = listener; @@ -42,14 +35,10 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - final boolean nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); + final boolean nightMode = isNightMode(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_history_bottom_sheet_dialog, container); - if (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); - } Bundle arguments = getArguments(); if (arguments != null) { @@ -98,59 +87,20 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends BottomSheetDialo } }); - 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.history_marker_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() - >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) { - 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); - } - } - }); + setupHeightAndBackground(mainView, R.id.history_marker_scroll_view); 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); - } + protected boolean isNightMode() { + return getMyApplication().getDaynightHelper().isNightModeForMapControls(); } interface HistoryMarkerMenuFragmentListener { + void onMakeMarkerActive(int pos); + void onDeleteMarker(int pos); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java index 8da8580f2f..34ec055c60 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java @@ -1,36 +1,27 @@ 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.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.BottomSheetDialogFragment; -import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; -public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment { +public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "OptionsBottomSheetDialogFragment"; public final static String SHOW_SORT_BY_ROW = "show_sort_by_row"; public final static String SHOW_MOVE_ALL_TO_HISTORY_ROW = "show_move_to_history_row"; private MarkerOptionsFragmentListener listener; - private boolean portrait; private boolean showSortBy; private boolean showMoveAllToHistory; @@ -50,17 +41,12 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { MapActivity mapActivity = (MapActivity) getActivity(); - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - final boolean nightMode = !getMyApplication().getSettings().isLightContent(); + final boolean nightMode = isNightMode(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_options_bottom_sheet_dialog, container); - if (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); - } - ((ImageView) mainView.findViewById(R.id.sort_by_icon)) - .setImageDrawable(getContentIcon(R.drawable.ic_sort_waypoint_dark)); + ((ImageView) mainView.findViewById(R.id.sort_by_icon)).setImageDrawable(getContentIcon(R.drawable.ic_sort_waypoint_dark)); OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); ImageView showDirectionIcon = (ImageView) mainView.findViewById(R.id.show_direction_icon); int imageResId = 0; @@ -76,14 +62,10 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment if (imageResId != 0) { showDirectionIcon.setImageDrawable(getIcon(imageResId, R.color.dashboard_blue)); } - ((ImageView) mainView.findViewById(R.id.coordinate_input_icon)) - .setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_longitude)); - ((ImageView) mainView.findViewById(R.id.build_route_icon)) - .setImageDrawable(getContentIcon(R.drawable.ic_action_gdirections_dark)); - ((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)) - .setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); - ((ImageView) mainView.findViewById(R.id.move_all_to_history_icon)) - .setImageDrawable(getContentIcon(R.drawable.ic_action_history2)); + ((ImageView) mainView.findViewById(R.id.coordinate_input_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_coordinates_longitude)); + ((ImageView) mainView.findViewById(R.id.build_route_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_gdirections_dark)); + ((ImageView) mainView.findViewById(R.id.save_as_new_track_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); + ((ImageView) mainView.findViewById(R.id.move_all_to_history_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_history2)); ((TextView) mainView.findViewById(R.id.show_direction_text_view)).setTextColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.color_dialog_buttons_dark : R.color.map_widget_blue_pressed)); ((TextView) mainView.findViewById(R.id.show_direction_text_view)).setText(getMyApplication().getSettings().MAP_MARKERS_MODE.get().toHumanString(getActivity())); @@ -160,60 +142,14 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment } }); - 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.marker_options_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() - >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) { - 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); - } - } - }); + setupHeightAndBackground(mainView, R.id.marker_options_scroll_view); 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, getMyApplication().getSettings().isLightContent() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark); + protected boolean isNightMode() { + return !getMyApplication().getSettings().isLightContent(); } interface MarkerOptionsFragmentListener { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java index c2cee573e1..662abffe13 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java @@ -1,32 +1,23 @@ 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.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.OsmandSettings; import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode; import net.osmand.plus.R; -import net.osmand.plus.base.BottomSheetDialogFragment; -import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; -public class OrderByBottomSheetDialogFragment extends BottomSheetDialogFragment { +public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "OrderByBottomSheetDialogFragment"; - private boolean portrait; private OsmandSettings settings; private OrderByFragmentListener listener; @@ -37,32 +28,21 @@ public class OrderByBottomSheetDialogFragment extends BottomSheetDialogFragment @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); settings = getMyApplication().getSettings(); - final boolean night = !settings.isLightContent(); + final boolean night = isNightMode(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_order_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.order_by_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); } ((TextView) mainView.findViewById(R.id.order_by_title)).setText(getString(R.string.order_by)); - ImageView distanceIcon = (ImageView) mainView.findViewById(R.id.distance_icon); - distanceIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_markers_dark)); - - ImageView nameIcon = (ImageView) mainView.findViewById(R.id.name_icon); - nameIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_name)); - - ImageView dateAddedAscIcon = (ImageView) mainView.findViewById(R.id.date_added_asc_icon); - dateAddedAscIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date)); - - ImageView dateAddedDescIcon = (ImageView) mainView.findViewById(R.id.date_added_desc_icon); - dateAddedDescIcon.setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date)); + ((ImageView) mainView.findViewById(R.id.distance_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_markers_dark)); + ((ImageView) mainView.findViewById(R.id.name_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_name)); + ((ImageView) mainView.findViewById(R.id.date_added_asc_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date)); + ((ImageView) mainView.findViewById(R.id.date_added_desc_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_by_date)); ((TextView) mainView.findViewById(R.id.date_added_asc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.ascendingly) + ")"); ((TextView) mainView.findViewById(R.id.date_added_desc_text)).setText(getString(R.string.date_added) + " (" + getString(R.string.descendingly) + ")"); @@ -79,60 +59,14 @@ public class OrderByBottomSheetDialogFragment extends BottomSheetDialogFragment } }); - 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.marker_order_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() - >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) { - AndroidUtils.setBackground(getActivity(), mainView, night, - R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); - } else { - AndroidUtils.setBackground(getActivity(), mainView, night, - 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); - } - } - }); + setupHeightAndBackground(mainView, R.id.marker_order_by_scroll_view); 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, settings.isLightContent() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark); + protected boolean isNightMode() { + return !getMyApplication().getSettings().isLightContent(); } private View.OnClickListener orderByModeOnClickListener = new View.OnClickListener() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java index 02228c50fc..fe26b7190e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java @@ -1,33 +1,24 @@ 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.CompoundButton; 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.base.MenuBottomSheetDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; -public class PlanRouteOptionsBottomSheetDialogFragment extends BottomSheetDialogFragment { +public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "PlanRouteOptionsBottomSheetDialogFragment"; - private boolean portrait; - private boolean night; private PlanRouteOptionsFragmentListener listener; private boolean selectAll; @@ -42,14 +33,11 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends BottomSheetDialog @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - night = getMyApplication().getDaynightHelper().isNightModeForMapControls(); + boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + boolean 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_options_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)); @@ -123,59 +111,14 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends BottomSheetDialog } }); - 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() >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) { - AndroidUtils.setBackground(getActivity(), mainView, night, - R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); - } else { - AndroidUtils.setBackground(getActivity(), mainView, night, - 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); - } - } - }); + setupHeightAndBackground(mainView, R.id.sort_by_scroll_view); 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); + protected boolean isNightMode() { + return getMyApplication().getDaynightHelper().isNightModeForMapControls(); } interface PlanRouteOptionsFragmentListener { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index a9530827fc..dc35ad760f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -2,10 +2,7 @@ package net.osmand.plus.mapmarkers; import android.app.Activity; import android.graphics.Typeface; -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; @@ -13,28 +10,22 @@ import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; -import android.view.ViewTreeObserver; -import android.view.Window; -import android.view.WindowManager; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.RadioButton; import android.widget.TextView; -import net.osmand.AndroidUtils; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.BottomSheetDialogFragment; -import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.helpers.FontCache; -public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFragment { +public class ShowDirectionBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "ShowDirectionBottomSheetDialogFragment"; private ShowDirectionFragmentListener listener; - private boolean portrait; private View mainView; private boolean night; @@ -46,14 +37,10 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final OsmandSettings settings = getMyApplication().getSettings(); - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - night = !settings.isLightContent(); + night = isNightMode(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container); - if (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); - } OsmandSettings.MapMarkersMode mode = settings.MAP_MARKERS_MODE.get(); highlightSelectedItem(mode, true); @@ -142,60 +129,14 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra } }); - 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.marker_show_direction_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() - >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) { - AndroidUtils.setBackground(getActivity(), mainView, night, - R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); - } else { - AndroidUtils.setBackground(getActivity(), mainView, night, - 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); - } - } - }); + setupHeightAndBackground(mainView, R.id.marker_show_direction_scroll_view); 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); + protected boolean isNightMode() { + return !getMyApplication().getSettings().isLightContent(); } private MapActivity getMapActivity() { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index d8fec9de3f..1b5214d548 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -1,34 +1,24 @@ package net.osmand.plus.measurementtool; -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.v7.widget.SwitchCompat; 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 net.osmand.AndroidUtils; import net.osmand.plus.R; -import net.osmand.plus.base.BottomSheetDialogFragment; -import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.widgets.TextViewEx; -public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment { +public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "OptionsBottomSheetDialogFragment"; private OptionsFragmentListener listener; private boolean addLineMode; - private boolean portrait; - private boolean nightMode; private boolean snapToRoadEnabled; public void setListener(OptionsFragmentListener listener) { @@ -46,14 +36,10 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + boolean nightMode = isNightMode(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_options_bottom_sheet_dialog, null); - if (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); - } if (nightMode) { ((TextViewEx) mainView.findViewById(R.id.options_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); @@ -131,64 +117,14 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment } }); - 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.measure_options_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() - >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) { - 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); - } - } - }); + setupHeightAndBackground(mainView, R.id.measure_options_scroll_view); 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, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); - } - - private Drawable getActiveIcon(@DrawableRes int id) { - return getIcon(id, nightMode ? R.color.osmand_orange : R.color.color_myloc_distance); + protected boolean isNightMode() { + return getMyApplication().getDaynightHelper().isNightModeForMapControls(); } interface OptionsFragmentListener { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index 91e143c1eb..b8100060ae 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -1,33 +1,23 @@ package net.osmand.plus.measurementtool; -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.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.MotionEvent; 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; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; -public class SaveAsNewTrackBottomSheetDialogFragment extends BottomSheetDialogFragment { +public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "SaveAsNewTrackBottomSheetDialogFragment"; private SaveAsNewTrackFragmentListener listener; - private boolean nightMode; - private boolean portrait; public void setListener(SaveAsNewTrackFragmentListener listener) { this.listener = listener; @@ -36,14 +26,10 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends BottomSheetDialogFr @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + boolean nightMode = isNightMode(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_save_as_new_track_bottom_sheet_dialog, container); - if (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); - } if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { mainView.findViewById(R.id.images_row).setVisibility(View.GONE); @@ -92,62 +78,11 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends BottomSheetDialogFr } }); - 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.save_as_new_track_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, 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); - } - } - }); + setupHeightAndBackground(mainView, R.id.save_as_new_track_scroll_view); 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, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); - } - private View.OnClickListener saveAsLineOnClickListener = new View.OnClickListener() { @Override public void onClick(View view) { @@ -168,6 +103,11 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends BottomSheetDialogFr } }; + @Override + protected boolean isNightMode() { + return getMyApplication().getDaynightHelper().isNightModeForMapControls(); + } + interface SaveAsNewTrackFragmentListener { void saveAsRoutePointOnClick(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index 6588e9fd12..a2d973ab65 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -1,42 +1,31 @@ package net.osmand.plus.measurementtool; 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.text.TextUtils; 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.GPXUtilities.WptPt; -import net.osmand.plus.IconsCache; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.base.BottomSheetDialogFragment; -import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.measurementtool.NewGpxData.ActionType; import net.osmand.util.MapUtils; import java.util.List; -public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFragment { +public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public final static String TAG = "SelectedPointBottomSheetDialogFragment"; private SelectedPointFragmentListener listener; - private boolean nightMode; - private boolean portrait; public void setListener(SelectedPointFragmentListener listener) { this.listener = listener; @@ -46,19 +35,13 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final MapActivity mapActivity = (MapActivity) getActivity(); - nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - portrait = AndroidUiHelper.isOrientationPortrait(mapActivity); - final IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); + boolean nightMode = isNightMode(); final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_selected_menu_bottom_sheet_dialog, null); - if (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); - } - int color = nightMode ? R.color.osmand_orange : R.color.color_myloc_distance; - ((ImageView) mainView.findViewById(R.id.selected_point_icon)).setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_measure_point, color)); + ((ImageView) mainView.findViewById(R.id.selected_point_icon)).setImageDrawable(getActiveIcon(R.drawable.ic_action_measure_point)); ((ImageView) mainView.findViewById(R.id.move_point_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_move_point)); ((ImageView) mainView.findViewById(R.id.delete_point_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_remove_dark)); ((ImageView) mainView.findViewById(R.id.add_point_after_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_addpoint_above)); @@ -157,60 +140,14 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra } } - 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.selected_point_options_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() - >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) { - 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); - } - } - }); + setupHeightAndBackground(mainView, R.id.selected_point_options_scroll_view); 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, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); + protected boolean isNightMode() { + return getMyApplication().getDaynightHelper().isNightModeForMapControls(); } @Override