From b96d84c8d874555cb9cbfd3801e00dc0ebd1e9ab Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 10 Jan 2018 12:10:57 +0200 Subject: [PATCH 1/3] Fix night text color in context menu --- .../context_menu_controller_text_color_dark.xml | 0 .../context_menu_controller_text_color_light.xml | 0 OsmAnd/res/layout/map_context_menu_fragment.xml | 10 +++++----- OsmAnd/res/values/attrs.xml | 1 - OsmAnd/res/values/styles.xml | 2 -- .../plus/mapcontextmenu/MapContextMenuFragment.java | 9 +++++++++ 6 files changed, 14 insertions(+), 8 deletions(-) rename OsmAnd/res/{drawable => color}/context_menu_controller_text_color_dark.xml (100%) rename OsmAnd/res/{drawable => color}/context_menu_controller_text_color_light.xml (100%) diff --git a/OsmAnd/res/drawable/context_menu_controller_text_color_dark.xml b/OsmAnd/res/color/context_menu_controller_text_color_dark.xml similarity index 100% rename from OsmAnd/res/drawable/context_menu_controller_text_color_dark.xml rename to OsmAnd/res/color/context_menu_controller_text_color_dark.xml diff --git a/OsmAnd/res/drawable/context_menu_controller_text_color_light.xml b/OsmAnd/res/color/context_menu_controller_text_color_light.xml similarity index 100% rename from OsmAnd/res/drawable/context_menu_controller_text_color_light.xml rename to OsmAnd/res/color/context_menu_controller_text_color_light.xml diff --git a/OsmAnd/res/layout/map_context_menu_fragment.xml b/OsmAnd/res/layout/map_context_menu_fragment.xml index 4a2ad7c61d..febbbea922 100644 --- a/OsmAnd/res/layout/map_context_menu_fragment.xml +++ b/OsmAnd/res/layout/map_context_menu_fragment.xml @@ -174,7 +174,7 @@ android:paddingRight="@dimen/context_menu_button_padding_x" android:textAllCaps="true" android:text="@string/recording_context_menu_play" - android:textColor="?attr/ctx_menu_controller_text_color" + tools:textColor="?attr/contextMenuButtonColor" android:textSize="@dimen/default_desc_text_size"/> @@ -246,7 +246,7 @@ android:paddingLeft="@dimen/context_menu_button_padding_x" android:paddingRight="@dimen/context_menu_button_padding_x" android:text="@string/shared_string_download" - android:textColor="?attr/ctx_menu_controller_text_color" + tools:textColor="?attr/contextMenuButtonColor" android:textSize="@dimen/default_desc_text_size"/> @@ -271,7 +271,7 @@ android:paddingLeft="@dimen/context_menu_button_padding_x" android:paddingRight="@dimen/context_menu_button_padding_x" android:text="@string/shared_string_delete" - android:textColor="?attr/ctx_menu_controller_text_color" + tools:textColor="?attr/contextMenuButtonColor" android:textSize="@dimen/default_desc_text_size"/> @@ -307,7 +307,7 @@ android:paddingRight="@dimen/context_menu_button_padding_x" android:text="@string/shared_string_others" android:textAllCaps="true" - android:textColor="?attr/ctx_menu_controller_text_color" + tools:textColor="?attr/contextMenuButtonColor" android:textSize="@dimen/default_desc_text_size" osmand:typeface="@string/font_roboto_medium"/> diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index 229b01fd7f..ce035224d8 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -25,7 +25,6 @@ - diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 324296db60..b3fe484df3 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -132,7 +132,6 @@ @drawable/dashboard_button_light @color/ctx_menu_info_view_bg_light @drawable/context_menu_controller_bg_light - @drawable/context_menu_controller_text_color_light @color/ctx_menu_buttons_divider_light @color/search_background_dark @drawable/ic_action_mode_back @@ -322,7 +321,6 @@ @drawable/dashboard_button_dark @color/ctx_menu_info_view_bg_dark @drawable/context_menu_controller_bg_dark - @drawable/context_menu_controller_text_color_dark @color/ctx_menu_buttons_divider_dark @color/color_white @drawable/switch_ex_background_dark diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index c8f78f6d9d..0896c3d01f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -3,6 +3,7 @@ package net.osmand.plus.mapcontextmenu; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.annotation.TargetApi; +import android.content.res.ColorStateList; import android.content.res.Resources; import android.graphics.drawable.Drawable; import android.os.Build; @@ -683,6 +684,9 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo TitleButtonController rightDownloadButtonController = menu.getRightDownloadButtonController(); TitleProgressController titleProgressController = menu.getTitleProgressController(); + ColorStateList textColorStateList = ContextCompat.getColorStateList(getContext(), + nightMode ? R.color.context_menu_controller_text_color_dark : R.color.context_menu_controller_text_color_light); + // Title buttons boolean showTitleButtonsContainer = (leftTitleButtonController != null || rightTitleButtonController != null); final View titleButtonsContainer = view.findViewById(R.id.title_button_container); @@ -694,6 +698,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo final TextView titleButtonRightText = (TextView) view.findViewById(R.id.title_button_right_text); if (leftTitleButtonController != null) { leftTitleButton.setText(leftTitleButtonController.caption); + leftTitleButton.setTextColor(textColorStateList); if (leftTitleButtonController.visible) { leftTitleButtonView.setVisibility(View.VISIBLE); Drawable leftIcon = leftTitleButtonController.getLeftIcon(); @@ -721,6 +726,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo final TextView rightTitleButton = (TextView) view.findViewById(R.id.title_button_right); if (rightTitleButtonController != null) { rightTitleButton.setText(rightTitleButtonController.caption); + rightTitleButton.setTextColor(textColorStateList); rightTitleButtonView.setVisibility(rightTitleButtonController.visible ? View.VISIBLE : View.INVISIBLE); Drawable leftIcon = rightTitleButtonController.getLeftIcon(); @@ -735,6 +741,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo final TextView bottomTitleButton = (TextView) view.findViewById(R.id.title_button_bottom); if (bottomTitleButtonController != null) { bottomTitleButton.setText(bottomTitleButtonController.caption); + bottomTitleButton.setTextColor(textColorStateList); bottomTitleButtonView.setVisibility(bottomTitleButtonController.visible ? View.VISIBLE : View.GONE); Drawable leftIcon = bottomTitleButtonController.getLeftIcon(); @@ -757,6 +764,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo final TextView leftDownloadButton = (TextView) view.findViewById(R.id.download_button_left); if (leftDownloadButtonController != null) { leftDownloadButton.setText(leftDownloadButtonController.caption); + leftDownloadButton.setTextColor(textColorStateList); leftDownloadButtonView.setVisibility(leftDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE); Drawable leftIcon = leftDownloadButtonController.getLeftIcon(); @@ -773,6 +781,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo final TextView rightDownloadButton = (TextView) view.findViewById(R.id.download_button_right); if (rightDownloadButtonController != null) { rightDownloadButton.setText(rightDownloadButtonController.caption); + rightDownloadButton.setTextColor(textColorStateList); rightDownloadButtonView.setVisibility(rightDownloadButtonController.visible ? View.VISIBLE : View.INVISIBLE); Drawable leftIcon = rightDownloadButtonController.getLeftIcon(); From 11b512b5d33d30b239874c3b9fa2ec8760a52031 Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 10 Jan 2018 13:09:05 +0200 Subject: [PATCH 2/3] Fix night button selector in context menu --- OsmAnd/res/layout/map_context_menu_fragment.xml | 10 +++++----- .../mapcontextmenu/MapContextMenuFragment.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/OsmAnd/res/layout/map_context_menu_fragment.xml b/OsmAnd/res/layout/map_context_menu_fragment.xml index febbbea922..3ed1aa6c28 100644 --- a/OsmAnd/res/layout/map_context_menu_fragment.xml +++ b/OsmAnd/res/layout/map_context_menu_fragment.xml @@ -157,7 +157,7 @@ android:layout_marginLeft="@dimen/context_menu_padding_margin_small" android:layout_marginRight="@dimen/context_menu_padding_margin_small" android:id="@+id/title_button_view" - android:background="?attr/ctx_menu_controller_bg" + tools:background="?attr/ctx_menu_controller_bg" android:layout_width="0dp" android:layout_weight="1" android:layout_height="@dimen/context_menu_controller_height" @@ -192,7 +192,7 @@ android:layout_marginLeft="@dimen/context_menu_padding_margin_small" android:layout_marginRight="@dimen/context_menu_padding_margin_small" android:id="@+id/title_button_right_view" - android:background="?attr/ctx_menu_controller_bg" + tools:background="?attr/ctx_menu_controller_bg" android:layout_width="0dp" android:layout_weight="1" android:layout_height="@dimen/context_menu_controller_height" @@ -228,7 +228,7 @@ + tools:background="?attr/ctx_menu_controller_bg"> Date: Wed, 10 Jan 2018 14:22:57 +0200 Subject: [PATCH 3/3] Add methods for creating state list drawables --- OsmAnd/src/net/osmand/AndroidUtils.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 04b6e89195..e792b0113f 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -7,8 +7,12 @@ import android.content.Context; import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.PointF; +import android.graphics.drawable.Drawable; +import android.graphics.drawable.StateListDrawable; import android.os.Build; import android.os.IBinder; +import android.support.annotation.DrawableRes; +import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.text.format.DateFormat; import android.util.DisplayMetrics; @@ -114,6 +118,23 @@ public class AndroidUtils { return null; } + public static StateListDrawable createStateListDrawable(Context ctx, boolean night, + @DrawableRes int lightNormal, @DrawableRes int lightPressed, + @DrawableRes int darkNormal, @DrawableRes int darkPressed) { + return createStateListDrawable(night, + ContextCompat.getDrawable(ctx, lightNormal), ContextCompat.getDrawable(ctx, lightPressed), + ContextCompat.getDrawable(ctx, darkNormal), ContextCompat.getDrawable(ctx, darkPressed)); + } + + public static StateListDrawable createStateListDrawable(boolean night, + Drawable lightNormal, Drawable lightPressed, + Drawable darkNormal, Drawable darkPressed) { + StateListDrawable res = new StateListDrawable(); + res.addState(new int[]{android.R.attr.state_pressed}, night ? darkPressed : lightPressed); + res.addState(new int[]{}, night ? darkNormal : lightNormal); + return res; + } + @SuppressLint("NewApi") @SuppressWarnings("deprecation") public static void setBackground(Context ctx, View view, boolean night, int lightResId, int darkResId) {