Java Code Examples for android.graphics.ColorMatrix#setSaturation()

The following examples show how to use android.graphics.ColorMatrix#setSaturation() . 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: ArcusProductFragment.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
/**
 * convert the current screen color to grey
 * @param apply apply grey scale or not
 */
private void applyGreyScale(final boolean apply){

    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0f);
    final ColorFilter filter = new ColorMatrixColorFilter(cm);

    if (apply) {
        if (deviceImage != null) this.deviceImage.setColorFilter(filter);
        if (this.leftNav != null) this.leftNav.setColorFilter(null);
        if (this.rightNav != null) this.rightNav.setColorFilter(null);
        if (this.bottomView != null && !isBottomViewAlerting) this.bottomView.getBackground().setColorFilter(filter);
    } else {
        if (deviceImage != null) this.deviceImage.setColorFilter(null);
        if (this.leftNav != null) this.leftNav.setColorFilter(null);
        if (this.rightNav != null) this.rightNav.setColorFilter(null);
        if (this.bottomView != null && !isBottomViewAlerting) this.bottomView.getBackground().setColorFilter(null);
    }
}
 
Example 2
Source File: MainActivity.java    From ripple with GNU General Public License v3.0 6 votes vote down vote up
void setEnabled(boolean enabled) {
    if (enabled) {
        editableLabel.setVisibility(View.VISIBLE);
        appLabelView.setEnabled(true);
        iconView.setEnabled(true);
        iconView.setColorFilter(null);
    } else {
        editableLabel.setVisibility(View.GONE);
        appLabelView.setEnabled(false);
        iconView.setEnabled(false);
        // grey out app icon when disabled
        ColorMatrix matrix = new ColorMatrix();
        matrix.setSaturation(0);
        ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
        iconView.setColorFilter(filter);
    }
}
 
Example 3
Source File: ImageFilterUtils.java    From DevUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 饱和度处理
 * @param bitmap          待操作源图片
 * @param saturationValue 新的饱和度值
 * @return 改变了饱和度值之后的图片
 */
public static Bitmap saturation(final Bitmap bitmap, final int saturationValue) {
    if (bitmap == null) return null;
    try {
        // 计算出符合要求的饱和度值
        float newSaturationValue = saturationValue * 1.0F / 127;
        // 创建一个颜色矩阵
        ColorMatrix saturationColorMatrix = new ColorMatrix();
        // 设置饱和度值
        saturationColorMatrix.setSaturation(newSaturationValue);
        // 创建一个画笔并设置其颜色过滤器
        Paint paint = new Paint();
        paint.setColorFilter(new ColorMatrixColorFilter(saturationColorMatrix));
        // 创建一个新的图片并创建画布
        Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(newBitmap);
        // 将源图片使用给定的画笔画到画布上
        canvas.drawBitmap(bitmap, 0, 0, paint);
        return newBitmap;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "saturation");
    }
    return null;
}
 
Example 4
Source File: MyWatchFaceService.java    From io2015-codelabs with Apache License 2.0 5 votes vote down vote up
private void initGrayBackgroundBitmap() {
    mGrayBackgroundBitmap = Bitmap.createBitmap(mBackgroundBitmap.getWidth(),
            mBackgroundBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(mGrayBackgroundBitmap);
    Paint grayPaint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(0);
    ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);
    grayPaint.setColorFilter(filter);
    canvas.drawBitmap(mBackgroundBitmap, 0, 0, grayPaint);
}
 
Example 5
Source File: FoldingLayoutActivity.java    From FoldingLayout with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_fold);

    mImageView = (ImageView)findViewById(R.id.image_view);
    mImageView.setPadding(ANTIALIAS_PADDING, ANTIALIAS_PADDING, ANTIALIAS_PADDING,
            ANTIALIAS_PADDING);
    mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
    mImageView.setImageDrawable(getResources().getDrawable(R.drawable.image));

    mTextureView = new TextureView(this);
    mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);

    mAnchorSeekBar = (SeekBar)findViewById(R.id.anchor_seek_bar);
    mFoldLayout = (FoldingLayout)findViewById(R.id.fold_view);
    mFoldLayout.setBackgroundColor(Color.BLACK);
    mFoldLayout.setFoldListener(mOnFoldListener);

    mTouchSlop = ViewConfiguration.get(this).getScaledTouchSlop();

    mAnchorSeekBar.setOnSeekBarChangeListener(mSeekBarChangeListener);

    mScrollGestureDetector = new GestureDetector(this, new ScrollGestureDetector());
    mItemSelectedListener = new ItemSelectedListener();

    mDefaultPaint = new Paint();
    mSepiaPaint = new Paint();

    ColorMatrix m1 = new ColorMatrix();
    ColorMatrix m2 = new ColorMatrix();
    m1.setSaturation(0);
    m2.setScale(1f, .95f, .82f, 1.0f);
    m1.setConcat(m2, m1);
    mSepiaPaint.setColorFilter(new ColorMatrixColorFilter(m1));
}
 
Example 6
Source File: SquareProgressBar.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * You can set the image to b/w with this method. Works fine with the
 * opacity.
 * 
 * @param greyscale
 *            true if the grayscale should be activated.
 * @since 1.2.0
 */
public void setImageGrayscale(boolean greyscale) {
	this.greyscale = greyscale;
	if (greyscale) {
		ColorMatrix matrix = new ColorMatrix();
		matrix.setSaturation(0);
		imageView.setColorFilter(new ColorMatrixColorFilter(matrix));
	} else {
		imageView.setColorFilter(null);
	}
}
 
Example 7
Source File: UTilitiesActivity.java    From utexas-utilities with Apache License 2.0 5 votes vote down vote up
private void disableFeature(final ImageView featureButton) {
    // Some sort of bug in Android 4.x causes the ImageView to disappear if a ColorMatrix
    // is applied, so only do it in 2.3/5.0+
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ColorMatrix matrix = new ColorMatrix();
        matrix.setSaturation(0);
        ColorMatrixColorFilter filter = new ColorMatrixColorFilter(matrix);
        featureButton.setColorFilter(filter);
    }
    Utility.setImageAlpha(featureButton, 75);
    featureButton.setOnClickListener(disabledFeatureButtonListener);
}
 
Example 8
Source File: ImageFilterUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 亮度、色相、饱和度处理
 * @param bitmap          待操作源图片
 * @param lumValue        亮度值
 * @param hueValue        色相值
 * @param saturationValue 饱和度值
 * @return 亮度、色相、饱和度处理后的图片
 */
public static Bitmap lumHueSaturation(final Bitmap bitmap, final int lumValue, final int hueValue, final int saturationValue) {
    if (bitmap == null) return null;
    try {
        // 计算出符合要求的饱和度值
        float newSaturationValue = saturationValue * 1.0F / 127;
        // 计算出符合要求的亮度值
        float newlumValue = lumValue * 1.0F / 127;
        // 计算出符合要求的色相值
        float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;
        // 创建一个颜色矩阵并设置其饱和度
        ColorMatrix colorMatrix = new ColorMatrix();
        // 设置饱和度值
        colorMatrix.setSaturation(newSaturationValue);
        // 设置亮度值
        colorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
        // 控制让红色区在色轮上旋转的角度
        colorMatrix.setRotate(0, newHueValue);
        // 控制让绿红色区在色轮上旋转的角度
        colorMatrix.setRotate(1, newHueValue);
        // 控制让蓝色区在色轮上旋转的角度
        colorMatrix.setRotate(2, newHueValue);
        // 创建一个画笔并设置其颜色过滤器
        Paint paint = new Paint();
        paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
        // 创建一个新的图片并创建画布
        Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(newBitmap);
        // 将源图片使用给定的画笔画到画布上
        canvas.drawBitmap(bitmap, 0, 0, paint);
        return newBitmap;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "lumHueSaturation");
    }
    return null;
}
 
Example 9
Source File: ColorMatrixActivity.java    From AndroidDemo with Apache License 2.0 5 votes vote down vote up
private Bitmap getGreyBitmap(Bitmap bitmap) {
    Bitmap bmp = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bmp);
    Paint paint = new Paint();
    ColorMatrix matrix = new ColorMatrix();
    //饱和度设置为0则为灰度图
    matrix.setSaturation(0);
    paint.setColorFilter(new ColorMatrixColorFilter(matrix));
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return bmp;
}
 
Example 10
Source File: BezelImageView.java    From Lollipop-AppCompat-Widgets-Skeleton with Apache License 2.0 5 votes vote down vote up
public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView,
            defStyle, 0);

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }

    mBorderDrawable = a.getDrawable(R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress,
            mDesaturateOnPress);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);
    
    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}
 
Example 11
Source File: ImageCropActivity.java    From AndroidDocumentScanner with MIT License 5 votes vote down vote up
private void invertColor() {
    if (!isInverted) {
        Bitmap bmpMonochrome = Bitmap.createBitmap(cropImage.getWidth(), cropImage.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmpMonochrome);
        ColorMatrix ma = new ColorMatrix();
        ma.setSaturation(0);
        Paint paint = new Paint();
        paint.setColorFilter(new ColorMatrixColorFilter(ma));
        canvas.drawBitmap(cropImage, 0, 0, paint);
        cropImage = bmpMonochrome.copy(bmpMonochrome.getConfig(), true);
    } else {
        cropImage = cropImage.copy(cropImage.getConfig(), true);
    }
    isInverted = !isInverted;
}
 
Example 12
Source File: ColorFilterRelativeLayout.java    From SoloPi with Apache License 2.0 5 votes vote down vote up
/**
 * 重设饱和度
 * @param saturation
 */
public void setSaturation(float saturation) {
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(saturation);
    m_paint.setColorFilter(new ColorMatrixColorFilter(cm));

    invalidate();
}
 
Example 13
Source File: ViewUtil.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
/**
 * 修改一张源位图的饱和度来生成一个新位图
 * @param sourceBitmap 源位图
 * @param expectantSaturation 期望的饱和度值
 * @return 更改饱和度后的新位图
 */
public static Bitmap changeSrcBitmapSaturation(Bitmap sourceBitmap,int expectantSaturation) {
    int width = sourceBitmap.getWidth();
    int height = sourceBitmap.getHeight();
    Bitmap compoundResultBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(compoundResultBitmap);
    Paint paint = new Paint();
    ColorMatrix colorMatrix = new ColorMatrix();
    colorMatrix.setSaturation(expectantSaturation);
    ColorMatrixColorFilter colorMatrixFilter = new ColorMatrixColorFilter(colorMatrix);
    paint.setColorFilter(colorMatrixFilter);
    canvas.drawBitmap(sourceBitmap, 0, 0, paint);
    return compoundResultBitmap;
}
 
Example 14
Source File: EarthWatchFaceService.java    From earth with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreate(SurfaceHolder holder) {
    super.onCreate(holder);

    region = new Rect();

    paint = new Paint();
    paint.setFilterBitmap(true);

    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);

    ambientFilter = new ColorMatrixColorFilter(cm);
}
 
Example 15
Source File: UEImage.java    From Auie with GNU General Public License v2.0 5 votes vote down vote up
public UEImage addFilterToGray(){
	Drawable drawable = bitmapToDrawable();
	drawable.mutate();
	ColorMatrix matrix = new ColorMatrix();
	matrix.setSaturation(0);
	drawable.setColorFilter(new ColorMatrixColorFilter(matrix));
	drawableToBitmap(drawable);
	return this;
}
 
Example 16
Source File: BezelImageView.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
public BezelImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView,
            defStyle, 0);

    mMaskDrawable = a.getDrawable(R.styleable.BezelImageView_maskDrawable);
    if (mMaskDrawable != null) {
        mMaskDrawable.setCallback(this);
    }

    mBorderDrawable = a.getDrawable(R.styleable.BezelImageView_borderDrawable);
    if (mBorderDrawable != null) {
        mBorderDrawable.setCallback(this);
    }

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress,
            mDesaturateOnPress);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}
 
Example 17
Source File: BezelImageView.java    From KlyphMessenger with MIT License 5 votes vote down vote up
public BezelImageView(Context context, AttributeSet attrs, int defStyle)
{
	super(context, attrs, defStyle);

	// Attribute initialization
	final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, 0);

	setMaskDrawable(a.getDrawable(R.styleable.BezelImageView_maskDrawable));

	setBorderDrawable(a.getDrawable(R.styleable.BezelImageView_borderDrawable));

	mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress, mDesaturateOnPress);

	a.recycle();

	// Other initialization
	mBlackPaint = new Paint();
	mBlackPaint.setColor(0xff000000);

	mMaskedPaint = new Paint();
	mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

	// Always want a cache allocated.
	mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

	if (mDesaturateOnPress)
	{
		// Create a desaturate color filter for pressed state.
		ColorMatrix cm = new ColorMatrix();
		cm.setSaturation(0);
		mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
	}
}
 
Example 18
Source File: BitmapUtil.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 亮度、色相、饱和度处理
 *
 * @param bitmap          原图
 * @param lumValue        亮度值
 * @param hueValue        色相值
 * @param saturationValue 饱和度值
 * @return 亮度、色相、饱和度处理后的图片
 */
public static Bitmap lumAndHueAndSaturation(Bitmap bitmap, int lumValue,
                                            int hueValue, int saturationValue) {
    // 计算出符合要求的饱和度值
    float newSaturationValue = saturationValue * 1.0F / 127;
    // 计算出符合要求的亮度值
    float newlumValue = lumValue * 1.0F / 127;
    // 计算出符合要求的色相值
    float newHueValue = (hueValue - 127) * 1.0F / 127 * 180;

    // 创建一个颜色矩阵并设置其饱和度
    ColorMatrix colorMatrix = new ColorMatrix();

    // 设置饱和度值
    colorMatrix.setSaturation(newSaturationValue);
    // 设置亮度值
    colorMatrix.setScale(newlumValue, newlumValue, newlumValue, 1);
    // 控制让红色区在色轮上旋转的角度
    colorMatrix.setRotate(0, newHueValue);
    // 控制让绿红色区在色轮上旋转的角度
    colorMatrix.setRotate(1, newHueValue);
    // 控制让蓝色区在色轮上旋转的角度
    colorMatrix.setRotate(2, newHueValue);

    // 创建一个画笔并设置其颜色过滤器
    Paint paint = new Paint();
    paint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
    // 创建一个新的图片并创建画布
    Bitmap newBitmap = Bitmap.createBitmap(bitmap.getWidth(),
            bitmap.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(newBitmap);
    // 将原图使用给定的画笔画到画布上
    canvas.drawBitmap(bitmap, 0, 0, paint);
    return newBitmap;
}
 
Example 19
Source File: BlackberryVolumePanel.java    From Noyze with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void onPlayStateChanged(Pair<MediaMetadataCompat, PlaybackStateCompat> mediaInfo) {
    if (!created) return;
    super.onPlayStateChanged(mediaInfo);
    LOGI(TAG, "onPlayStateChanged()");

    // if (mMusicActive) transition.beginDelayedTransition(mediaContainer, TransitionCompat.KEY_AUDIO_TRANSITION);

    // Update button visibility based on the transport flags.
    /*if (null == info || info.mTransportControlFlags <= 0) {
        mBtnNext.setVisibility(View.VISIBLE);
        mBtnPrev.setVisibility(View.VISIBLE);
        playPause.setVisibility(View.VISIBLE);
    } else {
        final int flags = info.mTransportControlFlags;
        setVisibilityBasedOnFlag(mBtnPrev, flags, RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS);
        setVisibilityBasedOnFlag(mBtnNext, flags, RemoteControlClient.FLAG_KEY_MEDIA_NEXT);
        setVisibilityBasedOnFlag(playPause, flags,
                          RemoteControlClient.FLAG_KEY_MEDIA_PLAY
                        | RemoteControlClient.FLAG_KEY_MEDIA_PAUSE
                        | RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE
                        | RemoteControlClient.FLAG_KEY_MEDIA_STOP);
    }*/

    // If we have album art, use it!
    if (mMusicActive) {
        Bitmap albumArtBitmap = mediaInfo.first.getBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART);
        if (null != albumArtBitmap) {
            LOGI(TAG, "Loading artwork bitmap.");
            albumArt.setImageAlpha(0xFF);
            albumArt.setColorFilter(null);
            albumArt.setImageBitmap(albumArtBitmap);
            hasAlbumArt = true;
        } else {
            hasAlbumArt = false;
        }
    }

    // Next, we'll try to display the app's icon.
    if (mMusicActive && !hasAlbumArt && !TextUtils.isEmpty(musicPackageName)) {
        Drawable appIcon = getAppIcon(musicPackageName);
        if (null != appIcon) {
            LOGI(TAG, "Loading app icon instead of album art.");
            final int bbColor = getResources().getColor(R.color.bb_icons);
            final ColorMatrix cm = new ColorMatrix();
            cm.setSaturation(0);
            albumArt.setColorFilter(new ColorMatrixColorFilter(cm));
            appIcon.setColorFilter(bbColor, PorterDuff.Mode.MULTIPLY);
            albumArt.setImageAlpha(0xEF);
            albumArt.setImageDrawable(appIcon);
            hasAlbumArt = true;
        } else {
            hasAlbumArt = false;
        }
    }

    if (!mMusicActive) hasAlbumArt = false;

    albumArtContainer.setVisibility((hasAlbumArt) ? View.VISIBLE : View.GONE);
    if (mMusicActive) setMusicPanelVisibility(View.VISIBLE);
    if (!mMusicActive) {
        hideMusicWithPanel = true;
    }

    updatePlayState();

    String sTitle = mediaInfo.first.getString(MediaMetadataCompat.METADATA_KEY_TITLE);
    String sArtist = mediaInfo.first.getString(MediaMetadataCompat.METADATA_KEY_ARTIST);
    song.setText(sTitle);
    artist.setText(sArtist);
}
 
Example 20
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;
}