@Override
  protected void onDraw(Canvas canvas) {
    final int width = getWidth();
    final int height = getHeight() - getPaddingBottom();

    final Drawable secondary = mSecondary;
    if (secondary != null) {
      final int secondaryHeight = secondary.getIntrinsicHeight();

      final float[] vertTicks = mVert.getTickPoints();
      for (float y : vertTicks) {
        final int bottom = (int) Math.min(y + secondaryHeight, height);
        secondary.setBounds(0, (int) y, width, bottom);
        secondary.draw(canvas);
      }
    }

    final Drawable primary = mPrimary;
    if (primary != null) {
      final int primaryWidth = primary.getIntrinsicWidth();
      final int primaryHeight = primary.getIntrinsicHeight();

      final float[] horizTicks = mHoriz.getTickPoints();
      for (float x : horizTicks) {
        final int right = (int) Math.min(x + primaryWidth, width);
        primary.setBounds((int) x, 0, right, height);
        primary.draw(canvas);
      }
    }

    mBorder.setBounds(0, 0, width, height);
    mBorder.draw(canvas);

    final int padding = mLabelStart != null ? mLabelStart.getHeight() / 8 : 0;

    final Layout start = mLabelStart;
    if (start != null) {
      final int saveCount = canvas.save();
      canvas.translate(0, height + padding);
      start.draw(canvas);
      canvas.restoreToCount(saveCount);
    }

    final Layout mid = mLabelMid;
    if (mid != null) {
      final int saveCount = canvas.save();
      canvas.translate((width - mid.getWidth()) / 2, height + padding);
      mid.draw(canvas);
      canvas.restoreToCount(saveCount);
    }

    final Layout end = mLabelEnd;
    if (end != null) {
      final int saveCount = canvas.save();
      canvas.translate(width - end.getWidth(), height + padding);
      end.draw(canvas);
      canvas.restoreToCount(saveCount);
    }
  }
  private void sendTextBitmap(LiveViewAdapter mLiveViewAdapter, int mPluginId, String txt) {
    // Empty bitmap and link the canvas to it
    Bitmap bitmap = null;
    try {
      bitmap = Bitmap.createBitmap(128, 128, Bitmap.Config.RGB_565);
    } catch (IllegalArgumentException e) {
      return;
    }

    Canvas canvas = new Canvas(bitmap);

    // Set the text properties in the canvas
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(18);
    textPaint.setColor(Color.WHITE);

    // Create the text layout and draw it to the canvas
    Layout textLayout =
        new StaticLayout(txt, textPaint, 128, Layout.Alignment.ALIGN_CENTER, 1, 1, false);
    textLayout.draw(canvas);

    try {
      mLiveViewAdapter.sendImageAsBitmap(
          mPluginId, PluginUtils.centerX(bitmap), PluginUtils.centerY(bitmap), bitmap);
    } catch (Exception e) {
      Log.d(PluginConstants.LOG_TAG, "Failed to send bitmap", e);
    }
  }
  private void sendItemTextBitmap(
      LiveViewAdapter mLiveViewAdapter, int mPluginId, String tags, String item) {

    Log.d(LOG_TAG, "sendItemTextBitmap(): item: " + item);
    // Empty bitmap and link the canvas to it
    Bitmap bitmap = null;
    try {

      bitmap = Bitmap.createBitmap(128, 128, Bitmap.Config.RGB_565);

    } catch (IllegalArgumentException e) {
      return;
    }

    Canvas canvas = new Canvas(bitmap);

    // Set the text properties in the canvas
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(14);
    textPaint.setAntiAlias(true);
    textPaint.setColor(Color.WHITE);

    // Create the text layout and draw it to the canvas
    Layout textLayout =
        new StaticLayout(item, textPaint, 128, Layout.Alignment.ALIGN_NORMAL, 1, 1, false);
    textLayout.draw(canvas);

    //        textLayout.getWidth();
    //        textLayout.getHeight();

    if (!TextUtils.isEmpty(tags)) {
      // now smaller text
      textPaint.setTextSize(10);
      canvas.translate(1, textLayout.getHeight());
      // Create the text layout and draw it to the canvas
      textLayout =
          new StaticLayout(tags, textPaint, 128, Layout.Alignment.ALIGN_NORMAL, 1, 1, false);
      textLayout.draw(canvas);
    }

    try {
      mLiveViewAdapter.sendImageAsBitmap(mPluginId, 1, 1, bitmap);
    } catch (Exception e) {
      Log.d(PluginConstants.LOG_TAG, "Failed to send bitmap", e);
    }
  }
Exemple #4
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    // Draw the switch
    int switchLeft = mSwitchLeft;
    int switchTop = mSwitchTop;
    int switchRight = mSwitchRight;
    int switchBottom = mSwitchBottom;

    mTrackDrawable.setBounds(switchLeft, switchTop, switchRight, switchBottom);
    mTrackDrawable.draw(canvas);

    canvas.save();

    mTrackDrawable.getPadding(mTempRect);
    int switchInnerLeft = switchLeft + mTempRect.left;
    int switchInnerTop = switchTop + mTempRect.top;
    int switchInnerRight = switchRight - mTempRect.right;
    int switchInnerBottom = switchBottom - mTempRect.bottom;
    canvas.clipRect(switchInnerLeft, switchTop, switchInnerRight, switchBottom);

    mThumbDrawable.getPadding(mTempRect);
    final int thumbPos = (int) (mThumbPosition + 0.5f);
    int thumbLeft = switchInnerLeft - mTempRect.left + thumbPos;
    int thumbRight = switchInnerLeft + thumbPos + mThumbWidth + mTempRect.right;

    mThumbDrawable.setBounds(thumbLeft, switchTop, thumbRight, switchBottom);
    mThumbDrawable.draw(canvas);

    // mTextColors should not be null, but just in case
    if (mTextColors != null) {
      mTextPaint.setColor(
          mTextColors.getColorForState(getDrawableState(), mTextColors.getDefaultColor()));
    }
    mTextPaint.drawableState = getDrawableState();

    Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout;
    if (switchText != null) {
      canvas.translate(
          (thumbLeft + thumbRight) / 2 - switchText.getWidth() / 2,
          (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2);
      switchText.draw(canvas);
    }

    canvas.restore();
  }
Exemple #5
0
 /** @param canvas */
 private void drawMETARText(Canvas canvas) {
   /*
    * Draw TFRs, weather
    */
   if (mPref.shouldTFRAndMETARShow()) {
     /*
      * Write weather report
      * Use a static layout for showing as overlay and formatted to fit
      */
     float top = getHeight() / mTextDiv * 2 + mFontHeight;
     if (null != mWeatherLayout) {
       mPaint.setColor(mWeatherColor);
       mPaint.setShadowLayer(SHADOW, SHADOW, SHADOW, Color.BLACK);
       canvas.drawRect(SHADOW, top, getWidth() - SHADOW, mWeatherLayout.getHeight() + top, mPaint);
       canvas.save();
       canvas.translate(SHADOW + 2, top);
       mPaint.setShadowLayer(0, 0, 0, Color.BLACK);
       mWeatherLayout.draw(canvas);
       canvas.restore();
     }
   }
 }
Exemple #6
0
  @Override
  protected void onDraw(Canvas canvas) {

    if (layout == null) {
      requestLayout();
      return;
    }

    if (description == null) {
      return;
    }

    if (needNewUpdateTyping) {
      updateTyping();
    }

    if (layout.isEncrypted) {
      bounds(secureIcon, layout.layoutEncryptedLeft, layout.layoutEncryptedTop);
      secureIcon.draw(canvas);
    }

    if (layout.titleLayout != null) {
      canvas.save();
      canvas.translate(layout.layoutTitleLeft, layout.layoutTitleLayoutTop);
      layout.titleLayout.draw(canvas);
      canvas.restore();
    } else if (layout.titleString != null) {
      TextPaint paint =
          layout.isEncrypted
              ? titleEncryptedPaint
              : (layout.isHighlighted ? titleHighlightPaint : titlePaint);
      canvas.drawText(layout.titleString, layout.layoutTitleLeft, layout.layoutTitleTop, paint);
    }

    if (state != MessageState.FAILURE && description.getSenderId() == currentUserUid) {
      switch (state) {
        default:
        case MessageState.PENDING:
          bound(statePending, layout.layoutClockLeft, layout.layoutClockTop);
          statePending.draw(canvas);
          break;
        case MessageState.SENT:
          bound(stateSent, layout.layoutStateLeft, layout.layoutStateTop);
          stateSent.draw(canvas);
          break;
        case MessageState.READED:
          bound(stateSent, layout.layoutStateLeftDouble, layout.layoutStateTop);
          stateSent.draw(canvas);
          bound(stateHalfCheck, layout.layoutStateLeft, layout.layoutStateTop);
          stateHalfCheck.draw(canvas);
          break;
      }
    }

    TextPaint timePaint =
        HIGHLIGHT_UNDEAD ? (layout.isUnreadIn ? unreadClockPaint : readClockPaint) : readClockPaint;
    canvas.drawText(layout.time, layout.layoutTimeLeft, layout.layoutTimeTop, timePaint);

    if (typingLayout != null) {
      canvas.save();
      canvas.translate(layout.layoutMainLeft, layout.layoutMainContentTop);
      typingLayout.draw(canvas);
      canvas.restore();
    } else if (layout.bodyLayout != null) {
      canvas.save();
      canvas.translate(layout.layoutMainLeft, layout.layoutMainContentTop);
      layout.bodyLayout.draw(canvas);
      canvas.restore();
    } else if (layout.bodyString != null) {
      //            canvas.save();
      //            canvas.translate(layout.layoutMainLeft, layout.layoutMainTop);
      //            layout.bodyLayout.draw(canvas);
      //            canvas.restore();
      canvas.drawText(layout.bodyString, layout.layoutMainLeft, layout.layoutMainTop, bodyPaint);
    }

    if (avatarHolder != null) {
      long time = SystemClock.uptimeMillis() - avatarAppearTime;
      if (time > AVATAR_FADE_TIME || !AVATAR_FADE) {
        avatarPaint.setAlpha(255);
        canvas.drawBitmap(
            avatarHolder.getBitmap(), layout.layoutAvatarLeft, layout.layoutAvatarTop, avatarPaint);
      } else {
        drawPlaceHolder(canvas);

        float alpha = time / (float) AVATAR_FADE_TIME;
        avatarPaint.setAlpha((int) (255 * alpha));
        canvas.drawBitmap(
            avatarHolder.getBitmap(), layout.layoutAvatarLeft, layout.layoutAvatarTop, avatarPaint);

        inavalidateForAnimation();
      }
    } else {
      drawPlaceHolder(canvas);
    }

    if (description.isErrorState()
        || (state == MessageState.FAILURE && description.getSenderId() == currentUserUid)) {
      bound(stateFailure, layout.layoutMarkLeft, layout.layoutMarkTop);
      stateFailure.draw(canvas);
    } else if (description.getUnreadCount() > 0) {
      canvas.drawRoundRect(
          layout.layoutMarkRect, layout.layoutMarkRadius, layout.layoutMarkRadius, counterPaint);
      canvas.drawText(
          layout.unreadCountText,
          layout.layoutMarkLeft + layout.layoutMarkTextLeft,
          layout.layoutMarkTextTop,
          counterTitlePaint);
    }
  }