mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-18 19:52:19 +01:00
DroidFish: Handle screen resize (for example show/hide navigation bar)
when drawing the tour guide overlay.
This commit is contained in:
@@ -2,18 +2,15 @@ package tourguide.tourguide;
|
|||||||
|
|
||||||
import android.animation.AnimatorSet;
|
import android.animation.AnimatorSet;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Path;
|
||||||
|
import android.graphics.Path.FillType;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.PorterDuff;
|
|
||||||
import android.graphics.PorterDuffXfermode;
|
|
||||||
import android.support.v4.view.MotionEventCompat;
|
import android.support.v4.view.MotionEventCompat;
|
||||||
import android.text.TextPaint;
|
import android.text.TextPaint;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Display;
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -28,12 +25,9 @@ public class FrameLayoutWithHole extends FrameLayout {
|
|||||||
private TextPaint mTextPaint;
|
private TextPaint mTextPaint;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private TourGuide.MotionType mMotionType;
|
private TourGuide.MotionType mMotionType;
|
||||||
private Paint mEraser;
|
|
||||||
|
|
||||||
Bitmap mEraserBitmap;
|
private Path mPath;
|
||||||
private Canvas mEraserCanvas;
|
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
private Paint transparentPaint;
|
|
||||||
private View mViewHole; // This is the targeted view to be highlighted, where the hole should be placed
|
private View mViewHole; // This is the targeted view to be highlighted, where the hole should be placed
|
||||||
private int mRadius;
|
private int mRadius;
|
||||||
private int [] mPos;
|
private int [] mPos;
|
||||||
@@ -115,27 +109,10 @@ public class FrameLayoutWithHole extends FrameLayout {
|
|||||||
mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
|
mTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
|
||||||
mTextPaint.setTextAlign(Paint.Align.LEFT);
|
mTextPaint.setTextAlign(Paint.Align.LEFT);
|
||||||
|
|
||||||
Point size = new Point();
|
mPath = new Path();
|
||||||
size.x = mActivity.getResources().getDisplayMetrics().widthPixels;
|
|
||||||
size.y = mActivity.getResources().getDisplayMetrics().heightPixels;
|
|
||||||
|
|
||||||
mEraserBitmap = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888);
|
|
||||||
mEraserCanvas = new Canvas(mEraserBitmap);
|
|
||||||
|
|
||||||
mPaint = new Paint();
|
mPaint = new Paint();
|
||||||
mPaint.setColor(0xcc000000);
|
mPaint.setAntiAlias(true);
|
||||||
transparentPaint = new Paint();
|
|
||||||
transparentPaint.setColor(getResources().getColor(android.R.color.transparent));
|
|
||||||
transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
|
|
||||||
|
|
||||||
mEraser = new Paint();
|
|
||||||
mEraser.setColor(0xFFFFFFFF);
|
|
||||||
mEraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
|
|
||||||
mEraser.setFlags(Paint.ANTI_ALIAS_FLAG);
|
|
||||||
|
|
||||||
Log.d("tourguide","getHeight: "+ size.y);
|
|
||||||
Log.d("tourguide","getWidth: " + size.x);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean mCleanUpLock = false;
|
private boolean mCleanUpLock = false;
|
||||||
@@ -168,9 +145,6 @@ public class FrameLayoutWithHole extends FrameLayout {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDetachedFromWindow() {
|
protected void onDetachedFromWindow() {
|
||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
/* cleanup reference to prevent memory leak */
|
|
||||||
mEraserCanvas.setBitmap(null);
|
|
||||||
mEraserBitmap = null;
|
|
||||||
|
|
||||||
if (mAnimatorSetArrayList != null && mAnimatorSetArrayList.size() > 0){
|
if (mAnimatorSetArrayList != null && mAnimatorSetArrayList.size() > 0){
|
||||||
for(int i=0;i<mAnimatorSetArrayList.size();i++){
|
for(int i=0;i<mAnimatorSetArrayList.size();i++){
|
||||||
@@ -266,19 +240,24 @@ public class FrameLayoutWithHole extends FrameLayout {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDraw(Canvas canvas) {
|
protected void onDraw(Canvas canvas) {
|
||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
mEraserBitmap.eraseColor(Color.TRANSPARENT);
|
if (mOverlay != null) {
|
||||||
|
mPath.rewind();
|
||||||
if (mOverlay!=null) {
|
mPath.addRect(0, 0, canvas.getWidth(), canvas.getHeight(), Path.Direction.CW);
|
||||||
mEraserCanvas.drawColor(mOverlay.mBackgroundColor);
|
|
||||||
int padding = (int) (10 * mDensity);
|
|
||||||
if (mOverlay.mStyle == Overlay.Style.Rectangle) {
|
if (mOverlay.mStyle == Overlay.Style.Rectangle) {
|
||||||
mEraserCanvas.drawRect(mPos[0] - padding, mPos[1] - padding, mPos[0] + mViewHole.getWidth() + padding, mPos[1] + mViewHole.getHeight() + padding, mEraser);
|
int padding = (int) (10 * mDensity);
|
||||||
|
mPath.addRect(mPos[0] - padding, mPos[1] - padding,
|
||||||
|
mPos[0] + mViewHole.getWidth() + padding,
|
||||||
|
mPos[1] + mViewHole.getHeight() + padding,
|
||||||
|
Path.Direction.CCW);
|
||||||
} else {
|
} else {
|
||||||
mEraserCanvas.drawCircle(mPos[0] + mViewHole.getWidth() / 2, mPos[1] + mViewHole.getHeight() / 2, mRadius, mEraser);
|
mPath.addCircle(mPos[0] + mViewHole.getWidth() / 2,
|
||||||
|
mPos[1] + mViewHole.getHeight() / 2,
|
||||||
|
mRadius, Path.Direction.CCW);
|
||||||
}
|
}
|
||||||
|
mPath.setFillType(FillType.WINDING);
|
||||||
|
mPaint.setColor(mOverlay.mBackgroundColor);
|
||||||
|
canvas.drawPath(mPath, mPaint);
|
||||||
}
|
}
|
||||||
canvas.drawBitmap(mEraserBitmap, 0, 0, null);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onAttachedToWindow() {
|
protected void onAttachedToWindow() {
|
||||||
|
|||||||
Reference in New Issue
Block a user