Skip to content

Commit d9f96f5

Browse files
committed
Add some helper methods for extended functionality
1 parent bc3a660 commit d9f96f5

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/BufferTextInputLayout.java

+24
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public class BufferTextInputLayout extends LinearLayout {
141141

142142
private int charactersRemainingUntilCounterDisplay;
143143
private CounterMode counterMode;
144+
private TextInputListener textInputListener;
144145

145146
public BufferTextInputLayout(Context context) {
146147
this(context, null);
@@ -229,6 +230,28 @@ public void addView(View child, int index, final ViewGroup.LayoutParams params)
229230
}
230231
}
231232

233+
/**
234+
* Manually update the enabled state of the input label
235+
*/
236+
public void updateEnabledState(int contentLength) {
237+
setCounterEnabled(contentLength >= (getCounterMaxLength() -
238+
charactersRemainingUntilCounterDisplay));
239+
}
240+
241+
/**
242+
* Set a listener for when text changes in the edit text
243+
*/
244+
public void setTextInputListener(TextInputListener textInputListener) {
245+
this.textInputListener = textInputListener;
246+
}
247+
248+
/**
249+
* Manually set the counter length for the label
250+
*/
251+
public void setCounterLength(int length) {
252+
updateCounter(length);
253+
}
254+
232255
/**
233256
* Set the count value that the counter labvel should be hidden until.
234257
*/
@@ -311,6 +334,7 @@ public void afterTextChanged(Editable s) {
311334
if (counterEnabled) {
312335
updateCounter(s.length());
313336
}
337+
if (textInputListener != null) textInputListener.onTextChanged(s.toString());
314338
}
315339

316340
@Override
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.buffer.android.buffertextinputlayout;
2+
3+
public interface TextInputListener {
4+
void onTextChanged(String text);
5+
}

0 commit comments

Comments
 (0)