@@ -27,10 +27,12 @@ public class AutoCompletionView extends FrameLayout {
27
27
private LinearLayout mExtendContent ;
28
28
private ScrollView mScrollView ;
29
29
private View mSeparator ;
30
- private int mKeyWidth ;
30
+ private View mExtendButtonSeparator ;
31
+ private int mMinKeyWidth ;
31
32
private int mKeyHeight ;
32
33
private int mLineWidth ;
33
34
private int mLineHeight ;
35
+ private int mItemPadding ;
34
36
private UIButton mExtendButton ;
35
37
private int mExtendedHeight ;
36
38
private ArrayList <Words > mExtraItems = new ArrayList <>();
@@ -61,6 +63,7 @@ private void initialize(Context aContext) {
61
63
inflate (aContext , R .layout .autocompletion_bar , this );
62
64
mFirstLine = findViewById (R .id .autoCompletionFirstLine );
63
65
mSeparator = findViewById (R .id .autoCompletionSeparator );
66
+ mExtendButtonSeparator = findViewById (R .id .extendButtonSeparator );
64
67
mScrollView = findViewById (R .id .autoCompletionScroll );
65
68
mExtendButton = findViewById (R .id .extendButton );
66
69
mExtendButton .setTintColorList (R .drawable .main_button_icon_color );
@@ -72,9 +75,11 @@ private void initialize(Context aContext) {
72
75
enterExtend ();
73
76
}
74
77
});
75
- mKeyWidth = mKeyHeight = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_button_size );
78
+ mMinKeyWidth = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_min_item_width );
79
+ mKeyHeight = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_item_height );
76
80
mLineWidth = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_line_width );
77
81
mLineHeight = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_line_height );
82
+ mItemPadding = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_item_padding );
78
83
mExtendedHeight = mLineHeight * 6 ;
79
84
setFocusable (false );
80
85
}
@@ -90,15 +95,15 @@ public void setDelegate(AutoCompletionView.Delegate aDelegate) {
90
95
private UITextButton createButton (Words aWords , OnClickListener aHandler ) {
91
96
UITextButton key = new UITextButton (getContext ());
92
97
key .setTintColorList (R .drawable .main_button_icon_color );
93
- key .setBackground (getContext ().getDrawable (R .drawable .keyboard_key_background ));
98
+ key .setBackground (getContext ().getDrawable (R .drawable .autocompletion_item_background ));
94
99
if (aHandler != null ) {
95
100
key .setOnClickListener (aHandler );
96
101
}
97
102
LinearLayout .LayoutParams params = new LinearLayout .LayoutParams (ViewGroup .LayoutParams .WRAP_CONTENT , mKeyHeight );
98
- key .setMinWidth (mKeyWidth );
103
+ key .setMinWidth (mMinKeyWidth );
99
104
params .gravity = CENTER_VERTICAL ;
100
105
key .setLayoutParams (params );
101
- key .setPadding (10 , 20 , 10 , 0 );
106
+ key .setPadding (mItemPadding , 20 , mItemPadding , 0 );
102
107
key .setIncludeFontPadding (false );
103
108
key .setText (aWords .value );
104
109
key .setTextAlignment (TEXT_ALIGNMENT_CENTER );
@@ -121,18 +126,24 @@ public void setItems(List<Words> aItems) {
121
126
if (aItems == null || aItems .size () == 0 ) {
122
127
exitExtend ();
123
128
mExtendButton .setVisibility (View .GONE );
129
+ mExtendButtonSeparator .setVisibility (View .GONE );
124
130
return ;
125
131
}
126
132
127
133
int n = 0 ;
128
134
int currentWidth = 0 ;
135
+ int extendButtonWidth = mExtendButton .getWidth ();
129
136
130
137
for (Words item : aItems ) {
131
138
UITextButton textBtn = createButton (item , clickHandler );
139
+ if (n == 0 ) {
140
+ textBtn .setBackground (getContext ().getDrawable (R .drawable .autocompletion_item_background_first ));
141
+ textBtn .setTintColorList (R .drawable .autocompletion_item_active_color );
142
+ }
132
143
textBtn .measure (MeasureSpec .UNSPECIFIED , MeasureSpec .UNSPECIFIED );
133
144
currentWidth += textBtn .getMeasuredWidth ();
134
145
135
- if (currentWidth < mLineWidth ) {
146
+ if (currentWidth < ( mLineWidth - extendButtonWidth ) ) {
136
147
mFirstLine .addView (textBtn );
137
148
} else {
138
149
mExtraItems .add (item );
@@ -141,6 +152,7 @@ public void setItems(List<Words> aItems) {
141
152
}
142
153
143
154
mExtendButton .setVisibility (currentWidth >= mLineWidth ? View .VISIBLE : View .GONE );
155
+ mExtendButtonSeparator .setVisibility (mExtendButton .getVisibility ());
144
156
}
145
157
146
158
public boolean isExtended () {
@@ -161,13 +173,14 @@ private void layoutExtendedItems() {
161
173
int index = 0 ;
162
174
int currentWidth = 0 ;
163
175
LinearLayout current = createRow ();
176
+ int padding = mScrollView .getPaddingStart () + mScrollView .getPaddingEnd ();
164
177
165
178
for (Words item : mExtraItems ) {
166
179
UITextButton textBtn = createButton (item , clickHandler );
167
180
textBtn .measure (MeasureSpec .UNSPECIFIED , MeasureSpec .UNSPECIFIED );
168
181
currentWidth += textBtn .getMeasuredWidth ();
169
182
170
- if (currentWidth < mLineWidth ) {
183
+ if (currentWidth < ( mLineWidth - padding ) ) {
171
184
current .addView (textBtn );
172
185
index ++;
173
186
} else {
@@ -193,6 +206,8 @@ private void enterExtend() {
193
206
layoutExtendedItems ();
194
207
}
195
208
209
+ mExtendButton .setScaleY (-1 );
210
+
196
211
RelativeLayout .LayoutParams params = (RelativeLayout .LayoutParams ) getLayoutParams ();
197
212
params .height = mExtendedHeight ;
198
213
setLayoutParams (params );
@@ -208,6 +223,7 @@ private void exitExtend() {
208
223
mIsExtended = false ;
209
224
mScrollView .setVisibility (View .GONE );
210
225
mSeparator .setVisibility (View .GONE );
226
+ mExtendButton .setScaleY (1 );
211
227
RelativeLayout .LayoutParams params = (RelativeLayout .LayoutParams ) getLayoutParams ();
212
228
params .height = WidgetPlacement .pixelDimension (getContext (), R .dimen .autocompletion_widget_line_height );
213
229
setLayoutParams (params );
0 commit comments