diff --git a/BuffereTextInputLayout.gif b/BuffereTextInputLayout.gif new file mode 100644 index 0000000..006c422 Binary files /dev/null and b/BuffereTextInputLayout.gif differ diff --git a/buffertextinputlayout/build.gradle b/buffertextinputlayout/build.gradle index 59c2596..836a2af 100644 --- a/buffertextinputlayout/build.gradle +++ b/buffertextinputlayout/build.gradle @@ -1,12 +1,12 @@ apply plugin: 'com.android.library' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { minSdkVersion 15 - targetSdkVersion 25 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -21,7 +21,7 @@ android { } dependencies { - final SUPPORT_LIBRARY_VERSION = '25.1.0' - compile fileTree(dir: 'libs', include: ['*.jar']) - compile "com.android.support:design:$SUPPORT_LIBRARY_VERSION" + final SUPPORT_LIBRARY_VERSION = '27.1.0' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "com.android.support:design:$SUPPORT_LIBRARY_VERSION" } 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 8d103c9..a3e9b8e 100644 --- a/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/BufferTextInputLayout.java +++ b/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/BufferTextInputLayout.java @@ -80,15 +80,15 @@ /** * A simple customisation of the {@link android.support.design.widget.TextInputLayout} from the * design support library. - * + *
* The difference with the BufferTextInputLayout is that the counter can be displayed in three * different ways, being: - * + *
* DESCENDING - Starting from the set maximum counter value, the counter will decrement in value - * as the user types + * as the user types * ASCENDING - Starting from 0, the counter will increment in value as the user types * STANDARD - Displayed in the same way as the design support library (default). E.g 10/100 - * + *
* As well as this, it is possible to set a value for charactersRemainingUntilCounterDisplay, this
* value simply declares how many characters should be remaining until the counter becomes visible.
* (Note, if this value is not set then the counter will always be visible).
@@ -141,6 +141,7 @@ public class BufferTextInputLayout extends LinearLayout {
private int charactersRemainingUntilCounterDisplay;
private CounterMode counterMode;
+ private HintCollapseMode collapseMode;
private TextInputListener textInputListener;
public BufferTextInputLayout(Context context) {
@@ -197,6 +198,9 @@ public BufferTextInputLayout(Context context, AttributeSet attrs, int defStyleAt
counterMode = CounterMode.fromId(
a.getInt(R.styleable.BufferTextInputLayout_counterMode, 2));
+ collapseMode = HintCollapseMode.fromId(
+ a.getInt(R.styleable.BufferTextInputLayout_hintCollapseBoundsMode, 0));
+
charactersRemainingUntilCounterDisplay = a.getInt(
R.styleable.BufferTextInputLayout_displayFromCount, getCounterMaxLength());
@@ -263,7 +267,8 @@ public void setCharactersRemainingUntilCounterDisplay(int remainingCharacters) {
/**
* Retrieve the value set for characters remaining until the counter is displayed
- * @return int the value set for remaining characters until the counter is displayed
+ *
+ * @return int the value set for remaining characters until the counter is displayed
*/
public int getCharactersRemainingUntilCounterDisplay() {
return charactersRemainingUntilCounterDisplay;
@@ -279,6 +284,7 @@ public void setCounterMode(CounterMode counterMode) {
/**
* Retrieve the current counter mode set for the BufferTextInputLayout
+ *
* @return CounterMode the counter mode currently set
*/
public CounterMode getCounterMode() {
@@ -1237,14 +1243,21 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
if (isHintEnabled && editText != null) {
final Rect rect = tempRect;
ViewGroupUtils.getDescendantRect(this, editText, rect);
+
final int l = rect.left + editText.getCompoundPaddingLeft();
final int r = rect.right - editText.getCompoundPaddingRight();
+
+ final int collapseLeft = collapseMode == HintCollapseMode.DISCARD_DRAWABLE_PADDING
+ ? rect.left
+ : l;
+
+
collapsingTextHelper.setExpandedBounds(
l, rect.top + editText.getCompoundPaddingTop(),
r, rect.bottom - editText.getCompoundPaddingBottom());
// Set the collapsed bounds to be the the full height (minus padding) to match the
// EditText's editable area
- collapsingTextHelper.setCollapsedBounds(l, getPaddingTop(),
+ collapsingTextHelper.setCollapsedBounds(collapseLeft, getPaddingTop(),
r, bottom - top - getPaddingBottom());
collapsingTextHelper.recalculate();
}
diff --git a/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/HintCollapseMode.java b/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/HintCollapseMode.java
new file mode 100644
index 0000000..6a9eaca
--- /dev/null
+++ b/buffertextinputlayout/src/main/java/org/buffer/android/buffertextinputlayout/HintCollapseMode.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2009 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.buffer.android.buffertextinputlayout;
+
+public enum HintCollapseMode {
+ DEFAULT_MODE(0), DISCARD_DRAWABLE_PADDING(1);
+
+ int id;
+
+ HintCollapseMode(int id) {
+ this.id = id;
+ }
+
+ static HintCollapseMode fromId(int id) {
+ for (HintCollapseMode counterMode : values()) {
+ if (counterMode.id == id) return counterMode;
+ }
+ throw new IllegalArgumentException();
+ }
+}
\ No newline at end of file
diff --git a/buffertextinputlayout/src/main/res/values/attrs.xml b/buffertextinputlayout/src/main/res/values/attrs.xml
index 99bbfb5..f9929bd 100644
--- a/buffertextinputlayout/src/main/res/values/attrs.xml
+++ b/buffertextinputlayout/src/main/res/values/attrs.xml
@@ -29,6 +29,10 @@