List of usage examples for android.graphics Paint setTypeface
public Typeface setTypeface(Typeface typeface)
From source file:com.mappn.gfan.ui.HomeTabActivity.java
private Bitmap drawText(DisplayMetrics dm, Resources res, Bitmap bm, int num) { final int height = bm.getScaledHeight(dm); final int width = bm.getScaledWidth(dm); Bitmap newBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(newBitmap); canvas.drawBitmap(bm, new Matrix(), new Paint()); Paint textPainter = new Paint(Paint.ANTI_ALIAS_FLAG); textPainter.setColor(res.getColor(R.color.tab_app_num)); textPainter.setTextSize(dm.scaledDensity * 12); textPainter.setTypeface(Typeface.DEFAULT_BOLD); float textWidth = textPainter.measureText(String.valueOf(num)) / 2; canvas.drawText(String.valueOf(num), width / 2 - textWidth, height / 2 + (dm.scaledDensity * 6), textPainter);//from w w w .j ava2 s. c o m canvas.save(); return newBitmap; }
From source file:com.cssweb.android.view.PriceMini.java
public void drawHKIndex(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);/*from w w w .j a v a 2 s. c o m*/ if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); double zrsp = jo.getDouble("zrsp"); double zjcj = jo.getDouble("zjcj"); paint.setTextSize(mTextSize * 2); setColor(paint, zjcj, zrsp); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(DX * 0.5f, DY * 2f); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint); paint.setStyle(Paint.Style.STROKE); paint.setTextSize(mTextSize); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY * 0.8f); String zhangdie = Utils.dataFormation(zhangd, stockdigit); if (zhangdie.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangdie, x, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(DX * 3.5f, 0); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit); if (zhangfu.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangfu + "%", x, y, paint); paint.setColor(GlobalColor.colorLabelName); canvas.translate(-DX * 4f, DY * 1.2f); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("??", x, y, paint); canvas.translate(width / 2, -DY * 1); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint); paint.setColor(GlobalColor.colorLabelName); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(0, -DY * 4); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 3); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } else {//????? paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(DX, DY * 2f); canvas.drawText("-", x, y, paint); paint.setStyle(Paint.Style.STROKE); paint.setTextSize(mTextSize); canvas.translate(-DX / 2, DY * 0.8f); canvas.drawText("-", x, y, paint); canvas.translate(DX * 2.5f, 0); canvas.drawText("-", x, y, paint); canvas.translate(-DX * 3, DY * 1.2f); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("??", x, y, paint); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(width / 2, -DY * 4); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); } }
From source file:com.androidmapsextensions.DefaultClusterOptionsProvider.java
private Paint createTextPaint(Resources resources) { Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(resources.getColor(R.color.ame_default_cluster_text_color)); shadowBlurRadius = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_blur_radius); if (shadowBlurRadius > 0.0f) { shadowOffsetX = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_offset_x); shadowOffsetY = resources.getDimension(R.dimen.ame_default_cluster_text_shadow_offset_y); int shadowColor = resources.getColor(R.color.ame_default_cluster_text_shadow_color); paint.setShadowLayer(shadowBlurRadius, shadowOffsetX, shadowOffsetY, shadowColor); }/*from w w w . j a va 2s . co m*/ paint.setTextSize(resources.getDimension(R.dimen.ame_default_cluster_text_size)); paint.setTypeface(Typeface.DEFAULT_BOLD); return paint; }
From source file:com.cssweb.android.view.PriceMini.java
public void drawIndex(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);// www. ja v a 2 s.c o m if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); double zrsp = jo.getDouble("zrsp"); double zjcj = jo.getDouble("zjcj"); paint.setTextSize(mTextSize * 2); setColor(paint, zjcj, zrsp); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(DX * 0.5f, DY * 2f); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint); paint.setStyle(Paint.Style.STROKE); paint.setTextSize(mTextSize); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(0, DY * 0.8f); String zhangdie = Utils.dataFormation(zhangd, stockdigit); if (zhangdie.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangdie, x, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(DX * 3.5f, 0); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit); if (zhangfu.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangfu + "%", x, y, paint); paint.setColor(GlobalColor.colorLabelName); canvas.translate(-DX * 3.5f, DY * 1.2f); //canvas.translate(-DX*0.5f, DY*2f); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("??", x, y, paint); canvas.translate(0, DY); canvas.drawText("??", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); paint.setColor(GlobalColor.colorLabelName); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(width / 2 - DX, -DY * 7); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, 0); canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x, y, paint); canvas.translate(width / 2, -DY * 3); paint.setTextAlign(Paint.Align.RIGHT); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit), x, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit), x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); double amp = jo.getDouble("amp"); if (amp == 0) canvas.drawText("", x, y, paint); else canvas.drawText(Utils.dataFormation(jo.getDouble("amp") * 100, 1) + "%", x, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorpriceUp); canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorPriceDown); canvas.drawText(String.valueOf(jo.getInt("dj")), x, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } else {//????? paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(DX, DY * 2f); canvas.drawText("-", x, y, paint); paint.setStyle(Paint.Style.STROKE); paint.setTextSize(mTextSize); canvas.translate(-DX / 2, DY * 0.8f); canvas.drawText("-", x, y, paint); canvas.translate(DX * 2.5f, 0); canvas.drawText("-", x, y, paint); canvas.translate(-DX * 2.5f, DY * 1.2f); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("??", x, y, paint); canvas.translate(0, DY); canvas.drawText("??", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(width / 2 - DX, -DY * 7); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); } }
From source file:com.cssweb.android.view.PriceMini.java
public void drawQihuo(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);/*from ww w . ja va 2 s. c o m*/ if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); String str = ""; double zrsp = jo.getDouble("zrsp"); double zjcj = jo.getDouble("zjcj"); paint.setTextSize(mTextSize * 2); setColor(paint, zjcj, zrsp); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(DX, DY * 2f); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint); paint.setStyle(Paint.Style.STROKE); paint.setTextSize(mTextSize); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(-DX / 2, DY * 0.8f); String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp")); if (zhangdie.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangdie, x, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(DX * 2.5f, 0); String zhangfu = Utils.dataFormation(zhangf * 100, 1); if (zhangfu.equals("-") || zhangfu.equals("")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangfu + "%", x, y, paint); paint.setColor(GlobalColor.colorLabelName); canvas.translate(-DX * 3, DY * 1.2f); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText(" ", x, y, paint); canvas.translate(width / 2, -DY * 2); paint.setTextAlign(Paint.Align.RIGHT); double temp2 = jo.getDouble("sjw1"); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); canvas.drawText(str, x - tips, y, paint); canvas.translate(0, DY); temp2 = jo.getDouble("bjw1"); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); canvas.drawText(str, x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorLabelName); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(0, -DY * 5); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("??", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText(" ", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 5); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl1"), false), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl1"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0, jo.getInt("tp")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } else {//????? paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(DX, DY * 2f); canvas.drawText("-", x, y, paint); paint.setStyle(Paint.Style.STROKE); paint.setTextSize(mTextSize); canvas.translate(-DX / 2, DY * 0.8f); canvas.drawText("-", x, y, paint); canvas.translate(DX * 2.5f, 0); canvas.drawText("-", x, y, paint); canvas.translate(-DX * 3, DY * 1.2f); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText(" ", x, y, paint); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(width / 2, -DY * 5); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("??", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText(" ", x, y, paint); } }
From source file:com.cssweb.android.view.PriceMini.java
public void drawPrice(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);/*from www.ja va 2 s. co m*/ if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); String str = ""; double zrsp = jo.getDouble("zrsp"); double zjcj = jo.getDouble("zjcj"); paint.setTextSize(mTextSize * 2); setColor(paint, zjcj, zrsp); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(DX, DY * 2f); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x, y, paint); paint.setStyle(Paint.Style.STROKE); paint.setTextSize(mTextSize); double zhangd = jo.getDouble("zd"); if (zhangd < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangd > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(-DX / 2, DY * 0.8f); String zhangdie = Utils.dataFormation(zhangd, stockdigit, jo.getInt("tp")); if (zhangdie.equals("-")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangdie, x, y, paint); double zhangf = jo.getDouble("zf"); if (zhangf < 0) { paint.setColor(GlobalColor.colorPriceDown); } else if (zhangf > 0) { paint.setColor(GlobalColor.colorpriceUp); } else { paint.setColor(GlobalColor.colorPriceEqual); } canvas.translate(DX * 2.5f, 0); //String zhangfu = Utils.dataFormation(zhangf*100, stockdigit); //?????2? String zhangfu = Utils.dataFormation(zhangf * 100, 1, jo.getInt("tp")); if (zhangfu.equals("-") || zhangfu.equals("")) canvas.drawText("", x, y, paint); else canvas.drawText(zhangfu + "%", x, y, paint); paint.setColor(GlobalColor.colorLabelName); canvas.translate(-DX * 3, DY * 1.2f); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(DX * 2, -DY * 4); for (int i = 1; i <= 5; i++) { double temp2 = jo.getDouble("sjw" + i); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); canvas.drawText(str, x, y, paint); if (i != 5) canvas.translate(0, DY); } paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2 - DX * 2, -DY * 4); for (int i = 1; i <= 5; i++) { paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(Utils.getAmountFormat(jo.getInt("ssl" + i), false), x - tips, y, paint); if (i != 5) canvas.translate(0, DY); } paint.setColor(GlobalColor.colorLabelName); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(0, -DY * 7); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); //paint.setTextAlign(Paint.Align.CENTER); canvas.translate(DX * 2, -DY * 7); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit, jo.getInt("tp")), x, y, paint); canvas.translate(0, DY); double zg = jo.getDouble("zgcj"); setColor(paint, zg, zrsp); canvas.drawText(Utils.dataFormation(zg, stockdigit, jo.getInt("tp")), x, y, paint); canvas.translate(0, DY); double zd = jo.getDouble("zdcj"); setColor(paint, zd, zrsp); canvas.drawText(Utils.dataFormation(zd, stockdigit, jo.getInt("tp")), x, y, paint); canvas.translate(0, DY); for (int i = 1; i <= 5; i++) { double temp2 = jo.getDouble("bjw" + i); setColor(paint, temp2, zrsp); str = Utils.dataFormation(temp2, stockdigit, jo.getInt("tp")); canvas.drawText(str, x, y, paint); if (i != 5) canvas.translate(0, DY); } paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2 - DX * 2, -DY * 4); for (int i = 1; i <= 5; i++) { paint.setTextAlign(Paint.Align.RIGHT); canvas.drawText(Utils.getAmountFormat(jo.getInt("bsl" + i), false), x - tips, y, paint); if (i != 5) canvas.translate(0, DY); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } else {//????? paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(DX, DY * 2f); canvas.drawText("-", x, y, paint); paint.setStyle(Paint.Style.STROKE); paint.setTextSize(mTextSize); canvas.translate(-DX / 2, DY * 0.8f); canvas.drawText("-", x, y, paint); canvas.translate(DX * 2.5f, 0); canvas.drawText("-", x, y, paint); canvas.translate(-DX * 3, DY * 1.2f); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); paint.setTextAlign(Paint.Align.LEFT); canvas.translate(width / 2, -DY * 7); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); } }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
/** * Applies the specified text appearance resource to a paint, returning the * text color if one is set in the text appearance. * * @param p the paint to modify/*from w w w .ja va 2 s . co m*/ * @param resId the resource ID of the text appearance * @return the text color, if available */ private ColorStateList applyTextAppearance(Paint p, int resId) { final TypedArray ta = getContext().obtainStyledAttributes(null, R.styleable.TextAppearance, 0, resId); final String fontFamily = ta.getString(R.styleable.TextAppearance_android_fontFamily); if (fontFamily != null) { p.setTypeface(Typeface.create(fontFamily, 0)); } p.setTextSize(ta.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, (int) p.getTextSize())); final ColorStateList textColor = ta.getColorStateList(R.styleable.TextAppearance_android_textColor); if (textColor != null) { final int enabledColor = textColor.getColorForState(ENABLED_STATE_SET, 0); p.setColor(enabledColor); } ta.recycle(); return textColor; }
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
/** * If the canvas is null, then only touch calculations are performed to pick * the target candidate.//from w w w. j av a 2s.c om */ @Override protected void onDraw(Canvas canvas) { if (canvas != null) { super.onDraw(canvas); } mTotalWidth = 0; final int height = getHeight(); if (mBgPadding == null) { mBgPadding = new Rect(0, 0, 0, 0); if (getBackground() != null) { getBackground().getPadding(mBgPadding); } mDivider.setBounds(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight()); } final int dividerYOffset = (height - mDivider.getMinimumHeight()) / 2; final int count = mSuggestions.size(); final Rect bgPadding = mBgPadding; final Paint paint = mPaint; final int touchX = mTouchX; final int scrollX = getScrollX(); final boolean scrolled = mScrolled; final boolean typedWordValid = mTypedWordValid; int x = 0; for (int i = 0; i < count; i++) { CharSequence suggestion = mSuggestions.get(i); if (suggestion == null) continue; final int wordLength = suggestion.length(); paint.setColor(mColorNormal); if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) { paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setColor(mColorRecommended); // existsAutoCompletion = true; } else if (i != 0 || (wordLength == 1 && count > 1)) { // HACK: even if i == 0, we use mColorOther when this // suggestion's length is 1 and // there are multiple suggestions, such as the default // punctuation list. paint.setColor(mColorOther); } // now that we set the typeFace, we can measure int wordWidth; if ((wordWidth = mWordWidth[i]) == 0) { float textWidth = paint.measureText(suggestion, 0, wordLength); // wordWidth = Math.max(0, (int) textWidth + X_GAP * 2); wordWidth = (int) (textWidth + mHorizontalGap * 2); mWordWidth[i] = wordWidth; } mWordX[i] = x; if (touchX != OUT_OF_BOUNDS_X_CORD && !scrolled && touchX + scrollX >= x && touchX + scrollX < x + wordWidth) { if (canvas != null && !mShowingAddToDictionary) { canvas.translate(x, 0); mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height); mSelectionHighlight.draw(canvas); canvas.translate(-x, 0); } mSelectedString = suggestion; mSelectedIndex = i; } if (canvas != null) { // (+)This is the trick to get RTL/LTR text correct if (AnyApplication.getConfig().workaround_alwaysUseDrawText()) { final int y = (int) (height + paint.getTextSize() - paint.descent()) / 2; canvas.drawText(suggestion, 0, wordLength, x + wordWidth / 2, y, paint); } else { final int y = (int) (height - paint.getTextSize() + paint.descent()) / 2; // no matter what: StaticLayout float textX = x + (wordWidth / 2) - mHorizontalGap; float textY = y - bgPadding.bottom - bgPadding.top; canvas.translate(textX, textY); mTextPaint.setTypeface(paint.getTypeface()); mTextPaint.setColor(paint.getColor()); StaticLayout suggestionText = new StaticLayout(suggestion, mTextPaint, wordWidth, Alignment.ALIGN_CENTER, 1.0f, 0.0f, false); suggestionText.draw(canvas); canvas.translate(-textX, -textY); } // (-) paint.setColor(mColorOther); canvas.translate(x + wordWidth, 0); // Draw a divider unless it's after the hint //or the last suggested word if (count > 1 && (!mShowingAddToDictionary) && i != (count - 1)) { canvas.translate(0, dividerYOffset); mDivider.draw(canvas); canvas.translate(0, -dividerYOffset); } canvas.translate(-x - wordWidth, 0); } paint.setTypeface(Typeface.DEFAULT); x += wordWidth; } mTotalWidth = x; if (mTargetScrollX != scrollX) { scrollToTarget(); } }
From source file:com.yek.keyboard.keyboards.views.CandidateView.java
/** * If the canvas is null, then only touch calculations are performed to pick * the target candidate./*from w w w.j av a 2s. c om*/ */ @Override protected void onDraw(Canvas canvas) { if (canvas != null) { super.onDraw(canvas); } mTotalWidth = 0; final int height = getHeight(); if (mBgPadding == null) { mBgPadding = new Rect(0, 0, 0, 0); if (getBackground() != null) { getBackground().getPadding(mBgPadding); } mDivider.setBounds(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight()); } final int dividerYOffset = (height - mDivider.getMinimumHeight()) / 2; final int count = mSuggestions.size(); final Rect bgPadding = mBgPadding; final Paint paint = mPaint; final int touchX = mTouchX; final int scrollX = getScrollX(); final boolean scrolled = mScrolled; final boolean typedWordValid = mTypedWordValid; int x = 0; for (int i = 0; i < count; i++) { CharSequence suggestion = mSuggestions.get(i); if (suggestion == null) continue; final int wordLength = suggestion.length(); paint.setColor(mColorNormal); if (mHaveMinimalSuggestion && ((i == 1 && !typedWordValid) || (i == 0 && typedWordValid))) { paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setColor(mColorRecommended); // existsAutoCompletion = true; } else if (i != 0 || (wordLength == 1 && count > 1)) { // HACK: even if i == 0, we use mColorOther when this // suggestion's length is 1 and // there are multiple suggestions, such as the default // punctuation list. paint.setColor(mColorOther); } // now that we set the typeFace, we can measure int wordWidth; if ((wordWidth = mWordWidth[i]) == 0) { float textWidth = paint.measureText(suggestion, 0, wordLength); // wordWidth = Math.max(0, (int) textWidth + X_GAP * 2); wordWidth = (int) (textWidth + mXGap * 2); mWordWidth[i] = wordWidth; } mWordX[i] = x; if (touchX != OUT_OF_BOUNDS_X_CORD && !scrolled && touchX + scrollX >= x && touchX + scrollX < x + wordWidth) { if (canvas != null && !mShowingAddToDictionary) { canvas.translate(x, 0); mSelectionHighlight.setBounds(0, bgPadding.top, wordWidth, height); mSelectionHighlight.draw(canvas); canvas.translate(-x, 0); } mSelectedString = suggestion; mSelectedIndex = i; } if (canvas != null) { // (+)This is the trick to get RTL/LTR text correct if (AnyApplication.getConfig().workaround_alwaysUseDrawText()) { final int y = (int) (height + paint.getTextSize() - paint.descent()) / 2; canvas.drawText(suggestion, 0, wordLength, x + wordWidth / 2, y, paint); } else { final int y = (int) (height - paint.getTextSize() + paint.descent()) / 2; // no matter what: StaticLayout float textX = x + (wordWidth / 2) - mXGap; float textY = y - bgPadding.bottom - bgPadding.top; canvas.translate(textX, textY); mTextPaint.setTypeface(paint.getTypeface()); mTextPaint.setColor(paint.getColor()); StaticLayout suggestionText = new StaticLayout(suggestion, mTextPaint, wordWidth, Alignment.ALIGN_CENTER, 1.0f, 0.0f, false); suggestionText.draw(canvas); canvas.translate(-textX, -textY); } // (-) paint.setColor(mColorOther); canvas.translate(x + wordWidth, 0); // Draw a divider unless it's after the hint //or the last suggested word if (count > 1 && (!mShowingAddToDictionary) && i != (count - 1)) { canvas.translate(0, dividerYOffset); mDivider.draw(canvas); canvas.translate(0, -dividerYOffset); } canvas.translate(-x - wordWidth, 0); } paint.setTypeface(Typeface.DEFAULT); x += wordWidth; } mTotalWidth = x; if (mTargetScrollX != scrollX) { scrollToTarget(); } }
From source file:com.example.psumaps.MapView.java
private void drawMarker(LatLng point, String str) { // Creating an instance of MarkerOptions MarkerOptions markerOptions = new MarkerOptions(); //IconGenerator tc = new IconGenerator(this); //Bitmap bmp = tc.makeIcon("hello"); Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), R.drawable.bubble_white);// get the image same as your EditText int h = bitmap.getHeight() * 2; int w = bitmap.getWidth() * 2; bitmap = convertToMutable(bitmap);// converting the bitmap to mutable Bitmap incrsize = Bitmap.createScaledBitmap(bitmap, w, h, false); Canvas cs = new Canvas(incrsize); Paint pt = new Paint(); pt.setColor(Color.BLACK);/*from www . j a va 2 s . c o m*/ //Typeface tf = Typeface.create("Helvetica",Typeface.BOLD); pt.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); String iam = str.toUpperCase(Locale.getDefault()); pt.setTextSize(25); cs.drawText(iam, 0, iam.length(), (h / 2) + 10, (w / 2) / 2, pt); //pt.setColor(Color.RED); //cs.drawText("this is praki", 0, 13, h / 2, w / 3, pt); // Setting latitude and longitude for the marker markerOptions.position(point).title(str).icon(BitmapDescriptorFactory.fromBitmap(incrsize)); // Adding marker on the Google Map map.addMarker(markerOptions); }