Java Code Examples for org.telegram.messenger.AndroidUtilities#dpf2()

The following examples show how to use org.telegram.messenger.AndroidUtilities#dpf2() . 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: ReorderingHintDrawable.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void drawStage2(Canvas canvas, float progress) {
    final Rect bounds = getBounds();

    progress = interpolator.getInterpolation(progress);

    tempRect.left = (int) (AndroidUtilities.dp(2) * scaleX);
    tempRect.bottom = bounds.bottom - ((int) (AndroidUtilities.dp(6) * scaleY));
    tempRect.right = bounds.right - tempRect.left;
    tempRect.top = tempRect.bottom - ((int) (AndroidUtilities.dp(4) * scaleY));
    tempRect.offset(0, AndroidUtilities.dp(AndroidUtilities.lerp(0, -8, progress)));
    secondaryRectDrawable.setBounds(tempRect);
    secondaryRectDrawable.draw(canvas);

    tempRect.left = (int) (AndroidUtilities.dpf2(AndroidUtilities.lerp(1, 2, progress)) * scaleX);
    tempRect.top = (int) (AndroidUtilities.dpf2(AndroidUtilities.lerp(5, 6, progress)) * scaleY);
    tempRect.right = bounds.right - tempRect.left;
    tempRect.bottom = tempRect.top + (int) (AndroidUtilities.dpf2(AndroidUtilities.lerp(6, 4, progress)) * scaleY);
    tempRect.offset(0, AndroidUtilities.dp(AndroidUtilities.lerp(0, 8, progress)));
    primaryRectDrawable.setBounds(tempRect);
    primaryRectDrawable.setAlpha(255);
    primaryRectDrawable.draw(canvas);
}
 
Example 2
Source File: ReorderingHintDrawable.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void drawStage2(Canvas canvas, float progress) {
    final Rect bounds = getBounds();

    progress = interpolator.getInterpolation(progress);

    tempRect.left = (int) (AndroidUtilities.dp(2) * scaleX);
    tempRect.bottom = bounds.bottom - ((int) (AndroidUtilities.dp(6) * scaleY));
    tempRect.right = bounds.right - tempRect.left;
    tempRect.top = tempRect.bottom - ((int) (AndroidUtilities.dp(4) * scaleY));
    tempRect.offset(0, AndroidUtilities.dp(AndroidUtilities.lerp(0, -8, progress)));
    secondaryRectDrawable.setBounds(tempRect);
    secondaryRectDrawable.draw(canvas);

    tempRect.left = (int) (AndroidUtilities.dpf2(AndroidUtilities.lerp(1, 2, progress)) * scaleX);
    tempRect.top = (int) (AndroidUtilities.dpf2(AndroidUtilities.lerp(5, 6, progress)) * scaleY);
    tempRect.right = bounds.right - tempRect.left;
    tempRect.bottom = tempRect.top + (int) (AndroidUtilities.dpf2(AndroidUtilities.lerp(6, 4, progress)) * scaleY);
    tempRect.offset(0, AndroidUtilities.dp(AndroidUtilities.lerp(0, 8, progress)));
    primaryRectDrawable.setBounds(tempRect);
    primaryRectDrawable.setAlpha(255);
    primaryRectDrawable.draw(canvas);
}
 
Example 3
Source File: ScrollSlidingTextTabStrip.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public ScrollSlidingTextTabStrip(Context context) {
    super(context);

    selectorDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, null);
    float rad = AndroidUtilities.dpf2(3);
    selectorDrawable.setCornerRadii(new float[]{rad, rad, rad, rad, 0, 0, 0, 0});
    selectorDrawable.setColor(Theme.getColor(tabLineColorKey));

    setFillViewport(true);
    setWillNotDraw(false);

    setHorizontalScrollBarEnabled(false);
    tabsContainer = new LinearLayout(context) {
        @Override
        public void setAlpha(float alpha) {
            super.setAlpha(alpha);
            ScrollSlidingTextTabStrip.this.invalidate();
        }
    };
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setPadding(AndroidUtilities.dp(7), 0, AndroidUtilities.dp(7), 0);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    addView(tabsContainer);
}
 
Example 4
Source File: ScrollSlidingTextTabStrip.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
public ScrollSlidingTextTabStrip(Context context) {
    super(context);

    selectorDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, null);
    float rad = AndroidUtilities.dpf2(3);
    selectorDrawable.setCornerRadii(new float[]{rad, rad, rad, rad, 0, 0, 0, 0});
    selectorDrawable.setColor(Theme.getColor(tabLineColorKey));

    setFillViewport(true);
    setWillNotDraw(false);

    setHorizontalScrollBarEnabled(false);
    tabsContainer = new LinearLayout(context) {
        @Override
        public void setAlpha(float alpha) {
            super.setAlpha(alpha);
            ScrollSlidingTextTabStrip.this.invalidate();
        }
    };
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setPadding(AndroidUtilities.dp(7), 0, AndroidUtilities.dp(7), 0);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    addView(tabsContainer);
}
 
Example 5
Source File: RadialProgress.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    int x = getBounds().centerX() - AndroidUtilities.dp(12);
    int y = getBounds().centerY() - AndroidUtilities.dp(6);
    float p = progress != 1.0f ? decelerateInterpolator.getInterpolation(progress) : 1.0f;
    int endX = (int) (AndroidUtilities.dp(7.0f) - AndroidUtilities.dp(6) * p);
    int endY = (int) (AndroidUtilities.dpf2(13.0f) - AndroidUtilities.dp(6) * p);
    canvas.drawLine(x + AndroidUtilities.dp(7.0f), y + (int) AndroidUtilities.dpf2(13.0f), x + endX, y + endY, paint);
    endX = (int) (AndroidUtilities.dpf2(7.0f) + AndroidUtilities.dp(13) * p);
    endY = (int) (AndroidUtilities.dpf2(13.0f) - AndroidUtilities.dp(13) * p);
    canvas.drawLine(x + (int) AndroidUtilities.dpf2(7.0f), y + (int) AndroidUtilities.dpf2(13.0f), x + endX, y + endY, paint);
}
 
Example 6
Source File: SnowflakesEffect.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void draw(Canvas canvas) {
    switch (type) {
        case 0: {
            particlePaint.setAlpha((int) (255 * alpha));
            canvas.drawPoint(x, y, particlePaint);
            break;
        }
        case 1:
        default: {
            particleThinPaint.setAlpha((int) (255 * alpha));

            float angle = (float) -Math.PI / 2;

            float px = AndroidUtilities.dpf2(2.0f) * 2 * scale;
            float px1 = -AndroidUtilities.dpf2(0.57f) * 2 * scale;
            float py1 = AndroidUtilities.dpf2(1.55f) * 2 * scale;
            for (int a = 0; a < 6; a++) {
                float x1 = (float) Math.cos(angle) * px;
                float y1 = (float) Math.sin(angle) * px;
                float cx = x1 * 0.66f;
                float cy = y1 * 0.66f;
                canvas.drawLine(x, y, x + x1, y + y1, particleThinPaint);

                float angle2 = (float) (angle - Math.PI / 2);
                x1 = (float) (Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                x1 = (float) (-Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (-Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                angle += angleDiff;
            }
            break;
        }
    }

}
 
Example 7
Source File: RadialProgress.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    int x = getBounds().centerX() - AndroidUtilities.dp(12);
    int y = getBounds().centerY() - AndroidUtilities.dp(6);
    float p = progress != 1.0f ? decelerateInterpolator.getInterpolation(progress) : 1.0f;
    int endX = (int) (AndroidUtilities.dp(7.0f) - AndroidUtilities.dp(6) * p);
    int endY = (int) (AndroidUtilities.dpf2(13.0f) - AndroidUtilities.dp(6) * p);
    canvas.drawLine(x + AndroidUtilities.dp(7.0f), y + (int) AndroidUtilities.dpf2(13.0f), x + endX, y + endY, paint);
    endX = (int) (AndroidUtilities.dpf2(7.0f) + AndroidUtilities.dp(13) * p);
    endY = (int) (AndroidUtilities.dpf2(13.0f) - AndroidUtilities.dp(13) * p);
    canvas.drawLine(x + (int) AndroidUtilities.dpf2(7.0f), y + (int) AndroidUtilities.dpf2(13.0f), x + endX, y + endY, paint);
}
 
Example 8
Source File: SnowflakesEffect.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void draw(Canvas canvas) {
    switch (type) {
        case 0: {
            particlePaint.setAlpha((int) (255 * alpha));
            canvas.drawPoint(x, y, particlePaint);
            break;
        }
        case 1:
        default: {
            particleThinPaint.setAlpha((int) (255 * alpha));

            float angle = (float) -Math.PI / 2;

            float px = AndroidUtilities.dpf2(2.0f) * 2 * scale;
            float px1 = -AndroidUtilities.dpf2(0.57f) * 2 * scale;
            float py1 = AndroidUtilities.dpf2(1.55f) * 2 * scale;
            for (int a = 0; a < 6; a++) {
                float x1 = (float) Math.cos(angle) * px;
                float y1 = (float) Math.sin(angle) * px;
                float cx = x1 * 0.66f;
                float cy = y1 * 0.66f;
                canvas.drawLine(x, y, x + x1, y + y1, particleThinPaint);

                float angle2 = (float) (angle - Math.PI / 2);
                x1 = (float) (Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                x1 = (float) (-Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (-Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                angle += angleDiff;
            }
            break;
        }
    }

}
 
Example 9
Source File: SnowflakesEffect.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void draw(Canvas canvas) {
    switch (type) {
        case 0: {
            particlePaint.setAlpha((int) (255 * alpha));
            canvas.drawPoint(x, y, particlePaint);
            break;
        }
        case 1:
        default: {
            particleThinPaint.setAlpha((int) (255 * alpha));

            float angle = (float) -Math.PI / 2;

            float px = AndroidUtilities.dpf2(2.0f) * 2 * scale;
            float px1 = -AndroidUtilities.dpf2(0.57f) * 2 * scale;
            float py1 = AndroidUtilities.dpf2(1.55f) * 2 * scale;
            for (int a = 0; a < 6; a++) {
                float x1 = (float) Math.cos(angle) * px;
                float y1 = (float) Math.sin(angle) * px;
                float cx = x1 * 0.66f;
                float cy = y1 * 0.66f;
                canvas.drawLine(x, y, x + x1, y + y1, particleThinPaint);

                float angle2 = (float) (angle - Math.PI / 2);
                x1 = (float) (Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                x1 = (float) (-Math.cos(angle2) * px1 - Math.sin(angle2) * py1);
                y1 = (float) (-Math.sin(angle2) * px1 + Math.cos(angle2) * py1);
                canvas.drawLine(x + cx, y + cy, x + x1, y + y1, particleThinPaint);

                angle += angleDiff;
            }
            break;
        }
    }

}
 
Example 10
Source File: ScrollSlidingTabStrip.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setType(Type type) {
    if (type != null && this.type != type) {
        this.type = type;
        switch (type) {
            case LINE:
                indicatorDrawable.setCornerRadius(0);
                break;
            case TAB:
                float rad = AndroidUtilities.dpf2(3);
                indicatorDrawable.setCornerRadii(new float[]{rad, rad, rad, rad, 0, 0, 0, 0});
                break;
        }
    }
}
 
Example 11
Source File: RadialProgress.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    int x = getBounds().centerX() - AndroidUtilities.dp(12);
    int y = getBounds().centerY() - AndroidUtilities.dp(6);
    float p = progress != 1.0f ? decelerateInterpolator.getInterpolation(progress) : 1.0f;
    int endX = (int) (AndroidUtilities.dp(7.0f) - AndroidUtilities.dp(6) * p);
    int endY = (int) (AndroidUtilities.dpf2(13.0f) - AndroidUtilities.dp(6) * p);
    canvas.drawLine(x + AndroidUtilities.dp(7.0f), y + (int) AndroidUtilities.dpf2(13.0f), x + endX, y + endY, paint);
    endX = (int) (AndroidUtilities.dpf2(7.0f) + AndroidUtilities.dp(13) * p);
    endY = (int) (AndroidUtilities.dpf2(13.0f) - AndroidUtilities.dp(13) * p);
    canvas.drawLine(x + (int) AndroidUtilities.dpf2(7.0f), y + (int) AndroidUtilities.dpf2(13.0f), x + endX, y + endY, paint);
}
 
Example 12
Source File: SeekBarWaveform.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void draw(Canvas canvas) {
    if (waveformBytes == null || width == 0) {
        return;
    }
    float totalBarsCount = width / AndroidUtilities.dp(3);
    if (totalBarsCount <= 0.1f) {
        return;
    }
    byte value;
    int samplesCount = (waveformBytes.length * 8 / 5);
    float samplesPerBar = samplesCount / totalBarsCount;
    float barCounter = 0;
    int nextBarNum = 0;

    paintInner.setColor(messageObject != null && !messageObject.isOutOwner() && messageObject.isContentUnread() && thumbX == 0 ? outerColor : (selected ? selectedColor : innerColor));
    paintOuter.setColor(outerColor);

    int y = (height - AndroidUtilities.dp(14)) / 2;
    int barNum = 0;
    int lastBarNum;
    int drawBarCount;

    for (int a = 0; a < samplesCount; a++) {
        if (a != nextBarNum) {
            continue;
        }
        drawBarCount = 0;
        lastBarNum = nextBarNum;
        while (lastBarNum == nextBarNum) {
            barCounter += samplesPerBar;
            nextBarNum = (int) barCounter;
            drawBarCount++;
        }

        int bitPointer = a * 5;
        int byteNum = bitPointer / 8;
        int byteBitOffset = bitPointer - byteNum * 8;
        int currentByteCount = 8 - byteBitOffset;
        int nextByteRest = 5 - currentByteCount;
        value = (byte) ((waveformBytes[byteNum] >> byteBitOffset) & ((2 << (Math.min(5, currentByteCount) - 1)) - 1));
        if (nextByteRest > 0 && byteNum + 1 < waveformBytes.length) {
            value <<= nextByteRest;
            value |= waveformBytes[byteNum + 1] & ((2 << (nextByteRest - 1)) - 1);
        }

        for (int b = 0; b < drawBarCount; b++) {
            float x = barNum * AndroidUtilities.dpf2(3);
            float h = AndroidUtilities.dpf2(Math.max(0, 7 * value / 31.0f));

            if (x < thumbX && x + AndroidUtilities.dp(2) < thumbX) {
                drawLine(canvas,x, y, h, paintOuter);
            } else {
                drawLine(canvas,x, y, h, paintInner);
                if (x < thumbX) {
                    canvas.save();
                    canvas.clipRect(x - AndroidUtilities.dpf2(1), y, thumbX, y + AndroidUtilities.dp(14));
                    drawLine(canvas,x, y, h, paintOuter);
                    canvas.restore();
                }
            }
            barNum++;
        }
    }
}
 
Example 13
Source File: CheckBoxSquare.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    if (getVisibility() != VISIBLE) {
        return;
    }

    float checkProgress;
    float bounceProgress;
    int uncheckedColor = Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareUnchecked : Theme.key_checkboxSquareUnchecked);
    int color = Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareBackground : Theme.key_checkboxSquareBackground);
    if (progress <= 0.5f) {
        bounceProgress = checkProgress = progress / 0.5f;
        int rD = (int) ((Color.red(color) - Color.red(uncheckedColor)) * checkProgress);
        int gD = (int) ((Color.green(color) - Color.green(uncheckedColor)) * checkProgress);
        int bD = (int) ((Color.blue(color) - Color.blue(uncheckedColor)) * checkProgress);
        int c = Color.rgb(Color.red(uncheckedColor) + rD, Color.green(uncheckedColor) + gD, Color.blue(uncheckedColor) + bD);
        Theme.checkboxSquare_backgroundPaint.setColor(c);
    } else {
        bounceProgress = 2.0f - progress / 0.5f;
        checkProgress = 1.0f;
        Theme.checkboxSquare_backgroundPaint.setColor(color);
    }
    if (isDisabled) {
        Theme.checkboxSquare_backgroundPaint.setColor(Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareDisabled : Theme.key_checkboxSquareDisabled));
    }
    float bounce = AndroidUtilities.dp(1) * bounceProgress;
    rectF.set(bounce, bounce, AndroidUtilities.dp(18) - bounce, AndroidUtilities.dp(18) - bounce);

    drawBitmap.eraseColor(0);
    drawCanvas.drawRoundRect(rectF, AndroidUtilities.dp(2), AndroidUtilities.dp(2), Theme.checkboxSquare_backgroundPaint);

    if (checkProgress != 1) {
        float rad = Math.min(AndroidUtilities.dp(7), AndroidUtilities.dp(7) * checkProgress + bounce);
        rectF.set(AndroidUtilities.dp(2) + rad, AndroidUtilities.dp(2) + rad, AndroidUtilities.dp(16) - rad, AndroidUtilities.dp(16) - rad);
        drawCanvas.drawRect(rectF, Theme.checkboxSquare_eraserPaint);
    }

    if (progress > 0.5f) {
        Theme.checkboxSquare_checkPaint.setColor(Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareCheck : Theme.key_checkboxSquareCheck));

        int endX = (int) (AndroidUtilities.dp(7) - AndroidUtilities.dp(3) * (1.0f - bounceProgress));
        int endY = (int) (AndroidUtilities.dpf2(13) - AndroidUtilities.dp(3) * (1.0f - bounceProgress));
        drawCanvas.drawLine(AndroidUtilities.dp(7), (int) AndroidUtilities.dpf2(13), endX, endY, Theme.checkboxSquare_checkPaint);

        endX = (int) (AndroidUtilities.dpf2(7) + AndroidUtilities.dp(7) * (1.0f - bounceProgress));
        endY = (int) (AndroidUtilities.dpf2(13) - AndroidUtilities.dp(7) * (1.0f - bounceProgress));
        drawCanvas.drawLine((int) AndroidUtilities.dpf2(7), (int) AndroidUtilities.dpf2(13), endX, endY, Theme.checkboxSquare_checkPaint);
    }
    canvas.drawBitmap(drawBitmap, 0, 0, null);
}
 
Example 14
Source File: SeekBarWaveform.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public void draw(Canvas canvas) {
    if (waveformBytes == null || width == 0) {
        return;
    }
    float totalBarsCount = width / AndroidUtilities.dp(3);
    if (totalBarsCount <= 0.1f) {
        return;
    }
    byte value;
    int samplesCount = (waveformBytes.length * 8 / 5);
    float samplesPerBar = samplesCount / totalBarsCount;
    float barCounter = 0;
    int nextBarNum = 0;

    paintInner.setColor(messageObject != null && !messageObject.isOutOwner() && messageObject.isContentUnread() && thumbX == 0 ? outerColor : (selected ? selectedColor : innerColor));
    paintOuter.setColor(outerColor);

    int y = (height - AndroidUtilities.dp(14)) / 2;
    int barNum = 0;
    int lastBarNum;
    int drawBarCount;

    for (int a = 0; a < samplesCount; a++) {
        if (a != nextBarNum) {
            continue;
        }
        drawBarCount = 0;
        lastBarNum = nextBarNum;
        while (lastBarNum == nextBarNum) {
            barCounter += samplesPerBar;
            nextBarNum = (int) barCounter;
            drawBarCount++;
        }

        int bitPointer = a * 5;
        int byteNum = bitPointer / 8;
        int byteBitOffset = bitPointer - byteNum * 8;
        int currentByteCount = 8 - byteBitOffset;
        int nextByteRest = 5 - currentByteCount;
        value = (byte) ((waveformBytes[byteNum] >> byteBitOffset) & ((2 << (Math.min(5, currentByteCount) - 1)) - 1));
        if (nextByteRest > 0 && byteNum + 1 < waveformBytes.length) {
            value <<= nextByteRest;
            value |= waveformBytes[byteNum + 1] & ((2 << (nextByteRest - 1)) - 1);
        }

        for (int b = 0; b < drawBarCount; b++) {
            float x = barNum * AndroidUtilities.dpf2(3);
            float h = AndroidUtilities.dpf2(Math.max(0, 7 * value / 31.0f));

            if (x < thumbX && x + AndroidUtilities.dp(2) < thumbX) {
                drawLine(canvas,x, y, h, paintOuter);
            } else {
                drawLine(canvas,x, y, h, paintInner);
                if (x < thumbX) {
                    canvas.save();
                    canvas.clipRect(x - AndroidUtilities.dpf2(1), y, thumbX, y + AndroidUtilities.dp(14));
                    drawLine(canvas,x, y, h, paintOuter);
                    canvas.restore();
                }
            }
            barNum++;
        }
    }
}
 
Example 15
Source File: TextSelectionHint.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    if (textLayout == null) {
        return;
    }
    super.onDraw(canvas);

    canvas.save();
    int topPadding = (getMeasuredHeight() - textLayout.getHeight()) >> 1;
    canvas.translate(padding, topPadding);
    if (enterValue != 0) {
        drawSelection(canvas, textLayout, currentStart, currentEnd);
    }
    textLayout.draw(canvas);

    int handleViewSize = AndroidUtilities.dp(14);

    int line = textLayout.getLineForOffset(currentEnd);
    float x = textLayout.getPrimaryHorizontal(currentEnd);
    int y = textLayout.getLineBottom(line);


    if (currentEnd == animateToEnd) {
        roundedRect(path, textLayout.getPrimaryHorizontal(animateToEnd), textLayout.getLineTop(line), textLayout.getPrimaryHorizontal(animateToEnd) + AndroidUtilities.dpf2(4), textLayout.getLineBottom(line), AndroidUtilities.dpf2(4), AndroidUtilities.dpf2(4), false, true);
        canvas.drawPath(path, selectionPaint);
    }

    float enterProgress = interpolator.getInterpolation(enterValue);
    int xOffset = (int) (textLayout.getPrimaryHorizontal(animateToEnd) + (AndroidUtilities.dpf2(4) * (1f - endOffsetValue)) + (textLayout.getPrimaryHorizontal(end) - textLayout.getPrimaryHorizontal(animateToEnd)) * endOffsetValue);
    canvas.save();
    canvas.translate(xOffset, y);

    canvas.scale(enterProgress, enterProgress, handleViewSize / 2f, handleViewSize / 2f);
    path.reset();
    path.addCircle(handleViewSize / 2f, handleViewSize / 2f, handleViewSize / 2f, Path.Direction.CCW);
    path.addRect(0, 0, handleViewSize / 2f, handleViewSize / 2f, Path.Direction.CCW);
    canvas.drawPath(path, textPaint);
    canvas.restore();

    line = textLayout.getLineForOffset(currentStart);
    x = textLayout.getPrimaryHorizontal(currentStart);
    y = textLayout.getLineBottom(line);

    if (currentStart == animateToStart) {
        roundedRect(path, -AndroidUtilities.dp(4), textLayout.getLineTop(line), 0, textLayout.getLineBottom(line), AndroidUtilities.dp(4), AndroidUtilities.dp(4), true, false);
        canvas.drawPath(path, selectionPaint);
    }

    canvas.save();
    xOffset = (int) (textLayout.getPrimaryHorizontal(animateToStart) - (AndroidUtilities.dp(4) * (1f - startOffsetValue)) + (textLayout.getPrimaryHorizontal(start) - textLayout.getPrimaryHorizontal(animateToStart)) * startOffsetValue);
    canvas.translate(xOffset - handleViewSize, y);


    canvas.scale(enterProgress, enterProgress, handleViewSize / 2f, handleViewSize / 2f);

    path.reset();
    path.addCircle(handleViewSize / 2f, handleViewSize / 2f, handleViewSize / 2f, Path.Direction.CCW);
    path.addRect(handleViewSize / 2f, 0, handleViewSize, handleViewSize / 2f, Path.Direction.CCW);
    canvas.drawPath(path, textPaint);
    canvas.restore();
    canvas.restore();

}
 
Example 16
Source File: FlatCheckBox.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    super.draw(canvas);


    float textTranslation = 0f;

    if (progress <= 0.5f) {
        float checkProgress = textTranslation = progress / 0.5f;
        int rD = (int) ((Color.red(colorInactive) - Color.red(colorActive)) * checkProgress);
        int gD = (int) ((Color.green(colorInactive) - Color.green(colorActive)) * checkProgress);
        int bD = (int) ((Color.blue(colorInactive) - Color.blue(colorActive)) * checkProgress);
        int c = Color.rgb(Color.red(colorActive) + rD, Color.green(colorActive) + gD, Color.blue(colorActive) + bD);

        fillPaint.setColor(c);

        rD = (int) ((Color.red(colorTextActive) - Color.red(colorInactive)) * checkProgress);
        gD = (int) ((Color.green(colorTextActive) - Color.green(colorInactive)) * checkProgress);
        bD = (int) ((Color.blue(colorTextActive) - Color.blue(colorInactive)) * checkProgress);
        c = Color.rgb(Color.red(colorInactive) + rD, Color.green(colorInactive) + gD, Color.blue(colorInactive) + bD);

        textPaint.setColor(c);
    } else {
        textTranslation = 1f;
        textPaint.setColor(colorTextActive);
        fillPaint.setColor(colorInactive);
    }


    int heightHalf = (getMeasuredHeight() >> 1);

    outLinePaint.setColor(colorInactive);
    canvas.drawRoundRect(rectF, HEIGHT / 2f, HEIGHT / 2f, fillPaint);
    canvas.drawRoundRect(rectF, HEIGHT / 2f, HEIGHT / 2f, outLinePaint);
    if (text != null) {
        canvas.drawText(text,
                (getMeasuredWidth() >> 1) + (textTranslation * TRANSLETE_TEXT),
                heightHalf + (textPaint.getTextSize() * 0.35f),
                textPaint
        );
    }

    float bounceProgress = 2.0f - progress / 0.5f;
    canvas.save();
    canvas.scale(0.9f, 0.9f, AndroidUtilities.dpf2(7f), heightHalf);
    canvas.translate(AndroidUtilities.dp(12), heightHalf - AndroidUtilities.dp(9));

    if (progress > 0.5f) {
        checkPaint.setColor(colorTextActive);
        int endX = (int) (AndroidUtilities.dpf2(7f) - AndroidUtilities.dp(4) * (1.0f - bounceProgress));
        int endY = (int) (AndroidUtilities.dpf2(13f) - AndroidUtilities.dp(4) * (1.0f - bounceProgress));
        canvas.drawLine(AndroidUtilities.dpf2(7f), (int) AndroidUtilities.dpf2(13f), endX, endY, checkPaint);
        endX = (int) (AndroidUtilities.dpf2(7f) + AndroidUtilities.dp(8) * (1.0f - bounceProgress));
        endY = (int) (AndroidUtilities.dpf2(13f) - AndroidUtilities.dp(8) * (1.0f - bounceProgress));
        canvas.drawLine((int) AndroidUtilities.dpf2(7f), (int) AndroidUtilities.dpf2(13f), endX, endY, checkPaint);
    }
    canvas.restore();


}
 
Example 17
Source File: CheckBoxSquare.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    if (getVisibility() != VISIBLE) {
        return;
    }

    float checkProgress;
    float bounceProgress;
    int uncheckedColor = Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareUnchecked : Theme.key_checkboxSquareUnchecked);
    int color = Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareBackground : Theme.key_checkboxSquareBackground);
    if (progress <= 0.5f) {
        bounceProgress = checkProgress = progress / 0.5f;
        int rD = (int) ((Color.red(color) - Color.red(uncheckedColor)) * checkProgress);
        int gD = (int) ((Color.green(color) - Color.green(uncheckedColor)) * checkProgress);
        int bD = (int) ((Color.blue(color) - Color.blue(uncheckedColor)) * checkProgress);
        int c = Color.rgb(Color.red(uncheckedColor) + rD, Color.green(uncheckedColor) + gD, Color.blue(uncheckedColor) + bD);
        Theme.checkboxSquare_backgroundPaint.setColor(c);
    } else {
        bounceProgress = 2.0f - progress / 0.5f;
        checkProgress = 1.0f;
        Theme.checkboxSquare_backgroundPaint.setColor(color);
    }
    if (isDisabled) {
        Theme.checkboxSquare_backgroundPaint.setColor(Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareDisabled : Theme.key_checkboxSquareDisabled));
    }
    float bounce = AndroidUtilities.dp(1) * bounceProgress;
    rectF.set(bounce, bounce, AndroidUtilities.dp(18) - bounce, AndroidUtilities.dp(18) - bounce);

    drawBitmap.eraseColor(0);
    drawCanvas.drawRoundRect(rectF, AndroidUtilities.dp(2), AndroidUtilities.dp(2), Theme.checkboxSquare_backgroundPaint);

    if (checkProgress != 1) {
        float rad = Math.min(AndroidUtilities.dp(7), AndroidUtilities.dp(7) * checkProgress + bounce);
        rectF.set(AndroidUtilities.dp(2) + rad, AndroidUtilities.dp(2) + rad, AndroidUtilities.dp(16) - rad, AndroidUtilities.dp(16) - rad);
        drawCanvas.drawRect(rectF, Theme.checkboxSquare_eraserPaint);
    }

    if (progress > 0.5f) {
        Theme.checkboxSquare_checkPaint.setColor(Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareCheck : Theme.key_checkboxSquareCheck));

        int endX = (int) (AndroidUtilities.dp(7) - AndroidUtilities.dp(3) * (1.0f - bounceProgress));
        int endY = (int) (AndroidUtilities.dpf2(13) - AndroidUtilities.dp(3) * (1.0f - bounceProgress));
        drawCanvas.drawLine(AndroidUtilities.dp(7), (int) AndroidUtilities.dpf2(13), endX, endY, Theme.checkboxSquare_checkPaint);

        endX = (int) (AndroidUtilities.dpf2(7) + AndroidUtilities.dp(7) * (1.0f - bounceProgress));
        endY = (int) (AndroidUtilities.dpf2(13) - AndroidUtilities.dp(7) * (1.0f - bounceProgress));
        drawCanvas.drawLine((int) AndroidUtilities.dpf2(7), (int) AndroidUtilities.dpf2(13), endX, endY, Theme.checkboxSquare_checkPaint);
    }
    canvas.drawBitmap(drawBitmap, 0, 0, null);
}
 
Example 18
Source File: TextSelectionHint.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    if (textLayout == null) {
        return;
    }
    super.onDraw(canvas);

    canvas.save();
    int topPadding = (getMeasuredHeight() - textLayout.getHeight()) >> 1;
    canvas.translate(padding, topPadding);
    if (enterValue != 0) {
        drawSelection(canvas, textLayout, currentStart, currentEnd);
    }
    textLayout.draw(canvas);

    int handleViewSize = AndroidUtilities.dp(14);

    int line = textLayout.getLineForOffset(currentEnd);
    float x = textLayout.getPrimaryHorizontal(currentEnd);
    int y = textLayout.getLineBottom(line);


    if (currentEnd == animateToEnd) {
        roundedRect(path, textLayout.getPrimaryHorizontal(animateToEnd), textLayout.getLineTop(line), textLayout.getPrimaryHorizontal(animateToEnd) + AndroidUtilities.dpf2(4), textLayout.getLineBottom(line), AndroidUtilities.dpf2(4), AndroidUtilities.dpf2(4), false, true);
        canvas.drawPath(path, selectionPaint);
    }

    float enterProgress = interpolator.getInterpolation(enterValue);
    int xOffset = (int) (textLayout.getPrimaryHorizontal(animateToEnd) + (AndroidUtilities.dpf2(4) * (1f - endOffsetValue)) + (textLayout.getPrimaryHorizontal(end) - textLayout.getPrimaryHorizontal(animateToEnd)) * endOffsetValue);
    canvas.save();
    canvas.translate(xOffset, y);

    canvas.scale(enterProgress, enterProgress, handleViewSize / 2f, handleViewSize / 2f);
    path.reset();
    path.addCircle(handleViewSize / 2f, handleViewSize / 2f, handleViewSize / 2f, Path.Direction.CCW);
    path.addRect(0, 0, handleViewSize / 2f, handleViewSize / 2f, Path.Direction.CCW);
    canvas.drawPath(path, textPaint);
    canvas.restore();

    line = textLayout.getLineForOffset(currentStart);
    x = textLayout.getPrimaryHorizontal(currentStart);
    y = textLayout.getLineBottom(line);

    if (currentStart == animateToStart) {
        roundedRect(path, -AndroidUtilities.dp(4), textLayout.getLineTop(line), 0, textLayout.getLineBottom(line), AndroidUtilities.dp(4), AndroidUtilities.dp(4), true, false);
        canvas.drawPath(path, selectionPaint);
    }

    canvas.save();
    xOffset = (int) (textLayout.getPrimaryHorizontal(animateToStart) - (AndroidUtilities.dp(4) * (1f - startOffsetValue)) + (textLayout.getPrimaryHorizontal(start) - textLayout.getPrimaryHorizontal(animateToStart)) * startOffsetValue);
    canvas.translate(xOffset - handleViewSize, y);


    canvas.scale(enterProgress, enterProgress, handleViewSize / 2f, handleViewSize / 2f);

    path.reset();
    path.addCircle(handleViewSize / 2f, handleViewSize / 2f, handleViewSize / 2f, Path.Direction.CCW);
    path.addRect(handleViewSize / 2f, 0, handleViewSize, handleViewSize / 2f, Path.Direction.CCW);
    canvas.drawPath(path, textPaint);
    canvas.restore();
    canvas.restore();

}
 
Example 19
Source File: CheckBoxSquare.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    if (getVisibility() != VISIBLE) {
        return;
    }

    float checkProgress;
    float bounceProgress;
    int uncheckedColor = Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareUnchecked : Theme.key_checkboxSquareUnchecked);
    int color = Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareBackground : Theme.key_checkboxSquareBackground);
    if (progress <= 0.5f) {
        bounceProgress = checkProgress = progress / 0.5f;
        int rD = (int) ((Color.red(color) - Color.red(uncheckedColor)) * checkProgress);
        int gD = (int) ((Color.green(color) - Color.green(uncheckedColor)) * checkProgress);
        int bD = (int) ((Color.blue(color) - Color.blue(uncheckedColor)) * checkProgress);
        int c = Color.rgb(Color.red(uncheckedColor) + rD, Color.green(uncheckedColor) + gD, Color.blue(uncheckedColor) + bD);
        Theme.checkboxSquare_backgroundPaint.setColor(c);
    } else {
        bounceProgress = 2.0f - progress / 0.5f;
        checkProgress = 1.0f;
        Theme.checkboxSquare_backgroundPaint.setColor(color);
    }
    if (isDisabled) {
        Theme.checkboxSquare_backgroundPaint.setColor(Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareDisabled : Theme.key_checkboxSquareDisabled));
    }
    float bounce = AndroidUtilities.dp(1) * bounceProgress;
    rectF.set(bounce, bounce, AndroidUtilities.dp(18) - bounce, AndroidUtilities.dp(18) - bounce);

    drawBitmap.eraseColor(0);
    drawCanvas.drawRoundRect(rectF, AndroidUtilities.dp(2), AndroidUtilities.dp(2), Theme.checkboxSquare_backgroundPaint);

    if (checkProgress != 1) {
        float rad = Math.min(AndroidUtilities.dp(7), AndroidUtilities.dp(7) * checkProgress + bounce);
        rectF.set(AndroidUtilities.dp(2) + rad, AndroidUtilities.dp(2) + rad, AndroidUtilities.dp(16) - rad, AndroidUtilities.dp(16) - rad);
        drawCanvas.drawRect(rectF, Theme.checkboxSquare_eraserPaint);
    }

    if (progress > 0.5f) {
        Theme.checkboxSquare_checkPaint.setColor(Theme.getColor(isAlert ? Theme.key_dialogCheckboxSquareCheck : Theme.key_checkboxSquareCheck));
        int endX = (int) (AndroidUtilities.dp(7.5f) - AndroidUtilities.dp(5) * (1.0f - bounceProgress));
        int endY = (int) (AndroidUtilities.dpf2(13.5f) - AndroidUtilities.dp(5) * (1.0f - bounceProgress));
        drawCanvas.drawLine(AndroidUtilities.dp(7.5f), (int) AndroidUtilities.dpf2(13.5f), endX, endY, Theme.checkboxSquare_checkPaint);
        endX = (int) (AndroidUtilities.dpf2(6.5f) + AndroidUtilities.dp(9) * (1.0f - bounceProgress));
        endY = (int) (AndroidUtilities.dpf2(13.5f) - AndroidUtilities.dp(9) * (1.0f - bounceProgress));
        drawCanvas.drawLine((int) AndroidUtilities.dpf2(6.5f), (int) AndroidUtilities.dpf2(13.5f), endX, endY, Theme.checkboxSquare_checkPaint);
    }
    canvas.drawBitmap(drawBitmap, 0, 0, null);
}
 
Example 20
Source File: FlatCheckBox.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void draw(Canvas canvas) {
    super.draw(canvas);


    float textTranslation = 0f;

    if (progress <= 0.5f) {
        float checkProgress = textTranslation = progress / 0.5f;
        int rD = (int) ((Color.red(colorInactive) - Color.red(colorActive)) * checkProgress);
        int gD = (int) ((Color.green(colorInactive) - Color.green(colorActive)) * checkProgress);
        int bD = (int) ((Color.blue(colorInactive) - Color.blue(colorActive)) * checkProgress);
        int c = Color.rgb(Color.red(colorActive) + rD, Color.green(colorActive) + gD, Color.blue(colorActive) + bD);

        fillPaint.setColor(c);

        rD = (int) ((Color.red(colorTextActive) - Color.red(colorInactive)) * checkProgress);
        gD = (int) ((Color.green(colorTextActive) - Color.green(colorInactive)) * checkProgress);
        bD = (int) ((Color.blue(colorTextActive) - Color.blue(colorInactive)) * checkProgress);
        c = Color.rgb(Color.red(colorInactive) + rD, Color.green(colorInactive) + gD, Color.blue(colorInactive) + bD);

        textPaint.setColor(c);
    } else {
        textTranslation = 1f;
        textPaint.setColor(colorTextActive);
        fillPaint.setColor(colorInactive);
    }


    int heightHalf = (getMeasuredHeight() >> 1);

    outLinePaint.setColor(colorInactive);
    canvas.drawRoundRect(rectF, HEIGHT / 2f, HEIGHT / 2f, fillPaint);
    canvas.drawRoundRect(rectF, HEIGHT / 2f, HEIGHT / 2f, outLinePaint);
    if (text != null) {
        canvas.drawText(text,
                (getMeasuredWidth() >> 1) + (textTranslation * TRANSLETE_TEXT),
                heightHalf + (textPaint.getTextSize() * 0.35f),
                textPaint
        );
    }

    float bounceProgress = 2.0f - progress / 0.5f;
    canvas.save();
    canvas.scale(0.9f, 0.9f, AndroidUtilities.dpf2(7f), heightHalf);
    canvas.translate(AndroidUtilities.dp(12), heightHalf - AndroidUtilities.dp(9));

    if (progress > 0.5f) {
        checkPaint.setColor(colorTextActive);
        int endX = (int) (AndroidUtilities.dpf2(7f) - AndroidUtilities.dp(4) * (1.0f - bounceProgress));
        int endY = (int) (AndroidUtilities.dpf2(13f) - AndroidUtilities.dp(4) * (1.0f - bounceProgress));
        canvas.drawLine(AndroidUtilities.dpf2(7f), (int) AndroidUtilities.dpf2(13f), endX, endY, checkPaint);
        endX = (int) (AndroidUtilities.dpf2(7f) + AndroidUtilities.dp(8) * (1.0f - bounceProgress));
        endY = (int) (AndroidUtilities.dpf2(13f) - AndroidUtilities.dp(8) * (1.0f - bounceProgress));
        canvas.drawLine((int) AndroidUtilities.dpf2(7f), (int) AndroidUtilities.dpf2(13f), endX, endY, checkPaint);
    }
    canvas.restore();


}