Skip to content

Commit

Permalink
Merge branch 'release/1.0.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliffus committed Oct 11, 2017
2 parents c58061b + 37122bd commit 307282b
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 50 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ Fixed some issues related to rotating a device from portrait to landscape (and t
1.0.3
-----
Removed attributes from AndroidManifest, because they may conflict with the ones in your app AndroidManifest

1.0.4
-----
Added support for Android O
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Android-ExpandableTextView
==========================
An expandable TextView for Android applications (4.0+).
An expandable TextView for Android applications (4.1+).

[ ![Download](https://api.bintray.com/packages/blogcat/maven/android-expandabletextview/images/download.svg) ](https://bintray.com/blogcat/maven/android-expandabletextview/_latestVersion)

Demo
----
This repository also contains a demo project.

![Demo](https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/release/1.0.3/demo.gif)
![Demo](https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/release/1.0.4/demo.gif)

Add dependency
--------------
Expand All @@ -32,7 +32,7 @@ library dependency

```groovy
dependencies {
compile 'at.blogc:expandabletextview:1.0.3'
compile 'at.blogc:expandabletextview:1.0.4'
}
```

Expand Down Expand Up @@ -131,13 +131,6 @@ expandableTextView.setOnExpandListener(new ExpandableTextView.OnExpandListener()
});
```

Roadmap
=======

* add method to know if the TextView is expandable or not
* optional fading edge at the bottom of the TextView
* update demo project with more examples

License
=======

Expand Down
11 changes: 6 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 26
buildToolsVersion "26.0.2"

defaultConfig {
applicationId "blogc.at.android.views"
minSdkVersion 14
targetSdkVersion 23
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0.0"
}
Expand All @@ -21,7 +21,8 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:support-annotations:25.3.1'
compile project(':expandabletextview')

testCompile 'junit:junit:4.12'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package at.blogc.android.activities;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
Expand Down Expand Up @@ -81,16 +82,16 @@ public void onClick(final View v)
});

// listen for expand / collapse events
expandableTextView.setOnExpandListener(new ExpandableTextView.OnExpandListener()
expandableTextView.addOnExpandListener(new ExpandableTextView.OnExpandListener()
{
@Override
public void onExpand(final ExpandableTextView view)
public void onExpand(@NonNull final ExpandableTextView view)
{
Log.d(TAG, "ExpandableTextView expanded");
}

@Override
public void onCollapse(final ExpandableTextView view)
public void onCollapse(@NonNull final ExpandableTextView view)
{
Log.d(TAG, "ExpandableTextView collapsed");
}
Expand Down
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
}
}

Expand Down
12 changes: 7 additions & 5 deletions expandabletextview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

def fullVersion = '1.0.3'
def fullVersion = '1.0.4'

group = 'at.blogc'
version = fullVersion

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
compileSdkVersion 26
buildToolsVersion "26.0.2"

defaultConfig {
minSdkVersion 14
targetSdkVersion 23
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName fullVersion

Expand All @@ -33,6 +33,8 @@ repositories {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-annotations:25.3.1'

testCompile 'junit:junit:4.12'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.TextView;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import at.blogc.expandabletextview.BuildConfig;
import at.blogc.expandabletextview.R;
Expand All @@ -39,7 +43,7 @@ public class ExpandableTextView extends TextView
// copy off TextView.LINES
private static final int MAXMODE_LINES = 1;

private OnExpandListener onExpandListener;
private final List<OnExpandListener> onExpandListeners;
private TimeInterpolator expandInterpolator;
private TimeInterpolator collapseInterpolator;

Expand All @@ -54,12 +58,12 @@ public ExpandableTextView(final Context context)
this(context, null);
}

public ExpandableTextView(final Context context, final AttributeSet attrs)
public ExpandableTextView(final Context context, @Nullable final AttributeSet attrs)
{
this(context, attrs, 0);
}

public ExpandableTextView(final Context context, final AttributeSet attrs, final int defStyle)
public ExpandableTextView(final Context context, @Nullable final AttributeSet attrs, final int defStyle)
{
super(context, attrs, defStyle);

Expand All @@ -71,6 +75,9 @@ public ExpandableTextView(final Context context, final AttributeSet attrs, final
// keep the original value of maxLines
this.maxLines = this.getMaxLines();

// create bucket for OnExpandListener instances
this.onExpandListeners = new ArrayList<>();

// create default interpolators
this.expandInterpolator = new AccelerateDecelerateInterpolator();
this.collapseInterpolator = new AccelerateDecelerateInterpolator();
Expand Down Expand Up @@ -102,6 +109,9 @@ public int getMaxLines()
}
}


//region public helper methods

/**
* Toggle the expanded state of this {@link ExpandableTextView}.
* @return true if toggled, false otherwise.
Expand All @@ -124,10 +134,7 @@ public boolean expand()
this.animating = true;

// notify listener
if (this.onExpandListener != null)
{
this.onExpandListener.onExpand(this);
}
this.notifyOnExpand();

// get collapsed height
this.measure
Expand Down Expand Up @@ -205,10 +212,7 @@ public boolean collapse()
this.animating = true;

// notify listener
if (this.onExpandListener != null)
{
this.onExpandListener.onCollapse(this);
}
this.notifyOnCollapse();

// get expanded height
final int expandedHeight = this.getMeasuredHeight();
Expand Down Expand Up @@ -260,6 +264,10 @@ public void onAnimationEnd(final Animator animation)
return false;
}

//endregion

//region public getters and setters

/**
* Sets the duration of the expand / collapse animation.
* @param animationDuration duration in milliseconds.
Expand All @@ -270,21 +278,21 @@ public void setAnimationDuration(final long animationDuration)
}

/**
* Sets a listener which receives updates about this {@link ExpandableTextView}.
* Adds a listener which receives updates about this {@link ExpandableTextView}.
* @param onExpandListener the listener.
*/
public void setOnExpandListener(final OnExpandListener onExpandListener)
public void addOnExpandListener(final OnExpandListener onExpandListener)
{
this.onExpandListener = onExpandListener;
this.onExpandListeners.add(onExpandListener);
}

/**
* Returns the {@link OnExpandListener}.
* @return the listener.
* Removes a listener which receives updates about this {@link ExpandableTextView}.
* @param onExpandListener the listener.
*/
public OnExpandListener getOnExpandListener()
public void removeOnExpandListener(final OnExpandListener onExpandListener)
{
return this.onExpandListener;
this.onExpandListeners.remove(onExpandListener);
}

/**
Expand Down Expand Up @@ -342,6 +350,32 @@ public boolean isExpanded()
return this.expanded;
}

//endregion

/**
* This method will notify the listener about this view being expanded.
*/
private void notifyOnCollapse()
{
for (final OnExpandListener onExpandListener : this.onExpandListeners)
{
onExpandListener.onCollapse(this);
}
}

/**
* This method will notify the listener about this view being collapsed.
*/
private void notifyOnExpand()
{
for (final OnExpandListener onExpandListener : this.onExpandListeners)
{
onExpandListener.onExpand(this);
}
}

//region public interfaces

/**
* Interface definition for a callback to be invoked when
* a {@link ExpandableTextView} is expanded or collapsed.
Expand All @@ -352,12 +386,34 @@ public interface OnExpandListener
* The {@link ExpandableTextView} is being expanded.
* @param view the textview
*/
void onExpand(ExpandableTextView view);
void onExpand(@NonNull ExpandableTextView view);

/**
* The {@link ExpandableTextView} is being collapsed.
* @param view the textview
*/
void onCollapse(ExpandableTextView view);
void onCollapse(@NonNull ExpandableTextView view);
}

/**
* Simple implementation of the {@link OnExpandListener} interface with stub
* implementations of each method. Extend this if you do not intend to override
* every method of {@link OnExpandListener}.
*/
public static class SimpleOnExpandListener implements OnExpandListener
{
@Override
public void onExpand(@NonNull final ExpandableTextView view)
{
// empty implementation
}

@Override
public void onCollapse(@NonNull final ExpandableTextView view)
{
// empty implementation
}
}

//endregion
}
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
#Wed Oct 11 14:19:54 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip

0 comments on commit 307282b

Please sign in to comment.