Merge pull request #9845 from osmandapp/PlanRouteFixDarkTheme

Fix Dark theme
This commit is contained in:
vshcherb 2020-09-18 15:22:16 +02:00 committed by GitHub
commit 8ba35cd94c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 143 additions and 58 deletions

View file

@ -18,7 +18,7 @@
android:id="@+id/route_menu_top_shadow_all" android:id="@+id/route_menu_top_shadow_all"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/card_and_list_background_basic" android:background="?attr/bg_color"
android:minHeight="@dimen/bottom_sheet_title_height" android:minHeight="@dimen/bottom_sheet_title_height"
android:orientation="vertical"> android:orientation="vertical">

View file

@ -4,7 +4,7 @@
android:id="@+id/import_track_card" android:id="@+id/import_track_card"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/card_and_list_background_basic" android:background="?attr/bg_color"
android:orientation="vertical"> android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx <net.osmand.plus.widgets.TextViewEx

View file

@ -3,6 +3,7 @@
xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical" android:orientation="vertical"
android:background="?attr/bg_color"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">

View file

@ -18,7 +18,7 @@
android:id="@+id/route_menu_top_shadow_all" android:id="@+id/route_menu_top_shadow_all"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/card_and_list_background_basic" android:background="?attr/bg_color"
android:minHeight="@dimen/bottom_sheet_title_height" android:minHeight="@dimen/bottom_sheet_title_height"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="@dimen/content_padding" android:paddingLeft="@dimen/content_padding"

View file

@ -47,10 +47,12 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout; import net.osmand.plus.mapcontextmenu.InterceptorLinearLayout;
import net.osmand.plus.views.controls.HorizontalSwipeConfirm; import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.views.controls.SingleTapConfirm; import net.osmand.plus.views.controls.SingleTapConfirm;
import net.osmand.plus.views.layers.MapControlsLayer;
import static net.osmand.plus.mapcontextmenu.MapContextMenuFragment.CURRENT_Y_UNDEFINED; import static net.osmand.plus.mapcontextmenu.MapContextMenuFragment.CURRENT_Y_UNDEFINED;
public abstract class ContextMenuFragment extends BaseOsmAndFragment { public abstract class ContextMenuFragment extends BaseOsmAndFragment
implements MapControlsLayer.MapControlsThemeInfoProvider {
public static class MenuState { public static class MenuState {
public static final int HEADER_ONLY = 1; public static final int HEADER_ONLY = 1;
@ -174,10 +176,19 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
return topView; return topView;
} }
@Override
public boolean isNightModeForMapControls() {
return nightMode;
}
public boolean isNightMode() { public boolean isNightMode() {
return nightMode; return nightMode;
} }
protected String getThemeInfoProviderTag() {
return null;
}
public void updateNightMode() { public void updateNightMode() {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
if (app != null) { if (app != null) {
@ -597,6 +608,10 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
if (!wasDrawerDisabled) { if (!wasDrawerDisabled) {
mapActivity.disableDrawer(); mapActivity.disableDrawer();
} }
String tag = getThemeInfoProviderTag();
if (tag != null) {
mapActivity.getMapLayers().getMapControlsLayer().addThemeInfoProviderTag(tag);
}
} }
} }
@ -611,8 +626,14 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
} }
} }
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (!wasDrawerDisabled && mapActivity != null) { if (mapActivity != null) {
mapActivity.enableDrawer(); if (!wasDrawerDisabled) {
mapActivity.enableDrawer();
}
String tag = getThemeInfoProviderTag();
if (tag != null) {
mapActivity.getMapLayers().getMapControlsLayer().removeThemeInfoProviderTag(tag);
}
} }
} }

View file

@ -3,7 +3,9 @@ package net.osmand.plus.base;
import android.app.Activity; import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
@ -207,12 +209,12 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
// 8dp is the shadow height // 8dp is the shadow height
boolean showTopShadow = screenHeight - statusBarHeight - mainView.getHeight() >= AndroidUtils.dpToPx(activity, 8); boolean showTopShadow = screenHeight - statusBarHeight - mainView.getHeight() >= AndroidUtils.dpToPx(activity, 8);
if (AndroidUiHelper.isOrientationPortrait(activity)) { if (AndroidUiHelper.isOrientationPortrait(activity)) {
mainView.setBackgroundResource(showTopShadow ? getPortraitBgResId() : getBgColorId()); AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity));
if (!showTopShadow) { if (!showTopShadow) {
mainView.setPadding(0, 0, 0, 0); mainView.setPadding(0, 0, 0, 0);
} }
} else { } else {
mainView.setBackgroundResource(showTopShadow ? getLandscapeTopsidesBgResId() : getLandscapeSidesBgResId()); AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity));
} }
} }
}); });
@ -304,19 +306,27 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
return nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light; return nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light;
} }
@DrawableRes protected Drawable getColoredBg(@NonNull Context ctx) {
protected int getPortraitBgResId() { int bgColor = ContextCompat.getColor(ctx, getBgColorId());
return nightMode ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_menu_light; return new ColorDrawable(bgColor);
} }
@DrawableRes protected Drawable getPortraitBg(@NonNull Context ctx) {
protected int getLandscapeTopsidesBgResId() { return createBackgroundDrawable(ctx, R.drawable.bg_contextmenu_shadow_top_light);
return nightMode ? R.drawable.bg_bottom_sheet_topsides_landscape_dark : R.drawable.bg_bottom_sheet_topsides_landscape_light;
} }
@DrawableRes protected Drawable getLandscapeTopsidesBg(@NonNull Context ctx) {
protected int getLandscapeSidesBgResId() { return createBackgroundDrawable(ctx, R.drawable.bg_shadow_bottomsheet_topsides);
return nightMode ? R.drawable.bg_bottom_sheet_sides_landscape_dark : R.drawable.bg_bottom_sheet_sides_landscape_light; }
protected Drawable getLandscapeSidesBg(@NonNull Context ctx) {
return createBackgroundDrawable(ctx, R.drawable.bg_shadow_bottomsheet_sides);
}
private LayerDrawable createBackgroundDrawable(@NonNull Context ctx, @DrawableRes int shadowDrawableResId) {
Drawable shadowDrawable = ContextCompat.getDrawable(ctx, shadowDrawableResId);
Drawable[] layers = new Drawable[]{shadowDrawable, getColoredBg(ctx)};
return new LayerDrawable(layers);
} }
protected boolean isNightMode(@NonNull OsmandApplication app) { protected boolean isNightMode(@NonNull OsmandApplication app) {

View file

@ -140,26 +140,6 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF
return getIcon(id, nightMode ? R.color.ctx_menu_direction_color_dark : R.color.map_widget_blue); return getIcon(id, nightMode ? R.color.ctx_menu_direction_color_dark : R.color.map_widget_blue);
} }
@Override
protected int getBgColorId() {
return nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light;
}
@Override
protected int getPortraitBgResId() {
return nightMode ? R.drawable.bg_additional_menu_dark : R.drawable.bg_bottom_menu_light;
}
@Override
protected int getLandscapeTopsidesBgResId() {
return nightMode ? R.drawable.bg_additional_menu_topsides_dark : R.drawable.bg_bottom_sheet_topsides_landscape_light;
}
@Override
protected int getLandscapeSidesBgResId() {
return nightMode ? R.drawable.bg_additional_menu_sides_dark : R.drawable.bg_bottom_sheet_sides_landscape_light;
}
private Drawable getBackgroundIcon(@DrawableRes int resId) { private Drawable getBackgroundIcon(@DrawableRes int resId) {
return getIcon(resId, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light); return getIcon(resId, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light);
} }

View file

@ -233,16 +233,16 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
} else { } else {
topShadow.setVisibility(View.VISIBLE); topShadow.setVisibility(View.VISIBLE);
AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(),
R.color.card_and_list_background_light, R.color.card_and_list_background_dark); R.color.list_background_color_light, R.color.list_background_color_dark);
AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(),
R.color.card_and_list_background_light, R.color.card_and_list_background_dark); R.color.list_background_color_light, R.color.list_background_color_dark);
} }
} }
} }
private void updateButtons(View view) { private void updateButtons(View view) {
View buttonsContainer = view.findViewById(R.id.buttons_container); View buttonsContainer = view.findViewById(R.id.buttons_container);
buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.route_info_bg)); buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.bg_color));
applyButton.setOnClickListener(new View.OnClickListener() { applyButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -415,6 +415,11 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
} }
} }
@Override
protected String getThemeInfoProviderTag() {
return TAG;
}
public interface GpxApproximationFragmentListener { public interface GpxApproximationFragmentListener {
void onGpxApproximationDone(GpxRouteApproximation gpxApproximation, ApplicationMode mode); void onGpxApproximationDone(GpxRouteApproximation gpxApproximation, ApplicationMode mode);

View file

@ -78,6 +78,7 @@ import net.osmand.plus.measurementtool.command.ReversePointsCommand;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback; import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import net.osmand.plus.views.layers.MapControlsLayer;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarView;
@ -107,7 +108,7 @@ import static net.osmand.plus.measurementtool.command.ClearPointsCommand.ClearCo
public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener, public class MeasurementToolFragment extends BaseOsmAndFragment implements RouteBetweenPointsFragmentListener,
OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener, OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener,
SaveAsNewTrackFragmentListener { SaveAsNewTrackFragmentListener, MapControlsLayer.MapControlsThemeInfoProvider {
public static final String TAG = MeasurementToolFragment.class.getSimpleName(); public static final String TAG = MeasurementToolFragment.class.getSimpleName();
public static final String TAPS_DISABLED_KEY = "taps_disabled_key"; public static final String TAPS_DISABLED_KEY = "taps_disabled_key";
@ -529,6 +530,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
super.onResume(); super.onResume();
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
mapActivity.getMapLayers().getMapControlsLayer().addThemeInfoProviderTag(TAG);
mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden(); mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden();
cachedMapPosition = mapActivity.getMapView().getMapPosition(); cachedMapPosition = mapActivity.getMapView().getMapPosition();
setDefaultMapPosition(); setDefaultMapPosition();
@ -539,6 +541,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMapLayers().getMapControlsLayer().removeThemeInfoProviderTag(TAG);
}
setMapPosition(cachedMapPosition); setMapPosition(cachedMapPosition);
} }
@ -2052,4 +2058,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
AndroidUiHelper.setVisibility(mapActivity, View.VISIBLE, R.id.map_ruler_container); AndroidUiHelper.setVisibility(mapActivity, View.VISIBLE, R.id.map_ruler_container);
} }
} }
public boolean isNightModeForMapControls() {
return nightMode;
}
} }

View file

@ -68,6 +68,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
if (app == null) { if (app == null) {
return; return;
} }
int highlightColorId = nightMode ? R.color.list_background_color_dark : R.color.activity_background_color_light;
if (savedInstanceState != null) { if (savedInstanceState != null) {
showOnMap = savedInstanceState.getBoolean(SHOW_ON_MAP_KEY); showOnMap = savedInstanceState.getBoolean(SHOW_ON_MAP_KEY);
simplifiedTrack = savedInstanceState.getBoolean(SIMPLIFIED_TRACK_KEY); simplifiedTrack = savedInstanceState.getBoolean(SIMPLIFIED_TRACK_KEY);
@ -85,7 +87,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
View editNameView = View.inflate(UiUtilities.getThemedContext(app, nightMode), View editNameView = View.inflate(UiUtilities.getThemedContext(app, nightMode),
R.layout.track_name_edit_text, null); R.layout.track_name_edit_text, null);
nameTextBox = editNameView.findViewById(R.id.name_text_box); nameTextBox = editNameView.findViewById(R.id.name_text_box);
nameTextBox.setBoxBackgroundColorResource(R.color.material_text_input_layout_bg); nameTextBox.setBoxBackgroundColorResource(highlightColorId);
nameTextBox.setHint(app.getString(R.string.ltr_or_rtl_combine_via_colon, nameTextBox.setHint(app.getString(R.string.ltr_or_rtl_combine_via_colon,
app.getString(R.string.shared_string_file_name), "").trim()); app.getString(R.string.shared_string_file_name), "").trim());
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
@ -190,14 +192,16 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
GradientDrawable background = (GradientDrawable) AppCompatResources.getDrawable(app, GradientDrawable background = (GradientDrawable) AppCompatResources.getDrawable(app,
R.drawable.bg_select_group_button_outline); R.drawable.bg_select_group_button_outline);
if (background != null) { if (background != null) {
int backgroundColor = AndroidUtils.getColorFromAttr(UiUtilities.getThemedContext(app, nightMode), int highlightColor = ContextCompat.getColor(app,nightMode ?
R.attr.activity_background_color); R.color.list_background_color_dark : R.color.activity_background_color_light);
int strokedColor = AndroidUtils.getColorFromAttr(UiUtilities.getThemedContext(app, nightMode),
R.attr.stroked_buttons_and_links_outline);
background = (GradientDrawable) background.mutate(); background = (GradientDrawable) background.mutate();
if (checked) { if (checked) {
background.setStroke(0, Color.TRANSPARENT); background.setStroke(0, Color.TRANSPARENT);
background.setColor(backgroundColor); background.setColor(highlightColor);
} else { } else {
background.setStroke(app.getResources().getDimensionPixelSize(R.dimen.map_button_stroke), backgroundColor); background.setStroke(app.getResources().getDimensionPixelSize(R.dimen.map_button_stroke), strokedColor);
} }
} }
return background; return background;
@ -328,6 +332,11 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
return false; return false;
} }
@Override
protected int getBgColorId() {
return nightMode ? R.color.activity_background_color_dark : R.color.list_background_color_light;
}
public interface SaveAsNewTrackFragmentListener { public interface SaveAsNewTrackFragmentListener {
void onSaveAsNewTrack(String folderName, String fileName, boolean showOnMap, boolean simplifiedTrack); void onSaveAsNewTrack(String folderName, String fileName, boolean showOnMap, boolean simplifiedTrack);

View file

@ -62,6 +62,7 @@ import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder; import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.views.layers.MapControlsLayer;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -69,7 +70,8 @@ import java.io.File;
import java.util.List; import java.util.List;
public class FollowTrackFragment extends ContextMenuScrollFragment implements CardListener, IRouteInformationListener { public class FollowTrackFragment extends ContextMenuScrollFragment implements CardListener,
IRouteInformationListener, MapControlsLayer.MapControlsThemeInfoProvider {
public static final String TAG = FollowTrackFragment.class.getName(); public static final String TAG = FollowTrackFragment.class.getName();
@ -556,15 +558,15 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.drawable.travel_card_bg_light, R.drawable.travel_card_bg_dark); AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.drawable.travel_card_bg_light, R.drawable.travel_card_bg_dark);
} else { } else {
topShadow.setVisibility(View.VISIBLE); topShadow.setVisibility(View.VISIBLE);
AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.card_and_list_background_light, R.color.card_and_list_background_dark); AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark);
AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.color.card_and_list_background_light, R.color.card_and_list_background_dark); AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark);
} }
} }
} }
private void setupButtons(View view) { private void setupButtons(View view) {
View buttonsContainer = view.findViewById(R.id.buttons_container); View buttonsContainer = view.findViewById(R.id.buttons_container);
buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.route_info_bg)); buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.bg_color));
View cancelButton = view.findViewById(R.id.dismiss_button); View cancelButton = view.findViewById(R.id.dismiss_button);
cancelButton.setOnClickListener(new View.OnClickListener() { cancelButton.setOnClickListener(new View.OnClickListener() {
@ -639,4 +641,9 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
public void routeWasFinished() { public void routeWasFinished() {
} }
@Override
protected String getThemeInfoProviderTag() {
return TAG;
}
} }

View file

@ -29,7 +29,8 @@ public class ImportTrackCard extends BaseCard {
@Override @Override
protected void updateContent() { protected void updateContent() {
int color = ContextCompat.getColor(app, R.color.preference_category_title); int color = ContextCompat.getColor(app, nightMode ?
R.color.active_color_primary_dark : R.color.active_color_primary_light);
Typeface typeface = FontCache.getRobotoMedium(app); Typeface typeface = FontCache.getRobotoMedium(app);
String importTrack = app.getString(R.string.plan_route_import_track); String importTrack = app.getString(R.string.plan_route_import_track);
SpannableString spannable = UiUtilities.createCustomFontSpannable(typeface, importTrack, importTrack, importTrack); SpannableString spannable = UiUtilities.createCustomFontSpannable(typeface, importTrack, importTrack, importTrack);

View file

@ -23,6 +23,7 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -196,13 +197,12 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
return; return;
} }
if (AndroidUiHelper.isOrientationPortrait(activity)) { if (AndroidUiHelper.isOrientationPortrait(activity)) {
mainView.setBackgroundResource(showTopShadow ? getPortraitBgResId() : getBgColorId()); AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity));
if (!showTopShadow) { if (!showTopShadow) {
mainView.setPadding(0, 0, 0, 0); mainView.setPadding(0, 0, 0, 0);
} }
} else { } else {
mainView.setBackgroundResource(showTopShadow AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity));
? getLandscapeTopsidesBgResId() : getLandscapeSidesBgResId());
} }
} }
}; };

View file

@ -432,15 +432,15 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.drawable.travel_card_bg_light, R.drawable.travel_card_bg_dark); AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.drawable.travel_card_bg_light, R.drawable.travel_card_bg_dark);
} else { } else {
topShadow.setVisibility(View.VISIBLE); topShadow.setVisibility(View.VISIBLE);
AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.card_and_list_background_light, R.color.card_and_list_background_dark); AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark);
AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.color.card_and_list_background_light, R.color.card_and_list_background_dark); AndroidUtils.setBackground(mainView.getContext(), cardsContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark);
} }
} }
} }
private void setupButtons(View view) { private void setupButtons(View view) {
View buttonsContainer = view.findViewById(R.id.buttons_container); View buttonsContainer = view.findViewById(R.id.buttons_container);
buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.route_info_bg)); buttonsContainer.setBackgroundColor(AndroidUtils.getColorFromAttr(view.getContext(), R.attr.bg_color));
View saveButton = view.findViewById(R.id.right_bottom_button); View saveButton = view.findViewById(R.id.right_bottom_button);
saveButton.setOnClickListener(new View.OnClickListener() { saveButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -720,6 +720,11 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
} }
} }
@Override
protected String getThemeInfoProviderTag() {
return TAG;
}
public interface OnNeedScrollListener { public interface OnNeedScrollListener {
void onVerticalScrollNeeded(int y); void onVerticalScrollNeeded(int y);
} }

View file

@ -28,6 +28,8 @@ import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.core.view.ViewPropertyAnimatorCompat; import androidx.core.view.ViewPropertyAnimatorCompat;
import androidx.core.view.ViewPropertyAnimatorListener; import androidx.core.view.ViewPropertyAnimatorListener;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.slider.Slider; import com.google.android.material.slider.Slider;
@ -69,8 +71,10 @@ import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.corenative.NativeCoreContext; import net.osmand.plus.views.corenative.NativeCoreContext;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
import gnu.trove.list.array.TIntArrayList; import gnu.trove.list.array.TIntArrayList;
@ -133,6 +137,7 @@ public class MapControlsLayer extends OsmandMapLayer {
private boolean forceShowCompass; private boolean forceShowCompass;
private LatLon requestedLatLon; private LatLon requestedLatLon;
private long compassPressed; private long compassPressed;
private Set<String> themeInfoProviderTags = new HashSet<>();
public MapControlsLayer(MapActivity activity) { public MapControlsLayer(MapActivity activity) {
this.mapActivity = activity; this.mapActivity = activity;
@ -836,7 +841,7 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
private void updateControls(@NonNull RotatedTileBox tileBox, DrawSettings drawSettings) { private void updateControls(@NonNull RotatedTileBox tileBox, DrawSettings drawSettings) {
boolean isNight = drawSettings != null && drawSettings.isNightMode(); boolean isNight = isNightModeForMapControls(drawSettings);
boolean portrait = isPotrait(); boolean portrait = isPotrait();
// int shadw = isNight ? mapActivity.getResources().getColor(R.color.widgettext_shadow_night) : // int shadw = isNight ? mapActivity.getResources().getColor(R.color.widgettext_shadow_night) :
// mapActivity.getResources().getColor(R.color.widgettext_shadow_day); // mapActivity.getResources().getColor(R.color.widgettext_shadow_day);
@ -916,6 +921,25 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
} }
private boolean isNightModeForMapControls(DrawSettings drawSettings) {
MapControlsThemeInfoProvider themeInfoProvider = getThemeInfoProvider();
if (themeInfoProvider != null) {
return themeInfoProvider.isNightModeForMapControls();
}
return drawSettings != null && drawSettings.isNightMode();
}
private MapControlsThemeInfoProvider getThemeInfoProvider() {
FragmentManager fm = mapActivity.getSupportFragmentManager();
for (String tag : themeInfoProviderTags) {
Fragment f = fm.findFragmentByTag(tag);
if (f instanceof MapControlsThemeInfoProvider) {
return (MapControlsThemeInfoProvider) f;
}
}
return null;
}
public void updateCompass(boolean isNight) { public void updateCompass(boolean isNight) {
float mapRotate = mapActivity.getMapView().getRotate(); float mapRotate = mapActivity.getMapView().getRotate();
boolean showCompass = shouldShowCompass(); boolean showCompass = shouldShowCompass();
@ -1419,4 +1443,16 @@ public class MapControlsLayer extends OsmandMapLayer {
} }
} }
} }
public void addThemeInfoProviderTag(String tag) {
themeInfoProviderTags.add(tag);
}
public void removeThemeInfoProviderTag(String tag) {
themeInfoProviderTags.remove(tag);
}
public interface MapControlsThemeInfoProvider {
boolean isNightModeForMapControls();
}
} }