Code example for SparseArray

Methods: getindexOfKey

0
     
    public static Drawable getDrawable(Context ctx, int resId, boolean enabled) {
        if (enabled)
            return ctx.getResources().getDrawable(resId);
                 
        if (mGrayscaleCache.indexOfKey(resId) > 0) {
            return mGrayscaleCache.get(resId);
        } else { 
            Drawable drawable = convertDrawableToGrayScale(ctx, resId);
         
            mGrayscaleCache.put(resId, drawable);
             
            return drawable;
        } 
    } 
     
    public static Drawable convertDrawableToGrayScale(Context ctx, int resId) {
        Drawable res = ctx.getResources().getDrawable(resId).mutate();
         
        res.setColorFilter(Color.GRAY, Mode.SRC_IN);
Stop searching for code, let great code find you!  Add Codota to your java IDE