List of usage examples for android.graphics Canvas restore
public void restore()
From source file:org.wikipedia.page.shareafact.SnippetImage.java
private static int drawDescription(@NonNull Canvas canvas, @Nullable String description, int top, boolean isArticleRTL) { final int marginBottom = 5; final int maxHeight = 23; final int maxLines = 2; final float maxFontSize = 15.0f; final float minFontSize = 10.0f; if (TextUtils.isEmpty(description)) { return top - marginBottom; }/* w w w .j av a 2 s . c o m*/ TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true); textPaint.setColor(Color.WHITE); textPaint.setTextSize(maxFontSize); textPaint.setStyle(Paint.Style.FILL); textPaint.setShadowLayer(1.0f, 0.0f, 0.0f, Color.GRAY); StaticLayout textLayout = optimizeTextSize( new TextLayoutParams(description, textPaint, DESCRIPTION_WIDTH, SPACING_MULTIPLIER), maxHeight, maxLines, maxFontSize, minFontSize); int left = HORIZONTAL_PADDING; if (isArticleRTL) { left = WIDTH - HORIZONTAL_PADDING - textLayout.getWidth(); } top = top - marginBottom - textLayout.getHeight(); canvas.save(); canvas.translate(left, top); textLayout.draw(canvas); canvas.restore(); return top; }
From source file:com.android.mail.browse.SubjectAndFolderView.java
public void setFolders(ConversationViewHeaderCallbacks callbacks, Account account, Conversation conv) { mVisibleFolders = true;/*from w w w .ja v a2s. co m*/ final BidiFormatter bidiFormatter = getBidiFormatter(); final String wrappedSubject = mSubject == null ? "" : bidiFormatter.unicodeWrap(mSubject); final SpannableStringBuilder sb = new SpannableStringBuilder(wrappedSubject); sb.append('\u0020'); final Settings settings = account.settings; final int start = sb.length(); if (settings.importanceMarkersEnabled && conv.isImportant()) { sb.append(".\u0020"); sb.setSpan(new ReplacementSpan() { @Override public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { return mImportanceMarkerDrawable.getIntrinsicWidth(); } @Override public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int baseline, int bottom, Paint paint) { canvas.save(); final int transY = baseline + mChipVerticalOffset - mImportanceMarkerDrawable.getIntrinsicHeight(); canvas.translate(x, transY); mImportanceMarkerDrawable.draw(canvas); canvas.restore(); } }, start, start + 1, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); } mFolderDisplayer.loadConversationFolders(conv, null /* ignoreFolder */, -1 /* ignoreFolderType */); mFolderDisplayer.constructFolderChips(sb); final int end = sb.length(); sb.setSpan(new ChangeLabelsSpan(callbacks), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); setText(sb); setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:org.wikipedia.page.shareafact.SnippetImage.java
private static void drawWordmarkFromText(@NonNull Context context, @NonNull Canvas canvas, boolean isArticleRTL) { final int maxWidth = WIDTH - DESCRIPTION_WIDTH - 2 * HORIZONTAL_PADDING; final float fontSize = 20.0f; final float scaleX = 1.06f; TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true);/*from ww w . j a v a2 s . c o m*/ textPaint.setColor(Color.LTGRAY); textPaint.setTextSize(fontSize); textPaint.setTypeface(SERIF); textPaint.setTextScaleX(scaleX); Spanned wikipedia = StringUtil.fromHtml(context.getString(R.string.wp_stylized)); Layout.Alignment align = L10nUtil.isDeviceRTL() ? ALIGN_OPPOSITE : ALIGN_NORMAL; StaticLayout wordmarkLayout = buildLayout( new TextLayoutParams(wikipedia, textPaint, maxWidth, 1.0f, align)); final int width = (int) wordmarkLayout.getLineWidth(0); final int height = wordmarkLayout.getHeight(); final int bottom = HEIGHT - BOTTOM_PADDING; final int top = bottom - height; int left = WIDTH - HORIZONTAL_PADDING - width; if (isArticleRTL) { left = HORIZONTAL_PADDING; } canvas.save(); // -- canvas.translate(left, top); wordmarkLayout.draw(canvas); canvas.restore(); // -- }
From source file:org.telegram.ui.Cells.AboutLinkCell.java
@Override protected void onDraw(Canvas canvas) { canvas.save();//from www .j a v a 2 s . c o m canvas.translate(textX = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 71), textY = AndroidUtilities.dp(8)); if (pressedLink != null) { canvas.drawPath(urlPath, urlPaint); } try { if (textLayout != null) { textLayout.draw(canvas); } } catch (Exception e) { FileLog.e("tmessages", e); } canvas.restore(); }
From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java
protected void doDraw(Canvas canvas) { Bitmap preview = mMasterImage.getBitmap(); canvas.save(); drawImages(canvas, preview); canvas.restore(); }
From source file:foam.jellyfish.StarwispCanvas.java
public void DrawText(Canvas canvas, JSONArray prim, float sx, float sy) { try {//from w w w . j av a2s .c om canvas.save(); if (prim.getString(6).equals("vertical")) canvas.rotate(-90, prim.getInt(2) * sx, prim.getInt(3) * sy); Paint myPaint = new Paint(); JSONArray c = prim.getJSONArray(4); myPaint.setColor(Color.rgb(c.getInt(0), c.getInt(1), c.getInt(2))); myPaint.setTextSize(prim.getInt(5)); myPaint.setTypeface(m_Typeface); canvas.drawText(prim.getString(1), prim.getInt(2) * sx, prim.getInt(3) * sy, myPaint); canvas.restore(); } catch (JSONException e) { Log.e("starwisp", "Error parsing data " + e.toString()); } }
From source file:tw.firemaples.onscreenocr.views.AreaSelectionView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (!isInEditMode()) { canvas.save();/*w w w. ja v a 2 s . com*/ if (drawingStartPoint != null && drawingEndPoint != null) { // canvas.drawLine(drawingStartPoint.x, drawingStartPoint.y, drawingEndPoint.x, drawingEndPoint.y, drawingLinePaint); canvas.drawRect(getNewBox(drawingStartPoint, drawingEndPoint), drawingLinePaint); } for (Rect box : boxList) { canvas.drawRect(box, boxPaint); } canvas.restore(); } }
From source file:com.github.czy1121.view.CornerLabelView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); float xy = mHeight / SQRT2; canvas.save();//from w ww . j a va 2s. c om canvas.translate(xy, xy); canvas.rotate((mIsTop ? 1 : -1) * (mIsLeft ? -45 : 45)); canvas.drawPath(calcPath(), mPaint); mText1.draw(canvas, mPaddingBottom, mIsTop); if (mIsTriangle) { mText2.draw(canvas, mPaddingBottom + mPaddingCenter + mText1.height, mIsTop); } canvas.restore(); }
From source file:org.telegram.ui.Cells.BotHelpCell.java
@Override protected void onDraw(Canvas canvas) { int x = (canvas.getWidth() - width) / 2; int y = AndroidUtilities.dp(4); Theme.backgroundMediaDrawableIn.setBounds(x, y, width + x, height + y); Theme.backgroundMediaDrawableIn.draw(canvas); canvas.save();//from ww w . j ava 2 s .c o m canvas.translate(textX = AndroidUtilities.dp(2 + 9) + x, textY = AndroidUtilities.dp(2 + 9) + y); if (pressedLink != null) { canvas.drawPath(urlPath, urlPaint); } if (textLayout != null) { textLayout.draw(canvas); } canvas.restore(); }
From source file:com.ahamed.sample.common.decorator.ArticleItemDecorator.java
@SuppressLint("NewApi") private void draw(Canvas canvas, RecyclerView parent, View child) { canvas.save();/*ww w. j a v a 2s . c o m*/ final int left; final int right; if (parent.getClipToPadding()) { left = parent.getPaddingLeft(); right = parent.getWidth() - parent.getPaddingRight(); canvas.clipRect(left, parent.getPaddingTop(), right, parent.getHeight() - parent.getPaddingBottom()); } else { left = 0; right = parent.getWidth(); } parent.getDecoratedBoundsWithMargins(child, mBounds); final int bottom = mBounds.bottom + Math.round(ViewCompat.getTranslationY(child)); final int top = bottom - 16; canvas.drawRect(left, top, right, bottom, myPaint); canvas.restore(); }