Files
rk35xx-android14/packages/apps/UniversalMediaPlayer/java/com/android/pump/widget/PlaceholderImageView.java
T
hmz007 36ed224bac Rockchip Anroid14_SDK 20240628-rkr5 (2556df1a)
Signed-off-by: hmz007 <hmz007@gmail.com>
Change-Id: Ib87fdbe7a0be7dc961af3500fe9ea4589a127f9f
2024-10-29 18:12:02 +08:00

51 lines
1.4 KiB
Java

package com.android.pump.widget;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import androidx.annotation.AttrRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat;
import com.android.pump.R;
@UiThread
public class PlaceholderImageView extends AppCompatImageView {
private static final @DrawableRes int PLACEHOLDER_DRAWABLE = R.drawable.ic_placeholder;
public PlaceholderImageView(@NonNull Context context) {
super(context);
initialize();
}
public PlaceholderImageView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initialize();
}
public PlaceholderImageView(@NonNull Context context, @Nullable AttributeSet attrs,
@AttrRes int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize();
}
@Override
public void setImageDrawable(@Nullable Drawable drawable) {
if (drawable == null) {
drawable = ContextCompat.getDrawable(getContext(), PLACEHOLDER_DRAWABLE);
}
super.setImageDrawable(drawable);
}
private void initialize() {
if (getDrawable() == null) {
setImageDrawable(null);
}
}
}