Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

place the arrow centre on the popup windows #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions src/net/londatiga/android/QuickAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -387,4 +385,4 @@ public interface OnActionItemClickListener {
public interface OnDismissListener {
public abstract void onDismiss();
}
}
}