Skip to content

Commit 307282b

Browse files
committed
Merge branch 'release/1.0.4'
2 parents c58061b + 37122bd commit 307282b

File tree

8 files changed

+105
-50
lines changed

8 files changed

+105
-50
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ Fixed some issues related to rotating a device from portrait to landscape (and t
1616
1.0.3
1717
-----
1818
Removed attributes from AndroidManifest, because they may conflict with the ones in your app AndroidManifest
19+
20+
1.0.4
21+
-----
22+
Added support for Android O

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
Android-ExpandableTextView
22
==========================
3-
An expandable TextView for Android applications (4.0+).
3+
An expandable TextView for Android applications (4.1+).
44

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

77
Demo
88
----
99
This repository also contains a demo project.
1010

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

1313
Add dependency
1414
--------------
@@ -32,7 +32,7 @@ library dependency
3232

3333
```groovy
3434
dependencies {
35-
compile 'at.blogc:expandabletextview:1.0.3'
35+
compile 'at.blogc:expandabletextview:1.0.4'
3636
}
3737
```
3838

@@ -131,13 +131,6 @@ expandableTextView.setOnExpandListener(new ExpandableTextView.OnExpandListener()
131131
});
132132
```
133133

134-
Roadmap
135-
=======
136-
137-
* add method to know if the TextView is expandable or not
138-
* optional fading edge at the bottom of the TextView
139-
* update demo project with more examples
140-
141134
License
142135
=======
143136

app/build.gradle

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
apply plugin: 'com.android.application'
22

33
android {
4-
compileSdkVersion 23
5-
buildToolsVersion "23.0.3"
4+
compileSdkVersion 26
5+
buildToolsVersion "26.0.2"
66

77
defaultConfig {
88
applicationId "blogc.at.android.views"
9-
minSdkVersion 14
10-
targetSdkVersion 23
9+
minSdkVersion 16
10+
targetSdkVersion 26
1111
versionCode 1
1212
versionName "1.0.0"
1313
}
@@ -21,7 +21,8 @@ android {
2121

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

2728
testCompile 'junit:junit:4.12'

app/src/main/java/at/blogc/android/activities/MainActivity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package at.blogc.android.activities;
22

3+
import android.support.annotation.NonNull;
34
import android.support.v7.app.AppCompatActivity;
45
import android.os.Bundle;
56
import android.util.Log;
@@ -81,16 +82,16 @@ public void onClick(final View v)
8182
});
8283

8384
// listen for expand / collapse events
84-
expandableTextView.setOnExpandListener(new ExpandableTextView.OnExpandListener()
85+
expandableTextView.addOnExpandListener(new ExpandableTextView.OnExpandListener()
8586
{
8687
@Override
87-
public void onExpand(final ExpandableTextView view)
88+
public void onExpand(@NonNull final ExpandableTextView view)
8889
{
8990
Log.d(TAG, "ExpandableTextView expanded");
9091
}
9192

9293
@Override
93-
public void onCollapse(final ExpandableTextView view)
94+
public void onCollapse(@NonNull final ExpandableTextView view)
9495
{
9596
Log.d(TAG, "ExpandableTextView collapsed");
9697
}

build.gradle

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:2.0.0'
9-
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3'
10-
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6'
11-
// NOTE: Do not place your application dependencies here; they belong
12-
// in the individual module build.gradle files
8+
classpath 'com.android.tools.build:gradle:2.3.3'
9+
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
10+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
1311
}
1412
}
1513

expandabletextview/build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ apply plugin: 'com.android.library'
22
apply plugin: 'com.github.dcendents.android-maven'
33
apply plugin: 'com.jfrog.bintray'
44

5-
def fullVersion = '1.0.3'
5+
def fullVersion = '1.0.4'
66

77
group = 'at.blogc'
88
version = fullVersion
99

1010
android {
11-
compileSdkVersion 23
12-
buildToolsVersion "23.0.3"
11+
compileSdkVersion 26
12+
buildToolsVersion "26.0.2"
1313

1414
defaultConfig {
15-
minSdkVersion 14
16-
targetSdkVersion 23
15+
minSdkVersion 16
16+
targetSdkVersion 26
1717
versionCode 1
1818
versionName fullVersion
1919

@@ -33,6 +33,8 @@ repositories {
3333

3434
dependencies {
3535
compile fileTree(dir: 'libs', include: ['*.jar'])
36+
compile 'com.android.support:support-annotations:25.3.1'
37+
3638
testCompile 'junit:junit:4.12'
3739
}
3840

expandabletextview/src/main/java/at/blogc/android/views/ExpandableTextView.java

Lines changed: 76 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77
import android.content.Context;
88
import android.content.res.TypedArray;
99
import android.os.Build;
10+
import android.support.annotation.NonNull;
11+
import android.support.annotation.Nullable;
1012
import android.util.AttributeSet;
1113
import android.view.ViewGroup;
1214
import android.view.animation.AccelerateDecelerateInterpolator;
1315
import android.widget.TextView;
1416

1517
import java.lang.reflect.Field;
18+
import java.util.ArrayList;
19+
import java.util.List;
1620

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

42-
private OnExpandListener onExpandListener;
46+
private final List<OnExpandListener> onExpandListeners;
4347
private TimeInterpolator expandInterpolator;
4448
private TimeInterpolator collapseInterpolator;
4549

@@ -54,12 +58,12 @@ public ExpandableTextView(final Context context)
5458
this(context, null);
5559
}
5660

57-
public ExpandableTextView(final Context context, final AttributeSet attrs)
61+
public ExpandableTextView(final Context context, @Nullable final AttributeSet attrs)
5862
{
5963
this(context, attrs, 0);
6064
}
6165

62-
public ExpandableTextView(final Context context, final AttributeSet attrs, final int defStyle)
66+
public ExpandableTextView(final Context context, @Nullable final AttributeSet attrs, final int defStyle)
6367
{
6468
super(context, attrs, defStyle);
6569

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

78+
// create bucket for OnExpandListener instances
79+
this.onExpandListeners = new ArrayList<>();
80+
7481
// create default interpolators
7582
this.expandInterpolator = new AccelerateDecelerateInterpolator();
7683
this.collapseInterpolator = new AccelerateDecelerateInterpolator();
@@ -102,6 +109,9 @@ public int getMaxLines()
102109
}
103110
}
104111

112+
113+
//region public helper methods
114+
105115
/**
106116
* Toggle the expanded state of this {@link ExpandableTextView}.
107117
* @return true if toggled, false otherwise.
@@ -124,10 +134,7 @@ public boolean expand()
124134
this.animating = true;
125135

126136
// notify listener
127-
if (this.onExpandListener != null)
128-
{
129-
this.onExpandListener.onExpand(this);
130-
}
137+
this.notifyOnExpand();
131138

132139
// get collapsed height
133140
this.measure
@@ -205,10 +212,7 @@ public boolean collapse()
205212
this.animating = true;
206213

207214
// notify listener
208-
if (this.onExpandListener != null)
209-
{
210-
this.onExpandListener.onCollapse(this);
211-
}
215+
this.notifyOnCollapse();
212216

213217
// get expanded height
214218
final int expandedHeight = this.getMeasuredHeight();
@@ -260,6 +264,10 @@ public void onAnimationEnd(final Animator animation)
260264
return false;
261265
}
262266

267+
//endregion
268+
269+
//region public getters and setters
270+
263271
/**
264272
* Sets the duration of the expand / collapse animation.
265273
* @param animationDuration duration in milliseconds.
@@ -270,21 +278,21 @@ public void setAnimationDuration(final long animationDuration)
270278
}
271279

272280
/**
273-
* Sets a listener which receives updates about this {@link ExpandableTextView}.
281+
* Adds a listener which receives updates about this {@link ExpandableTextView}.
274282
* @param onExpandListener the listener.
275283
*/
276-
public void setOnExpandListener(final OnExpandListener onExpandListener)
284+
public void addOnExpandListener(final OnExpandListener onExpandListener)
277285
{
278-
this.onExpandListener = onExpandListener;
286+
this.onExpandListeners.add(onExpandListener);
279287
}
280288

281289
/**
282-
* Returns the {@link OnExpandListener}.
283-
* @return the listener.
290+
* Removes a listener which receives updates about this {@link ExpandableTextView}.
291+
* @param onExpandListener the listener.
284292
*/
285-
public OnExpandListener getOnExpandListener()
293+
public void removeOnExpandListener(final OnExpandListener onExpandListener)
286294
{
287-
return this.onExpandListener;
295+
this.onExpandListeners.remove(onExpandListener);
288296
}
289297

290298
/**
@@ -342,6 +350,32 @@ public boolean isExpanded()
342350
return this.expanded;
343351
}
344352

353+
//endregion
354+
355+
/**
356+
* This method will notify the listener about this view being expanded.
357+
*/
358+
private void notifyOnCollapse()
359+
{
360+
for (final OnExpandListener onExpandListener : this.onExpandListeners)
361+
{
362+
onExpandListener.onCollapse(this);
363+
}
364+
}
365+
366+
/**
367+
* This method will notify the listener about this view being collapsed.
368+
*/
369+
private void notifyOnExpand()
370+
{
371+
for (final OnExpandListener onExpandListener : this.onExpandListeners)
372+
{
373+
onExpandListener.onExpand(this);
374+
}
375+
}
376+
377+
//region public interfaces
378+
345379
/**
346380
* Interface definition for a callback to be invoked when
347381
* a {@link ExpandableTextView} is expanded or collapsed.
@@ -352,12 +386,34 @@ public interface OnExpandListener
352386
* The {@link ExpandableTextView} is being expanded.
353387
* @param view the textview
354388
*/
355-
void onExpand(ExpandableTextView view);
389+
void onExpand(@NonNull ExpandableTextView view);
356390

357391
/**
358392
* The {@link ExpandableTextView} is being collapsed.
359393
* @param view the textview
360394
*/
361-
void onCollapse(ExpandableTextView view);
395+
void onCollapse(@NonNull ExpandableTextView view);
362396
}
397+
398+
/**
399+
* Simple implementation of the {@link OnExpandListener} interface with stub
400+
* implementations of each method. Extend this if you do not intend to override
401+
* every method of {@link OnExpandListener}.
402+
*/
403+
public static class SimpleOnExpandListener implements OnExpandListener
404+
{
405+
@Override
406+
public void onExpand(@NonNull final ExpandableTextView view)
407+
{
408+
// empty implementation
409+
}
410+
411+
@Override
412+
public void onCollapse(@NonNull final ExpandableTextView view)
413+
{
414+
// empty implementation
415+
}
416+
}
417+
418+
//endregion
363419
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Mon Dec 28 10:00:20 PST 2015
1+
#Wed Oct 11 14:19:54 CEST 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip

0 commit comments

Comments
 (0)