Skip to content

Instantly share code, notes, and snippets.

@alorma
Created April 5, 2016 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alorma/63942c27b6b595d80266010b76ba2857 to your computer and use it in GitHub Desktop.
Save alorma/63942c27b6b595d80266010b76ba2857 to your computer and use it in GitHub Desktop.
Background compat
package com.anuntis.segundamano.views.compat;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
public class BackgroundCompat {
private static final BackgroundCompatImpl IMPL;
static {
final int version = Build.VERSION.SDK_INT;
if (version >= Build.VERSION_CODES.JELLY_BEAN) {
IMPL = new JellyBeanBackgroundCompat();
} else {
IMPL = new OldBackgroundCompat();
}
}
public static void setBackground(View view, Drawable drawable) {
IMPL.setBackground(view, drawable);
}
}
package com.anuntis.segundamano.views.compat;
import android.graphics.drawable.Drawable;
import android.view.View;
public interface BackgroundCompatImpl {
void setBackground(View view, Drawable drawable);
}
package com.anuntis.segundamano.views.compat;
import android.annotation.TargetApi;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) public class JellyBeanBackgroundCompat
implements BackgroundCompatImpl {
@Override
public void setBackground(View view, Drawable drawable) {
view.setBackground(drawable);
}
}
package com.anuntis.segundamano.views.compat;
import android.graphics.drawable.Drawable;
import android.view.View;
public class OldBackgroundCompat implements BackgroundCompatImpl {
@Override
public void setBackground(View view, Drawable drawable) {
view.setBackgroundDrawable(drawable);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment