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 @@ + + + + diff --git a/buffertextinputlayout/src/main/res/values/colors.xml b/buffertextinputlayout/src/main/res/values/colors.xml new file mode 100644 index 0000000..bc20ca4 --- /dev/null +++ b/buffertextinputlayout/src/main/res/values/colors.xml @@ -0,0 +1,4 @@ + + + #ffffff + \ No newline at end of file diff --git a/build.gradle b/build.gradle index 74b2ab0..ad6a928 100644 --- a/build.gradle +++ b/build.gradle @@ -3,9 +3,10 @@ buildscript { repositories { jcenter() + google() } dependencies { - classpath 'com.android.tools.build:gradle:2.2.3' + classpath 'com.android.tools.build:gradle:3.1.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -15,6 +16,7 @@ buildscript { allprojects { repositories { jcenter() + google() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 04e285f..a5979f7 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Mon Dec 28 10:00:20 PST 2015 +#Thu Aug 23 11:58:21 IST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/sample/build.gradle b/sample/build.gradle index 5f09389..74e5134 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,13 +1,13 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.2" + compileSdkVersion 27 + buildToolsVersion "27.0.3" defaultConfig { applicationId "android.buffer.org.sample" minSdkVersion 15 - targetSdkVersion 25 + targetSdkVersion 27 versionCode 1 versionName "1.0" } @@ -21,8 +21,8 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':buffertextinputlayout') - compile 'com.android.support:appcompat-v7:25.1.0' - testCompile 'junit:junit:4.12' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation project(':buffertextinputlayout') + implementation 'com.android.support:appcompat-v7:27.1.0' + testImplementation 'junit:junit:4.12' } diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 4de78b7..4398382 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -21,14 +21,17 @@ android:layout_marginBottom="28dp" app:counterEnabled="true" app:counterMaxLength="10" + app:counterMode="ascending" app:counterOverflowTextAppearance="@style/counterOverride" app:counterTextAppearance="@style/counterText" - app:hintEnabled="true" - app:counterMode="ascending"> + app:hintCollapseBoundsMode="dicardDrawablePadding" + app:hintEnabled="true"> @@ -39,51 +42,16 @@ android:layout_marginBottom="28dp" app:counterEnabled="true" app:counterMaxLength="10" + app:counterMode="descending" app:counterOverflowTextAppearance="@style/counterOverride" app:counterTextAppearance="@style/counterText" - app:hintEnabled="true" - app:counterMode="descending"> - - - - - - - - - - - - + app:hintEnabled="true">