List of usage examples for android.graphics Canvas save
public int save()
From source file:com.mikepenz.materialize.view.ScrimInsetsFrameLayout.java
@Override public void draw(Canvas canvas) { super.draw(canvas); int width = getWidth(); int height = getHeight(); if (mInsets != null && mInsetForeground != null) { int sc = canvas.save(); canvas.translate(getScrollX(), getScrollY()); if (!mSystemUIVisible) { mInsets.top = 0;/*w w w . ja v a 2 s. c om*/ mInsets.right = 0; mInsets.bottom = 0; mInsets.left = 0; } // Top if (mTintStatusBar) { mTempRect.set(0, 0, width, mInsets.top); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); } // Bottom if (mTintNavigationBar) { mTempRect.set(0, height - mInsets.bottom, width, height); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); } // Left mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); // Right mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom); mInsetForeground.setBounds(mTempRect); mInsetForeground.draw(canvas); canvas.restoreToCount(sc); } }
From source file:com.appsimobile.appsii.module.home.SunriseDrawable.java
@Override public void draw(Canvas canvas) { Rect bounds = getBounds();//from w ww .java 2 s .co m if (mIsRtl) { canvas.save(); canvas.scale(-1, 1, bounds.centerX(), bounds.centerY()); } float pct = drawArc(canvas, bounds); if (pct < 0) { pct = 0; } else if (pct > 1) { pct = 1; } int y = bounds.bottom - mBottomOffset; canvas.drawLine(bounds.left + mLeftOffset / 2, y, bounds.right - mRightOffset / 2, y, mLinePaint); drawSun(canvas, pct); if (mIsRtl) { canvas.restore(); } }
From source file:com.umeng.comm.ui.imagepicker.widgets.ViewPagerIndicator.java
/** * //from ww w. j av a2 s . co m */ @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); }
From source file:com.cocosw.accessory.views.layout.CollapsingTitleLayout.java
@Override public void draw(Canvas canvas) { final int saveCount = canvas.save(); final int toolbarHeight = mToolbar.getHeight(); canvas.clipRect(0, 0, canvas.getWidth(), interpolate(canvas.getHeight(), toolbarHeight, mScrollOffset)); // Now call super and let it draw the background, etc super.draw(canvas); if (mTitleToDraw != null) { float x = mTextLeft; float y = mTextTop; if (!mUseTexture) { // If we're not drawing a texture, we need to properly offset the text x -= mDrawnTextBounds.left;/* w ww . java 2 s.c o m*/ y -= mDrawnTextBounds.top; } if (DEBUG_DRAW) { // Just a debug tool, which drawn a Magneta rect in the text bounds canvas.drawRect(mTextLeft, mTextTop, mTextRight, mTextTop + mDrawnTextBounds.height(), DEBUG_DRAW_PAINT); } if (mScale != 1f) { canvas.scale(mScale, mScale, x, y); } if (mUseTexture && mExpandedTitleTexture != null) { // If we should use a texture, draw it instead of text canvas.drawBitmap(mExpandedTitleTexture, x, y, mTexturePaint); } else { canvas.drawText(mTitleToDraw, x, y, mTextPaint); } } canvas.restoreToCount(saveCount); }
From source file:de.baumann.thema.FragmentWallpaper.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == R.id.color) { ColorPickerDialogBuilder.with(getActivity()).initialColor(0xff2196f3).setTitle(R.string.custom) .wheelType(ColorPickerView.WHEEL_TYPE.FLOWER).density(9) .setPositiveButton(R.string.yes, new ColorPickerClickListener() { @Override//from w ww.j av a2 s . c o m public void onClick(DialogInterface dialog, int selectedColor, Integer[] allColors) { try { WallpaperManager wm = WallpaperManager.getInstance(getActivity()); // Create 1x1 bitmap to store the color Bitmap bmp = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); // Make a canvas with which we can draw to the bitmap Canvas canvas = new Canvas(bmp); // Fill with color and save canvas.drawColor(selectedColor); canvas.save(); wm.setBitmap(bmp); bmp.recycle(); Snackbar.make(imgHeader, R.string.applying, Snackbar.LENGTH_LONG).show(); } catch (IOException e) { // oh lord! } } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).build().show(); return false; } if (id == R.id.help) { SpannableString s; if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { s = new SpannableString( Html.fromHtml(getString(R.string.help_wallpaper), Html.FROM_HTML_MODE_LEGACY)); } else { //noinspection deprecation s = new SpannableString(Html.fromHtml(getString(R.string.help_wallpaper))); } Linkify.addLinks(s, Linkify.WEB_URLS); final AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()) .setTitle(R.string.title_wallpaper).setMessage(s) .setPositiveButton(getString(R.string.yes), null); dialog.show(); return false; } return super.onOptionsItemSelected(item); }
From source file:org.mozilla.focus.widget.AnimatedProgressBar.java
@Override public void onDraw(Canvas canvas) { if (mClipRegion == 0) { super.onDraw(canvas); } else {/*from w w w.j a v a 2 s.com*/ canvas.getClipBounds(tempRect); final float clipWidth = tempRect.width() * mClipRegion; final int saveCount = canvas.save(); if (mIsRtl) { canvas.clipRect(tempRect.left, tempRect.top, tempRect.right - clipWidth, tempRect.bottom); } else { canvas.clipRect(tempRect.left + clipWidth, tempRect.top, tempRect.right, tempRect.bottom); } super.onDraw(canvas); canvas.restoreToCount(saveCount); } }
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(); canvas.translate(textX = AndroidUtilities.dp(2 + 9) + x, textY = AndroidUtilities.dp(2 + 9) + y); if (pressedLink != null) { canvas.drawPath(urlPath, urlPaint); }/*from w w w . j a v a 2 s . c o m*/ if (textLayout != null) { textLayout.draw(canvas); } canvas.restore(); }
From source file:android.support.design.widget.ShadowDrawableWrapper.java
private void drawShadow(Canvas canvas) { final int rotateSaved = canvas.save(); canvas.rotate(mRotation, mContentBounds.centerX(), mContentBounds.centerY()); final float edgeShadowTop = -mCornerRadius - mShadowSize; final float shadowOffset = mCornerRadius; final boolean drawHorizontalEdges = mContentBounds.width() - 2 * shadowOffset > 0; final boolean drawVerticalEdges = mContentBounds.height() - 2 * shadowOffset > 0; final float shadowOffsetTop = mRawShadowSize - (mRawShadowSize * SHADOW_TOP_SCALE); final float shadowOffsetHorizontal = mRawShadowSize - (mRawShadowSize * SHADOW_HORIZ_SCALE); final float shadowOffsetBottom = mRawShadowSize - (mRawShadowSize * SHADOW_BOTTOM_SCALE); final float shadowScaleHorizontal = shadowOffset / (shadowOffset + shadowOffsetHorizontal); final float shadowScaleTop = shadowOffset / (shadowOffset + shadowOffsetTop); final float shadowScaleBottom = shadowOffset / (shadowOffset + shadowOffsetBottom); // LT// w ww . j a v a2s. co m int saved = canvas.save(); canvas.translate(mContentBounds.left + shadowOffset, mContentBounds.top + shadowOffset); canvas.scale(shadowScaleHorizontal, shadowScaleTop); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawHorizontalEdges) { // TE canvas.scale(1f / shadowScaleHorizontal, 1f); canvas.drawRect(0, edgeShadowTop, mContentBounds.width() - 2 * shadowOffset, -mCornerRadius, mEdgeShadowPaint); } canvas.restoreToCount(saved); // RB saved = canvas.save(); canvas.translate(mContentBounds.right - shadowOffset, mContentBounds.bottom - shadowOffset); canvas.scale(shadowScaleHorizontal, shadowScaleBottom); canvas.rotate(180f); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawHorizontalEdges) { // BE canvas.scale(1f / shadowScaleHorizontal, 1f); canvas.drawRect(0, edgeShadowTop, mContentBounds.width() - 2 * shadowOffset, -mCornerRadius + mShadowSize, mEdgeShadowPaint); } canvas.restoreToCount(saved); // LB saved = canvas.save(); canvas.translate(mContentBounds.left + shadowOffset, mContentBounds.bottom - shadowOffset); canvas.scale(shadowScaleHorizontal, shadowScaleBottom); canvas.rotate(270f); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawVerticalEdges) { // LE canvas.scale(1f / shadowScaleBottom, 1f); canvas.drawRect(0, edgeShadowTop, mContentBounds.height() - 2 * shadowOffset, -mCornerRadius, mEdgeShadowPaint); } canvas.restoreToCount(saved); // RT saved = canvas.save(); canvas.translate(mContentBounds.right - shadowOffset, mContentBounds.top + shadowOffset); canvas.scale(shadowScaleHorizontal, shadowScaleTop); canvas.rotate(90f); canvas.drawPath(mCornerShadowPath, mCornerShadowPaint); if (drawVerticalEdges) { // RE canvas.scale(1f / shadowScaleTop, 1f); canvas.drawRect(0, edgeShadowTop, mContentBounds.height() - 2 * shadowOffset, -mCornerRadius, mEdgeShadowPaint); } canvas.restoreToCount(saved); canvas.restoreToCount(rotateSaved); }
From source file:com.limxing.library.PullToRefresh.SwipeProgressBar.java
void draw(Canvas canvas) { // final int width = mBounds.width(); final int height = mBounds.height(); int restoreCount = canvas.save(); canvas.clipRect(mBounds);//from w w w . j av a2 s . com if (mRunning || (mFinishTime > 0)) { if (!mRunning) { mFinishTime = 0; return; } this.tips = processingTips; drawBar(canvas, height); // Keep running until we finish out the last cycle. ViewCompat.postInvalidateOnAnimation(mParent); } else { if (height > 0) { drawBar(canvas, height); } } if (state != FINISHED) { canvas.restoreToCount(restoreCount); } }
From source file:com.zzti.fyg.widgets.SwipeProgressBar.java
void draw(Canvas canvas) { // final int width = mBounds.width(); final int height = mBounds.height(); int restoreCount = canvas.save(); canvas.clipRect(mBounds);//from w w w . j a v a 2s .co m if (mRunning || (mFinishTime > 0)) { if (!mRunning) { mFinishTime = 0; return; } this.tips = processingTips; drawBar(canvas, height); // Keep running until we finish out the last cycle. ViewCompat.postInvalidateOnAnimation(mParent); } else { if (height > 0) { drawBar(canvas, height); } } if (state != FINISHED) { canvas.restoreToCount(restoreCount); } }