Picasso 라이브러리의 핵심기능 중 RequestCreator의 into() 함수에는 Target이라는 인터페이스를 파라미터로하는 함수가있는데, 이를 이용하면 간단하게 해결이 가능하다. Target을 implements하는 클래스로 만들어 주면 된다.
public class PicassoableLinearLayout extends LinearLayout implements Target {
public PicassoableLinearLayout(Context context) {
super(context);
}
public PicassoableLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public PicassoableLinearLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@SuppressLint("NewApi")
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom loadedFrom) {
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
setBackgroundDrawable(new BitmapDrawable(getResources(), bitmap));
} else {
setBackground(new BitmapDrawable(getResources(), bitmap));
}
}
@SuppressLint("NewApi")
@Override
public void onBitmapFailed(Drawable drawable) {
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
setBackgroundDrawable(drawable);
} else {
setBackground(drawable);
}
}
@SuppressLint("NewApi")
@Override
public void onPrepareLoad(Drawable drawable) {
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
setBackgroundDrawable(drawable);
} else {
setBackground(drawable);
}
}
}