Example usage for android.graphics Canvas saveLayerAlpha

List of usage examples for android.graphics Canvas saveLayerAlpha

Introduction

In this page you can find the example usage for android.graphics Canvas saveLayerAlpha.

Prototype

public int saveLayerAlpha(float left, float top, float right, float bottom, int alpha,
        @Saveflags int saveFlags) 

Source Link

Document

Helper for saveLayerAlpha() that takes 4 values instead of a RectF.

Usage

From source file:org.telegram.ui.Cells.ProfileSearchCell.java

@Override
protected void onDraw(Canvas canvas) {
    if (user == null && chat == null && encryptedChat == null) {
        return;/*  w  w  w . j a v  a  2s. co  m*/
    }

    if (useSeparator) {
        if (LocaleController.isRTL) {
            canvas.drawLine(0, getMeasuredHeight() - 1,
                    getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline),
                    getMeasuredHeight() - 1, linePaint);
        } else {
            canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1,
                    getMeasuredWidth(), getMeasuredHeight() - 1, linePaint);
        }
    }

    if (drawAlpha != 1) {
        canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), (int) (255 * drawAlpha),
                Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
    }

    if (drawNameLock) {
        setDrawableBounds(lockDrawable, nameLockLeft, nameLockTop);
        lockDrawable.draw(canvas);
    } else if (drawNameGroup) {
        setDrawableBounds(groupDrawable, nameLockLeft, nameLockTop);
        groupDrawable.draw(canvas);
    } else if (drawNameBroadcast) {
        setDrawableBounds(broadcastDrawable, nameLockLeft, nameLockTop);
        broadcastDrawable.draw(canvas);
    } else if (drawNameBot) {
        setDrawableBounds(botDrawable, nameLockLeft, nameLockTop);
        botDrawable.draw(canvas);
    }

    if (nameLayout != null) {
        canvas.save();
        canvas.translate(nameLeft, nameTop);
        nameLayout.draw(canvas);
        canvas.restore();
        if (drawCheck) {
            if (LocaleController.isRTL) {
                setDrawableBounds(checkDrawable,
                        nameLeft - AndroidUtilities.dp(4) - checkDrawable.getIntrinsicWidth(), nameLockTop);
            } else {
                setDrawableBounds(checkDrawable,
                        nameLeft + (int) nameLayout.getLineWidth(0) + AndroidUtilities.dp(4), nameLockTop);
            }
            checkDrawable.draw(canvas);
        }
    }

    if (onlineLayout != null) {
        canvas.save();
        canvas.translate(onlineLeft, AndroidUtilities.dp(40));
        onlineLayout.draw(canvas);
        canvas.restore();
    }

    if (countLayout != null) {
        if (MessagesController.getInstance().isDialogMuted(dialog_id)) {
            setDrawableBounds(countDrawableGrey, countLeft - AndroidUtilities.dp(5.5f), countTop,
                    countWidth + AndroidUtilities.dp(11), countDrawableGrey.getIntrinsicHeight());
            countDrawableGrey.draw(canvas);
        } else {
            setDrawableBounds(countDrawable, countLeft - AndroidUtilities.dp(5.5f), countTop,
                    countWidth + AndroidUtilities.dp(11), countDrawable.getIntrinsicHeight());
            countDrawable.draw(canvas);
        }
        canvas.save();
        canvas.translate(countLeft, countTop + AndroidUtilities.dp(4));
        countLayout.draw(canvas);
        canvas.restore();
    }

    avatarImage.draw(canvas);
}

From source file:io.doist.datetimepicker.time.RadialTimePickerView.java

@Override
public void onDraw(Canvas canvas) {
    if (!mInputEnabled) {
        canvas.saveLayerAlpha(0, 0, getWidth(), getHeight(), mDisabledAlpha, Canvas.ALL_SAVE_FLAG);
    } else {// w ww  .  j  ava 2 s .c o m
        canvas.save();
    }

    calculateGridSizesHours();
    calculateGridSizesMinutes();

    drawCircleBackground(canvas);
    drawSelector(canvas);

    drawTextElements(canvas, mTextSize[HOURS], mTypeface, mOuterTextHours, mTextGridWidths[HOURS],
            mTextGridHeights[HOURS], mPaint[HOURS], mColor[HOURS], mAlpha[HOURS].getValue());

    if (mIs24HourMode && mInnerTextHours != null) {
        drawTextElements(canvas, mInnerTextSize, mTypeface, mInnerTextHours, mInnerTextGridWidths,
                mInnerTextGridHeights, mPaint[HOURS], mColor[HOURS], mAlpha[HOURS].getValue());
    }

    drawTextElements(canvas, mTextSize[MINUTES], mTypeface, mOuterTextMinutes, mTextGridWidths[MINUTES],
            mTextGridHeights[MINUTES], mPaint[MINUTES], mColor[MINUTES], mAlpha[MINUTES].getValue());

    drawCenter(canvas);

    if (DEBUG) {
        drawDebug(canvas);
    }

    canvas.restore();
}