Skip to content

Commit 13d3421

Browse files
authored
Fix detection of keys on emoji popups (#1790)
mainly with long descriptions, but also fixes other quirks
1 parent 408de91 commit 13d3421

File tree

2 files changed

+37
-26
lines changed

2 files changed

+37
-26
lines changed

app/src/main/java/helium314/keyboard/keyboard/PopupKeysKeyboardView.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,19 +148,33 @@ private void showPopupKeysPanelInternal(final View parentView, final Controller
148148
+ getPaddingBottom();
149149

150150
parentView.getLocationInWindow(mCoordinates);
151+
final int containerY = y + CoordinateUtils.y(mCoordinates);
152+
container.setY(containerY);
153+
154+
// This is needed for cases where there's also a text popup above this keyboard
155+
final int panelMaxX = parentView.getMeasuredWidth() - getMeasuredWidth();
156+
var panelFinalX = Math.max(0, Math.min(panelMaxX, x));
157+
var center = panelFinalX + getMeasuredWidth() / 2;
158+
var layoutGravity = center < pointX - getKeyboard().mMostCommonKeyWidth / 2?
159+
Gravity.RIGHT : center > pointX + getKeyboard().mMostCommonKeyWidth / 2? Gravity.LEFT : Gravity.CENTER_HORIZONTAL;
160+
161+
int containerAdjustedX = x;
162+
if (getMeasuredWidth() < container.getMeasuredWidth()) {
163+
containerAdjustedX = layoutGravity == Gravity.LEFT? panelFinalX : layoutGravity == Gravity.RIGHT
164+
? panelFinalX + getMeasuredWidth() - container.getMeasuredWidth()
165+
: panelFinalX + (getMeasuredWidth() - container.getMeasuredWidth()) / 2;
166+
}
167+
151168
// Ensure the horizontal position of the panel does not extend past the parentView edges.
152-
final int maxX = parentView.getMeasuredWidth() - container.getMeasuredWidth();
153-
var finalX = Math.max(0, Math.min(maxX, x));
154-
final int panelX = finalX + CoordinateUtils.x(mCoordinates);
155-
final int panelY = y + CoordinateUtils.y(mCoordinates);
156-
container.setX(panelX);
157-
container.setY(panelY);
158-
159-
mOriginX = finalX + container.getPaddingLeft();
160-
mOriginY = y + container.getPaddingTop();
161-
var center = panelX + getMeasuredWidth() / 2;
162-
// This is needed for cases where there's also a long text popup above this keyboard
163-
controller.setLayoutGravity(center < pointX? Gravity.RIGHT : center > pointX? Gravity.LEFT : Gravity.CENTER_HORIZONTAL);
169+
int containerMaxX = parentView.getMeasuredWidth() - container.getMeasuredWidth();
170+
int containerFinalX = Math.max(0, Math.min(containerMaxX, containerAdjustedX));
171+
int containerX = containerFinalX + CoordinateUtils.x(mCoordinates);
172+
container.setX(containerX);
173+
setTranslationX(panelFinalX - containerFinalX);
174+
controller.setLayoutGravity(layoutGravity);
175+
176+
mOriginX = panelFinalX;
177+
mOriginY = y + container.getPaddingTop() + (int) getY();
164178
controller.onShowPopupKeysPanel(this);
165179
final PopupKeysKeyboardAccessibilityDelegate accessibilityDelegate = mAccessibilityDelegate;
166180
if (accessibilityDelegate != null

app/src/main/java/helium314/keyboard/keyboard/emoji/EmojiPageKeyboardView.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,10 @@ public boolean isShowingPopupKeysPanel() {
211211

212212
@Override
213213
public void setLayoutGravity(int layoutGravity) {
214-
var layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
215-
ViewGroup.LayoutParams.WRAP_CONTENT);
216-
layoutParams.gravity = mDescriptionView.getMeasuredWidth() > mPopupKeysKeyboardView.getMeasuredWidth()?
217-
layoutGravity : Gravity.CENTER_HORIZONTAL;
214+
var layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
215+
layoutParams.gravity = layoutGravity;
218216
mPopupKeysKeyboardContainer.setLayoutParams(layoutParams);
219217
mDescriptionView.setLayoutParams(layoutParams);
220-
mPopupKeysKeyboardView.setLayoutParams(layoutParams);
221218
}
222219

223220
@Override
@@ -306,15 +303,6 @@ private void onLongPressed(final Key key) {
306303

307304
final int x = mLastX;
308305
final int y = mLastY;
309-
if (popupKeysPanel != null) {
310-
final int translatedX = popupKeysPanel.translateX(x);
311-
final int translatedY = popupKeysPanel.translateY(y);
312-
popupKeysPanel.onDownEvent(translatedX, translatedY, mPointerId, 0 /* nor used for now */);
313-
// No need of re-allowing parent later as we don't
314-
// want any scroll to append during this entire input.
315-
disallowParentInterceptTouchEvent(true);
316-
}
317-
318306
if (popupKeysPanel != null || descriptionPanel != null) {
319307
mPopupKeysKeyboardContainer.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
320308

@@ -329,6 +317,15 @@ private void onLongPressed(final Key key) {
329317
(popupKeysPanel != null? popupKeysPanel : descriptionPanel)
330318
.showPopupKeysPanel(this, this, pointX, pointY, mEmojiViewCallback);
331319
}
320+
321+
if (popupKeysPanel != null) {
322+
final int translatedX = popupKeysPanel.translateX(x);
323+
final int translatedY = popupKeysPanel.translateY(y);
324+
popupKeysPanel.onDownEvent(translatedX, translatedY, mPointerId, 0 /* nor used for now */);
325+
// No need of re-allowing parent later as we don't
326+
// want any scroll to append during this entire input.
327+
disallowParentInterceptTouchEvent(true);
328+
}
332329
}
333330

334331
private PopupKeysPanel showDescription(Key key) {

0 commit comments

Comments
 (0)