List of usage examples for android.graphics Canvas drawText
public void drawText(@NonNull String text, float x, float y, @NonNull Paint paint)
From source file:com.mylikes.likes.etchasketch.Slate.java
private void drawStrokeDebugInfo(Canvas c) { final int ROW_HEIGHT = 24; final int ROW_MARGIN = 6; final int COLUMN_WIDTH = 55; final float FIRM_PRESSURE_LOW = 0.85f; final float FIRM_PRESSURE_HIGH = 1.25f; if (mStrokeDebugGraph == null) { final int width = c.getWidth() - 128; final int height = ROW_HEIGHT * mStrokes.length + 2 * ROW_MARGIN; mStrokeDebugGraph = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); if (mStrokeDebugGraph == null) { throw new RuntimeException( "drawStrokeDebugInfo: couldn't create debug bitmap (" + width + "x" + height + ")"); }/*from w w w .j a va 2 s.c om*/ mGraphPaint1 = new Paint(Paint.ANTI_ALIAS_FLAG); } Canvas graph = new Canvas(mStrokeDebugGraph); graph.save(); graph.clipRect(new Rect(0, 0, COLUMN_WIDTH, graph.getHeight())); graph.drawColor(0, PorterDuff.Mode.CLEAR); graph.restore(); int left = 4; int bottom = graph.getHeight() - ROW_MARGIN; final int STEP = 4; for (MarkersPlotter st : mStrokes) { float r = st.getLastPressure(); if (r >= FIRM_PRESSURE_LOW && r <= FIRM_PRESSURE_HIGH) mGraphPaint1.setColor(0xFF33FF33); else if (r < FIRM_PRESSURE_LOW) mGraphPaint1.setColor(0xFF808080); else mGraphPaint1.setColor(0xFFFF8000); String s = (r < 0) ? "--" : String.format("%s %.4f", ((st.getLastTool() == MotionEvent.TOOL_TYPE_STYLUS) ? "S" : "F"), r); graph.drawText(s, left, bottom - 2, mGraphPaint1); if (mGraphX + COLUMN_WIDTH > graph.getWidth()) { mGraphX = 0; graph.save(); graph.clipRect(new Rect(30, 0, graph.getWidth(), graph.getHeight())); graph.drawColor(0, PorterDuff.Mode.CLEAR); graph.restore(); } if (r >= 0) { int barsize = (int) (r * ROW_HEIGHT); graph.drawRect(mGraphX + COLUMN_WIDTH, bottom - barsize, mGraphX + COLUMN_WIDTH + STEP, bottom, mGraphPaint1); } else { graph.drawPoint(mGraphX + COLUMN_WIDTH + STEP, bottom, mGraphPaint1); } bottom -= (ROW_HEIGHT + ROW_MARGIN); } mGraphX += STEP; final int x = 96; final int y = 64; c.drawBitmap(mStrokeDebugGraph, x, y, null); invalidate(new Rect(x, y, x + c.getWidth(), y + c.getHeight())); }
From source file:org.stockchart.stickers.FibonacciSticker.java
@Override protected void draw(SeriesPaintInfo info, PointF p1, PointF p2, Canvas c) { PointF rightMost = Utils.getRightmost(p1, p2); PointF leftMost = Utils.getLeftmost(p1, p2); boolean isRising = Utils.isRising(p1, p2); float maxY = Math.max(p1.y, p2.y); float minY = Math.min(p1.y, p2.y); float height = maxY - minY; float originY = isRising ? minY : maxY; float m = fAppearance.getOutlineWidth(); // guideline/*from w w w . ja va 2 s. c o m*/ // fAppearance.applyOutline(fPaint); // PaintUtils.drawLine(c, p1.x, p1.y, p2.x, p2.y, fPaint); switch (fType) { case FANS: { float r382 = originY + height * 0.382f * (isRising ? 1f : -1f); float r500 = originY + height * 0.5f * (isRising ? 1f : -1f); float r618 = originY + height * 0.618f * (isRising ? 1f : -1f); fAppearance.applyOutline(fPaint); float rightMostX = Math.max(rightMost.x, c.getWidth() + 1f); PaintUtils.drawLine(c, leftMost.x, leftMost.y, rightMostX, Utils.getY(leftMost.x, leftMost.y, rightMost.x, r382, rightMostX), fPaint); PaintUtils.drawLine(c, leftMost.x, leftMost.y, rightMostX, Utils.getY(leftMost.x, leftMost.y, rightMost.x, r500, rightMostX), fPaint); PaintUtils.drawLine(c, leftMost.x, leftMost.y, rightMostX, Utils.getY(leftMost.x, leftMost.y, rightMost.x, r618, rightMostX), fPaint); } break; case RETRACEMENT: { Set<Entry<Float, String>> entrySet = RETRACEMENTS.entrySet(); Iterator<Entry<Float, String>> iterator = entrySet.iterator(); while (iterator.hasNext()) { Entry<Float, String> i = iterator.next(); float y = originY + height * i.getKey() * (isRising ? 1f : -1f); fAppearance.applyOutline(fPaint); PaintUtils.drawLine(c, 0, y, c.getWidth(), y, fPaint); fAppearance.applyText(fPaint); c.drawText(i.getValue(), 1f, y - m, fPaint); } } break; case ARCS: { float length = (float) Math.sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y)); // euclidean distance float r382 = length * 0.382f; float r500 = length * 0.5f; float r618 = length * 0.618f; fAppearance.applyOutline(fPaint); int a2 = isRising ? 180 : -180; fTempRectF.set(rightMost.x - r500, rightMost.y - r500, rightMost.x + r500, rightMost.y + r500); c.drawArc(fTempRectF, 0, a2, false, fPaint); fTempRectF.set(rightMost.x - r382, rightMost.y - r382, rightMost.x + r382, rightMost.y + r382); c.drawArc(fTempRectF, 0, a2, false, fPaint); fTempRectF.set(rightMost.x - r618, rightMost.y - r618, rightMost.x + r618, rightMost.y + r618); c.drawArc(fTempRectF, 0, a2, false, fPaint); } break; } }
From source file:com.blestep.sportsbracelet.view.TimelineChartView.java
private void drawTickLabels(Canvas c, SparseArray<Object[]> data) { final int size = data.size() - 1; final float graphCenterX = mGraphArea.left + (mGraphArea.width() / 2); final float halfItemBarWidth = mBarItemWidth / 2; for (int i = mItemsOnScreen[1]; i >= mItemsOnScreen[0] && i <= data.size(); i--) { final float barCenterX = graphCenterX + mCurrentOffset - (mBarWidth * (size - i)); float barLeft = barCenterX - halfItemBarWidth; float barRight = barCenterX + halfItemBarWidth; // Update the dynamic layout String label = (String) data.valueAt(i)[0]; // //from ww w . j a v a 2s. co m // Calculate the x position and draw the layout final float x = graphCenterX + mCurrentOffset - (mBarWidth * (size - i)) - (mLabelFgPaint.measureText(label) / 2); final int restoreCount = c.save(); c.translate(x, mFooterArea.top + (mFooterArea.height() / 2 - mTickLabelMinHeight / 2)); final Paint paint; // ? paint = barLeft < graphCenterX && barRight > graphCenterX && (mLastPosition == mCurrentPosition || (mState != STATE_SCROLLING)) ? mHighlightLabelFgPaint : mLabelFgPaint; c.drawText(label, 0, 0, paint); c.restoreToCount(restoreCount); } }
From source file:in.sc9.discreteslider.DiscreteSlider.java
private void drawTextArray(Canvas canvas, int thumbWidth, int halfThumb, float yPos, int left, float intervel) { int lenTextArray = textArray.length; if (lenTextArray == 0) return;/* www .j av a2 s.c o m*/ float currentLeft = left; Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(mtextColor); paint.setTextSize(mTextSize); //paint.setTypeface(); //TODO setTypeface in Discrete Seek Bar //elloWorldTextView2.setTextSize(activity.pixelsToSp(activity, textSize)); //paint.m for (int i = 0; i < lenTextArray; i++) { /*if((int)getThumbValue(0)==i*(int)scaleStep) paint.setColor(Color.parseColor("#ffff0000")); else paint.setColor(Color.parseColor("#ff22445b"));*/ float textLen = paint.measureText(textArray[i]); if (i == 0) { if (textStyle != NONE && (textStyle == ODD || textStyle == EXTREMES || textStyle == ALL)) canvas.drawText(textArray[i], currentLeft, yPos, paint); } else if (i == lenTextArray - 1) { if (textStyle != NONE) if ((textStyle == ALL) || (i % 2 == 0 && textStyle == ODD) || (i % 2 != 0 && textStyle == EVEN) || (textStyle == EXTREMES)) canvas.drawText(textArray[i], currentLeft - textLen, yPos, paint); } else { if (textStyle != 0 && textStyle != 3) { if ((textStyle == ALL) || (i % 2 == 0 && textStyle == ODD) || (i % 2 != 0 && textStyle == EVEN)) canvas.drawText(textArray[i], currentLeft - (textLen / 2), yPos, paint); } } currentLeft += intervel; } }
From source file:com.cssweb.android.view.PriceView.java
public void drawIndex(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);/*from w ww . j ava2 s . c o m*/ tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1); this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY * 7 + DY / 2, endX, DY * 7 + DY / 2, tPaint); canvas.drawLine(startX, DY * 18 + DY / 4, endX, DY * 18 + DY / 4, tPaint); if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); double zrsp = jo.getDouble("zrsp"); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY * 2); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("???", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("?", x + tips, y, paint); canvas.translate(0, DY * 1.5f); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(width, -DY * 15.5f); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("a"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("b"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("govbond"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("fund"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("warrant"), true), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("bond"), true), x - tips, y, paint); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.translate(0, DY * 1.5f); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x - tips, y, paint); canvas.translate(0, DY); double jrkp = jo.getDouble("jrkp"); setColor(paint, jrkp, zrsp); canvas.drawText(Utils.dataFormation(jrkp, stockdigit), x - tips, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorLabelName); canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint); 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); String zhangdie = Utils.dataFormation(zhangd, stockdigit); if (zhangdie.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangdie, x - tips, 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(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit); if (zhangfu.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangfu + "%", 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); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjsl"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), 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); canvas.translate(-width, DY * 1.7f); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(width / 2, 0); canvas.drawText(String.valueOf(jo.getInt("zj")), x, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(width / 2, 0); canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.cssweb.android.view.PriceView.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.com tPaint.setColor(GlobalColor.clrLine); tPaint.setStyle(Paint.Style.STROKE); tPaint.setStrokeWidth(1); this.x = 0; this.y = 0; startX = x + tips / 2; endX = width - tips / 2; canvas.drawRect(startX, DY + DY / 4, endX, height - DY / 4, tPaint); canvas.drawLine(startX, DY * 5 + DY / 2, endX, DY * 5 + DY / 2, tPaint); canvas.drawLine(startX, DY * 11 + DY / 8, endX, DY * 11 + DY / 8, tPaint); //canvas.drawLine(startX, DY*16+DY/4, endX, DY*16+DY/4, tPaint); if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); double zrsp = jo.getDouble("zrsp"); paint.setTextSize(mTextSize); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY * 2); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY * 1.5f); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); // canvas.translate(0, DY); // canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("??", x + tips, y, paint); canvas.translate(0, DY * 1.5f); // canvas.drawText("?", x + tips, y, paint); // canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(width, -DY * 13f); paint.setTextAlign(Paint.Align.RIGHT); double zjcj = jo.getDouble("zjcj"); setColor(paint, zjcj, zrsp); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(zjcj, stockdigit), x - tips, y, paint); 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); String zhangdie = Utils.dataFormation(zhangd, stockdigit); if (zhangdie.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangdie, x - tips, 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(0, DY); String zhangfu = Utils.dataFormation(zhangf * 100, stockdigit); if (zhangfu.equals("-")) canvas.drawText("", x - tips, y, paint); else canvas.drawText(zhangfu + "%", 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); canvas.translate(0, DY * 1.5f); paint.setColor(GlobalColor.colorLabelName); canvas.drawText(Utils.dataFormation(zrsp, stockdigit), x - tips, y, paint); canvas.translate(0, DY); 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.getAmountFormat(jo.getDouble("cjsl"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), true), x - tips, y, paint); canvas.translate(0, DY * 1.5f); //canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1), x - tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); //canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("zj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceEqual); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("pj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:info.bartowski.easteregg.LLand.java
@Override public void onDraw(Canvas c) { super.onDraw(c); if (!DEBUG_DRAW) return;/*from w ww . ja v a 2s. c om*/ final Paint pt = new Paint(); pt.setColor(0xFFFFFFFF); final int L = mDroid.corners.length; final int N = L / 2; for (int i = 0; i < N; i++) { final int x = (int) mDroid.corners[i * 2]; final int y = (int) mDroid.corners[i * 2 + 1]; c.drawCircle(x, y, 4, pt); c.drawLine(x, y, mDroid.corners[(i * 2 + 2) % L], mDroid.corners[(i * 2 + 3) % L], pt); } pt.setStyle(Paint.Style.STROKE); pt.setStrokeWidth(getResources().getDisplayMetrics().density); final int M = getChildCount(); pt.setColor(0x8000FF00); for (int i = 0; i < M; i++) { final View v = getChildAt(i); if (v == mDroid) continue; if (!(v instanceof GameView)) continue; if (v instanceof Pop) { final Pop p = (Pop) v; c.drawCircle(p.cx, p.cy, p.r, pt); } else { final Rect r = new Rect(); v.getHitRect(r); c.drawRect(r, pt); } } pt.setColor(Color.BLACK); final StringBuilder sb = new StringBuilder("obstacles: "); for (Obstacle ob : mObstaclesInPlay) { sb.append(ob.hitRect.toShortString()); sb.append(" "); } pt.setTextSize(20f); c.drawText(sb.toString(), 20, 100, pt); }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { int userId = Util.getUserId(Process.myUid()); boolean mounted = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); boolean updates = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingUpdates, false); menu.findItem(R.id.menu_export).setEnabled(mounted); menu.findItem(R.id.menu_import).setEnabled(mounted); menu.findItem(R.id.menu_submit).setEnabled(Util.hasValidFingerPrint(this)); menu.findItem(R.id.menu_pro).setVisible(!Util.isProEnabled() && Util.hasProLicense(this) == null); menu.findItem(R.id.menu_dump).setVisible(Util.isDebuggable(this)); menu.findItem(R.id.menu_update).setVisible(updates); menu.findItem(R.id.menu_update).setEnabled(mounted); // Update filter count // Get settings boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false); boolean fInternet = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFInternet, false); boolean fRestriction = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestriction, false); boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, true); boolean fOnDemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemand, false); boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true); boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false); // Count number of active filters int numberOfFilters = 0; if (fUsed)/* www .j a v a 2 s.c om*/ numberOfFilters++; if (fInternet) numberOfFilters++; if (fRestriction) numberOfFilters++; if (fPermission) numberOfFilters++; if (fOnDemand) numberOfFilters++; if (fUser) numberOfFilters++; if (fSystem) numberOfFilters++; if (numberOfFilters > 0) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_filter) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.GRAY); paint.setTextSize(bitmap.getWidth() / 3); paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); String text = Integer.toString(numberOfFilters); Canvas canvas = new Canvas(bitmap); canvas.drawText(text, bitmap.getWidth() - paint.measureText(text), bitmap.getHeight(), paint); MenuItem fMenu = menu.findItem(R.id.menu_filter); fMenu.setIcon(new BitmapDrawable(getResources(), bitmap)); } return super.onPrepareOptionsMenu(menu); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
public static Bitmap graphics_addWaterMarkToImage(Bitmap src, String watermark, Point location, int size, boolean underline) { Bitmap result = null;/*w ww .java2 s . c om*/ try { int w = src.getWidth(); int h = src.getHeight(); result = Bitmap.createBitmap(w, h, src.getConfig()); Canvas canvas = new Canvas(result); canvas.drawBitmap(src, 0, 0, null); Paint paint = new Paint(); paint.setColor(Color.RED); //paint.setAlpha(alpha); paint.setTextSize(size); paint.setAntiAlias(true); paint.setUnderlineText(underline); canvas.drawText(watermark, location.x, location.y, paint); } catch (Exception e) { result = null; if (LOG_ENABLE) Log.e(TAG, "ERROR: graphics_addWaterMarkToImage() [" + e.getMessage() + "]", e); } return result; }
From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java
/** * Draw the 12 text values at the positions specified by the textGrid parameters. */// w w w. jav a 2 s. c o m private void drawTextElements(Canvas canvas, float textSize, Typeface typeface, ColorStateList textColor, String[] texts, float[] textX, float[] textY, Paint paint, int alpha, boolean showActivated, int activatedDegrees, boolean activatedOnly) { paint.setTextSize(textSize); paint.setTypeface(typeface); // The activated index can touch a range of elements. final float activatedIndex = activatedDegrees / (360.0f / NUM_POSITIONS); final int activatedFloor = (int) activatedIndex; final int activatedCeil = ((int) Math.ceil(activatedIndex)) % NUM_POSITIONS; for (int i = 0; i < 12; i++) { final boolean activated = (activatedFloor == i || activatedCeil == i); if (activatedOnly && !activated) { continue; } final int stateMask = SUtils.STATE_ENABLED | (showActivated && activated ? SUtils.STATE_ACTIVATED : 0); final int color = textColor.getColorForState(SUtils.resolveStateSet(stateMask), 0); paint.setColor(color); paint.setAlpha(getMultipliedAlpha(color, alpha)); canvas.drawText(texts[i], textX[i], textY[i], paint); } }