Skip to content

Commit be1cd0b

Browse files
committed
Move files to relevant packages, add support for dynamically setting and getting BufferTextInputLayout properties
1 parent f404a98 commit be1cd0b

File tree

8 files changed

+82
-84
lines changed

8 files changed

+82
-84
lines changed

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

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
import android.widget.LinearLayout;
7070
import android.widget.TextView;
7171

72+
import org.buffer.android.buffertextinputlayout.animator.ValueAnimatorCompat;
7273
import org.buffer.android.buffertextinputlayout.util.AnimationUtils;
74+
import org.buffer.android.buffertextinputlayout.util.CollapsingTextHelper;
7375
import org.buffer.android.buffertextinputlayout.util.DrawableUtils;
7476
import org.buffer.android.buffertextinputlayout.util.ThemeUtils;
7577
import org.buffer.android.buffertextinputlayout.util.ViewGroupUtils;
@@ -138,7 +140,7 @@ public class BufferTextInputLayout extends LinearLayout {
138140
private boolean counterVisible;
139141

140142
private int charactersRemainingUntilCounterDisplay;
141-
private TextInputType textInputType;
143+
private CounterMode counterMode;
142144

143145
public BufferTextInputLayout(Context context) {
144146
this(context, null);
@@ -192,7 +194,7 @@ public BufferTextInputLayout(Context context, AttributeSet attrs, int defStyleAt
192194
counterVisible = counterEnabled;
193195

194196
int type = a.getInt(R.styleable.BufferTextInputLayout_textInputMode, 2);
195-
textInputType = TextInputType.fromId(type);
197+
counterMode = CounterMode.fromId(type);
196198

197199
charactersRemainingUntilCounterDisplay = a.getInt(
198200
R.styleable.BufferTextInputLayout_displayFromCount, getCounterMaxLength());
@@ -232,7 +234,32 @@ public void addView(View child, int index, final ViewGroup.LayoutParams params)
232234
*/
233235
public void setCharactersRemainingUntilCounterDisplay(int remainingCharacters) {
234236
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;
236263
}
237264

238265
/**
@@ -278,8 +305,8 @@ private void setEditText(EditText editText) {
278305
this.editText.addTextChangedListener(new TextWatcher() {
279306
@Override
280307
public void afterTextChanged(Editable s) {
281-
setCounterVisible(counterVisible &&
282-
s.length() >= (getCounterMaxLength() - charactersRemainingUntilCounterDisplay));
308+
setCounterVisible(counterVisible && s.length() >=
309+
(getCounterMaxLength() - charactersRemainingUntilCounterDisplay));
283310
updateLabelState(true);
284311
if (counterEnabled) {
285312
updateCounter(s.length());
@@ -750,7 +777,7 @@ void updateCounter(int length) {
750777

751778
void setCounterText(int length) {
752779
String text;
753-
switch (textInputType) {
780+
switch (counterMode) {
754781
case DESCENDING:
755782
text = String.valueOf(counterMaxLength - length);
756783
break;

buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/TextInputType.java renamed to buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/CounterMode.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
*/
1616
package org.buffer.android.buffertextinputlayout;
1717

18-
public enum TextInputType {
18+
public enum CounterMode {
1919
DESCENDING(0), ASCENDING(1), STANDARD(2);
2020

2121
int id;
2222

23-
TextInputType(int id) {
23+
CounterMode(int id) {
2424
this.id = id;
2525
}
2626

27-
static TextInputType fromId(int id) {
28-
for (TextInputType textInputType : values()) {
29-
if (textInputType.id == id) return textInputType;
27+
static CounterMode fromId(int id) {
28+
for (CounterMode counterMode : values()) {
29+
if (counterMode.id == id) return counterMode;
3030
}
3131
throw new IllegalArgumentException();
3232
}

buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/ValueAnimatorCompat.java renamed to buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/animator/ValueAnimatorCompat.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.buffer.android.buffertextinputlayout;
16+
package org.buffer.android.buffertextinputlayout.animator;
1717

1818

1919
import android.support.annotation.NonNull;
@@ -26,7 +26,7 @@
2626
*/
2727
public class ValueAnimatorCompat {
2828

29-
interface AnimatorUpdateListener {
29+
public interface AnimatorUpdateListener {
3030
/**
3131
* <p>Notifies the occurrence of another frame of the animation.</p>
3232
*
@@ -67,15 +67,15 @@ public void start() {
6767
impl.start();
6868
}
6969

70-
boolean isRunning() {
70+
public boolean isRunning() {
7171
return impl.isRunning();
7272
}
7373

7474
public void setInterpolator(Interpolator interpolator) {
7575
impl.setInterpolator(interpolator);
7676
}
7777

78-
void addUpdateListener(final AnimatorUpdateListener updateListener) {
78+
public void addUpdateListener(final AnimatorUpdateListener updateListener) {
7979
if (updateListener != null) {
8080
impl.addUpdateListener(new Impl.AnimatorUpdateListenerProxy() {
8181
@Override
@@ -88,19 +88,19 @@ public void onAnimationUpdate() {
8888
}
8989
}
9090

91-
void setFloatValues(float from, float to) {
91+
public void setFloatValues(float from, float to) {
9292
impl.setFloatValues(from, to);
9393
}
9494

95-
float getAnimatedFloatValue() {
95+
public float getAnimatedFloatValue() {
9696
return impl.getAnimatedFloatValue();
9797
}
9898

9999
public void setDuration(long duration) {
100100
impl.setDuration(duration);
101101
}
102102

103-
void cancel() {
103+
public void cancel() {
104104
impl.cancel();
105105
}
106106

buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/ValueAnimatorCompatImpl.java renamed to buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/animator/ValueAnimatorCompatImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
package org.buffer.android.buffertextinputlayout;
16+
package org.buffer.android.buffertextinputlayout.animator;
1717

1818
import android.animation.ValueAnimator;
1919
import android.view.animation.Interpolator;

0 commit comments

Comments
 (0)