From 7cf9470e20861369e77c280de32a17a13609911d Mon Sep 17 00:00:00 2001 From: linsea Date: Fri, 26 Dec 2014 15:26:36 +0800 Subject: [PATCH] place the arrow centre on the popup windows --- src/net/londatiga/android/QuickAction.java | 36 ++++++++++------------ 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/net/londatiga/android/QuickAction.java b/src/net/londatiga/android/QuickAction.java index 77b7855..9043dbf 100644 --- a/src/net/londatiga/android/QuickAction.java +++ b/src/net/londatiga/android/QuickAction.java @@ -247,24 +247,22 @@ public void show (View anchor) { int screenWidth = mWindowManager.getDefaultDisplay().getWidth(); int screenHeight = mWindowManager.getDefaultDisplay().getHeight(); - //automatically get X coord of popup (top left) - if ((anchorRect.left + rootWidth) > screenWidth) { - xPos = anchorRect.left - (rootWidth-anchor.getWidth()); - xPos = (xPos < 0) ? 0 : xPos; - - arrowPos = anchorRect.centerX()-xPos; - - } else { - if (anchor.getWidth() > rootWidth) { - xPos = anchorRect.centerX() - (rootWidth/2); - } else { - xPos = anchorRect.left; - } - - arrowPos = anchorRect.centerX()-xPos; - } - - int dyTop = anchorRect.top; + // //automatically get X coord of popup (top left) + int leftX = anchorRect.centerX() - rootWidth / 2; + int rightX = anchorRect.centerX() + rootWidth / 2; + + if (leftX >= 0) {// enough space for left + if (rightX <= screenWidth) { // enough space for right + xPos = leftX; + } else { + xPos = screenWidth - rootWidth - 5;//magin right 5. + } + } else { + xPos = 5;// magin left 5 + } + arrowPos = anchorRect.centerX() - xPos; + + int dyTop = anchorRect.top; int dyBottom = screenHeight - anchorRect.bottom; boolean onTop = (dyTop > dyBottom) ? true : false; @@ -387,4 +385,4 @@ public interface OnActionItemClickListener { public interface OnDismissListener { public abstract void onDismiss(); } -} \ No newline at end of file +}