Skip to content

Commit bfa94d4

Browse files
committed
Catapult: Add blurred watch next art as background
It looks little bit better on non 16:9 art. Change-Id: I2cc26890c485027a6a5fb597b87367519e34c706
1 parent cde6f68 commit bfa94d4

3 files changed

Lines changed: 71 additions & 1 deletion

File tree

app/src/main/java/org/lineageos/tv/launcher/view/WatchNextCard.kt

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ package org.lineageos.tv.launcher.view
77

88
import android.animation.AnimatorInflater
99
import android.content.Context
10+
import android.graphics.PorterDuff
11+
import android.graphics.PorterDuffColorFilter
12+
import android.graphics.RenderEffect
13+
import android.graphics.Shader
1014
import android.util.AttributeSet
1115
import android.widget.ImageView
1216
import android.widget.TextView
17+
import androidx.core.content.ContextCompat
1318
import androidx.core.view.isInvisible
1419
import androidx.core.view.isVisible
1520
import androidx.tvprovider.media.tv.BasePreviewProgram
21+
import androidx.tvprovider.media.tv.TvContractCompat
1622
import coil.load
23+
import coil.size.Scale
24+
import coil.transform.RoundedCornersTransformation
1725
import com.google.android.material.progressindicator.LinearProgressIndicator
1826
import org.lineageos.tv.launcher.R
1927
import org.lineageos.tv.launcher.ext.getAttributeResourceId
@@ -22,7 +30,9 @@ class WatchNextCard @JvmOverloads constructor(
2230
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
2331
) : Card(context, attrs, defStyleAttr) {
2432
// Views
33+
private val bannerBackgroundView: ImageView by lazy { findViewById(R.id.app_banner_background)!! }
2534
private val bannerView: ImageView by lazy { findViewById(R.id.app_banner)!! }
35+
private val smallBannerView: ImageView by lazy { findViewById(R.id.app_banner_small)!! }
2636
private val title: TextView by lazy { findViewById(R.id.title)!! }
2737
private val progressView: LinearProgressIndicator by lazy { findViewById(R.id.watch_progress)!! }
2838

@@ -48,9 +58,12 @@ class WatchNextCard @JvmOverloads constructor(
4858

4959
@Suppress("RestrictedApi")
5060
fun setInfo(info: BasePreviewProgram) {
61+
bannerView.isVisible = false
62+
smallBannerView.isVisible = false
63+
progressView.isVisible = false
64+
5165
title.isInvisible = true
5266
label = info.title
53-
bannerView.isVisible = true
5467
launchIntent = info.intent
5568
title.text = info.title
5669

@@ -63,6 +76,43 @@ class WatchNextCard @JvmOverloads constructor(
6376
}
6477
}
6578

79+
// Other than 16:9, use blurred background and smaller art
80+
if (info.posterArtAspectRatio != TvContractCompat.PreviewPrograms.ASPECT_RATIO_16_9) {
81+
bannerView.isVisible = false
82+
smallBannerView.isVisible = true
83+
bannerBackgroundView.load(info.posterArtUri) {
84+
placeholder(
85+
context.getAttributeResourceId(
86+
com.google.android.material.R.attr.colorSecondaryContainer
87+
)
88+
)
89+
crossfade(500)
90+
scale(Scale.FILL)
91+
listener(onSuccess = { _, _ ->
92+
bannerBackgroundView.setRenderEffect(
93+
RenderEffect.createBlurEffect(
94+
25f, 25f, Shader.TileMode.CLAMP
95+
)
96+
)
97+
98+
bannerBackgroundView.colorFilter = PorterDuffColorFilter(
99+
ContextCompat.getColor(context, R.color.watchNextCardFilter),
100+
PorterDuff.Mode.SRC_ATOP
101+
)
102+
}
103+
)
104+
}
105+
106+
smallBannerView.load(info.posterArtUri) {
107+
crossfade(500)
108+
transformations(RoundedCornersTransformation(5F))
109+
}
110+
111+
return
112+
}
113+
114+
bannerView.isVisible = true
115+
smallBannerView.isVisible = false
66116
bannerView.load(info.posterArtUri) {
67117
placeholder(
68118
context.getAttributeResourceId(

app/src/main/res/layout/watch_next_card.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
android:clipChildren="true"
2121
android:clipToOutline="true">
2222

23+
24+
<ImageView
25+
android:id="@+id/app_banner_background"
26+
android:layout_width="match_parent"
27+
android:layout_height="match_parent"
28+
android:background="@drawable/card_border_only"
29+
android:clipToOutline="true"
30+
android:scaleType="centerCrop" />
31+
2332
<ImageView
2433
android:id="@+id/app_banner"
2534
android:layout_width="match_parent"
@@ -29,6 +38,16 @@
2938
android:clipToOutline="true"
3039
android:visibility="gone" />
3140

41+
<ImageView
42+
android:id="@+id/app_banner_small"
43+
android:layout_width="wrap_content"
44+
android:layout_height="match_parent"
45+
android:layout_gravity="center"
46+
android:layout_margin="4dp"
47+
android:adjustViewBounds="true"
48+
android:backgroundTint="@android:color/black"
49+
android:visibility="gone" />
50+
3251
<com.google.android.material.progressindicator.LinearProgressIndicator
3352
android:id="@+id/watch_progress"
3453
android:layout_width="match_parent"

app/src/main/res/values/colors.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
-->
66
<resources>
77
<color name="toggleButtonBackground">#0B2A2C</color>
8+
<color name="watchNextCardFilter">#80000000</color>
89
</resources>

0 commit comments

Comments
 (0)