1254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gupackage android.support.v17.leanback.widget; 2254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 3254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Guimport android.graphics.drawable.Drawable; 4254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Guimport android.os.Build; 5254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Guimport android.view.View; 6254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Guimport android.view.ViewGroup; 7254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 8254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gufinal class ForegroundHelper { 9254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 10254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu final static ForegroundHelper sInstance = new ForegroundHelper(); 11254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu ForegroundHelperVersionImpl mImpl; 12254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 13254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu /** 14254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu * Interface implemented by classes that support Shadow. 15254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu */ 16254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu static interface ForegroundHelperVersionImpl { 17254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 18254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu public void setForeground(View view, Drawable drawable); 19254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 20254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu public Drawable getForeground(View view); 21254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 22254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 23254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu /** 24254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu * Implementation used on api 23 (and above). 25254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu */ 26254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu private static final class ForegroundHelperApi23Impl implements ForegroundHelperVersionImpl { 27254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu @Override 28254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu public void setForeground(View view, Drawable drawable) { 29254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu ForegroundHelperApi23.setForeground(view, drawable); 30254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 31254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 32254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu @Override 33254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu public Drawable getForeground(View view) { 34254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu return ForegroundHelperApi23.getForeground(view); 35254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 36254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 37254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 38254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu /** 39254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu * Stub implementation 40254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu */ 41254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu private static final class ForegroundHelperStubImpl implements ForegroundHelperVersionImpl { 42254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu @Override 43254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu public void setForeground(View view, Drawable drawable) { 44254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 45254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 46254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu @Override 47254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu public Drawable getForeground(View view) { 48254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu return null; 49254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 50254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 51254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 52254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu private ForegroundHelper() { 53254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu if (supportsForeground()) { 54254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu mImpl = new ForegroundHelperApi23Impl(); 55254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } else { 56254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu mImpl = new ForegroundHelperStubImpl(); 57254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 58254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 59254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 60254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu public static ForegroundHelper getInstance() { 61254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu return sInstance; 62254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 63254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 64254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu /** 65254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu * Returns true if view.setForeground() is supported. 66254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu */ 67254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu public static boolean supportsForeground() { 68254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu return Build.VERSION.SDK_INT >= 23; 69254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 70254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 71254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu public Drawable getForeground(View view) { 72254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu return mImpl.getForeground(view); 73254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 74254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu 75254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu public void setForeground(View view, Drawable drawable) { 76254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu mImpl.setForeground(view, drawable); 77254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu } 78254b417129de2a8c5612826a152f8a26c8f1d0e8Dake Gu} 79