Android: Fix wrong position of EditPopupMenu
When Edit Popup Menu was not shown, the size of EditContextView was wrongly returned. That is why the popup appeared in the wrong position and then "jumped" to the right one. To get correct values even when Popup is invisible, size should be calculated manually by getting height/width of all visible buttons (with getMeasuredHeight/getMeasuredWidth[0]) and paddings of EditContextView. [0]https://developer.android.com/reference/android/view/View#getMeasuredWidth() Pick-to: 6.6 6.5 6.2 Fixes: QTBUG-115632 Change-Id: I5f6abffab1a1e836c59a922ffa727d893ca9820f Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
parent
90980a54e8
commit
51d331b13b
@ -5,6 +5,7 @@ package org.qtproject.qt.android;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.text.TextUtils;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
@ -74,6 +75,23 @@ public class EditContextView extends LinearLayout implements View.OnClickListene
|
||||
m_buttons.get(R.string.selectAll).setVisibility((buttonsLayout & SALL_BUTTON) != 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
public Point getCalculatedSize()
|
||||
{
|
||||
Point size = new Point(0, 0);
|
||||
for (ContextButton b : m_buttons.values()) {
|
||||
if (b.getVisibility() == View.VISIBLE) {
|
||||
b.measure(0, 0);
|
||||
size.x += b.getMeasuredWidth();
|
||||
size.y = Math.max(size.y, b.getMeasuredHeight());
|
||||
}
|
||||
}
|
||||
|
||||
size.x += getPaddingLeft() + getPaddingRight();
|
||||
size.y += getPaddingTop() + getPaddingBottom();
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
public EditContextView(Context context, OnClickListener onClickListener) {
|
||||
super(context);
|
||||
m_onClickListener = onClickListener;
|
||||
|
@ -5,6 +5,7 @@
|
||||
package org.qtproject.qt.android;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@ -69,6 +70,8 @@ public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.O
|
||||
initOverlay();
|
||||
|
||||
m_view.updateButtons(buttons);
|
||||
Point viewSize = m_view.getCalculatedSize();
|
||||
|
||||
final int[] layoutLocation = new int[2];
|
||||
m_layout.getLocationOnScreen(layoutLocation);
|
||||
|
||||
@ -81,9 +84,9 @@ public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.O
|
||||
int x2 = x + layoutLocation[0] - activityLocation[0];
|
||||
int y2 = y + layoutLocation[1] + (activityLocationInWindow[1] - activityLocation[1]);
|
||||
|
||||
x2 -= m_view.getWidth() / 2 ;
|
||||
x2 -= viewSize.x / 2 ;
|
||||
|
||||
y2 -= m_view.getHeight();
|
||||
y2 -= viewSize.y;
|
||||
if (y2 < 0) {
|
||||
if (cursorHandle != null) {
|
||||
y2 = cursorHandle.bottom();
|
||||
@ -94,8 +97,8 @@ public class EditPopupMenu implements ViewTreeObserver.OnPreDrawListener, View.O
|
||||
}
|
||||
}
|
||||
|
||||
if (m_layout.getWidth() < x + m_view.getWidth() / 2)
|
||||
x2 = m_layout.getWidth() - m_view.getWidth();
|
||||
if (m_layout.getWidth() < x + viewSize.x / 2)
|
||||
x2 = m_layout.getWidth() - viewSize.x;
|
||||
|
||||
if (x2 < 0)
|
||||
x2 = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user