1package android.support.v17.leanback.widget; 2 3import android.graphics.drawable.Drawable; 4import android.os.Build; 5import android.view.View; 6import android.view.ViewGroup; 7 8final class ForegroundHelper { 9 10 final static ForegroundHelper sInstance = new ForegroundHelper(); 11 ForegroundHelperVersionImpl mImpl; 12 13 /** 14 * Interface implemented by classes that support Shadow. 15 */ 16 static interface ForegroundHelperVersionImpl { 17 18 public void setForeground(View view, Drawable drawable); 19 20 public Drawable getForeground(View view); 21 } 22 23 /** 24 * Implementation used on api 23 (and above). 25 */ 26 private static final class ForegroundHelperApi23Impl implements ForegroundHelperVersionImpl { 27 @Override 28 public void setForeground(View view, Drawable drawable) { 29 ForegroundHelperApi23.setForeground(view, drawable); 30 } 31 32 @Override 33 public Drawable getForeground(View view) { 34 return ForegroundHelperApi23.getForeground(view); 35 } 36 } 37 38 /** 39 * Stub implementation 40 */ 41 private static final class ForegroundHelperStubImpl implements ForegroundHelperVersionImpl { 42 @Override 43 public void setForeground(View view, Drawable drawable) { 44 } 45 46 @Override 47 public Drawable getForeground(View view) { 48 return null; 49 } 50 } 51 52 private ForegroundHelper() { 53 if (supportsForeground()) { 54 mImpl = new ForegroundHelperApi23Impl(); 55 } else { 56 mImpl = new ForegroundHelperStubImpl(); 57 } 58 } 59 60 public static ForegroundHelper getInstance() { 61 return sInstance; 62 } 63 64 /** 65 * Returns true if view.setForeground() is supported. 66 */ 67 public static boolean supportsForeground() { 68 return Build.VERSION.SDK_INT >= 23; 69 } 70 71 public Drawable getForeground(View view) { 72 return mImpl.getForeground(view); 73 } 74 75 public void setForeground(View view, Drawable drawable) { 76 mImpl.setForeground(view, drawable); 77 } 78} 79