diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..ae66b2a --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @bufferapp/apps diff --git a/README.md b/README.md index 1120275..6a9ccb4 100644 --- a/README.md +++ b/README.md @@ -13,47 +13,48 @@ the counter so that the value displayed was: Hence why we created this simple component :) -##Ascending +## Ascending ![Ascending](/art/ascending.gif) -##Descending +## Descending ![Descending](/art/descending.gif) -##Standard +## Standard ![Standard](/art/standard.gif) -##Display when a given count away from the maximum value +## Display when a given count away from the maximum value ![Hidden](/art/hidden.gif) -#How to use +# How to use In exactly the same way as the support library! Simply wrap an edit text field like so: - +```xml + - + - + +``` - -#Setting attributes via XML +# Setting attributes via XML In our XML layout, we can set two extra attributes for the BufferTextInputLayout: @@ -62,16 +63,19 @@ In our XML layout, we can set two extra attributes for the BufferTextInputLayout e.g - app:displayFromCount="5" - app:counterMode="descending" +```xml +app:displayFromCount="5" +app:counterMode="descending" +``` -#Setting attributes programmatically +# Setting attributes programmatically - setCounterMode(CounterMode counterMode) -> Set the mode in which the counter should use when being displayed (DESCENDING, ASCENDING, STANDARD) - setCharactersRemainingUntilCounterDisplay(int remainingCharacters) -> Set the value for which how many characters should be remaining until the counter becomes visible e.g. - - bufferTextInputLayout.setCounterMode(CounterMode.DESCENDING); - bufferTextInputLayout.setCharactersRemainingUntilCounterDisplay(40); +```java +bufferTextInputLayout.setCounterMode(CounterMode.DESCENDING); +bufferTextInputLayout.setCharactersRemainingUntilCounterDisplay(40); +``` diff --git a/buffertextinputlayout/build.gradle b/buffertextinputlayout/build.gradle index 9160107..59c2596 100644 --- a/buffertextinputlayout/build.gradle +++ b/buffertextinputlayout/build.gradle @@ -2,10 +2,10 @@ apply plugin: 'com.android.library' android { compileSdkVersion 25 - buildToolsVersion "25.0.1" + buildToolsVersion "25.0.2" defaultConfig { - minSdkVersion 16 + minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" diff --git a/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/BufferTextInputLayout.java b/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/BufferTextInputLayout.java index aa66cdb..8d103c9 100644 --- a/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/BufferTextInputLayout.java +++ b/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/BufferTextInputLayout.java @@ -141,6 +141,7 @@ public class BufferTextInputLayout extends LinearLayout { private int charactersRemainingUntilCounterDisplay; private CounterMode counterMode; + private TextInputListener textInputListener; public BufferTextInputLayout(Context context) { this(context, null); @@ -229,6 +230,28 @@ public void addView(View child, int index, final ViewGroup.LayoutParams params) } } + /** + * Manually update the enabled state of the input label + */ + public void updateEnabledState(int contentLength) { + setCounterEnabled(contentLength >= (getCounterMaxLength() - + charactersRemainingUntilCounterDisplay)); + } + + /** + * Set a listener for when text changes in the edit text + */ + public void setTextInputListener(TextInputListener textInputListener) { + this.textInputListener = textInputListener; + } + + /** + * Manually set the counter length for the label + */ + public void setCounterLength(int length) { + updateCounter(length); + } + /** * Set the count value that the counter labvel should be hidden until. */ @@ -311,6 +334,7 @@ public void afterTextChanged(Editable s) { if (counterEnabled) { updateCounter(s.length()); } + if (textInputListener != null) textInputListener.onTextChanged(s.toString()); } @Override diff --git a/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/TextInputListener.java b/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/TextInputListener.java new file mode 100644 index 0000000..7574a2a --- /dev/null +++ b/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/TextInputListener.java @@ -0,0 +1,5 @@ +package org.buffer.android.buffertextinputlayout; + +public interface TextInputListener { + void onTextChanged(String text); +} diff --git a/build.gradle b/build.gradle index c20bca1..74b2ab0 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' + classpath 'com.android.tools.build:gradle:2.2.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/sample/build.gradle b/sample/build.gradle index 5a6faaa..5f09389 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -2,11 +2,11 @@ apply plugin: 'com.android.application' android { compileSdkVersion 25 - buildToolsVersion "25.0.1" + buildToolsVersion "25.0.2" defaultConfig { applicationId "android.buffer.org.sample" - minSdkVersion 16 + minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0" diff --git a/settings.gradle b/settings.gradle index 87d5561..4f6658b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':buffertextinputlayout', ':sample' +include ':buffertextinputlayout', ':sample'