Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added BuffereTextInputLayout.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions buffertextinputlayout/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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"
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@
/**
* A simple customisation of the {@link android.support.design.widget.TextInputLayout} from the
* design support library.
*
* <p>
* The difference with the BufferTextInputLayout is that the counter can be displayed in three
* different ways, being:
*
* <p>
* 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
*
* <p>
* 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).
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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;
Expand All @@ -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() {
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
4 changes: 4 additions & 0 deletions buffertextinputlayout/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
</attr>
<!-- The characters remaining value for which the counter should be displayed at -->
<attr name="displayFromCount" format="integer" />
<attr name="hintCollapseBoundsMode" format="enum">
<enum name="defaultMode" value="0" />
<enum name="dicardDrawablePadding" value="1" />
</attr>
</declare-styleable>

<declare-styleable name="DesignTheme">
Expand Down
4 changes: 4 additions & 0 deletions buffertextinputlayout/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="design_textinput_error_color_light">#ffffff</color>
</resources>
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -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"
}
Expand All @@ -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'
}
50 changes: 9 additions & 41 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_input_add"
android:drawableStart="@android:drawable/ic_input_add"
android:hint="@string/text_hint" />

</org.buffer.android.buffertextinputlayout.BufferTextInputLayout>
Expand All @@ -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">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/text_hint" />

</org.buffer.android.buffertextinputlayout.BufferTextInputLayout>

<org.buffer.android.buffertextinputlayout.BufferTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="28dp"
app:counterEnabled="true"
app:counterMaxLength="100"
app:counterOverflowTextAppearance="@style/counterOverride"
app:counterTextAppearance="@style/counterText"
app:hintEnabled="true"
app:counterMode="standard">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/text_hint" />

</org.buffer.android.buffertextinputlayout.BufferTextInputLayout>

<org.buffer.android.buffertextinputlayout.BufferTextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="28dp"
app:counterEnabled="true"
app:counterMaxLength="10"
app:counterOverflowTextAppearance="@style/counterOverride"
app:counterTextAppearance="@style/counterText"
app:hintEnabled="true"
app:displayFromCount="5"
app:counterMode="descending">
app:hintEnabled="true">

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@android:drawable/ic_input_add"
android:drawableStart="@android:drawable/ic_input_add"
android:hint="@string/text_hint" />

</org.buffer.android.buffertextinputlayout.BufferTextInputLayout>
Expand Down