Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 51d7f90

Browse files
MortimerGorokeianhzo
authored andcommitted
Autocompletion layout (#1378)
* Improve autocompletion line width for layout changes. * Fix autocompletion item overflow in the autocompletion bar
1 parent f8b42cb commit 51d7f90

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

app/src/common/shared/org/mozilla/vrbrowser/ui/views/AutoCompletionView.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class AutoCompletionView extends FrameLayout {
3838
private ArrayList<Words> mExtraItems = new ArrayList<>();
3939
private boolean mIsExtended;
4040
private Delegate mDelegate;
41+
private List<Words> mItems;
4142

4243
public interface Delegate {
4344
void onAutoCompletionItemClick(Words aItem);
@@ -77,7 +78,7 @@ private void initialize(Context aContext) {
7778
});
7879
mMinKeyWidth = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_min_item_width);
7980
mKeyHeight = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_item_height);
80-
mLineWidth = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_line_width);
81+
mLineWidth = getMeasuredWidth();
8182
mLineHeight = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_line_height);
8283
mItemPadding = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_item_padding);
8384
mExtendedHeight = mLineHeight * 6;
@@ -119,11 +120,34 @@ private LinearLayout createRow() {
119120
return row;
120121
}
121122

123+
@Override
124+
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
125+
super.onLayout(changed, left, top, right, bottom);
126+
int width = getMeasuredWidth();
127+
if (mLineWidth != width && width > 0) {
128+
mLineWidth = width;
129+
layoutItems();
130+
if (mIsExtended) {
131+
layoutExtendedItems();
132+
}
133+
}
134+
}
135+
122136
public void setItems(List<Words> aItems) {
137+
mItems = aItems;
138+
if (mLineWidth == 0) {
139+
mLineWidth = getMeasuredWidth();
140+
}
141+
if (mLineWidth > 0) {
142+
layoutItems();
143+
}
144+
}
145+
146+
private void layoutItems() {
123147
mFirstLine.removeAllViews();
124148
mExtraItems.clear();
125149
mExtendContent.removeAllViews();
126-
if (aItems == null || aItems.size() == 0) {
150+
if (mItems == null || mItems.size() == 0) {
127151
exitExtend();
128152
mExtendButton.setVisibility(View.GONE);
129153
mExtendButtonSeparator.setVisibility(View.GONE);
@@ -134,7 +158,7 @@ public void setItems(List<Words> aItems) {
134158
int currentWidth = 0;
135159
int extendButtonWidth = mExtendButton.getWidth();
136160

137-
for (Words item : aItems) {
161+
for (Words item : mItems) {
138162
UITextButton textBtn = createButton(item, clickHandler);
139163
if (n == 0) {
140164
textBtn.setBackground(getContext().getDrawable(R.drawable.autocompletion_item_background_first));

app/src/main/res/values/dimen.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,11 @@
107107
<dimen name="no_internet_z_distance" format="float" type="dimen">2.5</dimen>
108108

109109
<!-- Autocompletion Widget -->
110-
<dimen name="autocompletion_widget_line_width">674dp</dimen>
111110
<dimen name="autocompletion_widget_line_height">36dp</dimen>
112111
<dimen name="autocompletion_widget_extended_height">160dp</dimen>
113112
<dimen name="autocompletion_widget_margin">4dp</dimen>
114113
<dimen name="autocompletion_widget_min_item_width">56dp</dimen>
115-
<dimen name="autocompletion_widget_item_height">36dp</dimen>
114+
<dimen name="autocompletion_widget_item_height">34dp</dimen>
116115
<dimen name="autocompletion_widget_extend_button_width">74dp</dimen>
117116
<dimen name="autocompletion_widget_item_padding">20dp</dimen>
118117

0 commit comments

Comments
 (0)