diff --git a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java index b2d22bd3..832d6383 100644 --- a/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java +++ b/library/src/main/java/uk/co/deanwild/materialshowcaseview/MaterialShowcaseView.java @@ -3,7 +3,6 @@ import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; -import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; @@ -41,10 +40,6 @@ */ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchListener, View.OnClickListener { - private int mOldHeight; - private int mOldWidth; - private Bitmap mBitmap;// = new WeakReference<>(null); - private Canvas mCanvas; private Paint mEraser; private Target mTarget; private Shape mShape; @@ -67,7 +62,6 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis private long mFadeDurationInMillis = ShowcaseConfig.DEFAULT_FADE_TIME; private Handler mHandler; private long mDelayInMillis = ShowcaseConfig.DEFAULT_DELAY; - private int mBottomMargin = 0; private boolean mSingleUse = false; // should display only once private PrefsManager mPrefsManager; // used to store state doe single use mode List mListeners; // external listeners who want to observe when we show and dismiss @@ -76,27 +70,27 @@ public class MaterialShowcaseView extends FrameLayout implements View.OnTouchLis public MaterialShowcaseView(Context context) { super(context); - init(context); + init(); } public MaterialShowcaseView(Context context, AttributeSet attrs) { super(context, attrs); - init(context); + init(); } public MaterialShowcaseView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - init(context); + init(); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public MaterialShowcaseView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); - init(context); + init(); } - private void init(Context context) { + private void init() { setWillNotDraw(false); // create our animation factory @@ -114,12 +108,18 @@ private void init(Context context) { mMaskColour = Color.parseColor(ShowcaseConfig.DEFAULT_MASK_COLOUR); setVisibility(INVISIBLE); + // prepare eraser paint + mEraser = new Paint(); + mEraser.setColor(0xFFFFFFFF); + mEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + mEraser.setFlags(Paint.ANTI_ALIAS_FLAG); View contentView = LayoutInflater.from(getContext()).inflate(R.layout.showcase_content, this, true); mContentBox = contentView.findViewById(R.id.content_box); mContentTextView = (TextView) contentView.findViewById(R.id.tv_content); mDismissButton = (TextView) contentView.findViewById(R.id.tv_dismiss); mDismissButton.setOnClickListener(this); + setLayerType(LAYER_TYPE_SOFTWARE, null); } @@ -137,44 +137,14 @@ protected void onDraw(Canvas canvas) { // don't bother drawing if we're not ready if (!mShouldRender) return; - // get current dimensions - int width = getMeasuredWidth(); - int height = getMeasuredHeight(); - - // build a new canvas if needed i.e first pass or new dimensions - if (mBitmap == null || mCanvas == null || mOldHeight != height || mOldWidth != width) { - - if (mBitmap != null) mBitmap.recycle(); - - mBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); - - - mCanvas = new Canvas(mBitmap); - } - - // save our 'old' dimensions - mOldWidth = width; - mOldHeight = height; - // clear canvas - mCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); + canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); // draw solid background - mCanvas.drawColor(mMaskColour); - - // Prepare eraser Paint if needed - if (mEraser == null) { - mEraser = new Paint(); - mEraser.setColor(0xFFFFFFFF); - mEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); - mEraser.setFlags(Paint.ANTI_ALIAS_FLAG); - } + canvas.drawColor(mMaskColour); // draw (erase) shape - mShape.draw(mCanvas, mEraser, mXPosition, mYPosition, mShapePadding); - - // Draw the bitmap on our views canvas. - canvas.drawBitmap(mBitmap, 0, 0, null); + mShape.draw(canvas, mEraser, mXPosition, mYPosition, mShapePadding); } @Override @@ -257,11 +227,11 @@ public void setTarget(Target target) { * If we're on lollipop then make sure we don't draw over the nav bar */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - mBottomMargin = getSoftButtonsBarSizePort((Activity) getContext()); + int bottomMargin = getSoftButtonsBarSizePort((Activity) getContext()); FrameLayout.LayoutParams contentLP = (LayoutParams) getLayoutParams(); - if (contentLP != null && contentLP.bottomMargin != mBottomMargin) - contentLP.bottomMargin = mBottomMargin; + if (contentLP != null && contentLP.bottomMargin != bottomMargin) + contentLP.bottomMargin = bottomMargin; } // apply the target position @@ -617,14 +587,8 @@ public void removeFromWindow() { ((ViewGroup) getParent()).removeView(this); } - if (mBitmap != null) { - mBitmap.recycle(); - mBitmap = null; - } - mEraser = null; mAnimationFactory = null; - mCanvas = null; mHandler = null; getViewTreeObserver().removeGlobalOnLayoutListener(mLayoutListener);