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:layout_width="match_parent"
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:orientation="vertical">

View file

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

View file

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

View file

@ -18,7 +18,7 @@
android:id="@+id/route_menu_top_shadow_all"
android:layout_width="match_parent"
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:orientation="vertical"
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.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.views.controls.SingleTapConfirm;
import net.osmand.plus.views.layers.MapControlsLayer;
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 final int HEADER_ONLY = 1;
@ -174,10 +176,19 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
return topView;
}
@Override
public boolean isNightModeForMapControls() {
return nightMode;
}
public boolean isNightMode() {
return nightMode;
}
protected String getThemeInfoProviderTag() {
return null;
}
public void updateNightMode() {
OsmandApplication app = getMyApplication();
if (app != null) {
@ -597,6 +608,10 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
if (!wasDrawerDisabled) {
mapActivity.disableDrawer();
}
String tag = getThemeInfoProviderTag();
if (tag != null) {
mapActivity.getMapLayers().getMapControlsLayer().addThemeInfoProviderTag(tag);
}
}
}
@ -611,9 +626,15 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
}
}
MapActivity mapActivity = getMapActivity();
if (!wasDrawerDisabled && mapActivity != null) {
if (mapActivity != null) {
if (!wasDrawerDisabled) {
mapActivity.enableDrawer();
}
String tag = getThemeInfoProviderTag();
if (tag != null) {
mapActivity.getMapLayers().getMapControlsLayer().removeThemeInfoProviderTag(tag);
}
}
}
public int getViewY() {

View file

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

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);
}
@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) {
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 {
topShadow.setVisibility(View.VISIBLE);
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(),
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) {
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() {
@Override
public void onClick(View v) {
@ -415,6 +415,11 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
}
}
@Override
protected String getThemeInfoProviderTag() {
return TAG;
}
public interface GpxApproximationFragmentListener {
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.OsmandSettings;
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.TopToolbarControllerType;
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,
OptionsFragmentListener, GpxApproximationFragmentListener, SelectedPointFragmentListener,
SaveAsNewTrackFragmentListener {
SaveAsNewTrackFragmentListener, MapControlsLayer.MapControlsThemeInfoProvider {
public static final String TAG = MeasurementToolFragment.class.getSimpleName();
public static final String TAPS_DISABLED_KEY = "taps_disabled_key";
@ -529,6 +530,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
super.onResume();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMapLayers().getMapControlsLayer().addThemeInfoProviderTag(TAG);
mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden();
cachedMapPosition = mapActivity.getMapView().getMapPosition();
setDefaultMapPosition();
@ -539,6 +541,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override
public void onPause() {
super.onPause();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMapLayers().getMapControlsLayer().removeThemeInfoProviderTag(TAG);
}
setMapPosition(cachedMapPosition);
}
@ -2052,4 +2058,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
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) {
return;
}
int highlightColorId = nightMode ? R.color.list_background_color_dark : R.color.activity_background_color_light;
if (savedInstanceState != null) {
showOnMap = savedInstanceState.getBoolean(SHOW_ON_MAP_KEY);
simplifiedTrack = savedInstanceState.getBoolean(SIMPLIFIED_TRACK_KEY);
@ -85,7 +87,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
View editNameView = View.inflate(UiUtilities.getThemedContext(app, nightMode),
R.layout.track_name_edit_text, null);
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,
app.getString(R.string.shared_string_file_name), "").trim());
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
@ -190,14 +192,16 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
GradientDrawable background = (GradientDrawable) AppCompatResources.getDrawable(app,
R.drawable.bg_select_group_button_outline);
if (background != null) {
int backgroundColor = AndroidUtils.getColorFromAttr(UiUtilities.getThemedContext(app, nightMode),
R.attr.activity_background_color);
int highlightColor = ContextCompat.getColor(app,nightMode ?
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();
if (checked) {
background.setStroke(0, Color.TRANSPARENT);
background.setColor(backgroundColor);
background.setColor(highlightColor);
} 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;
@ -328,6 +332,11 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
return false;
}
@Override
protected int getBgColorId() {
return nightMode ? R.color.activity_background_color_dark : R.color.list_background_color_light;
}
public interface SaveAsNewTrackFragmentListener {
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.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.views.layers.MapControlsLayer;
import org.apache.commons.logging.Log;
@ -69,7 +70,8 @@ import java.io.File;
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();
@ -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);
} else {
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(), cardsContainer, 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.list_background_color_light, R.color.list_background_color_dark);
}
}
}
private void setupButtons(View view) {
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);
cancelButton.setOnClickListener(new View.OnClickListener() {
@ -639,4 +641,9 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
public void routeWasFinished() {
}
@Override
protected String getThemeInfoProviderTag() {
return TAG;
}
}

View file

@ -29,7 +29,8 @@ public class ImportTrackCard extends BaseCard {
@Override
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);
String importTrack = app.getString(R.string.plan_route_import_track);
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.recyclerview.widget.RecyclerView;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -196,13 +197,12 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
return;
}
if (AndroidUiHelper.isOrientationPortrait(activity)) {
mainView.setBackgroundResource(showTopShadow ? getPortraitBgResId() : getBgColorId());
AndroidUtils.setBackground(mainView, showTopShadow ? getPortraitBg(activity) : getColoredBg(activity));
if (!showTopShadow) {
mainView.setPadding(0, 0, 0, 0);
}
} else {
mainView.setBackgroundResource(showTopShadow
? getLandscapeTopsidesBgResId() : getLandscapeSidesBgResId());
AndroidUtils.setBackground(mainView, showTopShadow ? getLandscapeTopsidesBg(activity) : getLandscapeSidesBg(activity));
}
}
};

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);
} else {
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(), cardsContainer, 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.list_background_color_light, R.color.list_background_color_dark);
}
}
}
private void setupButtons(View view) {
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);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -720,6 +720,11 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
}
}
@Override
protected String getThemeInfoProviderTag() {
return TAG;
}
public interface OnNeedScrollListener {
void onVerticalScrollNeeded(int y);
}

View file

@ -28,6 +28,8 @@ import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.ViewPropertyAnimatorCompat;
import androidx.core.view.ViewPropertyAnimatorListener;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
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 java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import gnu.trove.list.array.TIntArrayList;
@ -133,6 +137,7 @@ public class MapControlsLayer extends OsmandMapLayer {
private boolean forceShowCompass;
private LatLon requestedLatLon;
private long compassPressed;
private Set<String> themeInfoProviderTags = new HashSet<>();
public MapControlsLayer(MapActivity activity) {
this.mapActivity = activity;
@ -836,7 +841,7 @@ public class MapControlsLayer extends OsmandMapLayer {
}
private void updateControls(@NonNull RotatedTileBox tileBox, DrawSettings drawSettings) {
boolean isNight = drawSettings != null && drawSettings.isNightMode();
boolean isNight = isNightModeForMapControls(drawSettings);
boolean portrait = isPotrait();
// int shadw = isNight ? mapActivity.getResources().getColor(R.color.widgettext_shadow_night) :
// 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) {
float mapRotate = mapActivity.getMapView().getRotate();
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();
}
}