List of usage examples for android.graphics Canvas restore
public void restore()
From source file:org.wikipedia.page.shareafact.SnippetImage.java
@NonNull private static Layout drawTextSnippet(@NonNull Canvas canvas, @NonNull CharSequence textSnippet) { final int top = TOP_PADDING; final int maxHeight = 225; final int maxLines = 5; final float maxFontSize = 195.0f; final float minFontSize = 32.0f; TextPaint textPaint = new TextPaint(); textPaint.setAntiAlias(true);/* w ww . j a va 2 s . c o m*/ textPaint.setColor(Color.WHITE); textPaint.setTextSize(maxFontSize); textPaint.setStyle(Paint.Style.FILL); textPaint.setTypeface(Typeface.DEFAULT_BOLD); textPaint.setShadowLayer(1.0f, 1.0f, 1.0f, Color.GRAY); StaticLayout textLayout = optimizeTextSize( new TextLayoutParams(textSnippet, textPaint, TEXT_WIDTH, SPACING_MULTIPLIER), maxHeight, maxLines, maxFontSize, minFontSize); canvas.save(); int horizontalCenterOffset = top + (maxHeight - textLayout.getHeight()) / QUARTER; canvas.translate(HORIZONTAL_PADDING, horizontalCenterOffset); textLayout.draw(canvas); canvas.restore(); return textLayout; }
From source file:Main.java
public static boolean drawDrawables(Canvas canvas, @Nonnull TextView textView) { final int compoundPaddingLeft = textView.getCompoundPaddingLeft(); final int compoundPaddingTop = textView.getCompoundPaddingTop(); final int compoundPaddingRight = textView.getCompoundPaddingRight(); final int compoundPaddingBottom = textView.getCompoundPaddingBottom(); final int scrollX = textView.getScrollX(); final int scrollY = textView.getScrollY(); final int right = textView.getRight(); final int left = textView.getLeft(); final int bottom = textView.getBottom(); final int top = textView.getTop(); final Drawable[] drawables = textView.getCompoundDrawables(); if (drawables != null) { int vspace = bottom - top - compoundPaddingBottom - compoundPaddingTop; int hspace = right - left - compoundPaddingRight - compoundPaddingLeft; Drawable topDr = drawables[1];/* w ww. j a v a 2 s . com*/ // IMPORTANT: The coordinates computed are also used in invalidateDrawable() // Make sure to update invalidateDrawable() when changing this code. if (topDr != null) { canvas.save(); canvas.translate(scrollX + compoundPaddingLeft + (hspace - topDr.getBounds().width()) / 2, scrollY + textView.getPaddingTop() + vspace / 2); topDr.draw(canvas); canvas.restore(); return true; } } return false; }
From source file:com.arbo.gaogao.widget.MyParallaxScrimageView.java
@Override protected void onDraw(Canvas canvas) { if (imageOffset != 0) { canvas.save();/*from w w w .j a va 2s .co m*/ canvas.translate(0f, imageOffset); canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset); super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); canvas.restore(); } else { super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); } }
From source file:com.handmark.pulltorefresh.library.internal.LoadingLayout.java
private void rotateArrow() { final Drawable drawable = mHeaderArrow.getDrawable(); final Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);/* w w w . ja va 2 s . com*/ final Canvas canvas = new Canvas(bitmap); canvas.save(); canvas.rotate(180.0f, canvas.getWidth() / 2.0f, canvas.getHeight() / 2.0f); drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); drawable.draw(canvas); canvas.restore(); mHeaderArrow.setImageBitmap(bitmap); }
From source file:io.github.sin3hz.wifispinnerview.WifiSpinnerDrawable.java
@Override public void draw(Canvas canvas) { canvas.save();// w w w.j a va 2 s. co m canvas.rotate(mGlobalAngle, mBounds.centerX(), mBounds.centerY()); for (int i = 0; i < mSpinnerCount; i++) { canvas.drawPath(mSpinners[i].path, mSpinners[i].paint); } canvas.restore(); }
From source file:br.com.leoleal.swipetorefresh.SwipeProgressBar.java
/** * Draws a circle centered in the view./*from www.j a v a 2s . c om*/ * * @param canvas the canvas to draw on * @param cx the center x coordinate * @param cy the center y coordinate * @param color the color to draw * @param pct the percentage of the view that the circle should cover */ private void drawCircle(Canvas canvas, float cx, float cy, int color, float pct) { mPaint.setColor(color); canvas.save(); canvas.translate(cx, cy); float radiusScale = INTERPOLATOR.getInterpolation(pct); canvas.scale(radiusScale, radiusScale); canvas.drawCircle(0, 0, cx, mPaint); canvas.restore(); }
From source file:com.lovejjfg.zhifou.ui.widget.ParallaxScrimageView.java
@Override protected void onDraw(Canvas canvas) { if (imageOffset != 0) { canvas.save();/*from w w w . j a v a 2 s .c o m*/ canvas.translate(0f, imageOffset); Log.i("imageOffset", "onDraw: " + imageOffset); canvas.clipRect(0f, 0f, canvas.getWidth(), canvas.getHeight() + imageOffset); super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); canvas.restore(); } else { super.onDraw(canvas); canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), scrimPaint); } }
From source file:chrisrenke.drawerarrowdrawable.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { if (flip) {/* w w w . j a v a 2 s . c o m*/ canvas.save(); canvas.scale(1f, -1f, getIntrinsicWidth() / 2, getIntrinsicHeight() / 2); } topLine.draw(canvas); middleLine.draw(canvas); bottomLine.draw(canvas); if (flip) canvas.restore(); }
From source file:com.flyn.smartandroid.views.DrawerArrowDrawable.java
@Override public void draw(Canvas canvas) { if (flip) {// w ww . j av a 2 s . c o m canvas.save(); canvas.scale(1f, -1f, getIntrinsicWidth() / 2, getIntrinsicHeight() / 2); } topLine.draw(canvas); middleLine.draw(canvas); bottomLine.draw(canvas); if (flip) { canvas.restore(); } }
From source file:com.umeng.comm.ui.imagepicker.widgets.ViewPagerIndicator.java
/** * /*w w w . j a v a 2 s .c om*/ */ @Override protected void dispatchDraw(Canvas canvas) { canvas.save(); // ? canvas.translate(mInitTranslationX + mTranslationX, getHeight() + 5); canvas.drawPath(mPath, mPaint); canvas.restore(); // tab canvas.drawLine(mTranslationX, getHeight() - 3, mTranslationX + mHalfScreenWidth, getHeight() - 3, mLinePaint); // canvas.drawLine(0, getHeight() - 1, 2 * mHalfScreenWidth, getHeight() - 1, mDividerLinePaint); super.dispatchDraw(canvas); }