[Android] Widgets: make the pressed selector indicator change depending on the widgets background color
Nicolas Pomepuy
git at videolan.org
Wed May 18 09:57:58 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu May 12 07:47:50 2022 +0200| [b961d1b32120bcc52690401fdd8a2cedb7841916] | committer: Duncan McNamara
Widgets: make the pressed selector indicator change depending on the widgets background color
> https://code.videolan.org/videolan/vlc-android/commit/b961d1b32120bcc52690401fdd8a2cedb7841916
---
.../main/res/drawable/round_black_transparent.xml | 30 +++++++++++++++++++++
.../main/res/drawable/round_white_transparent.xml | 2 +-
.../main/res/drawable/widget_touch_background.xml | 31 ++++++++++++++++++++++
.../res/drawable/widget_touch_background_dark.xml} | 0
.../vlc/widget/MiniPlayerAppWidgetProvider.kt | 6 ++++-
.../org/videolan/vlc/widget/utils/WidgetUtils.kt | 11 ++++++++
6 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/application/resources/src/main/res/drawable/round_black_transparent.xml b/application/resources/src/main/res/drawable/round_black_transparent.xml
new file mode 100644
index 000000000..822105088
--- /dev/null
+++ b/application/resources/src/main/res/drawable/round_black_transparent.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ *************************************************************************
+ ~ round_white_transparent.xml
+ ~ **************************************************************************
+ ~ Copyright © 2022 VLC authors and VideoLAN
+ ~ Author: Nicolas POMEPUY
+ ~ This program is free software; you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation; either version 2 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with this program; if not, write to the Free Software
+ ~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ ~ ***************************************************************************
+ ~
+ ~
+ -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+ android:shape="oval">
+ <solid android:color="@color/black_transparent_10" />
+
+</shape>
\ No newline at end of file
diff --git a/application/resources/src/main/res/drawable/round_white_transparent.xml b/application/resources/src/main/res/drawable/round_white_transparent.xml
index c19aafae1..ef11ccd96 100644
--- a/application/resources/src/main/res/drawable/round_white_transparent.xml
+++ b/application/resources/src/main/res/drawable/round_white_transparent.xml
@@ -25,6 +25,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
- <solid android:color="@color/white_more_transparent" />
+ <solid android:color="@color/white_transparent_20" />
</shape>
\ No newline at end of file
diff --git a/application/resources/src/main/res/drawable/widget_touch_background.xml b/application/resources/src/main/res/drawable/widget_touch_background.xml
new file mode 100644
index 000000000..1460f10dc
--- /dev/null
+++ b/application/resources/src/main/res/drawable/widget_touch_background.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ *************************************************************************
+ ~ widget_touch_background.xml
+ ~ **************************************************************************
+ ~ Copyright © 2022 VLC authors and VideoLAN
+ ~ Author: Nicolas POMEPUY
+ ~ This program is free software; you can redistribute it and/or modify
+ ~ it under the terms of the GNU General Public License as published by
+ ~ the Free Software Foundation; either version 2 of the License, or
+ ~ (at your option) any later version.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with this program; if not, write to the Free Software
+ ~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ ~ ***************************************************************************
+ ~
+ ~
+ -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:drawable="@drawable/round_black_transparent" android:state_focused="true" android:state_pressed="true"/>
+ <item android:drawable="@drawable/round_black_transparent" android:state_focused="true"/>
+ <item android:drawable="@drawable/round_black_transparent" android:state_pressed="true"/>
+
+
+</selector>
\ No newline at end of file
diff --git a/application/vlc-android/res/drawable/widget_touch_background.xml b/application/resources/src/main/res/drawable/widget_touch_background_dark.xml
similarity index 100%
rename from application/vlc-android/res/drawable/widget_touch_background.xml
rename to application/resources/src/main/res/drawable/widget_touch_background_dark.xml
diff --git a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
index 49fd65b30..5e4d8a447 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/MiniPlayerAppWidgetProvider.kt
@@ -237,7 +237,6 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
views.setImageViewBitmap(R.id.backward, context.getColoredBitmapFromColor(R.drawable.ic_widget_next_normal, foregroundColor))
views.setImageViewBitmap(R.id.seek_rewind, context.getColoredBitmapFromColor(R.drawable.ic_widget_forward_10, foregroundColor))
views.setImageViewBitmap(R.id.seek_forward, context.getColoredBitmapFromColor(R.drawable.ic_widget_rewind_10, foregroundColor))
- views.setImageViewBitmap(R.id.backward, context.getColoredBitmapFromColor(R.drawable.ic_widget_next_normal, foregroundColor))
} else {
views.setImageViewBitmap(R.id.forward, context.getColoredBitmapFromColor(R.drawable.ic_widget_next_normal, foregroundColor))
views.setImageViewBitmap(R.id.backward, context.getColoredBitmapFromColor(R.drawable.ic_widget_previous_normal, foregroundColor))
@@ -247,6 +246,11 @@ class MiniPlayerAppWidgetProvider : AppWidgetProvider() {
views.setImageViewBitmap(R.id.play_pause_background, context.getColoredBitmapFromColor(R.drawable.widget_rectangle_background, widgetCacheEntry.widget.getBackgroundSecondaryColor(context, palette = palette), 52.dp, 52.dp))
views.setImageViewBitmap(R.id.widget_configure, if (widgetCacheEntry.widget.showConfigure) context.getColoredBitmapFromColor(R.drawable.ic_widget_configure, foregroundColor, 24.dp, 24.dp) else null)
if (widgetType == WidgetType.PILL) views.setImageViewBitmap(R.id.cover_background, context.getColoredBitmapFromColor(R.drawable.widget_circle, widgetCacheEntry.widget.getSeparatorColor(context), 48.dp, 48.dp))
+
+ val rippleDrawable = if (backgroundColor.isLight()) R.drawable.widget_touch_background else R.drawable.widget_touch_background_dark
+ arrayOf(R.id.play_pause, R.id.forward, R.id.backward, R.id.seek_rewind, R.id.seek_forward, R.id.widget_configure).forEach {
+ views.setInt(it, "setBackgroundResource", rippleDrawable)
+ }
}
diff --git a/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt b/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
index df27edaea..8b47e7874 100644
--- a/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
+++ b/application/vlc-android/src/org/videolan/vlc/widget/utils/WidgetUtils.kt
@@ -161,6 +161,17 @@ fun Int.lightenOrDarkenColor(value: Float): Int {
return HSLToColor(hsl)
}
+/**
+ * Detects if the color represented by this Int is light
+ *
+ * @return true if the color is light, false if it's dark
+ */
+fun Int.isLight():Boolean {
+ val hsl = FloatArray(3)
+ colorToHSL(this, hsl)
+ return hsl[2] > 0.5F
+}
+
/**
* Generates a circular progress bar [Bitmap]
*
More information about the Android
mailing list