Skip to content

Commit 0bd141d

Browse files
committed
fix: float window covers the input text on top/bottom edge
1 parent 5dde264 commit 0bd141d

File tree

1 file changed

+22
-19
lines changed
  • app/src/main/java/com/osfans/trime/ime/core

1 file changed

+22
-19
lines changed

app/src/main/java/com/osfans/trime/ime/core/Trime.java

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,12 @@ public void run() {
144144
if (mCandidateRoot == null || mCandidateRoot.getWindowToken() == null) return;
145145
if (!isPopupWindowEnabled) return;
146146

147-
final int minX = popupMarginH;
148-
final int minY = popupMargin;
149-
150147
DisplayMetrics displayMetrics = new DisplayMetrics();
151148
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
152-
final int maxX = displayMetrics.widthPixels - mPopupWindow.getWidth() - minX;
153-
final int maxY = displayMetrics.heightPixels - mPopupWindow.getHeight() - minY;
149+
final int minX = popupMarginH;
150+
final int maxX = displayMetrics.widthPixels - mPopupWindow.getWidth() - popupMarginH;
151+
final int minY = popupMargin + BarUtils.getStatusBarHeight() + mPopupWindow.getHeight();
152+
final int maxY = displayMetrics.heightPixels - popupMargin - mPopupWindow.getHeight();
154153

155154
int x = minX, y = minY;
156155
if (isWinFixed() || !isCursorUpdated) {
@@ -177,31 +176,35 @@ public void run() {
177176
} else {
178177
switch (popupWindowPos) {
179178
case LEFT:
180-
x = (int) mPopupRectF.left;
181-
y = (int) mPopupRectF.bottom + popupMargin;
182-
break;
183179
case LEFT_UP:
184180
x = (int) mPopupRectF.left;
185-
y = (int) mPopupRectF.top - mPopupWindow.getHeight() - popupMargin;
186181
break;
187182
case RIGHT:
188-
x = (int) mPopupRectF.right;
189-
y = (int) mPopupRectF.bottom + popupMargin;
190-
break;
191183
case RIGHT_UP:
192184
default:
193185
x = (int) mPopupRectF.right;
194-
y = (int) mPopupRectF.top - mPopupWindow.getHeight() - popupMargin;
186+
}
187+
x = Math.max(minX, x);
188+
x = Math.min(maxX, x);
189+
190+
switch (popupWindowPos) {
191+
case RIGHT_UP:
192+
case LEFT_UP:
193+
y =
194+
((int) mPopupRectF.top < minY)
195+
? (int) mPopupRectF.bottom + popupMargin
196+
: (int) mPopupRectF.top - mPopupWindow.getHeight() - popupMargin;
195197
break;
198+
case RIGHT:
199+
case LEFT:
200+
default:
201+
y =
202+
((int) mPopupRectF.bottom > maxY)
203+
? (int) mPopupRectF.top - mPopupWindow.getHeight() - popupMargin
204+
: (int) mPopupRectF.bottom + popupMargin;
196205
}
197206
}
198-
199-
// 只要修正一次就可以,别让悬浮窗超出了屏幕界限
200-
x = Math.max(minX, x);
201-
x = Math.min(maxX, x);
202207
y -= BarUtils.getStatusBarHeight(); // 不包含狀態欄
203-
y = Math.max(minY, y);
204-
y = Math.min(maxY, y);
205208

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

0 commit comments

Comments
 (0)