├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── at
│ │ └── blogc
│ │ └── android
│ │ └── views
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── at
│ │ │ └── blogc
│ │ │ └── android
│ │ │ ├── activities
│ │ │ ├── MainActivity.java
│ │ │ └── RecyclerViewActivity.java
│ │ │ └── adapters
│ │ │ ├── RecyclerViewAdapter.java
│ │ │ └── viewholders
│ │ │ └── ExpandableTextViewHolder.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_recyclerview.xml
│ │ └── listitem_recyclerview.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── lorem_ipsum.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── at
│ └── blogc
│ └── android
│ └── views
│ └── ExampleUnitTest.java
├── build.gradle
├── demo.gif
├── demo_interpolator.gif
├── expandabletextview
├── .gitignore
├── build.gradle
├── gradle.properties
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── at
│ │ └── blogc
│ │ └── android
│ │ └── views
│ │ └── ExpandableTextView.java
│ └── res
│ └── values
│ ├── attrs.xml
│ └── strings.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 | # Android Studio Navigation editor temp files
29 | .navigation/
30 |
31 | # Android Studio captures folder
32 | captures/
33 |
34 | *.iml
35 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | CHANGE LOG
2 | ==========================
3 |
4 | 1.0.0
5 | -----
6 | Initial version of the ExpandableTextView
7 |
8 | 1.0.1
9 | -----
10 | 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)
15 |
16 | 1.0.3
17 | -----
18 | Removed attributes from AndroidManifest, because they may conflict with the ones in your app AndroidManifest
19 |
20 | 1.0.4
21 | -----
22 | Use latest build tools and target Android O
23 |
24 | 1.0.5
25 | -----
26 | - Added support for Android O
27 | - Added RecyclerView Demo
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Android-ExpandableTextView
2 | ==========================
3 | An expandable TextView for Android applications (4.1+).
4 |
5 | [  ](https://bintray.com/blogcat/maven/android-expandabletextview/_latestVersion)
6 |
7 | Latest Changes
8 | --------------
9 | - Added support for Android O
10 | - Added RecyclerView Demo
11 |
12 | Demo
13 | ----
14 | This repository also contains a demo project.
15 |
16 | 
17 |
18 | Add dependency
19 | --------------
20 | This library is released in Maven Central and jCenter:
21 |
22 | ```groovy
23 | repositories {
24 | mavenCentral()
25 | }
26 | ```
27 |
28 | or
29 |
30 | ```groovy
31 | repositories {
32 | jcenter()
33 | }
34 | ```
35 |
36 | library dependency
37 |
38 | ```groovy
39 | dependencies {
40 | compile 'at.blogc:expandabletextview:1.0.5'
41 | }
42 | ```
43 |
44 | Usage
45 | -----
46 | Using the ExpandableTextView is very easy, it's just a regular TextView with some extra functionality added to it. By defining the android:maxLines attribute, you can set the default number of lines for the TextView collapsed state.
47 |
48 | ```xml
49 |
55 |
56 |
64 |
65 |
66 |
67 |
72 |
73 |
74 | ```
75 |
76 | In your Activity or Fragment:
77 |
78 | ```java
79 | final ExpandableTextView expandableTextView = (ExpandableTextView) this.findViewById(R.id.expandableTextView);
80 | final Button buttonToggle = (Button) this.findViewById(R.id.button_toggle);
81 |
82 | // set animation duration via code, but preferable in your layout files by using the animation_duration attribute
83 | expandableTextView.setAnimationDuration(750L);
84 |
85 | // set interpolators for both expanding and collapsing animations
86 | expandableTextView.setInterpolator(new OvershootInterpolator());
87 |
88 | // or set them separately
89 | expandableTextView.setExpandInterpolator(new OvershootInterpolator());
90 | expandableTextView.setCollapseInterpolator(new OvershootInterpolator());
91 |
92 | // toggle the ExpandableTextView
93 | buttonToggle.setOnClickListener(new View.OnClickListener()
94 | {
95 | @Override
96 | public void onClick(final View v)
97 | {
98 | buttonToggle.setText(expandableTextView.isExpanded() ? R.string.expand : R.string.collapse);
99 | expandableTextView.toggle();
100 | }
101 | });
102 |
103 | // but, you can also do the checks yourself
104 | buttonToggle.setOnClickListener(new View.OnClickListener()
105 | {
106 | @Override
107 | public void onClick(final View v)
108 | {
109 | if (expandableTextView.isExpanded())
110 | {
111 | expandableTextView.collapse();
112 | buttonToggle.setText(R.string.expand);
113 | }
114 | else
115 | {
116 | expandableTextView.expand();
117 | buttonToggle.setText(R.string.collapse);
118 | }
119 | }
120 | });
121 |
122 | // listen for expand / collapse events
123 | expandableTextView.setOnExpandListener(new ExpandableTextView.OnExpandListener()
124 | {
125 | @Override
126 | public void onExpand(final ExpandableTextView view)
127 | {
128 | Log.d(TAG, "ExpandableTextView expanded");
129 | }
130 |
131 | @Override
132 | public void onCollapse(final ExpandableTextView view)
133 | {
134 | Log.d(TAG, "ExpandableTextView collapsed");
135 | }
136 | });
137 | ```
138 |
139 | License
140 | =======
141 |
142 | Copyright 2016 Cliff Ophalvens (Blogc.at)
143 |
144 | Licensed under the Apache License, Version 2.0 (the "License");
145 | you may not use this file except in compliance with the License.
146 | You may obtain a copy of the License at
147 |
148 | http://www.apache.org/licenses/LICENSE-2.0
149 |
150 | Unless required by applicable law or agreed to in writing, software
151 | distributed under the License is distributed on an "AS IS" BASIS,
152 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
153 | See the License for the specific language governing permissions and
154 | limitations under the License.
155 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion "26.0.2"
6 |
7 | defaultConfig {
8 | applicationId "blogc.at.android.views"
9 | minSdkVersion 16
10 | targetSdkVersion 26
11 | versionCode 1
12 | versionName "1.0.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | ext {
23 | supportLibraryVersion = '26.1.0'
24 | }
25 |
26 | dependencies {
27 | compile fileTree(dir: 'libs', include: ['*.jar'])
28 | compile "com.android.support:appcompat-v7:$supportLibraryVersion"
29 | compile "com.android.support:recyclerview-v7:$supportLibraryVersion"
30 | compile 'com.android.support:support-annotations:25.3.1'
31 | compile project(':expandabletextview')
32 |
33 | testCompile 'junit:junit:4.12'
34 | }
35 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Library/android-sdk-mac_x86/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/at/blogc/android/views/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package at.blogc.android.views;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase
10 | {
11 | public ApplicationTest()
12 | {
13 | super(Application.class);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
20 |
21 |
28 |
29 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/java/at/blogc/android/activities/MainActivity.java:
--------------------------------------------------------------------------------
1 | package at.blogc.android.activities;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.view.animation.OvershootInterpolator;
9 | import android.widget.Button;
10 |
11 | import at.blogc.android.views.ExpandableTextView;
12 | import at.blogc.android.views.R;
13 |
14 | /**
15 | * Copyright (C) 2017 Cliff Ophalvens (Blogc.at)
16 | *
17 | * Licensed under the Apache License, Version 2.0 (the "License");
18 | * you may not use this file except in compliance with the License.
19 | * You may obtain a copy of the License at
20 | *
21 | * http://www.apache.org/licenses/LICENSE-2.0
22 | *
23 | * Unless required by applicable law or agreed to in writing, software
24 | * distributed under the License is distributed on an "AS IS" BASIS,
25 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 | * See the License for the specific language governing permissions and
27 | * limitations under the License.
28 | */
29 | public class MainActivity extends AppCompatActivity
30 | {
31 | private static final String TAG = "ExpandableTextView";
32 |
33 | @SuppressWarnings("ConstantConditions")
34 | @Override
35 | protected void onCreate(final Bundle savedInstanceState)
36 | {
37 | super.onCreate(savedInstanceState);
38 | this.setContentView(R.layout.activity_main);
39 |
40 | final ExpandableTextView expandableTextView = this.findViewById(R.id.expandableTextView);
41 | final Button buttonToggle = this.findViewById(R.id.button_toggle);
42 |
43 | // set animation duration via code, but preferable in your layout files by using the animation_duration attribute
44 | expandableTextView.setAnimationDuration(750L);
45 |
46 | // set interpolators for both expanding and collapsing animations
47 | expandableTextView.setInterpolator(new OvershootInterpolator());
48 |
49 | // or set them separately
50 | expandableTextView.setExpandInterpolator(new OvershootInterpolator());
51 | expandableTextView.setCollapseInterpolator(new OvershootInterpolator());
52 |
53 | // toggle the ExpandableTextView
54 | buttonToggle.setOnClickListener(new View.OnClickListener()
55 | {
56 | @SuppressWarnings("ConstantConditions")
57 | @Override
58 | public void onClick(final View v)
59 | {
60 | buttonToggle.setText(expandableTextView.isExpanded() ? R.string.expand : R.string.collapse);
61 | expandableTextView.toggle();
62 | }
63 | });
64 |
65 | // but, you can also do the checks yourself
66 | buttonToggle.setOnClickListener(new View.OnClickListener()
67 | {
68 | @Override
69 | public void onClick(final View v)
70 | {
71 | if (expandableTextView.isExpanded())
72 | {
73 | expandableTextView.collapse();
74 | buttonToggle.setText(R.string.expand);
75 | }
76 | else
77 | {
78 | expandableTextView.expand();
79 | buttonToggle.setText(R.string.collapse);
80 | }
81 | }
82 | });
83 |
84 | // listen for expand / collapse events
85 | expandableTextView.addOnExpandListener(new ExpandableTextView.OnExpandListener()
86 | {
87 | @Override
88 | public void onExpand(@NonNull final ExpandableTextView view)
89 | {
90 | Log.d(TAG, "ExpandableTextView expanded");
91 | }
92 |
93 | @Override
94 | public void onCollapse(@NonNull final ExpandableTextView view)
95 | {
96 | Log.d(TAG, "ExpandableTextView collapsed");
97 | }
98 | });
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/app/src/main/java/at/blogc/android/activities/RecyclerViewActivity.java:
--------------------------------------------------------------------------------
1 | package at.blogc.android.activities;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.LinearLayoutManager;
7 | import android.support.v7.widget.RecyclerView;
8 |
9 | import at.blogc.android.adapters.RecyclerViewAdapter;
10 | import at.blogc.android.views.R;
11 |
12 | /**
13 | * Copyright (C) 2017 Cliff Ophalvens (Blogc.at)
14 | *
15 | * Licensed under the Apache License, Version 2.0 (the "License");
16 | * you may not use this file except in compliance with the License.
17 | * You may obtain a copy of the License at
18 | *
19 | * http://www.apache.org/licenses/LICENSE-2.0
20 | *
21 | * Unless required by applicable law or agreed to in writing, software
22 | * distributed under the License is distributed on an "AS IS" BASIS,
23 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24 | * See the License for the specific language governing permissions and
25 | * limitations under the License.
26 | */
27 | public class RecyclerViewActivity extends AppCompatActivity
28 | {
29 | private RecyclerView recyclerView;
30 |
31 | @Override
32 | protected void onCreate(@Nullable final Bundle savedInstanceState)
33 | {
34 | super.onCreate(savedInstanceState);
35 | this.setContentView(R.layout.activity_recyclerview);
36 |
37 | // find views
38 | this.recyclerView = this.findViewById(R.id.recyclerview);
39 |
40 | // create layout manager
41 | final LinearLayoutManager layoutManager = new LinearLayoutManager(this);
42 | this.recyclerView.setLayoutManager(layoutManager);
43 |
44 | // bind adapter to recyclerview
45 | final RecyclerViewAdapter adapter = new RecyclerViewAdapter();
46 | this.recyclerView.setAdapter(adapter);
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/app/src/main/java/at/blogc/android/adapters/RecyclerViewAdapter.java:
--------------------------------------------------------------------------------
1 | package at.blogc.android.adapters;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 |
10 | import at.blogc.android.adapters.viewholders.ExpandableTextViewHolder;
11 | import at.blogc.android.views.R;
12 |
13 | /**
14 | * Copyright (C) 2017 Cliff Ophalvens (Blogc.at)
15 | *
16 | * Licensed under the Apache License, Version 2.0 (the "License");
17 | * you may not use this file except in compliance with the License.
18 | * You may obtain a copy of the License at
19 | *
20 | * http://www.apache.org/licenses/LICENSE-2.0
21 | *
22 | * Unless required by applicable law or agreed to in writing, software
23 | * distributed under the License is distributed on an "AS IS" BASIS,
24 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 | * See the License for the specific language governing permissions and
26 | * limitations under the License.
27 | */
28 | public class RecyclerViewAdapter extends RecyclerView.Adapter
29 | {
30 | private LayoutInflater layoutInflater;
31 |
32 | private LayoutInflater getLayoutInflater(@NonNull final Context context)
33 | {
34 | if (this.layoutInflater == null)
35 | {
36 | this.layoutInflater = LayoutInflater.from(context);
37 | }
38 |
39 | return this.layoutInflater;
40 | }
41 |
42 | @Override
43 | public ExpandableTextViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType)
44 | {
45 | final View itemView = this.getLayoutInflater(parent.getContext()).inflate(R.layout.listitem_recyclerview, parent, false);
46 |
47 | return new ExpandableTextViewHolder(itemView);
48 | }
49 |
50 | @Override
51 | public void onBindViewHolder(final ExpandableTextViewHolder holder, final int position)
52 | {
53 | holder.bindPosition(position);
54 | }
55 |
56 | @Override
57 | public int getItemCount()
58 | {
59 | return 100;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/app/src/main/java/at/blogc/android/adapters/viewholders/ExpandableTextViewHolder.java:
--------------------------------------------------------------------------------
1 | package at.blogc.android.adapters.viewholders;
2 |
3 | import android.support.v7.widget.RecyclerView;
4 | import android.view.View;
5 | import android.view.animation.OvershootInterpolator;
6 | import android.widget.Button;
7 |
8 | import at.blogc.android.views.ExpandableTextView;
9 | import at.blogc.android.views.R;
10 |
11 | /**
12 | * Copyright (C) 2017 Cliff Ophalvens (Blogc.at)
13 | *
14 | * Licensed under the Apache License, Version 2.0 (the "License");
15 | * you may not use this file except in compliance with the License.
16 | * You may obtain a copy of the License at
17 | *
18 | * http://www.apache.org/licenses/LICENSE-2.0
19 | *
20 | * Unless required by applicable law or agreed to in writing, software
21 | * distributed under the License is distributed on an "AS IS" BASIS,
22 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 | * See the License for the specific language governing permissions and
24 | * limitations under the License.
25 | */
26 | public class ExpandableTextViewHolder extends RecyclerView.ViewHolder
27 | implements View.OnClickListener
28 | {
29 | private final ExpandableTextView expandableTextView;
30 | private final Button buttonToggle;
31 |
32 | public ExpandableTextViewHolder(final View itemView)
33 | {
34 | super(itemView);
35 |
36 | // find views
37 | this.expandableTextView = itemView.findViewById(R.id.expandableTextView);
38 | this.buttonToggle = itemView.findViewById(R.id.button_toggle);
39 |
40 | // set interpolators for both expanding and collapsing animations
41 | this.expandableTextView.setInterpolator(new OvershootInterpolator());
42 |
43 | // toggle the ExpandableTextView
44 | this.buttonToggle.setOnClickListener(this);
45 | }
46 |
47 | public void bindPosition(final int position)
48 | {
49 | final String loremIpsum = position + ": " + this.itemView.getContext().getString(R.string.lorem_ipsum);
50 | this.expandableTextView.setText(loremIpsum);
51 | }
52 |
53 | //region View.OnClickListener interface
54 |
55 | @Override
56 | public void onClick(final View v)
57 | {
58 | this.buttonToggle.setText(this.expandableTextView.isExpanded() ? R.string.expand : R.string.collapse);
59 | this.expandableTextView.toggle();
60 | }
61 |
62 | //endregion
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
28 |
29 |
37 |
38 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_recyclerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/listitem_recyclerview.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
25 |
26 |
34 |
35 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/6bc3b5c310bee611ccecc93695d8e7548f19a651/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/6bc3b5c310bee611ccecc93695d8e7548f19a651/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/6bc3b5c310bee611ccecc93695d8e7548f19a651/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/6bc3b5c310bee611ccecc93695d8e7548f19a651/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/6bc3b5c310bee611ccecc93695d8e7548f19a651/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
20 | 64dp
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 | #3F51B5
18 | #303F9F
19 | #FF4081
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 | 16dp
19 | 16dp
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/lorem_ipsum.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse a risus sed nulla faucibus commodo. Donec iaculis pretium facilisis. Praesent rutrum varius arcu, sed viverra ipsum malesuada id. Suspendisse nec mauris eleifend, maximus elit et, venenatis quam. Duis at maximus nisi, a congue sapien. Curabitur facilisis at nisi vitae vulputate. Phasellus vel orci et massa scelerisque ultrices. Morbi eget ipsum porttitor arcu volutpat convallis. Pellentesque velit libero, interdum sed consequat at, eleifend et nisi. Interdum et malesuada fames ac ante ipsum primis in faucibus. Sed convallis massa imperdiet, consectetur lectus sodales, finibus velit. Donec quis tortor vel quam porta hendrerit. Vivamus vitae consectetur orci, sed feugiat turpis.
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 | ExpandableTextView
19 | Expand
20 | Collapse
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/test/java/at/blogc/android/views/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package at.blogc.android.views;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest
11 | {
12 | @Test
13 | public void addition_isCorrect() throws Exception
14 | {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
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'
11 | }
12 | }
13 |
14 | allprojects {
15 | repositories {
16 | jcenter()
17 | google()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
--------------------------------------------------------------------------------
/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/6bc3b5c310bee611ccecc93695d8e7548f19a651/demo.gif
--------------------------------------------------------------------------------
/demo_interpolator.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/6bc3b5c310bee611ccecc93695d8e7548f19a651/demo_interpolator.gif
--------------------------------------------------------------------------------
/expandabletextview/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/expandabletextview/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | def fullVersion = '1.0.5'
6 |
7 | group = 'at.blogc'
8 | version = fullVersion
9 |
10 | android {
11 | compileSdkVersion 26
12 | buildToolsVersion "26.0.2"
13 |
14 | defaultConfig {
15 | minSdkVersion 16
16 | targetSdkVersion 26
17 | versionCode 1
18 | versionName fullVersion
19 |
20 | buildConfigField 'int', 'DEFAULT_ANIMATION_DURATION', '750'
21 | }
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | }
29 |
30 | repositories {
31 | mavenCentral()
32 | }
33 |
34 | dependencies {
35 | compile fileTree(dir: 'libs', include: ['*.jar'])
36 | compile 'com.android.support:support-annotations:25.3.1'
37 |
38 | testCompile 'junit:junit:4.12'
39 | }
40 |
41 | task sourcesJar(type: Jar) {
42 | from android.sourceSets.main.java.srcDirs
43 | classifier = 'sources'
44 | }
45 |
46 | task javadoc(type: Javadoc) {
47 | source = android.sourceSets.main.java.srcDirs
48 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
49 | }
50 |
51 | task javadocJar(type: Jar, dependsOn: javadoc) {
52 | classifier = 'javadoc'
53 | from javadoc.destinationDir
54 | }
55 |
56 | artifacts {
57 | archives javadocJar
58 | archives sourcesJar
59 | }
60 |
61 | install {
62 | repositories.mavenInstaller {
63 | pom.project {
64 | name 'Android ExpandableTextview'
65 | description 'An expandable TextView for Android.'
66 | url 'https://github.com/Blogcat/Android-ExpandableTextView'
67 | inceptionYear '2016'
68 |
69 | packaging 'aar'
70 | groupId 'at.blogc'
71 | artifactId 'expandabletextview'
72 | version fullVersion
73 |
74 | licenses {
75 | license {
76 | name 'The Apache Software License, Version 2.0'
77 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
78 | distribution 'repo'
79 | }
80 | }
81 | scm {
82 | connection 'https://github.com/Blogcat/Android-ExpandableTextView.git'
83 | url 'https://github.com/Blogcat/Android-ExpandableTextView'
84 |
85 | }
86 | developers {
87 | developer {
88 | id 'cliffus'
89 | name 'Cliff Ophalvens'
90 | email 'cliff.ophalvens@gmail.com'
91 | }
92 | }
93 | }
94 | }
95 | }
96 |
97 | bintray {
98 | user = "${bintray_user}"
99 | key = "${bintray_apikey}"
100 | configurations = ['archives']
101 |
102 | dryRun = false
103 |
104 | pkg {
105 | repo = 'maven'
106 | name = 'android-expandabletextview'
107 | userOrg = "blogcat"
108 | licenses = ['Apache-2.0']
109 | websiteUrl = 'https://github.com/Blogcat/Android-ExpandableTextView'
110 | issueTrackerUrl = 'https://github.com/Blogcat/Android-ExpandableTextView/issues'
111 | vcsUrl = 'https://github.com/Blogcat/Android-ExpandableTextView.git'
112 | githubRepo = 'Blogcat/Android-ExpandableTextView'
113 | githubReleaseNotesFile = 'CHANGELOG.md'
114 |
115 | version {
116 | name = fullVersion
117 | released = new Date()
118 | vcsTag = fullVersion
119 |
120 | gpg {
121 | sign = true
122 | passphrase = "${bintray_gpg_password}"
123 | }
124 | }
125 | }
126 | }
--------------------------------------------------------------------------------
/expandabletextview/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_NAME=Expandable TextView
2 | POM_ARTIFACT_ID=expandabletextview
3 | POM_PACKAGING=aar
4 |
--------------------------------------------------------------------------------
/expandabletextview/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Library/android-sdk-mac_x86/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/expandabletextview/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/expandabletextview/src/main/java/at/blogc/android/views/ExpandableTextView.java:
--------------------------------------------------------------------------------
1 | package at.blogc.android.views;
2 |
3 | import android.animation.Animator;
4 | import android.animation.AnimatorListenerAdapter;
5 | import android.animation.TimeInterpolator;
6 | import android.animation.ValueAnimator;
7 | import android.content.Context;
8 | import android.content.res.TypedArray;
9 | import android.support.annotation.NonNull;
10 | import android.support.annotation.Nullable;
11 | import android.util.AttributeSet;
12 | import android.view.ViewGroup;
13 | import android.view.animation.AccelerateDecelerateInterpolator;
14 | import android.widget.TextView;
15 |
16 | import java.util.ArrayList;
17 | import java.util.List;
18 |
19 | import at.blogc.expandabletextview.BuildConfig;
20 | import at.blogc.expandabletextview.R;
21 |
22 | /**
23 | * Copyright (C) 2017 Cliff Ophalvens (Blogc.at)
24 | *
25 | * Licensed under the Apache License, Version 2.0 (the "License");
26 | * you may not use this file except in compliance with the License.
27 | * You may obtain a copy of the License at
28 | *
29 | * http://www.apache.org/licenses/LICENSE-2.0
30 | *
31 | * Unless required by applicable law or agreed to in writing, software
32 | * distributed under the License is distributed on an "AS IS" BASIS,
33 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34 | * See the License for the specific language governing permissions and
35 | * limitations under the License.
36 | *
37 | * @author Cliff Ophalvens (Blogc.at)
38 | */
39 | public class ExpandableTextView extends TextView
40 | {
41 | private final List onExpandListeners;
42 | private TimeInterpolator expandInterpolator;
43 | private TimeInterpolator collapseInterpolator;
44 |
45 | private final int maxLines;
46 | private long animationDuration;
47 | private boolean animating;
48 | private boolean expanded;
49 | private int collapsedHeight;
50 |
51 | public ExpandableTextView(final Context context)
52 | {
53 | this(context, null);
54 | }
55 |
56 | public ExpandableTextView(final Context context, @Nullable final AttributeSet attrs)
57 | {
58 | this(context, attrs, 0);
59 | }
60 |
61 | public ExpandableTextView(final Context context, @Nullable final AttributeSet attrs, final int defStyle)
62 | {
63 | super(context, attrs, defStyle);
64 |
65 | // read attributes
66 | final TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.ExpandableTextView, defStyle, 0);
67 | this.animationDuration = attributes.getInt(R.styleable.ExpandableTextView_animation_duration, BuildConfig.DEFAULT_ANIMATION_DURATION);
68 | attributes.recycle();
69 |
70 | // keep the original value of maxLines
71 | this.maxLines = this.getMaxLines();
72 |
73 | // create bucket of OnExpandListener instances
74 | this.onExpandListeners = new ArrayList<>();
75 |
76 | // create default interpolators
77 | this.expandInterpolator = new AccelerateDecelerateInterpolator();
78 | this.collapseInterpolator = new AccelerateDecelerateInterpolator();
79 | }
80 |
81 | @Override
82 | protected void onMeasure(final int widthMeasureSpec, int heightMeasureSpec)
83 | {
84 | // if this TextView is collapsed and maxLines = 0,
85 | // than make its height equals to zero
86 | if (this.maxLines == 0 && !this.expanded && !this.animating)
87 | {
88 | heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY);
89 | }
90 |
91 | super.onMeasure(widthMeasureSpec, heightMeasureSpec);
92 | }
93 |
94 | //region public helper methods
95 |
96 | /**
97 | * Toggle the expanded state of this {@link ExpandableTextView}.
98 | * @return true if toggled, false otherwise.
99 | */
100 | public boolean toggle()
101 | {
102 | return this.expanded
103 | ? this.collapse()
104 | : this.expand();
105 | }
106 |
107 | /**
108 | * Expand this {@link ExpandableTextView}.
109 | * @return true if expanded, false otherwise.
110 | */
111 | public boolean expand()
112 | {
113 | if (!this.expanded && !this.animating && this.maxLines >= 0)
114 | {
115 | // notify listener
116 | this.notifyOnExpand();
117 |
118 | // measure collapsed height
119 | this.measure
120 | (
121 | MeasureSpec.makeMeasureSpec(this.getMeasuredWidth(), MeasureSpec.EXACTLY),
122 | MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
123 | );
124 |
125 | this.collapsedHeight = this.getMeasuredHeight();
126 |
127 | // indicate that we are now animating
128 | this.animating = true;
129 |
130 | // set maxLines to MAX Integer, so we can calculate the expanded height
131 | this.setMaxLines(Integer.MAX_VALUE);
132 |
133 | // measure expanded height
134 | this.measure
135 | (
136 | MeasureSpec.makeMeasureSpec(this.getMeasuredWidth(), MeasureSpec.EXACTLY),
137 | MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
138 | );
139 |
140 | final int expandedHeight = this.getMeasuredHeight();
141 |
142 | // animate from collapsed height to expanded height
143 | final ValueAnimator valueAnimator = ValueAnimator.ofInt(this.collapsedHeight, expandedHeight);
144 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
145 | {
146 | @Override
147 | public void onAnimationUpdate(final ValueAnimator animation)
148 | {
149 | ExpandableTextView.this.setHeight((int) animation.getAnimatedValue());
150 | }
151 | });
152 |
153 | // wait for the animation to end
154 | valueAnimator.addListener(new AnimatorListenerAdapter()
155 | {
156 | @Override
157 | public void onAnimationEnd(final Animator animation)
158 | {
159 | // reset min & max height (previously set with setHeight() method)
160 | ExpandableTextView.this.setMaxHeight(Integer.MAX_VALUE);
161 | ExpandableTextView.this.setMinHeight(0);
162 |
163 | // if fully expanded, set height to WRAP_CONTENT, because when rotating the device
164 | // the height calculated with this ValueAnimator isn't correct anymore
165 | final ViewGroup.LayoutParams layoutParams = ExpandableTextView.this.getLayoutParams();
166 | layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
167 | ExpandableTextView.this.setLayoutParams(layoutParams);
168 |
169 | // keep track of current status
170 | ExpandableTextView.this.expanded = true;
171 | ExpandableTextView.this.animating = false;
172 | }
173 | });
174 |
175 | // set interpolator
176 | valueAnimator.setInterpolator(this.expandInterpolator);
177 |
178 | // start the animation
179 | valueAnimator
180 | .setDuration(this.animationDuration)
181 | .start();
182 |
183 | return true;
184 | }
185 |
186 | return false;
187 | }
188 |
189 | /**
190 | * Collapse this {@link TextView}.
191 | * @return true if collapsed, false otherwise.
192 | */
193 | public boolean collapse()
194 | {
195 | if (this.expanded && !this.animating && this.maxLines >= 0)
196 | {
197 | // notify listener
198 | this.notifyOnCollapse();
199 |
200 | // measure expanded height
201 | final int expandedHeight = this.getMeasuredHeight();
202 |
203 | // indicate that we are now animating
204 | this.animating = true;
205 |
206 | // animate from expanded height to collapsed height
207 | final ValueAnimator valueAnimator = ValueAnimator.ofInt(expandedHeight, this.collapsedHeight);
208 | valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
209 | {
210 | @Override
211 | public void onAnimationUpdate(final ValueAnimator animation)
212 | {
213 | ExpandableTextView.this.setHeight((int) animation.getAnimatedValue());
214 | }
215 | });
216 |
217 | // wait for the animation to end
218 | valueAnimator.addListener(new AnimatorListenerAdapter()
219 | {
220 | @Override
221 | public void onAnimationEnd(final Animator animation)
222 | {
223 | // keep track of current status
224 | ExpandableTextView.this.expanded = false;
225 | ExpandableTextView.this.animating = false;
226 |
227 | // set maxLines back to original value
228 | ExpandableTextView.this.setMaxLines(ExpandableTextView.this.maxLines);
229 |
230 | // if fully collapsed, set height back to WRAP_CONTENT, because when rotating the device
231 | // the height previously calculated with this ValueAnimator isn't correct anymore
232 | final ViewGroup.LayoutParams layoutParams = ExpandableTextView.this.getLayoutParams();
233 | layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
234 | ExpandableTextView.this.setLayoutParams(layoutParams);
235 | }
236 | });
237 |
238 | // set interpolator
239 | valueAnimator.setInterpolator(this.collapseInterpolator);
240 |
241 | // start the animation
242 | valueAnimator
243 | .setDuration(this.animationDuration)
244 | .start();
245 |
246 | return true;
247 | }
248 |
249 | return false;
250 | }
251 |
252 | //endregion
253 |
254 | //region public getters and setters
255 |
256 | /**
257 | * Sets the duration of the expand / collapse animation.
258 | * @param animationDuration duration in milliseconds.
259 | */
260 | public void setAnimationDuration(final long animationDuration)
261 | {
262 | this.animationDuration = animationDuration;
263 | }
264 |
265 | /**
266 | * Adds a listener which receives updates about this {@link ExpandableTextView}.
267 | * @param onExpandListener the listener.
268 | */
269 | public void addOnExpandListener(final OnExpandListener onExpandListener)
270 | {
271 | this.onExpandListeners.add(onExpandListener);
272 | }
273 |
274 | /**
275 | * Removes a listener which receives updates about this {@link ExpandableTextView}.
276 | * @param onExpandListener the listener.
277 | */
278 | public void removeOnExpandListener(final OnExpandListener onExpandListener)
279 | {
280 | this.onExpandListeners.remove(onExpandListener);
281 | }
282 |
283 | /**
284 | * Sets a {@link TimeInterpolator} for expanding and collapsing.
285 | * @param interpolator the interpolator
286 | */
287 | public void setInterpolator(final TimeInterpolator interpolator)
288 | {
289 | this.expandInterpolator = interpolator;
290 | this.collapseInterpolator = interpolator;
291 | }
292 |
293 | /**
294 | * Sets a {@link TimeInterpolator} for expanding.
295 | * @param expandInterpolator the interpolator
296 | */
297 | public void setExpandInterpolator(final TimeInterpolator expandInterpolator)
298 | {
299 | this.expandInterpolator = expandInterpolator;
300 | }
301 |
302 | /**
303 | * Returns the current {@link TimeInterpolator} for expanding.
304 | * @return the current interpolator, null by default.
305 | */
306 | public TimeInterpolator getExpandInterpolator()
307 | {
308 | return this.expandInterpolator;
309 | }
310 |
311 | /**
312 | * Sets a {@link TimeInterpolator} for collpasing.
313 | * @param collapseInterpolator the interpolator
314 | */
315 | public void setCollapseInterpolator(final TimeInterpolator collapseInterpolator)
316 | {
317 | this.collapseInterpolator = collapseInterpolator;
318 | }
319 |
320 | /**
321 | * Returns the current {@link TimeInterpolator} for collapsing.
322 | * @return the current interpolator, null by default.
323 | */
324 | public TimeInterpolator getCollapseInterpolator()
325 | {
326 | return this.collapseInterpolator;
327 | }
328 |
329 | /**
330 | * Is this {@link ExpandableTextView} expanded or not?
331 | * @return true if expanded, false if collapsed.
332 | */
333 | public boolean isExpanded()
334 | {
335 | return this.expanded;
336 | }
337 |
338 | //endregion
339 |
340 | /**
341 | * This method will notify the listener about this view being expanded.
342 | */
343 | private void notifyOnCollapse()
344 | {
345 | for (final OnExpandListener onExpandListener : this.onExpandListeners)
346 | {
347 | onExpandListener.onCollapse(this);
348 | }
349 | }
350 |
351 | /**
352 | * This method will notify the listener about this view being collapsed.
353 | */
354 | private void notifyOnExpand()
355 | {
356 | for (final OnExpandListener onExpandListener : this.onExpandListeners)
357 | {
358 | onExpandListener.onExpand(this);
359 | }
360 | }
361 |
362 | //region public interfaces
363 |
364 | /**
365 | * Interface definition for a callback to be invoked when
366 | * a {@link ExpandableTextView} is expanded or collapsed.
367 | */
368 | public interface OnExpandListener
369 | {
370 | /**
371 | * The {@link ExpandableTextView} is being expanded.
372 | * @param view the textview
373 | */
374 | void onExpand(@NonNull ExpandableTextView view);
375 |
376 | /**
377 | * The {@link ExpandableTextView} is being collapsed.
378 | * @param view the textview
379 | */
380 | void onCollapse(@NonNull ExpandableTextView view);
381 | }
382 |
383 | /**
384 | * Simple implementation of the {@link OnExpandListener} interface with stub
385 | * implementations of each method. Extend this if you do not intend to override
386 | * every method of {@link OnExpandListener}.
387 | */
388 | public static class SimpleOnExpandListener implements OnExpandListener
389 | {
390 | @Override
391 | public void onExpand(@NonNull final ExpandableTextView view)
392 | {
393 | // empty implementation
394 | }
395 |
396 | @Override
397 | public void onCollapse(@NonNull final ExpandableTextView view)
398 | {
399 | // empty implementation
400 | }
401 | }
402 |
403 | //endregion
404 | }
405 |
--------------------------------------------------------------------------------
/expandabletextview/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/expandabletextview/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
16 |
17 | ExpandableTextView
18 |
19 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/6bc3b5c310bee611ccecc93695d8e7548f19a651/gradle.properties
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Blogcat/Android-ExpandableTextView/6bc3b5c310bee611ccecc93695d8e7548f19a651/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 11 14:19:54 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name='expandabletextview-root'
2 |
3 | include ':app', ':expandabletextview'
4 |
--------------------------------------------------------------------------------