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

Autocompletion layout #1378

Merged
merged 2 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class AutoCompletionView extends FrameLayout {
private ArrayList<Words> mExtraItems = new ArrayList<>();
private boolean mIsExtended;
private Delegate mDelegate;
private List<Words> mItems;

public interface Delegate {
void onAutoCompletionItemClick(Words aItem);
Expand Down Expand Up @@ -77,7 +78,7 @@ private void initialize(Context aContext) {
});
mMinKeyWidth = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_min_item_width);
mKeyHeight = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_item_height);
mLineWidth = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_line_width);
mLineWidth = getMeasuredWidth();
mLineHeight = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_line_height);
mItemPadding = WidgetPlacement.pixelDimension(getContext(), R.dimen.autocompletion_widget_item_padding);
mExtendedHeight = mLineHeight * 6;
Expand Down Expand Up @@ -119,11 +120,34 @@ private LinearLayout createRow() {
return row;
}

@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
int width = getMeasuredWidth();
if (mLineWidth != width && width > 0) {
mLineWidth = width;
layoutItems();
if (mIsExtended) {
layoutExtendedItems();
}
}
}

public void setItems(List<Words> aItems) {
mItems = aItems;
if (mLineWidth == 0) {
mLineWidth = getMeasuredWidth();
}
if (mLineWidth > 0) {
layoutItems();
}
}

private void layoutItems() {
mFirstLine.removeAllViews();
mExtraItems.clear();
mExtendContent.removeAllViews();
if (aItems == null || aItems.size() == 0) {
if (mItems == null || mItems.size() == 0) {
exitExtend();
mExtendButton.setVisibility(View.GONE);
mExtendButtonSeparator.setVisibility(View.GONE);
Expand All @@ -134,7 +158,7 @@ public void setItems(List<Words> aItems) {
int currentWidth = 0;
int extendButtonWidth = mExtendButton.getWidth();

for (Words item : aItems) {
for (Words item : mItems) {
UITextButton textBtn = createButton(item, clickHandler);
if (n == 0) {
textBtn.setBackground(getContext().getDrawable(R.drawable.autocompletion_item_background_first));
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,11 @@
<dimen name="no_internet_z_distance" format="float" type="dimen">2.5</dimen>

<!-- Autocompletion Widget -->
<dimen name="autocompletion_widget_line_width">674dp</dimen>
<dimen name="autocompletion_widget_line_height">36dp</dimen>
<dimen name="autocompletion_widget_extended_height">160dp</dimen>
<dimen name="autocompletion_widget_margin">4dp</dimen>
<dimen name="autocompletion_widget_min_item_width">56dp</dimen>
<dimen name="autocompletion_widget_item_height">36dp</dimen>
<dimen name="autocompletion_widget_item_height">34dp</dimen>
<dimen name="autocompletion_widget_extend_button_width">74dp</dimen>
<dimen name="autocompletion_widget_item_padding">20dp</dimen>

Expand Down