Java Code Examples for android.graphics.drawable.Drawable#setFilterBitmap()

The following examples show how to use android.graphics.drawable.Drawable#setFilterBitmap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DrawableProperties.java    From ImageLoader with Apache License 2.0 6 votes vote down vote up
@SuppressLint("Range")
public void applyTo(Drawable drawable) {
  if (drawable == null) {
    return;
  }
  if (mAlpha != UNSET) {
    drawable.setAlpha(mAlpha);
  }
  if (mIsSetColorFilter) {
    drawable.setColorFilter(mColorFilter);
  }
  if (mDither != UNSET) {
    drawable.setDither(mDither != 0);
  }
  if (mFilterBitmap != UNSET) {
    drawable.setFilterBitmap(mFilterBitmap != 0);
  }
}
 
Example 2
Source File: DrawableProperties.java    From fresco with MIT License 6 votes vote down vote up
@SuppressLint("Range")
public void applyTo(Drawable drawable) {
  if (drawable == null) {
    return;
  }
  if (mAlpha != UNSET) {
    drawable.setAlpha(mAlpha);
  }
  if (mIsSetColorFilter) {
    drawable.setColorFilter(mColorFilter);
  }
  if (mDither != UNSET) {
    drawable.setDither(mDither != 0);
  }
  if (mFilterBitmap != UNSET) {
    drawable.setFilterBitmap(mFilterBitmap != 0);
  }
}
 
Example 3
Source File: DrawableUtils.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets various paint properties on the drawable
 * @param drawable Drawable on which to set the properties
 * @param properties wrapper around property values to set on the drawable
 */
public static void setDrawableProperties(Drawable drawable, DrawableProperties properties) {
  if (drawable == null || properties == null) {
    return;
  }

  drawable.setAlpha(properties.getAlpha());
  drawable.setColorFilter(properties.getColorFilter());
  drawable.setDither(properties.isDither());
  drawable.setFilterBitmap(properties.isFilterBitmap());
}
 
Example 4
Source File: ArrayDrawable.java    From fresco with MIT License 5 votes vote down vote up
@Override
public void setFilterBitmap(boolean filterBitmap) {
  mDrawableProperties.setFilterBitmap(filterBitmap);
  for (int i = 0; i < mLayers.length; i++) {
    Drawable drawable = mLayers[i];
    if (drawable != null) {
      drawable.setFilterBitmap(filterBitmap);
    }
  }
}
 
Example 5
Source File: GroupDrawable.java    From openlauncher with Apache License 2.0 4 votes vote down vote up
private void drawIcon(Canvas canvas, Drawable icon, float l, float t, float r, float b, Paint paint) {
    icon.setBounds((int) l, (int) t, (int) r, (int) b);
    icon.setFilterBitmap(true);
    icon.setAlpha(paint.getAlpha());
    icon.draw(canvas);
}
 
Example 6
Source File: WidgetPreviewLoader.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
private Bitmap generateShortcutPreview(
        Launcher launcher, ResolveInfo info, int maxWidth, int maxHeight, Bitmap preview) {
    final Canvas c = new Canvas();
    if (preview == null) {
        preview = Bitmap.createBitmap(maxWidth, maxHeight, Config.ARGB_8888);
        c.setBitmap(preview);
    } else if (preview.getWidth() != maxWidth || preview.getHeight() != maxHeight) {
        throw new RuntimeException("Improperly sized bitmap passed as argument");
    } else {
        // Reusing bitmap. Clear it.
        c.setBitmap(preview);
        c.drawColor(0, PorterDuff.Mode.CLEAR);
    }

    Drawable icon = mutateOnMainThread(mIconCache.getFullResIcon(info.activityInfo));
    icon.setFilterBitmap(true);

    // Draw a desaturated/scaled version of the icon in the background as a watermark
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    icon.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    icon.setAlpha((int) (255 * 0.06f));

    Resources res = mContext.getResources();
    int paddingTop = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_top);
    int paddingLeft = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_left);
    int paddingRight = res.getDimensionPixelOffset(R.dimen.shortcut_preview_padding_right);
    int scaledIconWidth = (maxWidth - paddingLeft - paddingRight);
    icon.setBounds(paddingLeft, paddingTop,
            paddingLeft + scaledIconWidth, paddingTop + scaledIconWidth);
    icon.draw(c);

    // Draw the final icon at top left corner.
    // TODO: use top right for RTL
    int appIconSize = launcher.getDeviceProfile().iconSizePx;

    icon.setAlpha(255);
    icon.setColorFilter(null);
    icon.setBounds(0, 0, appIconSize, appIconSize);
    icon.draw(c);

    c.setBitmap(null);
    return preview;
}