コード例 #1
0
ファイル: DialogView.java プロジェクト: johack0/telegram
 @Override
 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
   long start = System.currentTimeMillis();
   if (changed) {
     buildLayout();
   }
   // Logger.d(TAG, "onLayout in " + (System.currentTimeMillis() - start) + " ms");
 }
コード例 #2
0
ファイル: DialogView.java プロジェクト: johack0/telegram
 @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
   long start = System.currentTimeMillis();
   if (IS_LARGE) {
     setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), getPx(80));
   } else {
     setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), getPx(68));
   }
   // Logger.d(TAG, "onMeasure in " + (System.currentTimeMillis() - start) + " ms");
 }
コード例 #3
0
ファイル: MessageView.java プロジェクト: markadam/telegram
  @Override
  protected boolean drawBubble(Canvas canvas) {
    if (messageLayout == null) {
      requestLayout();
      return false;
    }

    boolean isAnimated = false;

    if (messageLayout.isForwarded) {
      canvas.drawText("Forwarded message", 0, getPx(16), messageLayout.forwardingPaint);
      canvas.drawText("From", 0, getPx(35), messageLayout.forwardingPaint);
      canvas.drawText(
          messageLayout.forwarderNameMeasured,
          messageLayout.forwardOffset,
          getPx(35),
          messageLayout.senderPaint);
      canvas.save();
      canvas.translate(0, getPx(19) * 2);
      messageLayout.layout.draw(canvas);
      canvas.restore();
    } else {
      if (!messageLayout.isOut & messageLayout.isGroup) {
        canvas.drawText(messageLayout.senderNameMeasured, 0, getPx(16), messageLayout.senderPaint);
        canvas.save();
        canvas.translate(0, getPx(19));
        messageLayout.layout.draw(canvas);
        canvas.restore();
      } else {
        messageLayout.layout.draw(canvas);
      }
    }

    if (messageLayout.showState) {
      if (state == MessageState.PENDING) {
        canvas.save();
        canvas.translate(
            messageLayout.layoutRealWidth - getPx(12),
            messageLayout.layoutHeight - getPx(12) - getPx(3));
        canvas.drawCircle(getPx(6), getPx(6), getPx(6), clockIconPaint);
        double time = (System.currentTimeMillis() / 15.0) % (12 * 60);
        double angle = (time / (6 * 60)) * Math.PI;

        int x = (int) (Math.sin(-angle) * getPx(4));
        int y = (int) (Math.cos(-angle) * getPx(4));
        canvas.drawLine(getPx(6), getPx(6), getPx(6) + x, getPx(6) + y, clockIconPaint);

        x = (int) (Math.sin(-angle * 12) * getPx(5));
        y = (int) (Math.cos(-angle * 12) * getPx(5));
        canvas.drawLine(getPx(6), getPx(6), getPx(6) + x, getPx(6) + y, clockIconPaint);

        canvas.restore();

        clockOutPaint.setColor(COLOR_NORMAL);

        isAnimated = true;
      } else if (state == MessageState.READED
          && prevState == MessageState.SENT
          && (SystemClock.uptimeMillis() - stateChangeTime < STATE_ANIMATION_TIME)) {
        long animationTime = SystemClock.uptimeMillis() - stateChangeTime;
        float progress = easeStateFade(animationTime / (float) STATE_ANIMATION_TIME);
        int offset = (int) (getPx(5) * progress);
        int alphaNew = (int) (progress * 255);

        bounds(
            stateSent,
            messageLayout.layoutRealWidth - stateSent.getIntrinsicWidth() - offset,
            messageLayout.layoutHeight - stateSent.getIntrinsicHeight() - getPx(3));
        stateSent.setAlpha(255);
        stateSent.draw(canvas);

        bounds(
            stateHalfCheck,
            messageLayout.layoutRealWidth - stateHalfCheck.getIntrinsicWidth() + getPx(5) - offset,
            messageLayout.layoutHeight - stateHalfCheck.getIntrinsicHeight() - getPx(3));
        stateHalfCheck.setAlpha(alphaNew);
        stateHalfCheck.draw(canvas);

        clockOutPaint.setColor(COLOR_NORMAL);

        isAnimated = true;
      } else {
        Drawable stateDrawable = getStateDrawable(state);

        bounds(
            stateDrawable,
            messageLayout.layoutRealWidth - stateDrawable.getIntrinsicWidth(),
            messageLayout.layoutHeight - stateDrawable.getIntrinsicHeight() - getPx(3));
        stateDrawable.setAlpha(255);
        stateDrawable.draw(canvas);

        if (state == MessageState.READED) {
          bounds(
              stateSent,
              messageLayout.layoutRealWidth - stateSent.getIntrinsicWidth() - getPx(5),
              messageLayout.layoutHeight - stateDrawable.getIntrinsicHeight() - getPx(3));
          stateSent.setAlpha(255);
          stateSent.draw(canvas);
        }

        if (state == MessageState.FAILURE) {
          clockOutPaint.setColor(COLOR_ERROR);
        } else {
          clockOutPaint.setColor(COLOR_NORMAL);
        }
      }
    } else {
      clockOutPaint.setColor(COLOR_IN);
    }
    canvas.drawText(
        wireframe.date,
        messageLayout.layoutRealWidth - messageLayout.timeWidth + getPx(6),
        messageLayout.layoutHeight - getPx(4),
        clockOutPaint);
    return isAnimated;
  }