From c50e1d0679f49e2ef4ae1828ec65a80c1df4ad64 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Thu, 28 Jan 2021 18:29:10 +0200 Subject: [PATCH] Night mode fix, separate layout --- OsmAnd/res/layout/custom_radio_buttons.xml | 55 ++++++++++++++- .../res/layout/custom_radio_buttons_group.xml | 68 +++++++++++++++++++ OsmAnd/src/net/osmand/plus/UiUtilities.java | 7 +- .../plus/myplaces/GPXItemPagerAdapter.java | 9 ++- .../plus/myplaces/SegmentGPXAdapter.java | 6 +- .../net/osmand/plus/track/SegmentsCard.java | 2 +- 6 files changed, 136 insertions(+), 11 deletions(-) create mode 100644 OsmAnd/res/layout/custom_radio_buttons_group.xml diff --git a/OsmAnd/res/layout/custom_radio_buttons.xml b/OsmAnd/res/layout/custom_radio_buttons.xml index d4bd1c8082..d5ef10977d 100644 --- a/OsmAnd/res/layout/custom_radio_buttons.xml +++ b/OsmAnd/res/layout/custom_radio_buttons.xml @@ -1,6 +1,7 @@ - + + - + - + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/custom_radio_buttons_group.xml b/OsmAnd/res/layout/custom_radio_buttons_group.xml new file mode 100644 index 0000000000..f0caa4a375 --- /dev/null +++ b/OsmAnd/res/layout/custom_radio_buttons_group.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/UiUtilities.java b/OsmAnd/src/net/osmand/plus/UiUtilities.java index 43c6ca94c5..8847f953eb 100644 --- a/OsmAnd/src/net/osmand/plus/UiUtilities.java +++ b/OsmAnd/src/net/osmand/plus/UiUtilities.java @@ -490,6 +490,7 @@ public class UiUtilities { } } + public static void updateCustomRadioButtonsGroup(Context app, View buttonsView, boolean nightMode, CustomRadioButtonTypeGroup buttonType) { int activeColor = ContextCompat.getColor(app, nightMode @@ -513,12 +514,14 @@ public class UiUtilities { GradientDrawable background = new GradientDrawable(); background.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f)); background.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f)); + GradientDrawable startButtonRoundedCorner = new GradientDrawable(); startButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); GradientDrawable endButtonRoundedCorner = new GradientDrawable(); endButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); GradientDrawable centerButtonSharpCorner = new GradientDrawable(); centerButtonSharpCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f)); + setStartEndCenterRoundedCorner(roundedCorner, isLayoutRtl, startButtonRoundedCorner, endButtonRoundedCorner, centerButtonSharpCorner); if (buttonType == CustomRadioButtonTypeGroup.START) { @@ -564,6 +567,7 @@ public class UiUtilities { centerButtonContainer.setBackgroundDrawable(endButtonRoundedCorner); centerButtonText.setTextColor(textColor); } + } else { if (isLayoutRtl) { background.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner}); @@ -595,6 +599,7 @@ public class UiUtilities { centerButtonSharpCorner.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0}); } + public static void setupCompoundButtonDrawable(Context ctx, boolean nightMode, @ColorInt int activeColor, Drawable drawable) { int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light); int[][] states = new int[][]{ @@ -747,7 +752,7 @@ public class UiUtilities { int activeDisableColor = getColorWithAlpha(activeColor, 0.25f); ColorStateList activeCsl = new ColorStateList(states, new int[] {activeColor, activeDisableColor}); int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_secondary_light); - ColorStateList inactiveCsl = new ColorStateList(states, new int[] {inactiveColor, inactiveColor}); + ColorStateList inactiveCsl = new ColorStateList(states, new int[] {activeDisableColor, inactiveColor}); slider.setTrackActiveTintList(activeCsl); slider.setTrackInactiveTintList(inactiveCsl); slider.setHaloTintList(activeCsl); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java index a9e36ff421..f3238c90b5 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java @@ -78,16 +78,19 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid private SegmentActionsListener actionsListener; private boolean chartClicked; + private boolean nightMode; public GPXItemPagerAdapter(@NonNull final PagerSlidingTabStrip tabs, @NonNull GpxDisplayItem gpxItem, @NonNull TrackDisplayHelper displayHelper, - @NonNull SegmentActionsListener actionsListener) { + @NonNull SegmentActionsListener actionsListener, + final boolean nightMode) { super(); this.tabs = tabs; this.gpxItem = gpxItem; this.displayHelper = displayHelper; + this.nightMode = nightMode; this.actionsListener = actionsListener; app = (OsmandApplication) tabs.getContext().getApplicationContext(); iconsCache = app.getUIUtilities(); @@ -106,7 +109,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid } View parent = (View) tabs.getChildAt(0); - UiUtilities.updateCustomRadioButtonsGroup(app, parent, false, type); + UiUtilities.updateCustomRadioButtonsGroup(app, parent, nightMode, type); } @Override @@ -644,7 +647,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid type = UiUtilities.CustomRadioButtonTypeGroup.END; } View parent = (View) tab.getParent(); - UiUtilities.updateCustomRadioButtonsGroup(app, parent, false, type); + UiUtilities.updateCustomRadioButtonsGroup(app, parent, nightMode, type); ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) parent.getLayoutParams(); int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java index f2d5c88617..9f2e234dcd 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SegmentGPXAdapter.java @@ -1,6 +1,7 @@ package net.osmand.plus.myplaces; import android.content.Context; +import android.graphics.drawable.GradientDrawable; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; @@ -21,7 +22,6 @@ import java.util.List; public class SegmentGPXAdapter extends ArrayAdapter { - private OsmandApplication app; private TrackDisplayHelper displayHelper; private SegmentActionsListener listener; private boolean nightMode; @@ -31,7 +31,7 @@ public class SegmentGPXAdapter extends ArrayAdapter { @NonNull SegmentActionsListener listener, boolean nightMode) { super(context, R.layout.gpx_list_item_tab_content, items); - this.app = (OsmandApplication) context.getApplicationContext(); + OsmandApplication app = (OsmandApplication) context.getApplicationContext(); this.displayHelper = displayHelper; this.listener = listener; this.nightMode = nightMode; @@ -56,7 +56,7 @@ public class SegmentGPXAdapter extends ArrayAdapter { WrapContentHeightViewPager pager = row.findViewById(R.id.pager); PagerSlidingTabStrip tabLayout = row.findViewById(R.id.sliding_tabs); - pager.setAdapter(new GPXItemPagerAdapter(tabLayout, item, displayHelper, listener)); + pager.setAdapter(new GPXItemPagerAdapter(tabLayout, item, displayHelper, listener, nightMode)); if (create) { tabLayout.setViewPager(pager); } else { diff --git a/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java b/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java index b3921a6889..421b8a9a8e 100644 --- a/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/SegmentsCard.java @@ -48,7 +48,7 @@ public class SegmentsCard extends BaseCard { WrapContentHeightViewPager pager = segmentView.findViewById(R.id.pager); PagerSlidingTabStrip tabLayout = segmentView.findViewById(R.id.sliding_tabs); - pager.setAdapter(new GPXItemPagerAdapter(tabLayout, displayItem, displayHelper, listener)); + pager.setAdapter(new GPXItemPagerAdapter(tabLayout, displayItem, displayHelper, listener, nightMode)); tabLayout.setViewPager(pager); container.addView(segmentView);