Skip to content

Commit 0de20df

Browse files
committed
Merge branch 'release/1.0.2'
2 parents fb45036 + fb04b56 commit 0de20df

File tree

5 files changed

+56
-21
lines changed

5 files changed

+56
-21
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ Initial version of the ExpandableTextView
88
1.0.1
99
-----
1010
Added support for Interpolators + update demo Activity
11+
12+
1.0.2
13+
-----
14+
Fixed some issues related to rotating a device from portrait to landscape (and the other way around)

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Demo
88
----
99
This repository also contains a demo project.
1010

11-
![Demo](https://github.com/Blogcat/Android-ExpandableTextView/release/1.0.1/demo.gif)
11+
![Demo](https://github.com/Blogcat/Android-ExpandableTextView/release/1.0.2/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.1@aar')
35+
compile ('at.blogc:expandabletextview:1.0.2@aar')
3636
}
3737
```
3838

@@ -134,6 +134,7 @@ expandableTextView.setOnExpandListener(new ExpandableTextView.OnExpandListener()
134134
Roadmap
135135
=======
136136

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

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
android:theme="@style/AppTheme"
2727
tools:ignore="AllowBackup">
2828

29-
<activity android:name="at.blogc.android.activities.MainActivity">
29+
<activity
30+
android:name="at.blogc.android.activities.MainActivity"
31+
android:configChanges="keyboardHidden|orientation|screenSize">
3032

3133
<intent-filter>
3234
<action android:name="android.intent.action.MAIN"/>

expandabletextview/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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.1'
5+
def fullVersion = '1.0.2'
66

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

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

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class ExpandableTextView extends TextView
4747
private long animationDuration;
4848
private boolean animating;
4949
private boolean expanded;
50-
private int originalHeight;
50+
private int collapsedHeight;
5151

5252
public ExpandableTextView(final Context context)
5353
{
@@ -108,12 +108,9 @@ public int getMaxLines()
108108
*/
109109
public boolean toggle()
110110
{
111-
if (this.expanded)
112-
{
113-
return this.collapse();
114-
}
115-
116-
return this.expand();
111+
return this.expanded
112+
? this.collapse()
113+
: this.expand();
117114
}
118115

119116
/**
@@ -132,28 +129,29 @@ public boolean expand()
132129
this.onExpandListener.onExpand(this);
133130
}
134131

135-
// get original height
132+
// get collapsed height
136133
this.measure
137134
(
138135
MeasureSpec.makeMeasureSpec(this.getMeasuredWidth(), MeasureSpec.EXACTLY),
139136
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
140137
);
141138

142-
this.originalHeight = this.getMeasuredHeight();
139+
this.collapsedHeight = this.getMeasuredHeight();
143140

144-
// set maxLines to MAX Integer
141+
// set maxLines to MAX Integer, so we can calculate the expanded height
145142
this.setMaxLines(Integer.MAX_VALUE);
146143

147-
// get new height
144+
// get expanded height
148145
this.measure
149146
(
150147
MeasureSpec.makeMeasureSpec(this.getMeasuredWidth(), MeasureSpec.EXACTLY),
151148
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
152149
);
153150

154-
final int fullHeight = this.getMeasuredHeight();
151+
final int expandedHeight = this.getMeasuredHeight();
155152

156-
final ValueAnimator valueAnimator = ValueAnimator.ofInt(this.originalHeight, fullHeight);
153+
// animate from collapsed height to expanded height
154+
final ValueAnimator valueAnimator = ValueAnimator.ofInt(this.collapsedHeight, expandedHeight);
157155
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
158156
{
159157
@Override
@@ -164,11 +162,19 @@ public void onAnimationUpdate(final ValueAnimator animation)
164162
ExpandableTextView.this.setLayoutParams(layoutParams);
165163
}
166164
});
165+
167166
valueAnimator.addListener(new AnimatorListenerAdapter()
168167
{
169168
@Override
170169
public void onAnimationEnd(final Animator animation)
171170
{
171+
// if fully expanded, set height to WRAP_CONTENT, because when rotating the device
172+
// the height calculated with this ValueAnimator isn't correct anymore
173+
final ViewGroup.LayoutParams layoutParams = ExpandableTextView.this.getLayoutParams();
174+
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
175+
ExpandableTextView.this.setLayoutParams(layoutParams);
176+
177+
// keep track of current status
172178
ExpandableTextView.this.expanded = true;
173179
ExpandableTextView.this.animating = false;
174180
}
@@ -204,10 +210,11 @@ public boolean collapse()
204210
this.onExpandListener.onCollapse(this);
205211
}
206212

207-
// get new height
208-
final int fullHeight = this.getMeasuredHeight();
213+
// get expanded height
214+
final int expandedHeight = this.getMeasuredHeight();
209215

210-
final ValueAnimator valueAnimator = ValueAnimator.ofInt(fullHeight, this.originalHeight);
216+
// animate from expanded height to collapsed height
217+
final ValueAnimator valueAnimator = ValueAnimator.ofInt(expandedHeight, this.collapsedHeight);
211218
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
212219
{
213220
@Override
@@ -218,6 +225,7 @@ public void onAnimationUpdate(final ValueAnimator animation)
218225
ExpandableTextView.this.setLayoutParams(layoutParams);
219226
}
220227
});
228+
221229
valueAnimator.addListener(new AnimatorListenerAdapter()
222230
{
223231
@Override
@@ -226,6 +234,13 @@ public void onAnimationEnd(final Animator animation)
226234
// set maxLines to original value
227235
ExpandableTextView.this.setMaxLines(ExpandableTextView.this.maxLines);
228236

237+
// if fully collapsed, set height to WRAP_CONTENT, because when rotating the device
238+
// the height calculated with this ValueAnimator isn't correct anymore
239+
final ViewGroup.LayoutParams layoutParams = ExpandableTextView.this.getLayoutParams();
240+
layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
241+
ExpandableTextView.this.setLayoutParams(layoutParams);
242+
243+
// keep track of current status
229244
ExpandableTextView.this.expanded = false;
230245
ExpandableTextView.this.animating = false;
231246
}
@@ -269,7 +284,7 @@ public void setOnExpandListener(final OnExpandListener onExpandListener)
269284
*/
270285
public OnExpandListener getOnExpandListener()
271286
{
272-
return onExpandListener;
287+
return this.onExpandListener;
273288
}
274289

275290
/**
@@ -327,9 +342,22 @@ public boolean isExpanded()
327342
return this.expanded;
328343
}
329344

345+
/**
346+
* Interface definition for a callback to be invoked when
347+
* a {@link ExpandableTextView} is expanded or collapsed.
348+
*/
330349
public interface OnExpandListener
331350
{
351+
/**
352+
* The {@link ExpandableTextView} is being expanded.
353+
* @param view the textview
354+
*/
332355
void onExpand(ExpandableTextView view);
356+
357+
/**
358+
* The {@link ExpandableTextView} is being collapsed.
359+
* @param view the textview
360+
*/
333361
void onCollapse(ExpandableTextView view);
334362
}
335363
}

0 commit comments

Comments
 (0)