[Android] Animate image appearance in lists
Nicolas Pomepuy
git at videolan.org
Fri Aug 2 14:57:47 CEST 2019
vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Thu Aug 1 15:09:31 2019 +0200| [125f04af1f743084ed3a5bc31102db85cae169c0] | committer: Geoffrey Métais
Animate image appearance in lists
(cherry picked from commit decca21056fc706d50e6bf1c5d55952d574f1e1e)
> https://code.videolan.org/videolan/vlc-android/commit/125f04af1f743084ed3a5bc31102db85cae169c0
---
vlc-android/res/layout/audio_browser_card_item.xml | 2 +-
vlc-android/res/layout/audio_browser_item.xml | 2 +-
vlc-android/res/layout/media_browser_tv_item.xml | 2 +-
.../videolan/vlc/gui/audio/AudioBrowserAdapter.kt | 2 +
.../org/videolan/vlc/gui/tv/FileTvItemAdapter.kt | 1 +
.../org/videolan/vlc/gui/tv/MediaTvItemAdapter.kt | 1 +
.../org/videolan/vlc/gui/view/FadableImageView.kt | 69 ++++++++++++++++++++++
7 files changed, 76 insertions(+), 3 deletions(-)
diff --git a/vlc-android/res/layout/audio_browser_card_item.xml b/vlc-android/res/layout/audio_browser_card_item.xml
index c3e964d91..34f575638 100644
--- a/vlc-android/res/layout/audio_browser_card_item.xml
+++ b/vlc-android/res/layout/audio_browser_card_item.xml
@@ -62,7 +62,7 @@
<!-- Image loading is handled by org.videolan.vlc.gui.helpers.ImageLoader.loadImage() -->
- <ImageView
+ <org.videolan.vlc.gui.view.FadableImageView
android:id="@+id/media_cover"
android:layout_width="0dp"
android:layout_height="0dp"
diff --git a/vlc-android/res/layout/audio_browser_item.xml b/vlc-android/res/layout/audio_browser_item.xml
index 8452d6d94..634556835 100644
--- a/vlc-android/res/layout/audio_browser_item.xml
+++ b/vlc-android/res/layout/audio_browser_item.xml
@@ -59,7 +59,7 @@
vlc:layout_constraintStart_toStartOf="parent"
vlc:layout_constraintTop_toTopOf="@+id/title" />
- <ImageView
+ <org.videolan.vlc.gui.view.FadableImageView
android:id="@+id/media_cover"
android:layout_height="@dimen/audio_browser_item_size"
android:layout_width="0dp"
diff --git a/vlc-android/res/layout/media_browser_tv_item.xml b/vlc-android/res/layout/media_browser_tv_item.xml
index 5a0f29952..8b96ce1ee 100644
--- a/vlc-android/res/layout/media_browser_tv_item.xml
+++ b/vlc-android/res/layout/media_browser_tv_item.xml
@@ -74,7 +74,7 @@
<!-- Image loading is handled by org.videolan.vlc.gui.helpers.ImageLoader.loadImage() -->
- <ImageView
+ <org.videolan.vlc.gui.view.FadableImageView
android:id="@+id/media_cover"
android:layout_width="match_parent"
android:layout_height="0dp"
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
index 1ddefdcdc..2455c0590 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.kt
@@ -235,6 +235,7 @@ class AudioBrowserAdapter @JvmOverloads constructor(
binding.cover = if (cardSize == SHOW_IN_LIST && defaultCover != null) defaultCover else null
binding.title.text = ""
binding.subtitle.text = ""
+ binding.mediaCover.resetFade()
}
override fun setCoverlay(selected: Boolean) {
@@ -272,6 +273,7 @@ class AudioBrowserAdapter @JvmOverloads constructor(
if (defaultCover != null) binding.cover = defaultCover
binding.title.text = ""
binding.subtitle.text = ""
+ binding.mediaCover.resetFade()
}
override fun setCoverlay(selected: Boolean) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/FileTvItemAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/tv/FileTvItemAdapter.kt
index fac2d49a7..6833c070a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/FileTvItemAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/FileTvItemAdapter.kt
@@ -125,6 +125,7 @@ class FileTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, va
defaultCover?.let { binding.cover = it }
binding.title.text = ""
binding.subtitle.text = ""
+ binding.mediaCover.resetFade()
}
override fun setItem(item: MediaLibraryItem?) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MediaTvItemAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/tv/MediaTvItemAdapter.kt
index 25b391980..e674b84db 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MediaTvItemAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MediaTvItemAdapter.kt
@@ -186,6 +186,7 @@ class MediaTvItemAdapter(type: Int, private val eventsHandler: IEventsHandler, v
if (defaultCover != null) binding.cover = defaultCover
binding.title.text = ""
binding.subtitle.text = ""
+ binding.mediaCover.resetFade()
}
override fun setItem(item: MediaLibraryItem?) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/FadableImageView.kt b/vlc-android/src/org/videolan/vlc/gui/view/FadableImageView.kt
new file mode 100644
index 000000000..a8fd7c8c0
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/view/FadableImageView.kt
@@ -0,0 +1,69 @@
+package org.videolan.vlc.gui.view
+
+import android.content.Context
+import android.graphics.Bitmap
+import android.graphics.drawable.Drawable
+import android.graphics.drawable.Icon
+import android.net.Uri
+import android.util.AttributeSet
+import androidx.appcompat.widget.AppCompatImageView
+
+class FadableImageView : AppCompatImageView {
+ constructor(context: Context) : super(context)
+
+ constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
+
+ constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
+
+ private fun fade() {
+ alpha = 0f
+ animate().cancel()
+ animate().alpha(1f)
+ }
+
+ fun resetFade() {
+ animate().cancel()
+ post {
+ alpha = 1f
+ }
+ }
+
+ private fun launchAnim(hasToFade: Boolean) {
+ if (!hasToFade) resetFade() else fade()
+ }
+
+ override fun setBackground(background: Drawable?) {
+ super.setBackground(background)
+ launchAnim(background != null)
+ }
+
+ override fun setBackgroundResource(resid: Int) {
+ super.setBackgroundResource(resid)
+ launchAnim(resid != 0)
+ }
+
+ override fun setImageBitmap(bm: Bitmap?) {
+ launchAnim(bm != null)
+ super.setImageBitmap(bm)
+ }
+
+ override fun setImageDrawable(drawable: Drawable?) {
+ launchAnim(drawable != null)
+ super.setImageDrawable(drawable)
+ }
+
+ override fun setImageIcon(icon: Icon?) {
+ launchAnim(icon != null)
+ super.setImageIcon(icon)
+ }
+
+ override fun setImageResource(resId: Int) {
+ launchAnim(resId != 0)
+ super.setImageResource(resId)
+ }
+
+ override fun setImageURI(uri: Uri?) {
+ launchAnim(uri != null)
+ super.setImageURI(uri)
+ }
+}
\ No newline at end of file
More information about the Android
mailing list