Skip to content

Commit

Permalink
fix: float window covers the input text on top/bottom edge
Browse files Browse the repository at this point in the history
  • Loading branch information
cabins committed Dec 6, 2023
1 parent 5dde264 commit 0bd141d
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions app/src/main/java/com/osfans/trime/ime/core/Trime.java
Expand Up @@ -144,13 +144,12 @@ public void run() {
if (mCandidateRoot == null || mCandidateRoot.getWindowToken() == null) return;
if (!isPopupWindowEnabled) return;

final int minX = popupMarginH;
final int minY = popupMargin;

DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
final int maxX = displayMetrics.widthPixels - mPopupWindow.getWidth() - minX;
final int maxY = displayMetrics.heightPixels - mPopupWindow.getHeight() - minY;
final int minX = popupMarginH;
final int maxX = displayMetrics.widthPixels - mPopupWindow.getWidth() - popupMarginH;
final int minY = popupMargin + BarUtils.getStatusBarHeight() + mPopupWindow.getHeight();
final int maxY = displayMetrics.heightPixels - popupMargin - mPopupWindow.getHeight();

int x = minX, y = minY;
if (isWinFixed() || !isCursorUpdated) {
Expand All @@ -177,31 +176,35 @@ public void run() {
} else {
switch (popupWindowPos) {
case LEFT:
x = (int) mPopupRectF.left;
y = (int) mPopupRectF.bottom + popupMargin;
break;
case LEFT_UP:
x = (int) mPopupRectF.left;
y = (int) mPopupRectF.top - mPopupWindow.getHeight() - popupMargin;
break;
case RIGHT:
x = (int) mPopupRectF.right;
y = (int) mPopupRectF.bottom + popupMargin;
break;
case RIGHT_UP:
default:
x = (int) mPopupRectF.right;
y = (int) mPopupRectF.top - mPopupWindow.getHeight() - popupMargin;
}
x = Math.max(minX, x);
x = Math.min(maxX, x);

switch (popupWindowPos) {
case RIGHT_UP:
case LEFT_UP:
y =
((int) mPopupRectF.top < minY)
? (int) mPopupRectF.bottom + popupMargin
: (int) mPopupRectF.top - mPopupWindow.getHeight() - popupMargin;
break;
case RIGHT:
case LEFT:
default:
y =
((int) mPopupRectF.bottom > maxY)
? (int) mPopupRectF.top - mPopupWindow.getHeight() - popupMargin
: (int) mPopupRectF.bottom + popupMargin;
}
}

// 只要修正一次就可以,别让悬浮窗超出了屏幕界限
x = Math.max(minX, x);
x = Math.min(maxX, x);
y -= BarUtils.getStatusBarHeight(); // 不包含狀態欄
y = Math.max(minY, y);
y = Math.min(maxY, y);

if (!mPopupWindow.isShowing()) {
mPopupWindow.showAtLocation(mCandidateRoot, Gravity.START | Gravity.TOP, x, y);
Expand Down

0 comments on commit 0bd141d

Please sign in to comment.