Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

Commit

Permalink
Fixed misalignment of GuideView and Skip on orientation change
Browse files Browse the repository at this point in the history
  • Loading branch information
Adw41t committed Aug 14, 2021
1 parent 0da9aa0 commit b81d2b8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ protected void onDraw(Canvas canvas)
_paint.setColor(_circleColor);

canvas.drawCircle(cx, cy, radius, _paint);

getLocationOnScreen(locationTarget);
getLocationInWindow(locationTarget);
int centerX = pl + halfUsableWidth + locationTarget[0];
int centerY = pt + halfUsableHeight + locationTarget[1];
_guidePath.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
import android.graphics.Xfermode;
import android.os.Build;
import android.text.Spannable;
import android.view.Display;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.widget.FrameLayout;
import android.widget.TextView;
Expand Down Expand Up @@ -133,7 +136,6 @@ private GuideView(Context context, View view) {
skipParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
((LayoutParams)skipParams).setMargins(0,0,10,140);
((LayoutParams)skipParams).gravity = android.view.Gravity.RIGHT | android.view.Gravity.BOTTOM;
skipButton.setLayoutParams(skipParams);

mMessageView.setPadding(
messageViewPadding,
Expand All @@ -157,9 +159,6 @@ public void onClick(View view) {
dismiss(lastTargetView);
}
});
if(setSkip) {
addView(skipButton, skipParams);
}
setMessageLocation(resolveMessageViewLocation());

ViewTreeObserver.OnGlobalLayoutListener layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
Expand All @@ -177,7 +176,7 @@ public void onGlobalLayout() {
targetRect = ((Targetable) target).boundingRect();
} else {
int[] locationTarget = new int[2];
target.getLocationOnScreen(locationTarget);
target.getLocationInWindow(locationTarget);
targetRect = new RectF(
locationTarget[0],
locationTarget[1],
Expand Down Expand Up @@ -281,6 +280,17 @@ private boolean isLandscape() {
return display_mode != Configuration.ORIENTATION_PORTRAIT;
}

private int checkOrientation(){
try{
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
return rotation;
}
catch (Exception e){
return Surface.ROTATION_0;
}
}

@Override
protected void onDraw(final Canvas canvas) {
super.onDraw(canvas);
Expand Down Expand Up @@ -475,6 +485,24 @@ public void show() {
this.startAnimation(startAnimation);
mIsShowing = true;
if(setSkip) {

switch(checkOrientation()){
case Surface.ROTATION_0:
((LayoutParams)skipParams).setMargins(0,0,10,140);
((LayoutParams)skipParams).gravity = android.view.Gravity.RIGHT | android.view.Gravity.BOTTOM;
break;

case Surface.ROTATION_90:
((LayoutParams)skipParams).setMargins(10,0,0,0);
((LayoutParams)skipParams).gravity = android.view.Gravity.LEFT | android.view.Gravity.BOTTOM;
break;

case Surface.ROTATION_270:
((LayoutParams)skipParams).setMargins(0,0,10,0);
((LayoutParams)skipParams).gravity = android.view.Gravity.RIGHT | android.view.Gravity.BOTTOM;
break;
}

addView(skipButton, skipParams);
}
}
Expand Down

0 comments on commit b81d2b8

Please sign in to comment.