Android: Fix wrong height of text editor context menu in some locales

Combined width of all four buttons (cut, copy, paste, select all) is
greater than width of the screen in some locales and/or on some devices.
This was causing width of the last button to be set to zero and height
of the whole popup to grow too much due to word wrapping in the last
button. The context menu used to look something like this then:

  Cut    Copy    Paste    S
                          e
                          l
                          e
                          c
                          t

                          a
                          l
                          l

This commit disables word wrapping and enables text ellipsizing for
button labels. This fixes height of the popup. In the long term though
Qt will probably have to implement an overflow button like in Android's
built context menu.

The linked bug report contains before and after screenshots.

Fixes: QTBUG-72933
Change-Id: I8e270dbf8ca66f99748cdc531a77e11a5ab11c2b
Reviewed-by: BogDan Vatra <bogdan@kdab.com>
This commit is contained in:
Vova Mshanetskiy 2019-05-07 15:26:32 +03:00
parent c905ff4392
commit 341c910688

View File

@ -41,6 +41,7 @@ package org.qtproject.qt5.android;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
@ -73,7 +74,7 @@ public class EditContextView extends LinearLayout implements View.OnClickListene
m_buttonId = stringId;
setText(stringId);
setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
ViewGroup.LayoutParams.WRAP_CONTENT, 1));
setGravity(Gravity.CENTER);
setTextColor(getResources().getColor(R.color.widget_edittext_dark));
EditContextView.this.setBackground(getResources().getDrawable(R.drawable.editbox_background_normal));
@ -81,6 +82,8 @@ public class EditContextView extends LinearLayout implements View.OnClickListene
int hPadding = (int)(16 * scale + 0.5f);
int vPadding = (int)(8 * scale + 0.5f);
setPadding(hPadding, vPadding, hPadding, vPadding);
setSingleLine();
setEllipsize(TextUtils.TruncateAt.END);
setOnClickListener(EditContextView.this);
}
}