/** Sets up the text and style properties for painting. */
  private void initPaints(Resources res) {
    final String monthTypeface = res.getString(R.string.date_picker_month_typeface);
    final String dayOfWeekTypeface = res.getString(R.string.date_picker_day_of_week_typeface);
    final String dayTypeface = res.getString(R.string.date_picker_day_typeface);

    final int monthTextSize = res.getDimensionPixelSize(R.dimen.date_picker_month_text_size);
    final int dayOfWeekTextSize =
        res.getDimensionPixelSize(R.dimen.date_picker_day_of_week_text_size);
    final int dayTextSize = res.getDimensionPixelSize(R.dimen.date_picker_day_text_size);

    mMonthPaint.setAntiAlias(true);
    mMonthPaint.setTextSize(monthTextSize);
    mMonthPaint.setTypeface(Typeface.create(monthTypeface, 0));
    mMonthPaint.setTextAlign(Align.CENTER);
    mMonthPaint.setStyle(Style.FILL);

    mDayOfWeekPaint.setAntiAlias(true);
    mDayOfWeekPaint.setTextSize(dayOfWeekTextSize);
    mDayOfWeekPaint.setTypeface(Typeface.create(dayOfWeekTypeface, 0));
    mDayOfWeekPaint.setTextAlign(Align.CENTER);
    mDayOfWeekPaint.setStyle(Style.FILL);

    mDaySelectorPaint.setAntiAlias(true);
    mDaySelectorPaint.setStyle(Style.FILL);

    mDayHighlightPaint.setAntiAlias(true);
    mDayHighlightPaint.setStyle(Style.FILL);

    mDayPaint.setAntiAlias(true);
    mDayPaint.setTextSize(dayTextSize);
    mDayPaint.setTypeface(Typeface.create(dayTypeface, 0));
    mDayPaint.setTextAlign(Align.CENTER);
    mDayPaint.setStyle(Style.FILL);
  }
 @Override
 public void setTypeface(final Typeface tf) {
   if (paint == null) paint = new TextPaint(getPaint());
   paint.setTypeface(tf);
   adjustTextSize();
   super.setTypeface(tf);
 }
  @Override
  public void updateDrawState(TextPaint tp) {
    tp.setTypeface(mTypeface);

    // Note: This flag is required for proper typeface rendering
    tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
  }
Exemple #4
0
  /**
   * Sets the typeface in which the text should be displayed on the switch. Note that not all
   * Typeface families actually have bold and italic variants, so you may need to use {@link
   * #setSwitchTypeface(Typeface, int)} to get the appearance that you actually want.
   *
   * @attr ref android.R.styleable#TextView_typeface
   * @attr ref android.R.styleable#TextView_textStyle
   */
  public void setSwitchTypeface(Typeface tf) {
    if (mTextPaint.getTypeface() != tf) {
      mTextPaint.setTypeface(tf);

      requestLayout();
      invalidate();
    }
  }
Exemple #5
0
  @Override
  public void updateDrawState(TextPaint textPaint) {
    super.updateDrawState(textPaint);

    textPaint.setUnderlineText(false);
    textPaint.setColor(activity.getResources().getColor(R.color.secondary_text));
    textPaint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.ITALIC));
  }
 public void setTypeface(@NonNull Typeface newTypeface) {
   final Typeface oldTypeface = baseTextPaint.getTypeface();
   if (oldTypeface == newTypeface) {
     return;
   }
   baseTextPaint.setTypeface(newTypeface);
   textView.setBaseTextPaint(baseTextPaint);
 }
  protected void init() {
    super.init();

    if (FontController.USE_SUBPIXEL) {
      senderPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    } else {
      senderPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    }
    senderPaint.setTypeface(FontController.loadTypeface(getContext(), "regular"));
    senderPaint.setTextSize(getSp(16));
    senderPaint.setColor(0xff000000);

    if (FontController.USE_SUBPIXEL) {
      bodyPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    } else {
      bodyPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    }
    bodyPaint.setTypeface(FontController.loadTypeface(getContext(), "regular"));
    bodyPaint.setTextSize(getSp(16));
    bodyPaint.setColor(0xff273e57);

    if (FontController.USE_SUBPIXEL) {
      clockOutPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
    } else {
      clockOutPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    }
    clockOutPaint.setTypeface(FontController.loadTypeface(getContext(), "regular"));
    clockOutPaint.setTextSize(getSp(12f));
    clockOutPaint.setColor(0xff70B15C);

    clockIconPaint = new Paint();
    clockIconPaint.setStyle(Paint.Style.STROKE);
    clockIconPaint.setColor(0xff12C000);
    clockIconPaint.setStrokeWidth(getPx(1));
    clockIconPaint.setAntiAlias(true);
    clockIconPaint.setFlags(Paint.ANTI_ALIAS_FLAG);

    addContactResource = getResources().getDrawable(R.drawable.st_bubble_ic_contact);

    placeHolderBgPaint = new Paint();

    avatarPaint = new Paint();

    loader = application.getUiKernel().getAvatarLoader();
  }
  public ProfileSearchCell(Context context) {
    super(context);

    if (namePaint == null) {
      namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      namePaint.setColor(0xff212121);
      namePaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

      nameEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      nameEncryptedPaint.setColor(0xff00a60e);
      nameEncryptedPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

      onlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      onlinePaint.setColor(Theme.MSG_LINK_TEXT_COLOR);

      offlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      offlinePaint.setColor(0xff999999);

      linePaint = new Paint();
      linePaint.setColor(0xffdcdcdc);

      countPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      countPaint.setColor(0xffffffff);
      countPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

      broadcastDrawable = getResources().getDrawable(R.drawable.list_broadcast);
      lockDrawable = getResources().getDrawable(R.drawable.list_secret);
      groupDrawable = getResources().getDrawable(R.drawable.list_group);
      countDrawable = getResources().getDrawable(R.drawable.dialogs_badge);
      countDrawableGrey = getResources().getDrawable(R.drawable.dialogs_badge2);
      checkDrawable = getResources().getDrawable(R.drawable.check_list);
      botDrawable = getResources().getDrawable(R.drawable.bot_list);
    }

    namePaint.setTextSize(AndroidUtilities.dp(17));
    nameEncryptedPaint.setTextSize(AndroidUtilities.dp(17));
    onlinePaint.setTextSize(AndroidUtilities.dp(16));
    offlinePaint.setTextSize(AndroidUtilities.dp(16));
    countPaint.setTextSize(AndroidUtilities.dp(13));

    avatarImage = new ImageReceiver(this);
    avatarImage.setRoundRadius(AndroidUtilities.dp(26));
    avatarDrawable = new AvatarDrawable();
  }
  private static void createAndSendWidget(Context context, String icon, String id, String label) {

    Log.d(Constants.LOG_TAG, "widget: icon:" + icon + " id:" + id + " label:" + label);

    if (typeface == null) {
      typeface = Typeface.createFromAsset(context.getAssets(), "metawatch_8pt_5pxl_CAPS.ttf");
    }

    TextPaint paintSmall = new TextPaint();
    paintSmall.setColor(Color.BLACK);
    paintSmall.setTextSize(8);
    paintSmall.setTypeface(typeface);
    paintSmall.setTextAlign(Align.CENTER);

    label = label.trim();

    // Create 16x16 widget
    {
      Bitmap iconBmp = loadBitmapFromAssets(context, icon + "_10.bmp");

      Bitmap bitmap = Bitmap.createBitmap(16, 16, Bitmap.Config.RGB_565);
      Canvas canvas = new Canvas(bitmap);
      canvas.drawColor(Color.WHITE);

      int y = label.length() == 0 ? 3 : 0;

      canvas.drawBitmap(iconBmp, 2, y, null);
      canvas.drawText(label, 8, 16, paintSmall);

      Intent i =
          createUpdateIntent(
              bitmap, "localeMWM_" + id + "_16_16", "Locale Plugin Widget (16x16)", 1);
      context.sendBroadcast(i);
    }

    // Create 24x32 widget
    {
      Bitmap iconBmp = loadBitmapFromAssets(context, icon + ".bmp");

      Bitmap bitmap = Bitmap.createBitmap(24, 32, Bitmap.Config.RGB_565);
      Canvas canvas = new Canvas(bitmap);
      canvas.drawColor(Color.WHITE);

      int y = label.length() == 0 ? 7 : 3;

      canvas.drawBitmap(iconBmp, 0, y, null);
      canvas.drawText(label, 12, 30, paintSmall);

      Intent i =
          createUpdateIntent(
              bitmap, "localeMWM_" + id + "_24_32", "Locale Plugin Widget (24x32)", 1);
      context.sendBroadcast(i);
    }
  }
  private static String getStringWithEllipsis(String string, float width, float fontSize) {
    if (TextUtils.isEmpty(string)) {
      return "";
    }

    TextPaint paint = new TextPaint();
    paint.setTypeface(Typeface.DEFAULT);
    paint.setTextSize(fontSize);

    return TextUtils.ellipsize(string, paint, width, TextUtils.TruncateAt.END).toString();
  }
  public PaperButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mPadding = getResources().getDimensionPixelSize(R.dimen.paper_padding);
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.PaperButton);
    mColor =
        attributes.getColor(
            R.styleable.PaperButton_paper_color,
            getResources().getColor(R.color.paper_button_color));
    mShadowColor =
        attributes.getColor(
            R.styleable.PaperButton_paper_shadow_color,
            getResources().getColor(R.color.paper_button_shadow_color));
    mCornerRadius =
        attributes.getDimensionPixelSize(
            R.styleable.PaperButton_paper_corner_radius,
            getResources().getDimensionPixelSize(R.dimen.paper_button_corner_radius));
    mText = attributes.getText(R.styleable.PaperButton_paper_text);
    mTextSize =
        attributes.getDimensionPixelSize(
            R.styleable.PaperButton_paper_text_size,
            getResources().getDimensionPixelSize(R.dimen.paper_text_size));
    mTextColor =
        attributes.getColor(
            R.styleable.PaperButton_paper_text_color,
            getResources().getColor(R.color.paper_text_color));
    final String assetPath = attributes.getString(R.styleable.PaperButton_paper_font);
    if (assetPath != null) {
      AssetManager assets = context.getAssets();
      Typeface typeface = Typeface.createFromAsset(assets, assetPath);
      textPaint.setTypeface(typeface);
    }
    mShadowRadius = attributes.getFloat(R.styleable.PaperButton_paper_shadow_radius, SHADOW_RADIUS);
    mShadowOffsetX =
        attributes.getFloat(R.styleable.PaperButton_paper_shadow_offset_x, SHADOW_OFFSET_X);
    mShadowOffsetY =
        attributes.getFloat(R.styleable.PaperButton_paper_shadow_offset_y, SHADOW_OFFSET_Y);
    attributes.recycle();

    backgroundPaint.setColor(mColor);
    backgroundPaint.setStyle(Paint.Style.FILL);
    int shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
    backgroundPaint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, shadowColor);

    textPaint.setColor(mTextColor);
    textPaint.setTextSize(mTextSize);
    textPaint.setTextAlign(TextPaint.Align.CENTER);

    ripplePaint.setColor(darkenColor(mColor));

    setWillNotDraw(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
  }
  public void setTypeface(Typeface tf, int style) {
    if (style > 0) {
      if (tf == null) {
        tf = Typeface.defaultFromStyle(style);
      } else {
        tf = Typeface.create(tf, style);
      }

      mTextPaint.setTypeface(tf);
      // now compute what (if any) algorithmic styling is needed
      int typefaceStyle = tf != null ? tf.getStyle() : 0;
      int need = style & ~typefaceStyle;
      mTextPaint.setFakeBoldText((need & Typeface.BOLD) != 0);
      mTextPaint.setTextSkewX((need & Typeface.ITALIC) != 0 ? -0.25f : 0);
    } else {
      mTextPaint.setFakeBoldText(false);
      mTextPaint.setTextSkewX(0);
      mTextPaint.setTypeface(tf);
    }
  }
  public void init(Context context, ArrayList<CharSequence> widgetIds) {
    this.context = context;

    paintSmall = new TextPaint();
    paintSmall.setColor(Color.BLACK);
    paintSmall.setTextSize(FontCache.instance(context).Small.size);
    paintSmall.setTypeface(FontCache.instance(context).Small.face);
    paintSmall.setTextAlign(Align.CENTER);

    paintSmallNumerals = new TextPaint();
    paintSmallNumerals.setColor(Color.BLACK);
    paintSmallNumerals.setTextSize(FontCache.instance(context).SmallNumerals.size);
    paintSmallNumerals.setTypeface(FontCache.instance(context).SmallNumerals.face);
    paintSmallNumerals.setTextAlign(Align.CENTER);

    paintNumerals = new TextPaint();
    paintNumerals.setColor(Color.BLACK);
    paintNumerals.setTextSize(FontCache.instance(context).Numerals.size);
    paintNumerals.setTypeface(FontCache.instance(context).Numerals.face);
    paintNumerals.setTextAlign(Align.CENTER);
  }
  public void init(int textColor, float textSize, float speed) {
    setFocusable(true);

    this.textColor = textColor;
    this.textSize = textSize;
    this.speed = speed;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);

    tp = new TextPaint();
    tp.setColor(textColor);
    tp.setTextSize(textSize);
    tp.setAntiAlias(true);
    tp.setTypeface(Typeface.MONOSPACE);
  }
  /**
   * 初始化定义的属性
   *
   * @param attrs
   * @param defStyle
   */
  private void init(AttributeSet attrs, int defStyle) {
    TypedArray a =
        getContext().obtainStyledAttributes(attrs, R.styleable.ProgressView, defStyle, 0);
    mText = a.getString(R.styleable.ProgressView_text);
    mTextColor = a.getColor(R.styleable.ProgressView_textColor, mTextColor);
    mTextSize = a.getDimension(R.styleable.ProgressView_textSize, (int) mTextSize);
    mInnerColor = a.getColor(R.styleable.ProgressView_innerColor, mInnerColor);
    mOuterColor = a.getColor(R.styleable.ProgressView_outerColor, mOuterColor);
    mProgressColor = a.getColor(R.styleable.ProgressView_progressColor, mProgressColor);
    mRadius = a.getDimension(R.styleable.ProgressView_radius, (int) mRadius);
    mStrokeWidth = a.getDimension(R.styleable.ProgressView_strokeWidth, (int) mStrokeWidth);
    mCurrentProgress = a.getInteger(R.styleable.ProgressView_currentProgress, mCurrentProgress);
    mMaxProgress = a.getInteger(R.styleable.ProgressView_maxProgress, mMaxProgress);

    a.recycle();

    mTextPaint = new TextPaint();
    mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mTextPaint.setTypeface(Typeface.MONOSPACE);
    mTextPaint.setTextSize(mTextSize);
    mTextPaint.setColor(mTextColor);

    mInnerPaint = new Paint();
    mInnerPaint.setAntiAlias(true);
    mInnerPaint.setDither(true);
    mInnerPaint.setStyle(Paint.Style.FILL);
    // mInnerPaint.setStrokeWidth(mStrokeWidth);
    mInnerPaint.setColor(mInnerColor);

    mOuterPaint = new Paint();
    mOuterPaint.setAntiAlias(true);
    mOuterPaint.setStyle(Paint.Style.STROKE);
    mOuterPaint.setStrokeWidth(mStrokeWidth);
    mOuterPaint.setColor(mOuterColor);

    mProgressPaint = new Paint();
    mProgressPaint.setAntiAlias(true);
    mProgressPaint.setStyle(Paint.Style.STROKE);
    mProgressPaint.setStrokeWidth(mStrokeWidth);
    mProgressPaint.setColor(mProgressColor);
  }
    public void initPaint(@NonNull TextPaint base) {
      paint.set(base);
      paint.setColor(color);
      paint.setAlpha(intAlpha());
      final Typeface typeface = base.getTypeface();
      if (typeface != null && typeface.getStyle() != Typeface.NORMAL) {
        paint.setTypeface(Typeface.create(typeface, Typeface.NORMAL));
      }

      // pre-calculate fixed height
      paint.setTextSize(Math.max(base.getTextSize() * DEF_SCALE, minTextSize));
      paint.getTextBounds("|", 0, 1, bounds);
      fixedTextHeight = bounds.height();

      // set real text size value
      paint.setTextSize(Math.max(base.getTextSize() * scale, minTextSize));

      initPaintShadow();
      invalidate(true);
    }
Exemple #17
0
  /** @param context */
  private void setup(Context context) {

    /*
     * Set up all graphics.
     */
    mContext = context;
    mPan = new Pan();
    mScale = new Scale();
    mOrigin = new Origin();
    mMovement = new Movement();
    mErrorStatus = null;
    mDestination = null;
    mImageDataSource = null;
    mGpsParams = new GpsParams(null);
    mPoint = null;
    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mShown = false;
    mTrackShape = null;
    mWeatherColor = Color.BLACK;

    mPref = new Preferences(context);
    mTextDiv = mPref.isPortrait() ? 24.f : 12.f;

    mFace = Typeface.createFromAsset(mContext.getAssets(), "LiberationMono-Bold.ttf");
    mPaint.setTypeface(mFace);
    mFontHeight = 8; // This is just double of all shadows

    mTextPaint = new TextPaint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setTypeface(mFace);

    setOnTouchListener(this);
    mAirplaneBitmap = new BitmapHolder(context, R.drawable.plane);
    mMultiTouchC = new MultiTouchController<Object>(this);
    mCurrTouchPoint = new PointInfo();

    mGestureDetector = new GestureDetector(context, new GestureListener());
  }
  public ChatMusicCell(Context context) {
    super(context);

    seekBar = new SeekBar(context);
    seekBar.delegate = this;
    radialProgress = new RadialProgress(this);
    drawForwardedName = false;

    if (timePaint == null) {
      timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
      timePaint.setTextSize(AndroidUtilities.dp(13));

      titlePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
      titlePaint.setTextSize(AndroidUtilities.dp(16));
      titlePaint.setColor(theme.ChatMusicCell_titlePaint_color);
      titlePaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));

      authorPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
      authorPaint.setTextSize(AndroidUtilities.dp(15));
      authorPaint.setColor(theme.ChatMusicCell_authorPaint_color);
    }
  }
Exemple #19
0
  /**
   * The graphical representation of the XY chart.
   *
   * @param canvas the canvas to paint to
   * @param x the top left x value of the view to draw to
   * @param y the top left y value of the view to draw to
   * @param width the width of the view to draw to
   * @param height the height of the view to draw to
   */
  @Override
  public void draw(Canvas canvas, int width, int height) {

    TextPaint hash_mark_label_paint = new TextPaint();
    hash_mark_label_paint.setTextSize(DEFAULT_HASH_MARK_TEXT_SIZE);
    hash_mark_label_paint.setTypeface(DefaultRenderer.REGULAR_TEXT_FONT);
    hash_mark_label_paint.setAntiAlias(getAntiAliased());

    boolean rotate = Orientation.VERTICAL.equals(mRenderer.getOrientation());
    mScale = (float) (height) / width;
    mTranslate = Math.abs(width - height) / 2;
    if (mScale < 1) {
      mTranslate *= -1;
    }
    mCenter = new PointF(width / 2, height / 2);
    if (rotate) {
      transform(canvas, mRenderer.getOrientation().getAngle(), false);
    }

    MinMax x_span = mRenderer.getXAxisSpan();

    float vertical_axis_hash_mark_width = 0;
    float vertical_secondary_axis_hash_mark_width = 0;
    float horizontal_axis_label_height = 0;

    // Measure all y-axis label widths to determine the axis line position
    if (mRenderer.isShowLabels() && mRenderer.getShowYAxis()) {
      vertical_axis_hash_mark_width = measurePrimaryYaxisTickLabels(hash_mark_label_paint);

      if (mRenderer.hasSecondaryYAxis()) {
        Log.e(TAG, "Has secondary axis!!!");
        vertical_secondary_axis_hash_mark_width =
            measureSecondaryYaxisTickLabels(hash_mark_label_paint);
      }
    }

    if (mRenderer.isShowLabels() && mRenderer.getShowXAxis()) {
      horizontal_axis_label_height = measureXaxisTickLabels(hash_mark_label_paint, x_span);
    }

    Rect frame =
        new Rect(
            (int) Math.ceil(vertical_axis_hash_mark_width),
            0,
            width - (int) Math.ceil(vertical_secondary_axis_hash_mark_width),
            height - (int) horizontal_axis_label_height);

    double xPixelsPerUnit = getPixelsPerUnit(frame.width(), x_span);
    double yPixelsPerUnit = getPixelsPerUnit(frame.height(), mRenderer.getYPrimaryAxisSpan());
    double ySecondaryPixelsPerUnit = 0;
    if (mRenderer.hasSecondaryYAxis())
      ySecondaryPixelsPerUnit = getPixelsPerUnit(frame.height(), mRenderer.getYSecondaryAxisSpan());

    if (mRenderer.isShowLabels() || mRenderer.isShowGrid()) {

      List<Double> xLabels = MathHelper.getLabels(x_span, mRenderer.getXLabels());
      if (mRenderer.isShowLabels()) {
        hash_mark_label_paint.setColor(mRenderer.getLabelsColor());
        hash_mark_label_paint.setTextAlign(Align.CENTER);
      }

      drawXLabels(
          xLabels,
          mRenderer.getXTextLabelLocations(),
          canvas,
          hash_mark_label_paint,
          frame.left,
          frame.top,
          frame.bottom,
          xPixelsPerUnit,
          x_span.min.doubleValue(),
          DEFAULT_HORIZONTAL_AXIS_HASH_MARK_LENGTH,
          horizontal_axis_label_height - DEFAULT_HORIZONTAL_AXIS_HASH_MARK_LENGTH);

      drawVerticalAxisLabels(
          canvas,
          frame,
          hash_mark_label_paint,
          yPixelsPerUnit,
          ySecondaryPixelsPerUnit,
          vertical_axis_hash_mark_width,
          vertical_secondary_axis_hash_mark_width);
    }

    // This draws the plot boundaries.
    drawPlotBoundaries(canvas, frame, hash_mark_label_paint);

    // This draws the plot boundaries.
    drawAllDataSets(
        canvas,
        frame,
        hash_mark_label_paint,
        xPixelsPerUnit,
        yPixelsPerUnit,
        ySecondaryPixelsPerUnit);

    if (rotate) {
      transform(canvas, mRenderer.getOrientation().getAngle(), true);
    }
  }
 @Override
 public void updateDrawState(TextPaint tp) {
   tp.setTypeface(mTypeface);
 }
  public NMapCalloutCustomOldOverlay(
      NMapOverlay itemOverlay,
      NMapOverlayItem item,
      Rect itemBounds,
      NMapCalloutCustomOldOverlay.ResourceProvider resourceProvider) {

    super(itemOverlay, item, itemBounds);

    mTextPaint.setAntiAlias(true);
    // set font style
    mTextPaint.setColor(CALLOUT_TEXT_COLOR);
    // set font size
    mTextPaint.setTextSize(CALLOUT_TEXT_SIZE * NMapResourceProvider.getScaleFactor());
    // set font type
    if (CALLOUT_TEXT_TYPEFACE != null) {
      mTextPaint.setTypeface(CALLOUT_TEXT_TYPEFACE);
    }

    mMarginX = NMapResourceProvider.toPixelFromDIP(CALLOUT_MARGIN_X);
    mPaddingX = NMapResourceProvider.toPixelFromDIP(CALLOUT_PADDING_X);
    mPaddingOffset = NMapResourceProvider.toPixelFromDIP(CALLOUT_PADDING_OFFSET);
    mPaddingY = NMapResourceProvider.toPixelFromDIP(CALLOUT_PADDING_Y);
    mMinimumWidth = NMapResourceProvider.toPixelFromDIP(CALLOUT_MIMIMUM_WIDTH);
    mTotalHeight = NMapResourceProvider.toPixelFromDIP(CALLOUT_TOTAL_HEIGHT);
    mBackgroundHeight = NMapResourceProvider.toPixelFromDIP(CALLOUT_BACKGROUND_HEIGHT);
    mItemGapY = NMapResourceProvider.toPixelFromDIP(CALLOUT_ITEM_GAP_Y);

    mTailGapX = NMapResourceProvider.toPixelFromDIP(CALLOUT_TAIL_GAP_X);
    mTailText = item.getTailText();

    mTitleOffsetY = NMapResourceProvider.toPixelFromDIP(CALLOUT_TITLE_OFFSET_Y);

    if (resourceProvider == null) {
      throw new IllegalArgumentException(
          "NMapCalloutCustomOverlay.ResourceProvider should be provided on creation of NMapCalloutCustomOverlay.");
    }

    mBackgroundDrawable = resourceProvider.getCalloutBackground(item);

    boolean hasRightAccessory = false;
    mDrawableRightButton = resourceProvider.getCalloutRightAccessory(item);
    if (mDrawableRightButton != null && mDrawableRightButton.length > 0) {
      hasRightAccessory = true;

      mRightButtonText = null;
    } else {
      mDrawableRightButton = resourceProvider.getCalloutRightButton(item);
      mRightButtonText = resourceProvider.getCalloutRightButtonText(item);
    }

    if (mDrawableRightButton != null) {
      if (hasRightAccessory) {
        mCalloutRightButtonWidth = mDrawableRightButton[0].getIntrinsicWidth();
        mCalloutRightButtonHeight = mDrawableRightButton[0].getIntrinsicHeight();
      } else {
        mCalloutRightButtonWidth = NMapResourceProvider.toPixelFromDIP(CALLOUT_RIGHT_BUTTON_WIDTH);
        mCalloutRightButtonHeight =
            NMapResourceProvider.toPixelFromDIP(CALLOUT_RIGHT_BUTTON_HEIGHT);
      }

      mRightButtonRect = new Rect();

      super.setItemCount(mCalloutButtonCount);
    } else {
      mCalloutRightButtonWidth = 0;
      mCalloutRightButtonHeight = 0;
      mRightButtonRect = null;
    }

    mTitleTruncated = null;
    mWidthTitleTruncated = 0;
  }
Exemple #22
0
 @Override
 public void updateMeasureState(TextPaint p) {
   p.setTypeface(typeface);
   p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
 }
 @Override
 public void updateMeasureState(TextPaint p) {
   p.setTypeface(mTypeface);
 }
Exemple #24
0
    public void build(MessageWireframe wireframe, int desiredWidth, StelsApplication application) {

      Logger.d(TAG, "Build layout start");

      checkResources(application);

      senderPaint = initTextPaint();
      senderPaint.setTypeface(FontController.loadTypeface(application, "regular"));
      senderPaint.setTextSize(bodyPaint.getTextSize());
      senderPaint.setColor(0xff000000);

      forwardingPaint = initTextPaint();
      forwardingPaint.setTypeface(FontController.loadTypeface(application, "light"));
      forwardingPaint.setTextSize(bodyPaint.getTextSize());
      forwardingPaint.setColor(0xff000000);

      this.layoutDesiredWidth = desiredWidth;
      this.isOut = wireframe.message.isOut();
      this.showState = isOut;
      this.isGroup = wireframe.message.getPeerType() == PeerType.PEER_CHAT && !isOut;
      if (isGroup) {
        User user = wireframe.senderUser;
        this.senderName = user.getDisplayName();
        if (!wireframe.message.isForwarded()) {
          senderPaint.setColor(
              Placeholders.USER_PLACEHOLDERS_COLOR[
                  wireframe.message.getSenderId() % Placeholders.USER_PLACEHOLDERS_COLOR.length]);
          forwardingPaint.setColor(
              Placeholders.USER_PLACEHOLDERS_COLOR[
                  wireframe.message.getSenderId() % Placeholders.USER_PLACEHOLDERS_COLOR.length]);
        }
      }

      if (wireframe.message.isForwarded()) {
        isForwarded = true;
        this.forwarderName = wireframe.forwardUser.getDisplayName();
        if (isOut) {
          forwardingPaint.setColor(0xff739f53);
          senderPaint.setColor(0xff739f53);
        } else {
          forwardingPaint.setColor(0xff4884cf);
          senderPaint.setColor(0xff4884cf);
        }
      } else {
        isForwarded = false;
      }

      if (isGroup) {
        User user = application.getEngine().getUser(wireframe.message.getSenderId());
        this.senderName = user.getDisplayName();
      }
      if (wireframe.message.isForwarded()) {
        isForwarded = true;
        this.forwarderName = wireframe.forwardUser.getDisplayName();
      } else {
        isForwarded = false;
      }

      layoutDesiredWidth = desiredWidth;
      long start = SystemClock.uptimeMillis();

      this.spannable =
          application
              .getEmojiProcessor()
              .processEmojiCompatMutable(
                  wireframe.message.getMessage(), EmojiProcessor.CONFIGURATION_BUBBLES);

      // spannable = new SpannableString(wireframe.message.getMessage());
      Logger.d(TAG, "Emoji processed in " + (SystemClock.uptimeMillis() - start) + " ms");
      start = SystemClock.uptimeMillis();
      Linkify.addLinks(
          this.spannable, Linkify.WEB_URLS | Linkify.PHONE_NUMBERS | Linkify.EMAIL_ADDRESSES);
      fixLinks(spannable);
      Logger.d(TAG, "Added links in " + (SystemClock.uptimeMillis() - start) + " ms");
      start = SystemClock.uptimeMillis();
      layout =
          new StaticLayout(
              spannable, bodyPaint, desiredWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, true);
      Logger.d(TAG, "Built base layout in " + (SystemClock.uptimeMillis() - start) + " ms");

      if (layout.getLineCount() < 20) {
        int layoutTextWidth = 0;

        for (int i = 0; i < layout.getLineCount(); i++) {
          layoutTextWidth = (int) Math.max(layout.getLineWidth(i), layoutTextWidth);
        }

        if (layoutTextWidth < layout.getWidth() - px(10)) {
          layout =
              new StaticLayout(
                  spannable,
                  bodyPaint,
                  layoutTextWidth + px(2),
                  Layout.Alignment.ALIGN_NORMAL,
                  1.0f,
                  0.0f,
                  true);
        }
      }

      layoutRealWidth = layout.getWidth();

      timeWidth = (int) clockOutPaint.measureText(wireframe.date) + px((showState ? 23 : 0) + 6);

      if (layout.getLineCount() == 1) {
        boolean isLastRtl = layout.getParagraphDirection(0) == Layout.DIR_RIGHT_TO_LEFT;
        if (!isLastRtl && desiredWidth - layoutRealWidth > timeWidth) {
          layoutRealWidth += timeWidth;
          layoutHeight = layout.getHeight() + px(3);
        } else if (isLastRtl && desiredWidth - layout.getWidth() > timeWidth) {
          layoutRealWidth = layout.getWidth() + timeWidth;
          layoutHeight = layout.getHeight() + px(3);
        } else {
          if (isLastRtl) {
            layoutRealWidth = layout.getWidth();
          }

          layoutHeight = layout.getHeight() + px(17);
        }
      } else {
        boolean isLastRtl =
            layout.getParagraphDirection(layout.getLineCount() - 1) == Layout.DIR_RIGHT_TO_LEFT;
        if (!isLastRtl
            && (desiredWidth - layout.getLineWidth(layout.getLineCount() - 1) > timeWidth)) {
          layoutRealWidth =
              (int)
                  Math.max(
                      layoutRealWidth, layout.getLineWidth(layout.getLineCount() - 1) + timeWidth);
          layoutHeight = layout.getHeight() + px(3);
        } else if (isLastRtl && (desiredWidth - layout.getWidth() > timeWidth)) {
          layoutRealWidth = (int) Math.max(layoutRealWidth, layout.getWidth() + timeWidth);
          layoutHeight = layout.getHeight() + px(3);
        } else {
          layoutHeight = layout.getHeight() + px(17);
        }
      }

      if (layoutRealWidth < timeWidth) {
        layoutRealWidth = timeWidth;
      }

      if (isForwarded) {
        layoutHeight += px(19) * 2;
        forwardOffset = (int) forwardingPaintBase.measureText("From ");
        layoutRealWidth =
            (int) Math.max(layoutRealWidth, forwardingPaintBase.measureText("Forwarded message"));
        forwarderNameMeasured =
            TextUtils.ellipsize(
                    forwarderName,
                    senderPaintBase,
                    desiredWidth - forwardOffset,
                    TextUtils.TruncateAt.END)
                .toString();
        layoutRealWidth =
            (int)
                Math.max(
                    layoutRealWidth,
                    forwardOffset + senderPaintBase.measureText(forwarderNameMeasured));
      }

      if (isGroup && !isOut && !isForwarded) {
        layoutHeight += px(19);
        senderNameMeasured =
            TextUtils.ellipsize(senderName, senderPaintBase, desiredWidth, TextUtils.TruncateAt.END)
                .toString();
        int width = (int) senderPaintBase.measureText(senderNameMeasured);
        layoutRealWidth = Math.max(layoutRealWidth, width);
      }

      Logger.d(TAG, "Build layout end");
    }
Exemple #25
0
 @Override
 public void updateDrawState(TextPaint tp) {
   tp.setTypeface(typeface);
   tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG);
 }
Exemple #26
0
  private static void checkResources(Context context) {
    if (isLoaded) {
      return;
    }

    StelsApplication application = (StelsApplication) context.getApplicationContext();

    int fontSize;
    int fontSizeClock;
    switch (application.getUserSettings().getBubbleFontSizeId()) {
      default:
      case UserSettings.BUBBLE_FONT_NORMAL:
        fontSize = UserSettings.BUBBLE_FONT_NORMAL_VALUE;
        fontSizeClock = UserSettings.BUBBLE_FONT_NORMAL_VALUE_CLOCK;
        break;
      case UserSettings.BUBBLE_FONT_HUGE:
        fontSize = UserSettings.BUBBLE_FONT_HUGE_VALUE;
        fontSizeClock = UserSettings.BUBBLE_FONT_HUGE_VALUE_CLOCK;
        break;
      case UserSettings.BUBBLE_FONT_SMALL:
        fontSize = UserSettings.BUBBLE_FONT_SMALL_VALUE;
        fontSizeClock = UserSettings.BUBBLE_FONT_SMALL_VALUE_CLOCK;
        break;
      case UserSettings.BUBBLE_FONT_TINY:
        fontSize = UserSettings.BUBBLE_FONT_TINY_VALUE;
        fontSizeClock = UserSettings.BUBBLE_FONT_TINY_VALUE_CLOCK;
        break;
      case UserSettings.BUBBLE_FONT_LARGE:
        fontSize = UserSettings.BUBBLE_FONT_LARGE_VALUE;
        fontSizeClock = UserSettings.BUBBLE_FONT_LARGE_VALUE_CLOCK;
        break;
    }

    bodyPaint = initTextPaint();
    bodyPaint.setTypeface(FontController.loadTypeface(context, "regular"));
    bodyPaint.setTextSize(sp(fontSize));
    bodyPaint.setColor(0xff000000);

    clockOutPaint = initTextPaint();
    clockOutPaint.setTypeface(FontController.loadTypeface(context, "regular"));
    clockOutPaint.setTextSize(sp(fontSizeClock));
    clockOutPaint.setColor(0xff70B15C);

    senderPaintBase = initTextPaint();
    senderPaintBase.setTypeface(FontController.loadTypeface(context, "regular"));
    senderPaintBase.setTextSize(sp(fontSize));
    senderPaintBase.setColor(0xff000000);

    forwardingPaintBase = initTextPaint();
    forwardingPaintBase.setTypeface(FontController.loadTypeface(context, "regular"));
    forwardingPaintBase.setTextSize(sp(fontSize));
    forwardingPaintBase.setColor(0xff000000);

    Drawable inBubble = context.getResources().getDrawable(R.drawable.st_bubble_in);
    inBubblePadding = new Rect();
    inBubble.getPadding(inBubblePadding);

    Drawable outBubble = context.getResources().getDrawable(R.drawable.st_bubble_out);
    outBubblePadding = new Rect();
    outBubble.getPadding(outBubblePadding);

    isLoaded = true;
  }
Exemple #27
0
 public void draw(Canvas paramCanvas) {
   boolean bool = DialogToastListActivity.f;
   super.draw(paramCanvas);
   Paint localPaint = new Paint();
   localPaint.setAntiAlias(true);
   RectF localRectF = new RectF(getBounds());
   if (this.d != null) {
     int i = (int) (13.333333F * j4.a(App.Mb.getApplicationContext()).d);
     int j = (int) (2.0F * i);
     Path localPath = new Path();
     localPath.moveTo(localRectF.left, localRectF.bottom - j);
     localPath.lineTo(localRectF.right, localRectF.bottom - j);
     localPath.lineTo(localRectF.right, localRectF.bottom - this.a);
     localPath.arcTo(
         new RectF(
             localRectF.right - 2.0F * this.a,
             localRectF.bottom - 2.0F * this.a,
             localRectF.right,
             localRectF.bottom),
         0.0F,
         90.0F);
     localPath.lineTo(localRectF.left + this.a, localRectF.bottom);
     localPath.arcTo(
         new RectF(
             localRectF.left,
             localRectF.bottom - 2.0F * this.a,
             localRectF.left + 2.0F * this.a,
             localRectF.bottom),
         90.0F,
         90.0F);
     localPath.lineTo(localRectF.left, localRectF.bottom - j);
     localPaint.setStyle(Paint.Style.FILL);
     if (this.b == 16842919) {
       localPaint.setColor(-1712291840);
       if (!bool) ;
     } else {
       localPaint.setColor(1073741824);
     }
     paramCanvas.drawPath(localPath, localPaint);
     TextPaint localTextPaint = new TextPaint();
     localTextPaint.setAntiAlias(true);
     localTextPaint.setColor(-1);
     localTextPaint.setTextSize(i);
     localTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
     localTextPaint.setTextAlign(Paint.Align.CENTER);
     paramCanvas.drawText(
         TextUtils.ellipsize(
                 this.d, localTextPaint, localRectF.width() - this.a, TextUtils.TruncateAt.END)
             .toString(),
         localRectF.left + localRectF.width() / 2.0F,
         localRectF.bottom - (j - i) / 2,
         localTextPaint);
   }
   localPaint.setStyle(Paint.Style.STROKE);
   localPaint.setStrokeJoin(Paint.Join.ROUND);
   localPaint.setStrokeCap(Paint.Cap.ROUND);
   localRectF.top = (1.0F + localRectF.top);
   localRectF.bottom = (1.0F + localRectF.bottom);
   localPaint.setStrokeWidth(1.5F);
   localPaint.setColor(-1711276033);
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
   localRectF.top -= 1.0F;
   localRectF.bottom -= 1.0F;
   if (this.b == 16842919) {
     localPaint.setColor(-1015808);
     if (!bool) ;
   } else {
     localPaint.setColor(1711276032);
   }
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
   localPaint.setStrokeWidth(1.0F);
   localPaint.setAntiAlias(false);
   if (this.b == 16842919) {
     localPaint.setColor(871399424);
     if (!bool) ;
   } else {
     localPaint.setColor(855638016);
   }
   paramCanvas.drawRoundRect(localRectF, this.a, this.a, localPaint);
 }
Exemple #28
0
  /**
   * 描述:TODO.
   *
   * @version v1.0
   * @param canvas the canvas
   * @see View#onDraw(Canvas)
   * @author: amsoft.cn
   * @date:2013-6-17 上午9:04:51
   */
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    canvas.getClipBounds(mRect);
    int top = mRect.top;
    int left = mRect.left;
    int width = mRect.width();
    int height = mRect.height();
    if (mRenderer.isInScroll()) {
      top = 0;
      left = 0;
      width = getMeasuredWidth();
      height = getMeasuredHeight();
    }
    mChart.draw(canvas, left, top, width, height, mPaint);

    if (mRenderer != null && mRenderer.isZoomEnabled() && mRenderer.isZoomButtonsVisible()) {
      mPaint.setColor(ZOOM_BUTTONS_COLOR);

      int bitmapWidth = zoomInImage.getWidth();
      int bitmapHeight = zoomInImage.getHeight();

      int rectMargin = 10;
      int topPadding = 15;
      int leftPadding = 20;
      int leftRect = width - bitmapWidth * 3 - rectMargin - 4 * leftPadding;
      int topRect = height - bitmapHeight - rectMargin - 2 * topPadding;
      int rightRect = width - rectMargin;
      int bottomRect = height - rectMargin;

      mZoomR.set(leftRect, topRect, rightRect, bottomRect);
      canvas.drawRoundRect(mZoomR, bitmapWidth / 2, bitmapWidth / 2, mPaint);
      // 画图标
      float buttonY = height - bitmapHeight - rectMargin - topPadding;
      canvas.drawBitmap(
          zoomInImage, width - rectMargin - bitmapWidth * 3 - 3 * leftPadding, buttonY, null);
      canvas.drawBitmap(
          zoomOutImage, width - rectMargin - bitmapWidth * 2 - 2 * leftPadding, buttonY, null);
      canvas.drawBitmap(
          fitZoomImage, width - rectMargin - bitmapWidth - leftPadding, buttonY, null);
    }

    if (mChart instanceof XYChart) {
      XYMultipleSeriesRenderer mXYMultipleSeriesRenderer = ((XYChart) mChart).getRenderer();

      if (mXYMultipleSeriesRenderer.isScaleLineEnabled()) {
        oldX = ((TouchHandler) mTouchHandler).getOldX();
        int scaleTopPadding = 50;
        // 从坐标轴往下
        int scaleBottomPadding = 20;
        int explainTextSize1 = mXYMultipleSeriesRenderer.getExplainTextSize1();
        int explainTextSize2 = mXYMultipleSeriesRenderer.getExplainTextSize2();
        int scaleCircleRadius = mXYMultipleSeriesRenderer.getScaleCircleRadius();
        // 按分辨率转换
        scaleTopPadding = AbViewUtil.scale(mContext, scaleTopPadding);
        scaleBottomPadding = AbViewUtil.scale(mContext, scaleBottomPadding);

        // Y轴位置
        int bottomY = 0;
        int topY = 0;
        if (mChart instanceof XYChart) {
          Rect mScreenR = ((XYChart) mChart).getScreenR();
          bottomY = mScreenR.bottom;
          topY = mScreenR.top;
          if (oldX == 0) {
            oldX = mScreenR.right;
          }
        } else {
        }

        // 标尺线与拖手
        mPaint.setColor(mXYMultipleSeriesRenderer.getScaleLineColor());
        canvas.drawLine(oldX, scaleTopPadding, oldX, bottomY + scaleBottomPadding, mPaint);
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(ZOOM_BUTTONS_COLOR);
        canvas.drawCircle(
            oldX, bottomY + scaleBottomPadding + scaleCircleRadius, scaleCircleRadius, mPaint);

        // 判断挂到哪个点上
        if (mChart instanceof XYChart) {
          List<Float> mPoints = null;
          List<Double> mValues = null;
          List<String> mExplains = null;
          float minValue = -1;
          int minIndex = -1;
          // 要显示的文本
          String showValue = "";
          String showExplain = "";
          Map<Integer, List<Float>> points = ((XYChart) mChart).getPoints();
          Map<Integer, List<Double>> values = ((XYChart) mChart).getValues();
          Map<Integer, List<String>> explains = ((XYChart) mChart).getExplains();
          for (Entry<Integer, List<Float>> value : points.entrySet()) {
            int index = value.getKey();
            mPoints = value.getValue();
            mValues = values.get(value.getKey());
            mExplains = explains.get(value.getKey());

            // 判断距离在2范围的点的索引
            minValue = 1000;
            minIndex = -1;

            for (int i = 0; i < mPoints.size(); i += 2) {
              Float f = mPoints.get(i);
              if (Math.abs(f - oldX) < minValue) {
                minValue = Math.abs(f - oldX);
                minIndex = i;
              }
            }
            if (index == 0) {
              showValue = String.valueOf((double) mValues.get(minIndex + 1)).replace(".0", "");
              String showExplainT = mExplains.get(minIndex / 2);
              if (showExplainT != null && !"".equals(showExplainT.trim())) {
                showExplain = mExplains.get(minIndex / 2);
              }
            } else {
              showValue =
                  showValue
                      + "/"
                      + String.valueOf((double) mValues.get(minIndex + 1)).replace(".0", "");
              String showExplainT = mExplains.get(minIndex / 2);
              if (showExplainT != null && !"".equals(showExplainT.trim())) {
                if (showExplain != null && !"".equals(showExplain.trim())) {
                  showExplain = showExplain + "/" + mExplains.get(minIndex / 2);
                } else {
                  showExplain = mExplains.get(minIndex / 2);
                }
              }
            }
          }
          if (minValue < 5) {

            boolean showRect = false;
            if (mXYMultipleSeriesRenderer.isDisplayValue0()) {
              showRect = true;
            } else {
              if ("0".equals(showValue) || "0/0".equals(showValue)) {
                showRect = false;
              } else {
                showRect = true;
              }
            }
            if (showRect) {
              // 画框框和点

              // 获取文本的高度
              TextPaint mTextPaint1 = new TextPaint(Paint.ANTI_ALIAS_FLAG);
              mTextPaint1.setColor(Color.WHITE);
              mTextPaint1.setTypeface(Typeface.DEFAULT);
              mTextPaint1.setTextSize(explainTextSize1);

              TextPaint mTextPaint2 = new TextPaint(Paint.ANTI_ALIAS_FLAG);
              mTextPaint2.setColor(Color.WHITE);
              mTextPaint2.setTypeface(Typeface.DEFAULT);
              mTextPaint2.setTextSize(explainTextSize2);

              // 行高
              float hSize1 = AbGraphicUtil.getDesiredHeight(mTextPaint1);

              // 行高
              float hSize2 = AbGraphicUtil.getDesiredHeight(mTextPaint2);

              int textPadding = 8;
              textPadding = AbViewUtil.scale(mContext, textPadding);

              // 设置个新的长方形
              // 判断文字是否超出设置的框框
              int row1 =
                  AbGraphicUtil.getDrawRowCount(
                      showValue, mXYMultipleSeriesRenderer.getScaleRectWidth() - 10, mTextPaint1);
              int row2 =
                  AbGraphicUtil.getDrawRowCount(
                      showExplain, mXYMultipleSeriesRenderer.getScaleRectWidth() - 10, mTextPaint2);
              RectF mRectF = null;
              int textHeight = (int) (row1 * hSize1 + row2 * hSize2 + textPadding);

              // 提示框的宽度和高度
              int realScaleRectWidth = mXYMultipleSeriesRenderer.getScaleRectWidth();
              int realScaleRectHeight = mXYMultipleSeriesRenderer.getScaleRectHeight();

              // 画圆角矩形  //充满
              mPaint.setStyle(Paint.Style.FILL);
              mPaint.setColor(mXYMultipleSeriesRenderer.getScaleRectColor());
              // 设置画笔的锯齿效果
              mPaint.setAntiAlias(true);

              int mRectLeft = (int) (double) mPoints.get(minIndex);
              int mRectTop = (int) (double) mPoints.get(minIndex + 1);
              int mRectRight = mRectLeft + realScaleRectWidth;
              int mRectBottom = mRectTop + realScaleRectHeight;

              if (textHeight > realScaleRectHeight) {
                realScaleRectHeight = textHeight;
                mRectBottom = mRectTop + realScaleRectHeight;
              }

              // 判断是否会超出屏幕
              if (mRectRight > width) {
                // 超出了
                mRectLeft =
                    (int) (double) mPoints.get(minIndex)
                        - 5
                        - mXYMultipleSeriesRenderer.getScaleRectWidth();
                mRectRight = (int) (double) mPoints.get(minIndex) - 5;
              }
              if (mRectBottom > bottomY) {
                // 超出了
                mRectTop = (int) (double) mPoints.get(minIndex + 1) - 5 - realScaleRectHeight;
                mRectBottom = (int) (double) mPoints.get(minIndex + 1) - 5;

                // 是否超出Y=0的位置的
                if (mRectTop < topY) {
                  mRectTop = mRectTop + realScaleRectHeight / 2;
                  mRectBottom = mRectBottom + realScaleRectHeight / 2;
                }
              }

              mRectF = new RectF(mRectLeft, mRectTop, mRectRight, mRectBottom);
              // 第二个参数是x半径,第三个参数是y半径
              canvas.drawRoundRect(mRectF, 5, 5, mPaint);

              AbGraphicUtil.drawText(
                  canvas,
                  showValue,
                  mXYMultipleSeriesRenderer.getScaleRectWidth(),
                  mTextPaint1,
                  mRectLeft + textPadding,
                  mRectTop + textPadding);
              AbGraphicUtil.drawText(
                  canvas,
                  showExplain,
                  mXYMultipleSeriesRenderer.getScaleRectWidth(),
                  mTextPaint2,
                  mRectLeft + textPadding,
                  (int) (mRectTop + textPadding + row1 * hSize1));
            }
          }
        }
      }
    }
  }
  public Bitmap update(Context context, boolean preview, int watchType) {

    TextPaint paintSmall = new TextPaint();
    paintSmall.setColor(Color.BLACK);
    paintSmall.setTextSize(FontCache.instance(context).Small.size);
    paintSmall.setTypeface(FontCache.instance(context).Small.face);

    TextPaint paintSmallOutline = new TextPaint();
    paintSmallOutline.setColor(Color.WHITE);
    paintSmallOutline.setTextSize(FontCache.instance(context).Small.size);
    paintSmallOutline.setTypeface(FontCache.instance(context).Small.face);

    TextPaint paintLarge = new TextPaint();
    paintLarge.setColor(Color.BLACK);
    paintLarge.setTextSize(FontCache.instance(context).Large.size);
    paintLarge.setTypeface(FontCache.instance(context).Large.face);

    TextPaint paintLargeOutline = new TextPaint();
    paintLargeOutline.setColor(Color.WHITE);
    paintLargeOutline.setTextSize(FontCache.instance(context).Large.size);
    paintLargeOutline.setTypeface(FontCache.instance(context).Large.face);

    MediaControl.TrackInfo lastTrack = MediaControl.getLastTrack();

    if (watchType == WatchType.DIGITAL) {

      Bitmap bitmap = Bitmap.createBitmap(96, 96, Bitmap.Config.RGB_565);
      Canvas canvas = new Canvas(bitmap);
      canvas.drawColor(Color.WHITE);

      if (lastTrack.isEmpty()) {
        canvas.drawBitmap(Utils.getBitmap(context, "media_player_idle.png"), 0, 0, null);
      } else {
        canvas.drawBitmap(Utils.getBitmap(context, "media_player.png"), 0, 0, null);

        StringBuilder lowerText = new StringBuilder();
        if (!lastTrack.artist.equals("")) {
          lowerText.append(lastTrack.artist);
        }
        if (!lastTrack.album.equals("")) {
          if (lowerText.length() > 0) lowerText.append("\n\n");
          lowerText.append(lastTrack.album);
        }

        Utils.autoText(
            context,
            canvas,
            lastTrack.track,
            0,
            8,
            96,
            35,
            Layout.Alignment.ALIGN_CENTER,
            Color.BLACK);
        Utils.autoText(
            context,
            canvas,
            lowerText.toString(),
            0,
            54,
            96,
            35,
            Layout.Alignment.ALIGN_CENTER,
            Color.BLACK);
      }
      drawDigitalAppSwitchIcon(context, canvas, preview);

      return bitmap;
    } else if (watchType == WatchType.ANALOG) {
      Bitmap bitmap = Bitmap.createBitmap(80, 32, Bitmap.Config.RGB_565);
      Canvas canvas = new Canvas(bitmap);
      canvas.drawColor(Color.WHITE);

      if (lastTrack.isEmpty()) {
        canvas.drawBitmap(Utils.getBitmap(context, "media_player_idle_oled.png"), 0, 0, null);
      } else {
        canvas.drawBitmap(Utils.getBitmap(context, "media_player_oled.png"), 0, 0, null);

        TextPaint tp = null;
        if (paintLarge.measureText(lastTrack.track) < 75) {
          tp = paintLarge;
        } else {
          tp = paintSmall;
        }

        canvas.save();
        StaticLayout layout =
            new StaticLayout(
                lastTrack.track, tp, 75, Layout.Alignment.ALIGN_CENTER, 1.2f, 0, false);
        int height = layout.getHeight();
        int textY = 8 - (height / 2);
        if (textY < 0) {
          textY = 0;
        }
        canvas.translate(0, textY); // position the text
        canvas.clipRect(0, 0, 75, 16);
        layout.draw(canvas);
        canvas.restore();

        canvas.save();
        StringBuilder lowerText = new StringBuilder();
        if (!lastTrack.artist.equals("")) {
          lowerText.append(lastTrack.artist);
        }
        if (!lastTrack.album.equals("")) {
          if (lowerText.length() > 0) lowerText.append("\n\n");
          lowerText.append(lastTrack.album);
        }

        if (paintLarge.measureText(lowerText.toString()) < 75) {
          tp = paintLarge;
        } else {
          tp = paintSmall;
        }

        layout =
            new StaticLayout(
                lowerText.toString(), tp, 75, Layout.Alignment.ALIGN_CENTER, 1.0f, 0, false);
        height = layout.getHeight();
        textY = 24 - (height / 2);
        if (textY < 16) {
          textY = 16;
        }
        canvas.translate(0, textY); // position the text
        canvas.clipRect(0, 0, 75, 16);
        layout.draw(canvas);
        canvas.restore();
      }

      return bitmap;
    }

    return null;
  }
 static {
   mTextPaint = new TextPaint();
   mTextPaint.setTypeface(Typeface.SANS_SERIF);
   mTextPaint.setTextAlign(Paint.Align.CENTER);
   mTextPaint.setAntiAlias(true);
 }