diff --git a/OsmAnd/res/drawable-hdpi/ic_empty_state_favorites_day.webp b/OsmAnd/res/drawable-hdpi/ic_empty_state_favorites_day.webp new file mode 100644 index 0000000000..4d7b0b97f4 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_empty_state_favorites_day.webp differ diff --git a/OsmAnd/res/drawable-hdpi/ic_empty_state_favorites_night.webp b/OsmAnd/res/drawable-hdpi/ic_empty_state_favorites_night.webp new file mode 100644 index 0000000000..c219dd7d0c Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_empty_state_favorites_night.webp differ diff --git a/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_group_day.webp b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_group_day.webp new file mode 100644 index 0000000000..0056c2d9f9 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_group_day.webp differ diff --git a/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_group_night.webp b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_group_night.webp new file mode 100644 index 0000000000..3975374a2d Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_group_night.webp differ diff --git a/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_history_day.webp b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_history_day.webp new file mode 100644 index 0000000000..6f8ed77b19 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_history_day.webp differ diff --git a/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_history_night.webp b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_history_night.webp new file mode 100644 index 0000000000..67321a5b82 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_history_night.webp differ diff --git a/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_list_day.webp b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_list_day.webp new file mode 100644 index 0000000000..567c44e591 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_list_day.webp differ diff --git a/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_list_night.webp b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_list_night.webp new file mode 100644 index 0000000000..51d33a864c Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_empty_state_marker_list_night.webp differ diff --git a/OsmAnd/res/drawable-hdpi/ic_empty_state_trip_day.webp b/OsmAnd/res/drawable-hdpi/ic_empty_state_trip_day.webp new file mode 100644 index 0000000000..830737bae5 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_empty_state_trip_day.webp differ diff --git a/OsmAnd/res/drawable-hdpi/ic_empty_state_trip_night.webp b/OsmAnd/res/drawable-hdpi/ic_empty_state_trip_night.webp new file mode 100644 index 0000000000..e39296dd06 Binary files /dev/null and b/OsmAnd/res/drawable-hdpi/ic_empty_state_trip_night.webp differ diff --git a/OsmAnd/res/drawable-mdpi/ic_empty_state_favorites_day.webp b/OsmAnd/res/drawable-mdpi/ic_empty_state_favorites_day.webp new file mode 100644 index 0000000000..a98df8d1b3 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_empty_state_favorites_day.webp differ diff --git a/OsmAnd/res/drawable-mdpi/ic_empty_state_favorites_night.webp b/OsmAnd/res/drawable-mdpi/ic_empty_state_favorites_night.webp new file mode 100644 index 0000000000..0ed6e20eb2 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_empty_state_favorites_night.webp differ diff --git a/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_group_day.webp b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_group_day.webp new file mode 100644 index 0000000000..d47d977bbc Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_group_day.webp differ diff --git a/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_group_night.webp b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_group_night.webp new file mode 100644 index 0000000000..00abbf4bed Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_group_night.webp differ diff --git a/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_history_day.webp b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_history_day.webp new file mode 100644 index 0000000000..3cf7b2ca57 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_history_day.webp differ diff --git a/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_history_night.webp b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_history_night.webp new file mode 100644 index 0000000000..f3b5746c31 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_history_night.webp differ diff --git a/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_list_day.webp b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_list_day.webp new file mode 100644 index 0000000000..b062c521dc Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_list_day.webp differ diff --git a/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_list_night.webp b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_list_night.webp new file mode 100644 index 0000000000..15fad6a559 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_empty_state_marker_list_night.webp differ diff --git a/OsmAnd/res/drawable-mdpi/ic_empty_state_trip_day.webp b/OsmAnd/res/drawable-mdpi/ic_empty_state_trip_day.webp new file mode 100644 index 0000000000..3518fd00c2 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_empty_state_trip_day.webp differ diff --git a/OsmAnd/res/drawable-mdpi/ic_empty_state_trip_night.webp b/OsmAnd/res/drawable-mdpi/ic_empty_state_trip_night.webp new file mode 100644 index 0000000000..cc8a3e5d38 Binary files /dev/null and b/OsmAnd/res/drawable-mdpi/ic_empty_state_trip_night.webp differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_empty_state_favorites_day.webp b/OsmAnd/res/drawable-xhdpi/ic_empty_state_favorites_day.webp new file mode 100644 index 0000000000..d6e362b8ab Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_empty_state_favorites_day.webp differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_empty_state_favorites_night.webp b/OsmAnd/res/drawable-xhdpi/ic_empty_state_favorites_night.webp new file mode 100644 index 0000000000..44bc4819cf Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_empty_state_favorites_night.webp differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_group_day.webp b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_group_day.webp new file mode 100644 index 0000000000..0c4ac96702 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_group_day.webp differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_group_night.webp b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_group_night.webp new file mode 100644 index 0000000000..a9e3566f53 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_group_night.webp differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_history_day.webp b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_history_day.webp new file mode 100644 index 0000000000..c98636bd25 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_history_day.webp differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_history_night.webp b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_history_night.webp new file mode 100644 index 0000000000..af50127256 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_history_night.webp differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_list_day.webp b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_list_day.webp new file mode 100644 index 0000000000..000793dd87 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_list_day.webp differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_list_night.webp b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_list_night.webp new file mode 100644 index 0000000000..b344274dfe Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_empty_state_marker_list_night.webp differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_empty_state_trip_day.webp b/OsmAnd/res/drawable-xhdpi/ic_empty_state_trip_day.webp new file mode 100644 index 0000000000..753a90d3c7 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_empty_state_trip_day.webp differ diff --git a/OsmAnd/res/drawable-xhdpi/ic_empty_state_trip_night.webp b/OsmAnd/res/drawable-xhdpi/ic_empty_state_trip_night.webp new file mode 100644 index 0000000000..5be598ab52 Binary files /dev/null and b/OsmAnd/res/drawable-xhdpi/ic_empty_state_trip_night.webp differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_empty_state_favorites_day.webp b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_favorites_day.webp new file mode 100644 index 0000000000..9e64732c29 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_favorites_day.webp differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_empty_state_favorites_night.webp b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_favorites_night.webp new file mode 100644 index 0000000000..365d2a1600 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_favorites_night.webp differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_group_day.webp b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_group_day.webp new file mode 100644 index 0000000000..7555b9f05d Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_group_day.webp differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_group_night.webp b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_group_night.webp new file mode 100644 index 0000000000..45f3371890 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_group_night.webp differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_history_day.webp b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_history_day.webp new file mode 100644 index 0000000000..905faf0cdd Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_history_day.webp differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_history_night.webp b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_history_night.webp new file mode 100644 index 0000000000..3ffa7dd8dc Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_history_night.webp differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_list_day.webp b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_list_day.webp new file mode 100644 index 0000000000..d4a0b5c907 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_list_day.webp differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_list_night.webp b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_list_night.webp new file mode 100644 index 0000000000..8334202616 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_marker_list_night.webp differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_empty_state_trip_day.webp b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_trip_day.webp new file mode 100644 index 0000000000..a311452305 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_trip_day.webp differ diff --git a/OsmAnd/res/drawable-xxhdpi/ic_empty_state_trip_night.webp b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_trip_night.webp new file mode 100644 index 0000000000..915ef55746 Binary files /dev/null and b/OsmAnd/res/drawable-xxhdpi/ic_empty_state_trip_night.webp differ 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..0a3687b8e3 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -0,0 +1,110 @@ +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; +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 { + + private static final String USED_ON_MAP_KEY = "used_on_map"; + + protected boolean usedOnMap = true; + protected boolean nightMode; + + public void setUsedOnMap(boolean usedOnMap) { + this.usedOnMap = usedOnMap; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (savedInstanceState != null) { + usedOnMap = savedInstanceState.getBoolean(USED_ON_MAP_KEY); + } + nightMode = isNightMode(); + } + + @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 + 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, nightMode ? R.color.ctx_menu_info_text_dark : R.color.on_map_icon_color); + } + + protected Drawable getActiveIcon(@DrawableRes int id) { + 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 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, 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, nightMode, + R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark); + } else { + AndroidUtils.setBackground(activity, 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); + } + } + }); + } + + protected boolean isNightMode() { + if (usedOnMap) { + return 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 3d2ade1e96..f67eb0beb7 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; @@ -545,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); @@ -605,13 +599,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,24 +633,19 @@ public class GpxImportHelper { @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - night = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + final 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 (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); - } - 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); @@ -687,59 +674,9 @@ 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); - } } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java index 3721a6f52d..6bd18e4920 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/CoordinateInputBottomSheetDialogFragment.java @@ -1,38 +1,28 @@ 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; private boolean useOsmandKeyboard = true; private CoordinateInputFormatChangeListener listener; @@ -58,17 +48,12 @@ 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(); - 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 (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); - } - if (night) { + if (nightMode) { ((TextView) mainView.findViewById(R.id.coordinate_input_title)).setTextColor(getResources().getColor(R.color.ctx_menu_info_text_dark)); } @@ -162,57 +147,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); @@ -221,14 +160,9 @@ 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); - } - 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); @@ -255,6 +189,5 @@ public class CoordinateInputBottomSheetDialogFragment extends BottomSheetDialogF void onKeyboardChanged(boolean useOsmandKeyboard); void onCancel(); - } } 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 c6b8d359be..3fe99d59cb 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,9 @@ 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 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 +86,15 @@ 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); - } - } - interface HistoryMarkerMenuFragmentListener { + void onMakeMarkerActive(int pos); + void onDeleteMarker(int pos); } } 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 8368cb8091..f2335ba0a6 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(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 8da8580f2f..24daa70f76 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,11 @@ 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 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 +61,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,62 +141,11 @@ 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); - } - 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 c2cee573e1..3bdd3d143b 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,20 @@ 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 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 (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); - } - 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)); - 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,62 +58,11 @@ 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); - } - private View.OnClickListener orderByModeOnClickListener = new View.OnClickListener() { @Override 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 02228c50fc..fe04c57e83 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,16 +33,12 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends BottomSheetDialog @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); - night = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - final int themeRes = night ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; + boolean portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); + 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 (portrait) { - AndroidUtils.setBackground(getActivity(), mainView, night, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark); - } - if (night) { + if (nightMode) { ((TextView) mainView.findViewById(R.id.title)).setTextColor(ContextCompat.getColor(getActivity(), R.color.ctx_menu_info_text_dark)); } @@ -123,61 +110,11 @@ 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); - } - 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 a9530827fc..16178ee0ab 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,30 +10,23 @@ 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; public void setListener(ShowDirectionFragmentListener listener) { this.listener = listener; @@ -46,14 +36,9 @@ 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(); - 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); - 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); @@ -63,7 +48,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra } 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 { @@ -88,7 +73,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra 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)); } @@ -142,62 +127,11 @@ 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); - } - private MapActivity getMapActivity() { Activity activity = getActivity(); if (activity != null) { @@ -209,7 +143,7 @@ public class ShowDirectionBottomSheetDialogFragment extends BottomSheetDialogFra 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/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 19fba1128e..a094f694f5 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 d8fec9de3f..ab83c69048 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,9 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); 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,66 +116,11 @@ 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); - } - 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 91e143c1eb..b277349831 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,9 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends BottomSheetDialogFr @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls(); - portrait = AndroidUiHelper.isOrientationPortrait(getActivity()); 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 +77,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) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SelectedPointBottomSheetDialogFragment.java index 6588e9fd12..58900037e5 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,12 @@ 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(); 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,62 +139,11 @@ 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); - } - @Override public void dismiss() { if (listener != null) { 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) {