[Android] Fix TV grid background on focus change
Nicolas Pomepuy
git at videolan.org
Thu Sep 2 10:10:27 UTC 2021
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Sep 2 11:48:51 2021 +0200| [f489653280f787d5d50ccab5e56a4753d746ab09] | committer: Nicolas Pomepuy
Fix TV grid background on focus change
> https://code.videolan.org/videolan/vlc-android/commit/f489653280f787d5d50ccab5e56a4753d746ab09
---
.../res/drawable/tv_card_background_focused.xml | 31 ++++++++++++++++++++++
.../res/drawable/tv_card_background_transition.xml | 30 +++++++++++++++++++++
.../res/drawable/tv_list_background_transition.xml | 30 +++++++++++++++++++++
.../television/ui/browser/TvAdapterUtils.kt | 12 +++------
.../src/main/res/layout/media_browser_tv_item.xml | 2 +-
.../main/res/layout/media_browser_tv_item_list.xml | 2 +-
6 files changed, 96 insertions(+), 11 deletions(-)
diff --git a/application/resources/src/main/res/drawable/tv_card_background_focused.xml b/application/resources/src/main/res/drawable/tv_card_background_focused.xml
new file mode 100644
index 000000000..fcac9ddff
--- /dev/null
+++ b/application/resources/src/main/res/drawable/tv_card_background_focused.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ *************************************************************************
+ ~ tv_card_background_focused.xml
+ ~ **************************************************************************
+ ~ Copyright © 2021 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="rectangle">
+
+ <solid android:color="@color/tv_card_content"/>
+ <corners android:radius="3dp" />
+</shape>
\ No newline at end of file
diff --git a/application/resources/src/main/res/drawable/tv_card_background_transition.xml b/application/resources/src/main/res/drawable/tv_card_background_transition.xml
new file mode 100644
index 000000000..32578a3d9
--- /dev/null
+++ b/application/resources/src/main/res/drawable/tv_card_background_transition.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ *************************************************************************
+ ~ tv_card_background_transition.xml
+ ~ **************************************************************************
+ ~ Copyright © 2021 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.
+ ~ ***************************************************************************
+ ~
+ ~
+ -->
+
+<transition xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- The drawables used here can be solid colors, gradients, shapes, images, etc. -->
+ <item android:drawable="@drawable/tv_card_background" />
+ <item android:drawable="@drawable/tv_card_background_focused" />
+</transition>
\ No newline at end of file
diff --git a/application/resources/src/main/res/drawable/tv_list_background_transition.xml b/application/resources/src/main/res/drawable/tv_list_background_transition.xml
new file mode 100644
index 000000000..7906ccac1
--- /dev/null
+++ b/application/resources/src/main/res/drawable/tv_list_background_transition.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ *************************************************************************
+ ~ tv_list_background_transition.xml
+ ~ **************************************************************************
+ ~ Copyright © 2021 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.
+ ~ ***************************************************************************
+ ~
+ ~
+ -->
+
+<transition xmlns:android="http://schemas.android.com/apk/res/android">
+ <!-- The drawables used here can be solid colors, gradients, shapes, images, etc. -->
+ <item android:drawable="@color/tv_card_content_dark" />
+ <item android:drawable="@color/tv_card_content" />
+</transition>
\ No newline at end of file
diff --git a/application/television/src/main/java/org/videolan/television/ui/browser/TvAdapterUtils.kt b/application/television/src/main/java/org/videolan/television/ui/browser/TvAdapterUtils.kt
index 7bf437ace..162e7c968 100644
--- a/application/television/src/main/java/org/videolan/television/ui/browser/TvAdapterUtils.kt
+++ b/application/television/src/main/java/org/videolan/television/ui/browser/TvAdapterUtils.kt
@@ -26,6 +26,7 @@ package org.videolan.television.ui.browser
import android.animation.ArgbEvaluator
import android.animation.ValueAnimator
+import android.graphics.drawable.TransitionDrawable
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
@@ -57,15 +58,8 @@ object TvAdapterUtils {
container.animate().scaleX(1f).scaleY(1f)
}
- if (isList) {
- val colorFrom = ContextCompat.getColor(container.context, R.color.tv_card_content_dark)
- val colorTo = ContextCompat.getColor(container.context, R.color.tv_card_content)
-
- val colorAnimation = if (hasFocus) ValueAnimator.ofObject(ArgbEvaluator(), colorFrom, colorTo) else ValueAnimator.ofObject(ArgbEvaluator(), colorTo, colorFrom)
- colorAnimation.duration = 250 // milliseconds
-
- colorAnimation.addUpdateListener { animator -> container.setBackgroundColor(animator.animatedValue as Int) }
- colorAnimation.start()
+ (container.background as? TransitionDrawable)?.let {
+ if (hasFocus) it.startTransition(250) else it.reverseTransition(250)
}
}
}
\ No newline at end of file
diff --git a/application/television/src/main/res/layout/media_browser_tv_item.xml b/application/television/src/main/res/layout/media_browser_tv_item.xml
index e3b814a70..a43596217 100644
--- a/application/television/src/main/res/layout/media_browser_tv_item.xml
+++ b/application/television/src/main/res/layout/media_browser_tv_item.xml
@@ -67,7 +67,7 @@
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:background="@drawable/tv_card_background"
+ android:background="@drawable/tv_card_background_transition"
android:clickable="true"
android:focusable="true"
android:longClickable="true"
diff --git a/application/television/src/main/res/layout/media_browser_tv_item_list.xml b/application/television/src/main/res/layout/media_browser_tv_item_list.xml
index d8c2a787f..2f61bf447 100644
--- a/application/television/src/main/res/layout/media_browser_tv_item_list.xml
+++ b/application/television/src/main/res/layout/media_browser_tv_item_list.xml
@@ -98,7 +98,7 @@
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:background="@color/tv_card_content_dark"
+ android:background="@drawable/tv_list_background_transition"
android:clickable="true"
android:focusable="true"
android:longClickable="true"
More information about the Android
mailing list