|
69 | 69 | import android.widget.LinearLayout; |
70 | 70 | import android.widget.TextView; |
71 | 71 |
|
| 72 | +import org.buffer.android.buffertextinputlayout.animator.ValueAnimatorCompat; |
72 | 73 | import org.buffer.android.buffertextinputlayout.util.AnimationUtils; |
| 74 | +import org.buffer.android.buffertextinputlayout.util.CollapsingTextHelper; |
73 | 75 | import org.buffer.android.buffertextinputlayout.util.DrawableUtils; |
74 | 76 | import org.buffer.android.buffertextinputlayout.util.ThemeUtils; |
75 | 77 | import org.buffer.android.buffertextinputlayout.util.ViewGroupUtils; |
@@ -138,7 +140,7 @@ public class BufferTextInputLayout extends LinearLayout { |
138 | 140 | private boolean counterVisible; |
139 | 141 |
|
140 | 142 | private int charactersRemainingUntilCounterDisplay; |
141 | | - private TextInputType textInputType; |
| 143 | + private CounterMode counterMode; |
142 | 144 |
|
143 | 145 | public BufferTextInputLayout(Context context) { |
144 | 146 | this(context, null); |
@@ -192,7 +194,7 @@ public BufferTextInputLayout(Context context, AttributeSet attrs, int defStyleAt |
192 | 194 | counterVisible = counterEnabled; |
193 | 195 |
|
194 | 196 | int type = a.getInt(R.styleable.BufferTextInputLayout_textInputMode, 2); |
195 | | - textInputType = TextInputType.fromId(type); |
| 197 | + counterMode = CounterMode.fromId(type); |
196 | 198 |
|
197 | 199 | charactersRemainingUntilCounterDisplay = a.getInt( |
198 | 200 | R.styleable.BufferTextInputLayout_displayFromCount, getCounterMaxLength()); |
@@ -232,7 +234,32 @@ public void addView(View child, int index, final ViewGroup.LayoutParams params) |
232 | 234 | */ |
233 | 235 | public void setCharactersRemainingUntilCounterDisplay(int remainingCharacters) { |
234 | 236 | charactersRemainingUntilCounterDisplay = remainingCharacters; |
235 | | - updateLabelState(true); |
| 237 | + setCounterVisible(counterVisible && editText.getText().length() >= |
| 238 | + (getCounterMaxLength() - charactersRemainingUntilCounterDisplay)); |
| 239 | + } |
| 240 | + |
| 241 | + /** |
| 242 | + * Retrieve the value set for characters remaining until the counter is displayed |
| 243 | + * @return int the value set for remaining characters until the counter is displayed |
| 244 | + */ |
| 245 | + public int getCharactersRemainingUntilCounterDisplay() { |
| 246 | + return charactersRemainingUntilCounterDisplay; |
| 247 | + } |
| 248 | + |
| 249 | + /** |
| 250 | + * Set the counter mode to be used when formatting the display of the text input counter. |
| 251 | + */ |
| 252 | + public void setCounterMode(CounterMode counterMode) { |
| 253 | + this.counterMode = counterMode; |
| 254 | + setCounterText(editText.getText().length()); |
| 255 | + } |
| 256 | + |
| 257 | + /** |
| 258 | + * Retrieve the current counter mode set for the BufferTextInputLayout |
| 259 | + * @return CounterMode the counter mode currently set |
| 260 | + */ |
| 261 | + public CounterMode getCounterMode() { |
| 262 | + return counterMode; |
236 | 263 | } |
237 | 264 |
|
238 | 265 | /** |
@@ -278,8 +305,8 @@ private void setEditText(EditText editText) { |
278 | 305 | this.editText.addTextChangedListener(new TextWatcher() { |
279 | 306 | @Override |
280 | 307 | public void afterTextChanged(Editable s) { |
281 | | - setCounterVisible(counterVisible && |
282 | | - s.length() >= (getCounterMaxLength() - charactersRemainingUntilCounterDisplay)); |
| 308 | + setCounterVisible(counterVisible && s.length() >= |
| 309 | + (getCounterMaxLength() - charactersRemainingUntilCounterDisplay)); |
283 | 310 | updateLabelState(true); |
284 | 311 | if (counterEnabled) { |
285 | 312 | updateCounter(s.length()); |
@@ -750,7 +777,7 @@ void updateCounter(int length) { |
750 | 777 |
|
751 | 778 | void setCounterText(int length) { |
752 | 779 | String text; |
753 | | - switch (textInputType) { |
| 780 | + switch (counterMode) { |
754 | 781 | case DESCENDING: |
755 | 782 | text = String.valueOf(counterMaxLength - length); |
756 | 783 | break; |
|
0 commit comments