Created
April 5, 2016 12:49
-
-
Save alorma/63942c27b6b595d80266010b76ba2857 to your computer and use it in GitHub Desktop.
Background compat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.anuntis.segundamano.views.compat; | |
import android.graphics.drawable.Drawable; | |
import android.view.View; | |
public interface BackgroundCompatImpl { | |
void setBackground(View view, Drawable drawable); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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