From f88b55470940bbb97e95a144482401e5823dcfc0 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 30 Oct 2017 11:25:09 +0200 Subject: [PATCH 1/5] 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 From d7bc5c840d36a383a7e436d6e4166476b9d5e781 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 30 Oct 2017 13:47:35 +0200 Subject: [PATCH 2/5] Fix getting type of content (light/dark) --- .../base/MenuBottomSheetDialogFragment.java | 26 ++++++++++++++++++- .../osmand/plus/helpers/GpxImportHelper.java | 6 +---- ...rdinateInputBottomSheetDialogFragment.java | 5 ---- ...ryMarkerMenuBottomSheetDialogFragment.java | 6 +---- .../OptionsBottomSheetDialogFragment.java | 5 ---- .../OrderByBottomSheetDialogFragment.java | 5 ---- ...RouteOptionsBottomSheetDialogFragment.java | 8 ++---- ...howDirectionBottomSheetDialogFragment.java | 5 ---- .../OptionsBottomSheetDialogFragment.java | 6 +---- ...veAsNewTrackBottomSheetDialogFragment.java | 6 +---- ...electedPointBottomSheetDialogFragment.java | 6 +---- 11 files changed, 32 insertions(+), 52 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 5ee1b9a6be..cd9aab37c1 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.base; import android.app.Activity; import android.graphics.drawable.Drawable; import android.os.Build; +import android.os.Bundle; import android.support.annotation.DrawableRes; import android.view.View; import android.view.ViewTreeObserver; @@ -15,6 +16,18 @@ import net.osmand.plus.helpers.AndroidUiHelper; public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFragment { + private static final String USED_ON_MAP_KEY = "used_on_map"; + + protected boolean usedOnMap; + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + if (savedInstanceState != null) { + usedOnMap = savedInstanceState.getBoolean(USED_ON_MAP_KEY); + } + } + @Override public void onStart() { super.onStart(); @@ -26,6 +39,12 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } } + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + outState.putBoolean(USED_ON_MAP_KEY, usedOnMap); + } + @Override protected Drawable getContentIcon(@DrawableRes int id) { return getIcon(id, isNightMode() ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); @@ -77,5 +96,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra }); } - protected abstract boolean isNightMode(); + protected boolean isNightMode() { + if (usedOnMap) { + getMyApplication().getDaynightHelper().isNightModeForMapControls(); + } + return !getMyApplication().getSettings().isLightContent(); + } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java index 4697fc7406..e7ab74f323 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java @@ -632,6 +632,7 @@ public class GpxImportHelper { @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + usedOnMap = true; boolean night = isNightMode(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; @@ -678,10 +679,5 @@ public class GpxImportHelper { return mainView; } - - @Override - 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 d10e7fb311..c4036f97fb 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -162,11 +162,6 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia } } - @Override - protected boolean isNightMode() { - return !getMyApplication().getSettings().isLightContent(); - } - private void highlightSelectedItem(boolean check) { int iconColor = check ? R.color.dashboard_blue : night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color; int textColor = ContextCompat.getColor(getContext(), check ? (night ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue) : night ? R.color.color_white : R.color.color_black); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index 2b5c153f08..22731ebcc2 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -35,6 +35,7 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + usedOnMap = true; final boolean nightMode = isNightMode(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; @@ -92,11 +93,6 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD return mainView; } - @Override - protected boolean isNightMode() { - return getMyApplication().getDaynightHelper().isNightModeForMapControls(); - } - interface HistoryMarkerMenuFragmentListener { void onMakeMarkerActive(int pos); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java index 34ec055c60..ee4e2d5bbf 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java @@ -147,11 +147,6 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm return mainView; } - @Override - protected boolean isNightMode() { - return !getMyApplication().getSettings().isLightContent(); - } - interface MarkerOptionsFragmentListener { void sortByOnClick(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java index 662abffe13..4e8b662bc6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java @@ -64,11 +64,6 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm return mainView; } - @Override - protected boolean isNightMode() { - return !getMyApplication().getSettings().isLightContent(); - } - private View.OnClickListener orderByModeOnClickListener = new View.OnClickListener() { @Override diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java index fe26b7190e..49ea0738d1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java @@ -33,8 +33,9 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + usedOnMap = true; boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - boolean 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_plan_route_options_bottom_sheet_dialog, container); @@ -116,11 +117,6 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi return mainView; } - @Override - protected boolean isNightMode() { - return getMyApplication().getDaynightHelper().isNightModeForMapControls(); - } - interface PlanRouteOptionsFragmentListener { void selectOnClick(); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index dc35ad760f..66a414ee1e 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -134,11 +134,6 @@ public class ShowDirectionBottomSheetDialogFragment extends MenuBottomSheetDialo return mainView; } - @Override - protected boolean isNightMode() { - return !getMyApplication().getSettings().isLightContent(); - } - private MapActivity getMapActivity() { Activity activity = getActivity(); if (activity != null) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index 1b5214d548..f395142ece 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -36,6 +36,7 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + usedOnMap = true; boolean nightMode = isNightMode(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; @@ -122,11 +123,6 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm return mainView; } - @Override - protected boolean isNightMode() { - return getMyApplication().getDaynightHelper().isNightModeForMapControls(); - } - interface OptionsFragmentListener { void snapToRoadOnCLick(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index b8100060ae..d47a61c1b4 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -26,6 +26,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + usedOnMap = true; boolean nightMode = isNightMode(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; @@ -103,11 +104,6 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial } }; - @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 a2d973ab65..35fb803cde 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -34,6 +34,7 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + usedOnMap = true; final MapActivity mapActivity = (MapActivity) getActivity(); boolean nightMode = isNightMode(); final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); @@ -145,11 +146,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo return mainView; } - @Override - protected boolean isNightMode() { - return getMyApplication().getDaynightHelper().isNightModeForMapControls(); - } - @Override public void dismiss() { if (listener != null) { From da49f91651a29665914fac81e9ce4f7ebda1ba30 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 30 Oct 2017 13:52:51 +0200 Subject: [PATCH 3/5] Add return --- .../src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index cd9aab37c1..2886f6533c 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -98,7 +98,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra protected boolean isNightMode() { if (usedOnMap) { - getMyApplication().getDaynightHelper().isNightModeForMapControls(); + return getMyApplication().getDaynightHelper().isNightModeForMapControls(); } return !getMyApplication().getSettings().isLightContent(); } From bfc273140fa9c225f2147cb9e087a4340dbe118e Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 30 Oct 2017 15:05:10 +0200 Subject: [PATCH 4/5] Create setter for usedOnMap --- .../net/osmand/plus/base/MenuBottomSheetDialogFragment.java | 4 ++++ OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java | 2 +- .../HistoryMarkerMenuBottomSheetDialogFragment.java | 1 - .../net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java | 1 + OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java | 1 + .../mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java | 1 - .../osmand/plus/measurementtool/MeasurementToolFragment.java | 3 +++ .../measurementtool/OptionsBottomSheetDialogFragment.java | 1 - .../SaveAsNewTrackBottomSheetDialogFragment.java | 1 - .../SelectedPointBottomSheetDialogFragment.java | 1 - 10 files changed, 10 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 2886f6533c..853359976c 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -20,6 +20,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra protected boolean usedOnMap; + public void setUsedOnMap(boolean usedOnMap) { + this.usedOnMap = usedOnMap; + } + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java index e7ab74f323..304a05a57e 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java @@ -538,6 +538,7 @@ public class GpxImportHelper { importFavoritesImpl(gpxFile, fileName, true); } else { ImportGpxBottomSheetDialogFragment fragment = new ImportGpxBottomSheetDialogFragment(); + fragment.setUsedOnMap(true); fragment.setGpxImportHelper(this); fragment.setGpxFile(gpxFile); fragment.setFileName(fileName); @@ -632,7 +633,6 @@ public class GpxImportHelper { @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - usedOnMap = true; boolean night = isNightMode(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index 22731ebcc2..be29129d25 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -35,7 +35,6 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - usedOnMap = true; final boolean nightMode = isNightMode(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index 8368cb8091..ea4d1dc83f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -191,6 +191,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel if (item instanceof MapMarker) { MapMarker marker = (MapMarker) item; HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment(); + fragment.setUsedOnMap(true); Bundle arguments = new Bundle(); arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos); arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity)); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index 6646126999..4911ec30d9 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -713,6 +713,7 @@ public class PlanRouteFragment extends Fragment implements OsmAndLocationListene MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { PlanRouteOptionsBottomSheetDialogFragment fragment = new PlanRouteOptionsBottomSheetDialogFragment(); + fragment.setUsedOnMap(true); fragment.setSelectAll(!(selectedCount == markersHelper.getMapMarkers().size() && markersHelper.isStartFromMyLocation())); fragment.setListener(createOptionsFragmentListener()); fragment.show(mapActivity.getSupportFragmentManager(), PlanRouteOptionsBottomSheetDialogFragment.TAG); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java index 49ea0738d1..0ee3e5da7f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java @@ -33,7 +33,6 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - usedOnMap = true; boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); boolean night = isNightMode(); final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index a87ab95735..4472cbf592 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -274,6 +274,7 @@ public class MeasurementToolFragment extends Fragment { @Override public void onClick(View view) { OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment(); + fragment.setUsedOnMap(true); fragment.setSnapToRoadEnabled(editingCtx.isInSnapToRoadMode()); fragment.setListener(createOptionsFragmentListener()); fragment.setAddLineMode(newGpxData != null); @@ -807,12 +808,14 @@ public class MeasurementToolFragment extends Fragment { private void openSelectedPointMenu(MapActivity mapActivity) { SelectedPointBottomSheetDialogFragment fragment = new SelectedPointBottomSheetDialogFragment(); + fragment.setUsedOnMap(true); fragment.setListener(createSelectedPointFragmentListener()); fragment.show(mapActivity.getSupportFragmentManager(), SelectedPointBottomSheetDialogFragment.TAG); } private void openSaveAsNewTrackMenu(MapActivity mapActivity) { SaveAsNewTrackBottomSheetDialogFragment fragment = new SaveAsNewTrackBottomSheetDialogFragment(); + fragment.setUsedOnMap(true); fragment.setListener(createSaveAsNewTrackFragmentListener()); fragment.show(mapActivity.getSupportFragmentManager(), SaveAsNewTrackBottomSheetDialogFragment.TAG); } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index f395142ece..33be06f716 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -36,7 +36,6 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - usedOnMap = true; boolean nightMode = isNightMode(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index d47a61c1b4..da3866080e 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -26,7 +26,6 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - usedOnMap = true; boolean nightMode = isNightMode(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index 35fb803cde..b955ef169d 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -34,7 +34,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - usedOnMap = true; final MapActivity mapActivity = (MapActivity) getActivity(); boolean nightMode = isNightMode(); final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); From 27636632020337298e3462cfd4bb1466ff43586f Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Mon, 30 Oct 2017 16:33:31 +0200 Subject: [PATCH 5/5] Fix some issues --- .../base/MenuBottomSheetDialogFragment.java | 19 ++++++++++--------- .../osmand/plus/helpers/GpxImportHelper.java | 9 ++++----- ...rdinateInputBottomSheetDialogFragment.java | 10 ++++------ .../CoordinateInputDialogFragment.java | 2 ++ ...ryMarkerMenuBottomSheetDialogFragment.java | 1 - .../mapmarkers/MapMarkersDialogFragment.java | 3 +++ .../mapmarkers/MapMarkersHistoryFragment.java | 2 +- .../OptionsBottomSheetDialogFragment.java | 1 - .../OrderByBottomSheetDialogFragment.java | 5 ++--- ...RouteOptionsBottomSheetDialogFragment.java | 5 ++--- ...howDirectionBottomSheetDialogFragment.java | 10 ++++------ .../OptionsBottomSheetDialogFragment.java | 1 - ...veAsNewTrackBottomSheetDialogFragment.java | 1 - ...electedPointBottomSheetDialogFragment.java | 1 - .../views/mapwidgets/MapWidgetRegistry.java | 1 + 15 files changed, 33 insertions(+), 38 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 853359976c..0a3687b8e3 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -18,18 +18,20 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra private static final String USED_ON_MAP_KEY = "used_on_map"; - protected boolean usedOnMap; + protected boolean usedOnMap = true; + protected boolean nightMode; public void setUsedOnMap(boolean usedOnMap) { this.usedOnMap = usedOnMap; } @Override - public void onActivityCreated(Bundle savedInstanceState) { - super.onActivityCreated(savedInstanceState); + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); if (savedInstanceState != null) { usedOnMap = savedInstanceState.getBoolean(USED_ON_MAP_KEY); } + nightMode = isNightMode(); } @Override @@ -51,16 +53,15 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra @Override protected Drawable getContentIcon(@DrawableRes int id) { - return getIcon(id, isNightMode() ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); + return getIcon(id, nightMode ? 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); + return getIcon(id, nightMode ? 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); @@ -79,13 +80,13 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } if (AndroidUiHelper.isOrientationPortrait(activity)) { - AndroidUtils.setBackground(activity, mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); + AndroidUtils.setBackground(activity, mainView, nightMode, 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, + AndroidUtils.setBackground(activity, mainView, nightMode, R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); } else { - AndroidUtils.setBackground(activity, mainView, night, + AndroidUtils.setBackground(activity, mainView, nightMode, R.drawable.bg_bottom_sheet_sides_landscape_light, R.drawable.bg_bottom_sheet_sides_landscape_dark); } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java index 304a05a57e..f67eb0beb7 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java @@ -633,20 +633,19 @@ public class GpxImportHelper { @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - boolean night = isNightMode(); - final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final int themeRes = nightMode ? 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 (night) { + if (nightMode) { ((TextView) mainView.findViewById(R.id.import_gpx_title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); } ((ImageView) mainView.findViewById(R.id.import_as_favorites_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_fav_dark)); ((ImageView) mainView.findViewById(R.id.import_as_gpx_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_polygom_dark)); - int nameColor = ContextCompat.getColor(getContext(), night ? R.color.osmand_orange : R.color.dashboard_blue); - int descrColor = ContextCompat.getColor(getContext(), night ? R.color.dashboard_subheader_text_dark : R.color.dashboard_subheader_text_light); + int nameColor = ContextCompat.getColor(getContext(), nightMode ? R.color.osmand_orange : R.color.dashboard_blue); + int descrColor = ContextCompat.getColor(getContext(), nightMode ? R.color.dashboard_subheader_text_dark : R.color.dashboard_subheader_text_light); String descr = getString(R.string.import_gpx_file_description); SpannableStringBuilder text = new SpannableStringBuilder(fileName).append(" ").append(descr); text.setSpan(new ForegroundColorSpan(nameColor), 0, fileName.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java index c4036f97fb..6bd18e4920 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -23,7 +23,6 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia public final static String TAG = "CoordinateInputBottomSheetDialogFragment"; private View mainView; - private boolean night; private int coordinateFormat = -1; private boolean useOsmandKeyboard = true; private CoordinateInputFormatChangeListener listener; @@ -49,13 +48,12 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final MapActivity mapActivity = (MapActivity) getActivity(); - night = isNightMode(); - final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final int themeRes = nightMode ? 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 (night) { + if (nightMode) { ((TextView) mainView.findViewById(R.id.coordinate_input_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); } @@ -163,8 +161,8 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia } private void highlightSelectedItem(boolean check) { - int iconColor = check ? R.color.dashboard_blue : night ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color; - int textColor = ContextCompat.getColor(getContext(), check ? (night ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue) : night ? R.color.color_white : R.color.color_black); + int iconColor = check ? R.color.dashboard_blue : nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color; + int textColor = ContextCompat.getColor(getContext(), check ? (nightMode ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue) : nightMode ? R.color.color_white : R.color.color_black); switch (coordinateFormat) { case PointDescription.FORMAT_DEGREES: ((TextView) mainView.findViewById(R.id.degrees_text)).setTextColor(textColor); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java index 151bddc2fc..7348a553a6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputDialogFragment.java @@ -65,6 +65,7 @@ public class CoordinateInputDialogFragment extends DialogFragment { setStyle(STYLE_NO_FRAME, themeId); CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment(); + fragment.setUsedOnMap(false); fragment.setListener(createCoordinateInputFormatChangeListener()); fragment.show(getMapActivity().getSupportFragmentManager(), CoordinateInputBottomSheetDialogFragment.TAG); } @@ -95,6 +96,7 @@ public class CoordinateInputDialogFragment extends DialogFragment { @Override public void onClick(View view) { CoordinateInputBottomSheetDialogFragment fragment = new CoordinateInputBottomSheetDialogFragment(); + fragment.setUsedOnMap(false); Bundle args = new Bundle(); args.putInt(COORDINATE_FORMAT, coordinateFormat); args.putBoolean(USE_OSMAND_KEYBOARD, useOsmandKeyboard); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java index be29129d25..3fe99d59cb 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/HistoryMarkerMenuBottomSheetDialogFragment.java @@ -35,7 +35,6 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - 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); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java index a1eba79338..35c6d04ab3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersDialogFragment.java @@ -131,6 +131,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm @Override public void onClick(View view) { OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment(); + fragment.setUsedOnMap(false); fragment.setListener(createOptionsFragmentListener()); Bundle args = new Bundle(); int pos = viewPager.getCurrentItem(); @@ -215,6 +216,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm public void sortByOnClick() { if (mapActivity != null) { OrderByBottomSheetDialogFragment fragment = new OrderByBottomSheetDialogFragment(); + fragment.setUsedOnMap(false); fragment.setListener(createOrderByFragmentListener()); fragment.show(mapActivity.getSupportFragmentManager(), OrderByBottomSheetDialogFragment.TAG); } @@ -224,6 +226,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm public void showDirectionOnClick() { if (mapActivity != null) { ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment(); + fragment.setUsedOnMap(false); fragment.setListener(createShowDirectionFragmentListener()); fragment.show(mapActivity.getSupportFragmentManager(), ShowDirectionBottomSheetDialogFragment.TAG); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index ea4d1dc83f..f2335ba0a6 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -191,7 +191,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel if (item instanceof MapMarker) { MapMarker marker = (MapMarker) item; HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment(); - fragment.setUsedOnMap(true); + fragment.setUsedOnMap(false); Bundle arguments = new Bundle(); arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos); arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity)); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java index ee4e2d5bbf..24daa70f76 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OptionsBottomSheetDialogFragment.java @@ -41,7 +41,6 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { MapActivity mapActivity = (MapActivity) getActivity(); - 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); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java index 4e8b662bc6..3bdd3d143b 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/OrderByBottomSheetDialogFragment.java @@ -29,12 +29,11 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { settings = getMyApplication().getSettings(); - final boolean night = isNightMode(); - final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final int themeRes = nightMode ? 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 (night) { + if (nightMode) { ((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)); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java index 0ee3e5da7f..fe04c57e83 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java @@ -34,12 +34,11 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - boolean night = isNightMode(); - final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final int themeRes = nightMode ? 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 (night) { + if (nightMode) { ((TextView) mainView.findViewById(R.id.title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java index 66a414ee1e..16178ee0ab 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/ShowDirectionBottomSheetDialogFragment.java @@ -27,7 +27,6 @@ public class ShowDirectionBottomSheetDialogFragment extends MenuBottomSheetDialo private ShowDirectionFragmentListener listener; private View mainView; - private boolean night; public void setListener(ShowDirectionFragmentListener listener) { this.listener = listener; @@ -37,8 +36,7 @@ public class ShowDirectionBottomSheetDialogFragment extends MenuBottomSheetDialo @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final OsmandSettings settings = getMyApplication().getSettings(); - night = isNightMode(); - final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_show_direction_bottom_sheet_dialog, container); @@ -50,7 +48,7 @@ public class ShowDirectionBottomSheetDialogFragment extends MenuBottomSheetDialo } else { ImageView topBarImage = (ImageView) mainView.findViewById(R.id.top_bar_image); ImageView widgetImage = (ImageView) mainView.findViewById(R.id.widget_image); - if (night) { + if (nightMode) { topBarImage.setImageResource(R.drawable.img_help_markers_topbar_night); widgetImage.setImageResource(R.drawable.img_help_markers_widgets_night); } else { @@ -75,7 +73,7 @@ public class ShowDirectionBottomSheetDialogFragment extends MenuBottomSheetDialo widgetImage.setOnClickListener(showDirectionOnClickListener); } - if (night) { + if (nightMode) { ((TextView) mainView.findViewById(R.id.show_direction_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); } @@ -145,7 +143,7 @@ public class ShowDirectionBottomSheetDialogFragment extends MenuBottomSheetDialo private void highlightSelectedItem(OsmandSettings.MapMarkersMode mode, boolean check) { int iconBgColor = check ? R.color.dashboard_blue : R.color.on_map_icon_color; int iconColor = check ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue; - int textColor = ContextCompat.getColor(getContext(), check ? (night ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue) : night ? R.color.color_white : R.color.color_black); + int textColor = ContextCompat.getColor(getContext(), check ? (nightMode ? R.color.color_dialog_buttons_dark : R.color.dashboard_blue) : nightMode ? R.color.color_white : R.color.color_black); Typeface typeface = FontCache.getFont(getContext(), check ? "fonts/Roboto-Medium.ttf" : "fonts/Roboto-Regular.ttf"); switch (mode) { case TOOLBAR: diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java index 33be06f716..ab83c69048 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/OptionsBottomSheetDialogFragment.java @@ -36,7 +36,6 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - 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); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index da3866080e..b277349831 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -26,7 +26,6 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - 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); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index b955ef169d..58900037e5 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java @@ -35,7 +35,6 @@ public class SelectedPointBottomSheetDialogFragment extends MenuBottomSheetDialo @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final MapActivity mapActivity = (MapActivity) getActivity(); - boolean nightMode = isNightMode(); final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index b95c2d5289..11448375a2 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -328,6 +328,7 @@ public class MapWidgetRegistry { @Override public boolean onContextMenuClick(final ArrayAdapter adapter, int itemId, final int position, boolean isChecked) { ShowDirectionBottomSheetDialogFragment fragment = new ShowDirectionBottomSheetDialogFragment(); + fragment.setUsedOnMap(true); fragment.setListener(new ShowDirectionBottomSheetDialogFragment.ShowDirectionFragmentListener() { @Override public void onMapMarkersModeChanged(boolean showDirectionEnabled) {