コード例 #1
0
ファイル: VEC_Element_TextOut.java プロジェクト: Utyff/pMetro
  @Override
  public void Draw(Canvas canvas, Paint paint) {

    Typeface tf = paint.getTypeface();
    paint.setUnderlineText(underline);
    paint.setTypeface(Typeface.create(tf, style));
    paint.setTextSize(size);
    paint.setStyle(Paint.Style.FILL);

    if (v.currBrushColor != -1) { // draw background rect
      int clr = paint.getColor();
      paint.setColor(v.currBrushColor + v.Opaque);
      canvas.drawRect(
          x - 1,
          y,
          x + paint.measureText(text) + 1,
          y - paint.ascent() + paint.descent() / 2,
          paint);
      paint.setColor(clr);
    }

    canvas.drawText(text, x, y - paint.ascent(), paint);

    paint.setStyle(Paint.Style.STROKE);
    paint.setUnderlineText(false);
    paint.setTypeface(tf);
  }
コード例 #2
0
    public NormalBatteryMeterDrawable(Resources res, boolean horizontal) {
      super();
      mHorizontal = horizontal;
      mDisposed = false;

      mFramePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mFramePaint.setColor(res.getColor(R.color.batterymeter_frame_color));
      mFramePaint.setDither(true);
      mFramePaint.setStrokeWidth(0);
      mFramePaint.setStyle(Paint.Style.FILL_AND_STROKE);
      mFramePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));

      mBatteryPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mBatteryPaint.setDither(true);
      mBatteryPaint.setStrokeWidth(0);
      mBatteryPaint.setStyle(Paint.Style.FILL_AND_STROKE);

      mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mTextPaint.setColor(res.getColor(R.color.batterymeter_bolt_color));
      Typeface font = Typeface.create("sans-serif-condensed", Typeface.BOLD);
      mTextPaint.setTypeface(font);
      mTextPaint.setTextAlign(Paint.Align.CENTER);

      mWarningTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mWarningTextPaint.setColor(mColors[1]);
      font = Typeface.create("sans-serif", Typeface.BOLD);
      mWarningTextPaint.setTypeface(font);
      mWarningTextPaint.setTextAlign(Paint.Align.CENTER);

      mBoltPaint = new Paint();
      mBoltPaint.setAntiAlias(true);
      mBoltPaint.setColor(res.getColor(R.color.batterymeter_bolt_color));
      mBoltPoints = loadBoltPoints(res);
    }
コード例 #3
0
ファイル: MonthView.java プロジェクト: Dedy54/CareGive
  /**
   * Sets up the text and style properties for painting. Override this if you want to use a
   * different paint.
   */
  protected void initView() {
    mMonthTitlePaint = new Paint();
    mMonthTitlePaint.setFakeBoldText(true);
    mMonthTitlePaint.setAntiAlias(true);
    mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE);
    mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD));
    mMonthTitlePaint.setColor(mDayTextColor);
    mMonthTitlePaint.setTextAlign(Align.CENTER);
    mMonthTitlePaint.setStyle(Style.FILL);

    mSelectedCirclePaint = new Paint();
    mSelectedCirclePaint.setFakeBoldText(true);
    mSelectedCirclePaint.setAntiAlias(true);
    mSelectedCirclePaint.setColor(mTodayNumberColor);
    mSelectedCirclePaint.setTextAlign(Align.CENTER);
    mSelectedCirclePaint.setStyle(Style.FILL);
    mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA);

    mMonthDayLabelPaint = new Paint();
    mMonthDayLabelPaint.setAntiAlias(true);
    mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE);
    mMonthDayLabelPaint.setColor(mMonthDayTextColor);
    mMonthDayLabelPaint.setTypeface(TypefaceHelper.get(getContext(), "Roboto-Medium"));
    mMonthDayLabelPaint.setStyle(Style.FILL);
    mMonthDayLabelPaint.setTextAlign(Align.CENTER);
    mMonthDayLabelPaint.setFakeBoldText(true);

    mMonthNumPaint = new Paint();
    mMonthNumPaint.setAntiAlias(true);
    mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE);
    mMonthNumPaint.setStyle(Style.FILL);
    mMonthNumPaint.setTextAlign(Align.CENTER);
    mMonthNumPaint.setFakeBoldText(false);
  }
コード例 #4
0
  private void init(Context context, CreditsParams p) {
    Paint paintPerson = new Paint();
    paintPerson.setAntiAlias(true);
    paintPerson.setStrokeWidth(5);
    paintPerson.setStrokeCap(Paint.Cap.ROUND);
    paintPerson.setTextSize(p.getTextSizeDefault());
    paintPerson.setTypeface(p.getTypefaceDefault());
    paintPerson.setColor(p.getColorDefault());
    paintPerson.setTextAlign(Paint.Align.CENTER);

    Person.setPaint(paintPerson);
    Person.setSpacings(p.getSpacingBeforeDefault(), p.getSpacingAfterDefault());

    Paint paintCategory = new Paint();
    paintCategory.setAntiAlias(true);
    paintCategory.setStrokeWidth(5);
    paintCategory.setStrokeCap(Paint.Cap.ROUND);
    paintCategory.setTextSize(p.getTextSizeCategory());
    paintCategory.setTypeface(p.getTypefaceCategory());
    paintCategory.setColor(p.getColorCategory());
    paintCategory.setTextAlign(Paint.Align.CENTER);

    Category.setPaint(paintCategory);
    Category.setSpacings(p.getSpacingBeforeCategory(), p.getSpacingAfterCategory());

    credits.add(new Person(context.getString(p.getAppNameRes())));
    credits.add(new Category(context.getString(p.getAppVersionRes())));
    loadFromResources(credits, p.getArrayCreditsRes());

    mBackground = BitmapFactory.decodeResource(getResources(), p.getBitmapBackgroundRes());
    mBackgroundLandscape =
        BitmapFactory.decodeResource(getResources(), p.getBitmapBackgroundLandscapeRes());
  }
コード例 #5
0
  public SimpleGraphView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    final Resources res = context.getResources();

    bitmapPaint = new Paint();
    bitmapPaint.setFilterBitmap(true);

    final Bitmap backgroundBitmap = BitmapFactory.decodeResource(res, R.drawable.test_box_small);
    width = backgroundBitmap.getWidth();
    height = backgroundBitmap.getHeight();
    genBackgroundBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(genBackgroundBitmap);
    // canvas.drawBitmap(backgroundBitmap, 0, 0, bitmapPaint);

    if (!isInEditMode()) backgroundBitmap.recycle();

    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setTextSize(coordFH(15, relH));
    paint.setColor(Color.parseColor("#C8ffffff"));
    paint.setTextAlign(Align.LEFT);
    canvas.drawText("0", coordFW(88, relW), coordFH(220, relH), paint);
    paint.setTextAlign(Align.RIGHT);
    canvas.drawText("8", coordFW(567, relW), coordFH(220, relH), paint);
    paint.setTextAlign(Align.CENTER);
    canvas.drawText("sec", coordFW(326, relW), coordFH(220, relH), paint);

    paint.setTextAlign(Align.LEFT);
    paint.setColor(Color.parseColor("#C800f940"));
    canvas.drawText(
        String.format("– %s", res.getString(R.string.test_mbps)),
        coordFW(9, relW),
        coordFH(110, relH),
        paint);
    paint.setTextAlign(Align.RIGHT);
    canvas.drawText("0", coordFW(72, relW), coordFH(220, relH), paint);
    canvas.drawText("100", coordFW(72, relW), coordFH(38, relH), paint);

    gridBitmap = BitmapFactory.decodeResource(res, R.drawable.test_grid);
    gridX = coordFW(55, relW);
    gridY = coordFH(16, relH);
    graphX = coordFW(80, relW);
    graphY = coordFH(16, relH);
    graphWidth = coordW(493, relW);
    graphHeight = coordH(183, relH);
    graphStrokeWidth = coordFW(4, relW);

    signalTextPaint = new Paint();
    signalTextPaint.setAntiAlias(true);
    signalTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
    signalTextPaint.setTextSize(coordFH(15, relH));
    signalTextPaint.setColor(Color.parseColor("#C8f8a000"));

    signalText = res.getString(R.string.test_dbm);
  }
コード例 #6
0
 private void setFontFace() {
   if (!isHighRes()) {
     tfTiny = getTypeface("6x12.ttf");
     fore.setTypeface(tfTiny);
   } else {
     tfStd = getTypeface("VeraMoBd.ttf");
     fore.setTypeface(tfStd);
   }
 }
コード例 #7
0
  /** 画下面的两个按钮 */
  public void drawBottomButton(Canvas canvas) {
    Paint paint = new Paint();
    paint.setTextAlign(Paint.Align.CENTER);
    paint.setTextSize(getResources().getDimension(R.dimen.pt_size));
    paint.setAntiAlias(true);
    paint.setTypeface(Typeface.MONOSPACE);
    // paint.setARGB(255, 189, 189, 189);
    paint.setColor(Color.GRAY);
    Paint p2 = new Paint();
    p2.setTextAlign(Paint.Align.CENTER);
    p2.setTextSize(getResources().getDimension(R.dimen.pt_size));
    p2.setAntiAlias(true);
    p2.setTypeface(Typeface.MONOSPACE);
    p2.setColor(Color.BLACK);
    canvas.drawLine(
        0,
        SetImagePasswordActivity.screenHeight / 10 * 8,
        SetImagePasswordActivity.screenWidth,
        SetImagePasswordActivity.screenHeight / 10 * 8,
        paint);
    canvas.drawLine(
        SetImagePasswordActivity.screenWidth / 2,
        SetImagePasswordActivity.screenHeight / 10 * 8,
        SetImagePasswordActivity.screenWidth / 2,
        SetImagePasswordActivity.screenHeight,
        paint);
    if (leftBtpress) {
      Log.e("tag", "drawleftBtbg");
      canvas.drawRect(leftRect, paint);
      //	canvas.drawRect(0,  SetImagePasswordActivity.screenHeight-90,
      // SetImagePasswordActivity.screenWidth/2, SetImagePasswordActivity.screenHeight, paint);
    }
    if (rightBtpress && rightBtClikable) {
      Log.e("tag", "drawrightBtbg");
      canvas.drawRect(rightRect, paint);
    }
    canvas.drawText(
        leftButtonText,
        SetImagePasswordActivity.screenWidth / 4,
        SetImagePasswordActivity.screenHeight / 10 * 9,
        p2);
    if (rightBtClikable) {

      canvas.drawText(
          rightButtonText,
          SetImagePasswordActivity.screenWidth / 4 * 3,
          SetImagePasswordActivity.screenHeight / 10 * 9,
          p2);
    } else {
      canvas.drawText(
          rightButtonText,
          SetImagePasswordActivity.screenWidth / 4 * 3,
          SetImagePasswordActivity.screenHeight / 10 * 9,
          paint);
    }
  }
コード例 #8
0
 private void initPainter() {
   digitPaint = new Paint();
   digitPaint.setAntiAlias(true);
   digitPaint.setTextSize(textSize);
   digitPaint.setColor(color);
   digitPaint.setTypeface(typeface);
   digitPaint.setTextAlign(Paint.Align.CENTER);
   textPaint = new TextPaint();
   textPaint.setAntiAlias(true);
   textPaint.setTextSize(textSize / 3);
   textPaint.setColor(color);
   textPaint.setTypeface(typeface);
   textPaint.setTextAlign(Paint.Align.CENTER);
 }
コード例 #9
0
    public CircleBatteryMeterDrawable(Resources res) {
      super();
      mDisposed = false;

      mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mTextPaint.setColor(res.getColor(R.color.status_bar_clock_color));
      Typeface font = Typeface.create("sans-serif-condensed", Typeface.NORMAL);
      mTextPaint.setTypeface(font);
      mTextPaint.setTextAlign(Paint.Align.CENTER);

      mFrontPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mFrontPaint.setStrokeCap(Paint.Cap.BUTT);
      mFrontPaint.setDither(true);
      mFrontPaint.setStrokeWidth(0);
      mFrontPaint.setStyle(Paint.Style.STROKE);
      mFrontPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));

      mBackPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
      mBackPaint.setColor(res.getColor(R.color.batterymeter_frame_color));
      mBackPaint.setStrokeCap(Paint.Cap.BUTT);
      mBackPaint.setDither(true);
      mBackPaint.setStrokeWidth(0);
      mBackPaint.setStyle(Paint.Style.STROKE);
      mBackPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.XOR));

      mBoltPaint = new Paint();
      mBoltPaint.setAntiAlias(true);
      mBoltPaint.setColor(getColorForLevel(50));
      mBoltPoints = loadBoltPoints(res);
    }
コード例 #10
0
  /** 重写这个方法 */
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // 获取焦点改变背景颜色.
    int height = getHeight(); // 获取对应高度
    int width = getWidth(); // 获取对应宽度
    int singleHeight = height / b.length; // 获取每一个字母的高度

    for (int i = 0; i < b.length; i++) {
      paint.setColor(Color.rgb(43, 126, 245));
      // paint.setColor(Color.WHITE);
      paint.setTypeface(Typeface.DEFAULT_BOLD);
      paint.setAntiAlias(true);
      paint.setTextSize(20);
      // 选中的状�?
      if (i == choose) {
        paint.setColor(Color.parseColor("#2b7efe"));
        paint.setFakeBoldText(true);
      }
      // x坐标等于中间-字符串宽度的�?��.
      float xPos = width / 2 - paint.measureText(b[i]) / 2;
      float yPos = singleHeight * i + singleHeight;
      canvas.drawText(b[i], xPos, yPos, paint);
      paint.reset(); // 重置画笔
    }
  }
コード例 #11
0
ファイル: MyBringBack.java プロジェクト: ajithkm/Android_Apps
  @Override
  protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    canvas.drawColor(Color.BLACK);

    Paint textPaint = new Paint();
    textPaint.setARGB(50, 254, 100, 45);
    textPaint.setTextAlign(Align.CENTER);
    textPaint.setTextSize(50);
    textPaint.setTypeface(font);
    canvas.drawText("Ajith is ..", canvas.getWidth() / 2, 200, textPaint);

    canvas.drawBitmap(star, (canvas.getWidth() / 2), y, null);
    if (y < canvas.getHeight()) {
      y += 10;
    } else {
      y = 0;
    }
    Rect middlRect = new Rect();
    middlRect.set(0, 400, canvas.getWidth(), 550);
    Paint ourBlue = new Paint();
    ourBlue.setColor(Color.BLUE);
    canvas.drawRect(middlRect, ourBlue);
    invalidate();
  }
コード例 #12
0
  public SliderDrawView(Context context, AttributeSet attrs) {
    super(context, attrs);

    measurePaint.setAntiAlias(true);
    measurePaint.setColor(Color.DKGRAY);
    measurePaint.setStrokeWidth(3f);
    measurePaint.setStyle(Paint.Style.STROKE);

    infoRectPaintFill.setAntiAlias(true);
    infoRectPaintFill.setColor(Color.BLUE);
    infoRectPaintFill.setAlpha(80);
    infoRectPaintFill.setStyle(Paint.Style.FILL);
    infoRectPaintStroke.setAntiAlias(true);
    infoRectPaintStroke.setStrokeWidth(1.5f);
    infoRectPaintStroke.setColor(Color.BLUE);
    infoRectPaintStroke.setStyle(Paint.Style.STROKE);

    measureTextPaint.setAntiAlias(true);
    int pixel =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics());
    measureTextPaint.setTextSize(pixel);
    measureTextPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));

    distanceString =
        context.getString(
            R.string.distance); // context.getResources().getString(R.string.distance);
  }
コード例 #13
0
 public ArtifactDrawable(Context context, Kind kind, String text) {
   this.context = context;
   if (kind == Kind.IMAGE) {
     this.kind = Kind.OPERATION;
     this.text = "\u273f";
   } else {
     this.kind = kind;
     this.text = text;
   }
   if (kind == Kind.MODULE
       || kind == Kind.OPERATION
       || kind == Kind.SOUND
       || kind == Kind.CONTINUOUS_OPERATION
       || kind == Kind.IMAGE) {
     rect = new RectF();
   }
   if (kind == Kind.PROPERTY || kind == Kind.TUTORIAL || kind == Kind.SOUND) {
     path = new Path();
   }
   if (kind == Kind.CLASSIFIER) {
     paint.setTypeface(Typeface.DEFAULT_BOLD);
   }
   paint.setTextAlign(Paint.Align.CENTER);
   paint.setAntiAlias(true);
   setEnabled(true);
 }
コード例 #14
0
ファイル: Marker.java プロジェクト: XiaoYuQin/osmdroid
  /**
   * Sets the icon for the marker. Can be changed at any time.
   *
   * @param icon if null, the default osmdroid marker is used.
   */
  public void setIcon(Drawable icon) {
    if (ENABLE_TEXT_LABELS_WHEN_NO_IMAGE
        && icon == null
        && this.mTitle != null
        && this.mTitle.length() > 0) {
      Paint background = new Paint();
      background.setColor(mTextLabelBackgroundColor);

      Paint p = new Paint();
      p.setTextSize(mTextLabelFontSize);
      p.setColor(mTextLabelForegroundColor);

      p.setAntiAlias(true);
      p.setTypeface(Typeface.DEFAULT_BOLD);
      p.setTextAlign(Paint.Align.LEFT);
      int width = (int) (p.measureText(getTitle()) + 0.5f);
      float baseline = (int) (-p.ascent() + 0.5f);
      int height = (int) (baseline + p.descent() + 0.5f);
      Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
      Canvas c = new Canvas(image);
      c.drawPaint(background);
      c.drawText(getTitle(), 0, baseline, p);

      mIcon = new BitmapDrawable(resource, image);
    }
    if (!ENABLE_TEXT_LABELS_WHEN_NO_IMAGE && icon != null) this.mIcon = icon;
    // there's still an edge case here, title label no defined, icon is null and textlabel is
    // enabled
    if (this.mIcon == null) mIcon = mDefaultIcon;
  }
コード例 #15
0
	/**
	 * @param cluster        a cluster to be rendered for this marker.
	 * @param markerIconBmps icon set for marker.
	 * @param screenDensity  screen density.
	 */
	public ClusterMarker(GeoClusterer.GeoCluster cluster, List<MarkerBitmap> markerIconBmps, float screenDensity) {
		this.cluster = cluster;
		this.markerIconBmps = markerIconBmps;
		center = this.cluster.getLocation();
		geoItems = this.cluster.getItemsOfCluster();
		this.screenDensity = screenDensity;
		paint = new Paint();
		paint.setStyle(Paint.Style.STROKE);
		paint.setAntiAlias(true);
		paint.setColor(Color.rgb(220, 220, 80));
		paint.setTextSize(TXTSIZE * this.screenDensity);
		paint.setTextAlign(Paint.Align.CENTER);
		paint.setTypeface(Typeface.DEFAULT_BOLD);
		Paint.FontMetrics metrics = paint.getFontMetrics();
		txtHeightOffset = (int) ((metrics.bottom + metrics.ascent) / 2.0f);
		/* check if we have selected item in cluster */
		selItem = 0;
		for (int i = 0; i < geoItems.size(); i++) {
			if (geoItems.get(i).isSelected()) {
				selItem = i;
				selected = true;
			}
		}
		setMarkerBitmap();
	}
コード例 #16
0
  private void drawText(byte[] packetData) {
    try {
      int x = xCoordinateMap(myConvertByteArrToInt_bigend(packetData, 4));
      int y = xCoordinateMap(myConvertByteArrToInt_bigend(packetData, 8));
      int fontFaceNum = myConvertByteArrToInt_bigend(packetData, 12);
      int fontSizeNum = myConvertByteArrToInt_bigend(packetData, 16);
      int penColorNum = myConvertByteArrToInt_bigend(packetData, 20);
      int strByteLen = myConvertByteArrToInt_bigend(packetData, 24);
      // String str = myConvertByteArrToStr_bigend(packetData, 30,
      // strByteLen);
      String str = myConvertByteArrToStr_bigend(packetData, 28, strByteLen);

      Paint paint = getAPaint();
      paint.setStrokeWidth(1);
      paint.setTypeface(fontFaceMap.get(fontFaceNum));
      paint.setTextSize(fontSizeMap.get(fontSizeNum)); // 单位是像素px
      paint.setColor(penColorMap.get(penColorNum));

      FontMetrics fm = paint.getFontMetrics();
      int textHeight = (int) Math.ceil(fm.descent - fm.top);
      y += textHeight;

      HistoryItem item = new HistoryItem(HistoryItem.TYPE_TEXT, paint, null, str, new Point(x, y));
      undoPathList.add(item);

      mCacheCanvas.drawText(str, x, y, paint);

      handler.sendEmptyMessage(CustomDrawViewCH_INVALIDATE);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #17
0
ファイル: SideBar.java プロジェクト: qinge/mail
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // 获取焦点改变背景色
    int height = getHeight();
    int width = getWidth();
    int singleHeight = height / b.length; // 获取每一个字母的高度

    for (int i = 0; i < b.length; i++) {
      paint.setColor(Color.rgb(33, 65, 98));
      paint.setTypeface(Typeface.DEFAULT_BOLD);
      paint.setAntiAlias(true);
      paint.setTextSize(20 * (int) (displayMetrics != null ? (displayMetrics.density / 1.5) : 1));

      // 选中的状态
      if (i == choose) {
        paint.setColor(Color.parseColor("#3399ff"));
        paint.setFakeBoldText(true);
      }
      // x 坐标等于中间 - 字符串宽度的一半
      float xPos = width / 2 - paint.measureText(b[i]) / 2;
      float yPos = singleHeight * i + singleHeight;
      canvas.drawText(b[i], xPos, yPos, paint);
      paint.reset();
    }
  }
コード例 #18
0
  /** 重写这个方法 */
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // 获取焦点改变背景颜色.
    int height = getHeight(); // 获取对应高度
    int width = getWidth(); // 获取对应宽度
    int singleHeight = height / b.length; // 获取每一个字母的高度

    for (int i = 0; i < b.length; i++) {
      paint.setColor(Color.parseColor("#9da0a4"));
      paint.setTypeface(Typeface.DEFAULT_BOLD);
      paint.setAntiAlias(true);
      //	paint.setTextSize(PixelUtil.sp2px(12));
      paint.setTextSize(25);

      // 选中的状态
      if (i == choose) {
        paint.setColor(Color.parseColor("#3399ff"));
        paint.setFakeBoldText(true);
      }
      // x坐标等于中间-字符串宽度的一半.
      float xPos = width / 2 - paint.measureText(b[i]) / 2;
      float yPos = singleHeight * i + singleHeight;
      canvas.drawText(b[i], xPos, yPos, paint);
      paint.reset(); // 重置画笔
    }
  }
コード例 #19
0
  /**
   * Create a skeleton FontMap for the requested font. This will allow the developer to query text
   * length, and height. Creation of models and textures is done later during the draw cycle.
   */
  public GLFontMap generateFontMap(
      final Typeface _typeface, final int _size, final String _charsToMap, int _spacing) {
    final Paint paint = new Paint();
    paint.setTypeface(_typeface);
    paint.setTextSize((float) _size);

    final int length = _charsToMap.length();
    float increment = 0;
    final char[] c = new char[1];
    final Glyph[] glyphs = new GLGlyph[length];

    for (int i = 0; i < length; i++) {
      c[0] = _charsToMap.charAt(i);
      final float start = increment + (i * _spacing);
      final float advance = paint.measureText(c, 0, 1);

      glyphs[i] = new GLGlyph(c[0], start, advance);
      // System.out.println( "Index: " + i + " Glyph: " + glyphs[i] ) ;
      increment += advance;
    }

    // Create a GLFontMap and wrap it around a FontMap
    final Rect bounds = new Rect();
    paint.getTextBounds(_charsToMap, 0, length, bounds);
    return new GLFontMap(new FontMap(glyphs, null, bounds.height()));
  }
コード例 #20
0
ファイル: FPSView.java プロジェクト: avgusti/Snakopoly
 public FPSView(Context context) {
   super(context);
   mPaint = new Paint();
   mPaint.setAntiAlias(true);
   mPaint.setTextSize(30);
   mPaint.setTypeface(Typeface.SERIF);
 }
コード例 #21
0
 private Paint createTextPaint(int color, Typeface typeface) {
   Paint paint = new Paint();
   paint.setColor(color);
   paint.setTypeface(typeface);
   paint.setAntiAlias(true);
   return paint;
 }
コード例 #22
0
ファイル: ProgressWheel.java プロジェクト: svujjini/app
  /** Set the properties of the paints we're using to draw the progress wheel */
  private void setupPaints() {
    barPaint.setColor(barColor);
    barPaint.setAntiAlias(true);
    barPaint.setStyle(Style.STROKE);
    barPaint.setStrokeWidth(barWidth);

    rimPaint.setColor(rimColor);
    rimPaint.setAntiAlias(true);
    rimPaint.setStyle(Style.STROKE);
    rimPaint.setStrokeWidth(rimWidth);

    circlePaint.setColor(circleColor);
    circlePaint.setAntiAlias(true);
    circlePaint.setStyle(Style.FILL);

    textPaint.setColor(textColor);
    textPaint.setStyle(Style.FILL);
    textPaint.setAntiAlias(true);
    textPaint.setTextSize(textSize);
    if (!isInEditMode()) {
      textPaint.setTypeface(
          Typeface.createFromAsset(getContext().getAssets(), "fonts/Fontello.ttf"));
    }

    contourPaint.setColor(contourColor);
    contourPaint.setAntiAlias(true);
    contourPaint.setStyle(Style.STROKE);
    contourPaint.setStrokeWidth(contourSize);
  }
コード例 #23
0
ファイル: Hardware.java プロジェクト: apuder/TRS-80
 private void generateASCIIFont(AsyncTask task) {
   String ascii =
       " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
   Paint p = new Paint();
   p.setTextAlign(Align.CENTER);
   Typeface tf = Fonts.getTypeface(configuration.getModel());
   p.setTypeface(tf);
   p.setTextScaleX(1.0f);
   p.setColor(configuration.getCharacterColorAsRGB());
   p.setAntiAlias(true);
   setFontSize(p);
   int xPos = trsCharWidth / 2;
   int yPos = (int) ((trsCharHeight / 2) - ((p.descent() + p.ascent()) / 2));
   for (int i = 0; i < ascii.length(); i++) {
     if (task.isCancelled()) {
       return;
     }
     Bitmap b = Bitmap.createBitmap(trsCharWidth, trsCharHeight, Bitmap.Config.RGB_565);
     Canvas c = new Canvas(b);
     c.drawColor(configuration.getScreenColorAsRGB());
     c.drawText(ascii.substring(i, i + 1), xPos, yPos, p);
     font[i + 32] = b;
   }
   // Use space for all other characters
   for (int i = 0; i < font.length; i++) {
     if (font[i] == null) {
       font[i] = font[32];
     }
   }
 }
コード例 #24
0
 private Paint createTextPaint(int textColor) {
   Paint paint = new Paint();
   paint.setColor(textColor);
   paint.setTypeface(NORMAL_TYPEFACE);
   paint.setAntiAlias(true);
   return paint;
 }
コード例 #25
0
  @Override
  protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.onDraw(canvas);
    int height = getHeight();
    int width = getWidth();
    int interval = height / assort.length;

    for (int i = 0, length = assort.length; i < length; i++) {
      // 抗锯齿
      paint.setAntiAlias(true);
      // 默认粗体
      paint.setTypeface(Typeface.DEFAULT_BOLD);
      // 白色
      paint.setColor(Color.WHITE);
      if (i == selectIndex) {
        // 被选择的字母改变颜色和粗体
        paint.setColor(Color.parseColor("#3399ff"));
        paint.setFakeBoldText(true);
        paint.setTextSize(30);
      }
      // 计算字母的X坐标
      float xPos = width / 2 - paint.measureText(assort[i]) / 2;
      // 计算字母的Y坐标
      float yPos = interval * i + interval;
      canvas.drawText(assort[i], xPos, yPos, paint);
      paint.reset();
    }
  }
コード例 #26
0
ファイル: ButtonControl.java プロジェクト: hirall/overplayed
  /**
   * Generates bitmap used for drawing button.
   *
   * @param radius Radius of button in pixels.
   */
  @Override
  void generateBitmap() {
    super.generateBitmap();
    // Size and shape
    buttonShape.setShape(new OvalShape());
    buttonShape.setBounds(
        new Rect(PADDING, PADDING, (int) radius * 2 - PADDING, (int) radius * 2 - PADDING));

    // Create button bitmap and render shape
    buttonBitmap = Bitmap.createBitmap((int) radius * 2, (int) radius * 2, Bitmap.Config.ARGB_4444);
    Canvas handleCanvas = new Canvas(buttonBitmap);
    buttonShape.getPaint().set(parent.fillPaint);
    buttonShape.draw(handleCanvas);

    // Set text style
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setTypeface(Typeface.DEFAULT_BOLD);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setColor(Color.BLACK);
    // Set size (one character has a standard design, more has dynamic size)
    if (label.length() == 1) textPaint.setTextSize(radius);
    else textPaint.setTextSize(radius / label.length() * 2.5f);

    // Set paint to clear text from button
    textPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

    // Render the button
    handleCanvas.drawText(label, radius, radius + (textPaint.getTextSize() * .33333f), textPaint);
  }
コード例 #27
0
ファイル: SideBar.java プロジェクト: wuchaofei/JikePart
  /** 重写这个方法 */
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    // 获取焦点改变背景颜色.
    int height = getHeight(); // 获取对应高度 1596 samsung s4
    int width = getWidth(); // 获取对应宽度
    int singleHeight = height / b.length; // 获取每一个字母的高度

    for (int i = 0; i < b.length; i++) {
      paint.setColor(Color.rgb(33, 65, 98)); // 右边字母导航条的颜色
      //			paint.setColor(Color.WHITE);
      paint.setTypeface(Typeface.DEFAULT_BOLD);
      paint.setAntiAlias(true);
      paint.setTextSize(height / 320 * 10); // 根据屏幕分辨率设置字体大小
      // 选中的状态
      if (i == choose) {
        paint.setColor(Color.parseColor("#3399ff"));
        paint.setFakeBoldText(true);
      }
      // x坐标等于中间-字符串宽度的一半.
      float xPos = width / 2 - paint.measureText(b[i]) / 2;
      float yPos = singleHeight * i + singleHeight;
      canvas.drawText(b[i], xPos, yPos, paint);
      paint.reset(); // 重置画笔
    }
  }
コード例 #28
0
  private TextDrawable(Builder builder) {
    super(builder.shape);

    // shape properties
    shape = builder.shape;
    height = builder.height;
    width = builder.width;
    radius = builder.radius;

    // text and color
    text = builder.toUpperCase ? builder.text.toUpperCase() : builder.text;
    color = builder.color;

    // text paint settings
    fontSize = builder.fontSize;
    textPaint = new Paint();
    textPaint.setColor(builder.textColor);
    textPaint.setAntiAlias(true);
    textPaint.setFakeBoldText(builder.isBold);
    textPaint.setStyle(Paint.Style.FILL);
    textPaint.setTypeface(builder.font);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setStrokeWidth(builder.borderThickness);

    // border paint settings
    borderThickness = builder.borderThickness;
    borderPaint = new Paint();
    borderPaint.setColor(getDarkerShade(color));
    borderPaint.setStyle(Paint.Style.STROKE);
    borderPaint.setStrokeWidth(borderThickness);

    // drawable paint color
    Paint paint = getPaint();
    paint.setColor(color);
  }
コード例 #29
0
 Engine() {
   super();
   prefs = GalleryWallpaper.this.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE);
   prefs.registerOnSharedPreferenceChangeListener(this);
   this.onSharedPreferenceChanged(prefs, GalleryWallpaper.SHARED_PREFS_REPLACEIMAGE);
   this.onSharedPreferenceChanged(prefs, GalleryWallpaper.SHARED_PREFS_SYNC);
   onSharedPreferenceChanged(prefs, null);
   backgroundPaint.setFilterBitmap(false);
   backgroundPaint.setAntiAlias(true);
   backgroundPaint.setColor(Color.BLACK);
   textPaint.setAntiAlias(true);
   textPaint.setColor(Color.WHITE);
   textPaint.setShadowLayer(5f, 1f, 1f, Color.GRAY);
   textPaint.setSubpixelText(true);
   textPaint.setTextAlign(Paint.Align.LEFT);
   textPaint.setTextSize(18);
   textPaint.setTypeface(Typeface.MONOSPACE);
   this.setTouchEventsEnabled(true);
   if (Build.VERSION.SDK_INT >= 14) {
     try {
       // hinting = textPaint.HINTING_ON;
       int hinting = textPaint.getClass().getField("HINTING_ON").getInt(textPaint);
       // textPaint.setHinting(hinting);
       textPaint.getClass().getMethod("setHinting", int.class).invoke(textPaint, hinting);
     } catch (IllegalAccessException e) {
       System.err.println(e.toString());
     } catch (InvocationTargetException e) {
       System.err.println(e.toString());
     } catch (NoSuchMethodException e) {
       System.err.println(e.toString());
     } catch (NoSuchFieldException e) {
       System.err.println(e.toString());
     }
   }
 }
コード例 #30
0
ファイル: BitmapUtils.java プロジェクト: tangfrei007/Demos
 /**
  * 图片加上水印
  *
  * @param src 底图
  * @param waterMak
  * @param title 文字
  * @return
  */
 public static Bitmap createBitmap(Bitmap src, Bitmap waterMak, String title) {
   if (src == null) {
     return src;
   }
   // 获取原始图片与水印图片的宽与高
   int w = src.getWidth();
   int h = src.getHeight();
   Bitmap newBitmap = Bitmap.createBitmap(w, h, Config.RGB_565);
   Canvas mCanvas = new Canvas(newBitmap);
   // 往位图中开始画入src原始图片
   mCanvas.drawBitmap(src, 0, 0, null);
   // 在src的右下角添加水印
   Paint paint = new Paint();
   if (waterMak != null) {
     int ww = waterMak.getWidth();
     int wh = waterMak.getHeight();
     mCanvas.drawBitmap(waterMak, w - ww - 5, h - wh - 5, paint);
   }
   // 开始加入文字
   if (null != title) {
     Paint textPaint = new Paint();
     textPaint.setColor(Color.WHITE);
     textPaint.setTextSize(18);
     String familyName = "宋体";
     Typeface typeface = Typeface.create(familyName, Typeface.BOLD_ITALIC);
     textPaint.setTypeface(typeface);
     textPaint.setTextAlign(Align.CENTER);
     mCanvas.drawText(title, w / 2, h - 30, textPaint);
   }
   mCanvas.save(Canvas.ALL_SAVE_FLAG);
   mCanvas.restore();
   return newBitmap;
 }