├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── app
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── gturedi
│ │ └── app
│ │ └── MainActivity.java
│ └── res
│ ├── anim
│ ├── in.xml
│ └── out.xml
│ ├── drawable
│ └── ic_bluetooth_disabled_black_24dp.xml
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.png
│ └── ic_launcher_round.png
│ └── values
│ ├── colors.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
├── mvnPush.gradle
├── quality
│ ├── checkstyle.xml
│ ├── findbugsExludeFilter.xml
│ ├── lint.xml
│ ├── pmdRuleSet.xml
│ └── quality.gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── gturedi
│ │ └── views
│ │ ├── CustomAnimationListener.java
│ │ ├── CustomStateOptions.java
│ │ └── StatefulLayout.java
│ └── res
│ ├── drawable
│ ├── stf_ic_empty.xml
│ ├── stf_ic_error.xml
│ ├── stf_ic_location_off.xml
│ └── stf_ic_offline.xml
│ ├── layout
│ └── stf_template.xml
│ └── values
│ ├── attrs.xml
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── sample.gif
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | .gradle
3 | .idea
4 | .DS_Store
5 |
6 | local.properties
7 |
8 | *.iml
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | android:
4 | components:
5 | - tools
6 | - platform-tools
7 | - build-tools-25.0.2
8 | - android-25
9 | - extra-android-m2repository
10 |
11 | jdk:
12 | - oraclejdk8
13 |
14 | notifications:
15 | email: true
16 |
17 | sudo: false
18 |
19 | script:
20 | - chmod +x gradlew
21 | - ./gradlew :library:assembleDebug
22 | - ./gradlew :library:check
23 |
24 | cache:
25 | directories:
26 | - $HOME/.m2
27 | - $HOME/.gradle
--------------------------------------------------------------------------------
/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 | ## StatefulLayout
2 |
3 | [](https://android-arsenal.com/details/1/5325) [](https://android-arsenal.com/api?level=14) [](https://oss.sonatype.org/content/repositories/releases/com/github/gturedi/stateful-layout/) [](https://travis-ci.org/gturedi/StatefulLayout) [](http://www.apache.org/licenses/LICENSE-2.0.html)
4 |
5 | Android layout to show most common state templates like loading, empty, error etc. To do that all you need to is wrap
6 | the target area(view) with StatefulLayout.
7 |
8 | 
9 |
10 | ## Usage
11 | You can download it from jitpack.io
12 | ```groovy
13 | allprojects {
14 | repositories {
15 | maven { url 'https://jitpack.io' }
16 | }
17 | }
18 | dependencies {
19 | compile 'com.github.gturedi:StatefulLayout:1.2.2'
20 | }
21 | ```
22 |
23 | Alternatively you can use Sonatype Repository, add dependecy to app/build.gradle
24 | ```groovy
25 | dependencies {
26 | compile 'com.github.gturedi:stateful-layout:1.2.1'
27 | }
28 | ```
29 | Snapshots of the development version are available in [Sonatype's `snapshots` repository](https://oss.sonatype.org/content/repositories/snapshots/com/github/gturedi)
30 |
31 | ```
32 |
33 | Then wrap a view which target area(view) to show states with StatefulLayout
34 | ```xml
35 |
43 |
44 |
45 |
50 | ...
51 |
52 |
53 |
54 | ```
55 |
56 | Finally in your activity/fragment get StatefulLayout reference and call showXXX methods
57 | ```java
58 | StatefulLayout stateful = (StatefulLayout) findViewById(R.id.stateful);
59 | stateful.showLoading();
60 | //stateful.showEmpty(getString(R.string.testMessage));
61 | //stateful.showError(getString(R.string.testMessage), clickListener);
62 | //etc.
63 | ```
64 |
65 | ## API
66 | State methods have overloads for customization. If you pass clickListener parameter as null, relevant state button
67 | will be hided. More customization please look [CustomStateOptions.java](library/src/main/java/com/gturedi/views/CustomStateOptions.java)
68 |
69 | - setAnimationEnabled(boolean animationEnabled)
70 | - setInAnimation(@AnimRes int inAnimation)
71 | - setOutAnimation(@AnimRes int outAnimation)
72 | - showContent()
73 | - showLoading(String message)
74 | - showEmpty(String message)
75 | - showError(String message, OnClickListener clickListener)
76 | - showOffline(String message, OnClickListener clickListener)
77 | - showLocationOff(String message, OnClickListener clickListener)
78 | - showCustom(CustomStateOptions options)
79 |
80 | ## Xml Attributes
81 | | Name | Type | Default | Description |
82 | |:----:|:----:|:-------:|:-----------:|
83 | | stfAnimationEnabled | boolean | true | Indicates whether to place the animation on state changes |
84 | | stfInAnimation | anim | @android:anim/fade_in | Animation started begin of state change |
85 | | stfOutAnimation | anim | @android:anim/fade_out | Animation started end of state change |
86 |
87 | ## Customization
88 | Just override relevant resource in your app to customize state views appearance
89 |
90 | - To Override **strings** [strings.xml variables](library/src/main/res/values/strings.xml)
91 |
92 | - To Override **styles** [styles.xml](library/src/main/res/values/styles.xml)
93 |
94 | - To Override **layout** [stf_template.xml](library/src/main/res/layout/stf_template.xml)
95 |
96 | ## License
97 | Copyright 2017 Gökhan Türedi (turedi.gokhan@gmail.com)
98 |
99 | Licensed under the Apache License, Version 2.0 (the "License");
100 | you may not use this file except in compliance with the License.
101 | You may obtain a copy of the License at
102 |
103 | http://www.apache.org/licenses/LICENSE-2.0
104 |
105 | Unless required by applicable law or agreed to in writing, software
106 | distributed under the License is distributed on an "AS IS" BASIS,
107 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
108 | See the License for the specific language governing permissions and
109 | limitations under the License.
110 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion project.compileSdkVersion
5 | buildToolsVersion project.buildToolsVersion
6 |
7 | defaultConfig {
8 | applicationId "com.gturedi.app"
9 | minSdkVersion project.minSdkVersion
10 | targetSdkVersion project.targetSdkVersion
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | }
15 |
16 | dependencies {
17 | compile project(':library')
18 | compile 'com.google.android:flexbox:0.2.5'
19 | //compile 'com.android.support:appcompat-v7:25.1.1'
20 | //compile 'com.google.android.gms:play-services-maps:9.4.0'
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/java/com/gturedi/app/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.gturedi.app;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.view.View;
6 | import android.widget.Toast;
7 |
8 | import com.gturedi.views.CustomStateOptions;
9 | import com.gturedi.views.StatefulLayout;
10 |
11 | /**
12 | * Created by gturedi on 17.02.2017.
13 | */
14 | public class MainActivity
15 | extends AppCompatActivity {
16 |
17 | private StatefulLayout stateful;
18 |
19 | private View.OnClickListener clickListener = new View.OnClickListener() {
20 | @Override
21 | public void onClick(View v) {
22 | Toast.makeText(MainActivity.this, "click!", Toast.LENGTH_SHORT).show();
23 | }
24 | };
25 |
26 | @Override
27 | public void onCreate(Bundle savedInstanceState) {
28 | super.onCreate(savedInstanceState);
29 | setContentView(R.layout.activity_main);
30 | stateful = (StatefulLayout) findViewById(R.id.stateful);
31 | }
32 |
33 | public void content(View view) {
34 | stateful.showContent();
35 | }
36 |
37 | public void loading(View view) {
38 | stateful.showLoading();
39 | //stateful.showLoading(R.string.testMessage);
40 | //stateful.showLoading(getString(R.string.testMessage));
41 | }
42 |
43 | public void empty(View view) {
44 | stateful.showEmpty();
45 | //stateful.showEmpty(R.string.testMessage);
46 | //stateful.showEmpty(getString(R.string.testMessage));
47 | }
48 |
49 | public void error(View view) {
50 | stateful.showError(clickListener);
51 | //stateful.showError(R.string.testMessage, clickListener);
52 | //stateful.showError(getString(R.string.testMessage), clickListener);
53 | }
54 |
55 | public void offline(View view) {
56 | stateful.showOffline(clickListener);
57 | //stateful.showOffline(R.string.testMessage, clickListener);
58 | //stateful.showOffline(getString(R.string.testMessage), clickListener);
59 | }
60 |
61 | public void locationOff(View view) {
62 | stateful.showLocationOff(clickListener);
63 | //stateful.showLocationOff(R.string.testMessage, clickListener);
64 | //stateful.showLocationOff(getString(R.string.testMessage), clickListener);
65 | }
66 |
67 | public void custom(View view) {
68 | //stateful.showCustom(new CustomStateOptions());
69 | //stateful.showCustom(new CustomStateOptions().image(R.drawable.ic_bluetooth_disabled_black_24dp));
70 | //stateful.showCustom(new CustomStateOptions().image(R.drawable.ic_bluetooth_disabled_black_24dp).message("please open bluetooth"));
71 | //stateful.showCustom(new CustomStateOptions().message("hey yow!"));
72 | //stateful.showCustom(new CustomStateOptions().message("hey yow!").buttonAction(clickListener));
73 | stateful.showCustom(new CustomStateOptions()
74 | .image(R.drawable.ic_bluetooth_disabled_black_24dp)
75 | .message("please open bluetooth")
76 | .buttonText("settings")
77 | .buttonClickListener(clickListener));
78 | }
79 |
80 | }
81 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/in.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/anim/out.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_bluetooth_disabled_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
16 |
17 |
23 |
24 |
30 |
31 |
37 |
38 |
44 |
45 |
51 |
52 |
58 |
59 |
65 |
66 |
67 |
68 |
78 |
79 |
85 |
86 |
92 |
93 |
99 |
100 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gturedi/StatefulLayout/e7ce7c41036a805419120647d40d4cdb7a8a8577/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gturedi/StatefulLayout/e7ce7c41036a805419120647d40d4cdb7a8a8577/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | StatefulLayout Sample
3 | This just a simple test message
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
14 |
15 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 |
6 | dependencies {
7 | classpath 'com.android.tools.build:gradle:2.3.0'
8 | classpath 'com.jakewharton:butterknife-gradle-plugin:8.5.1'
9 | }
10 | }
11 |
12 | allprojects {
13 | repositories {
14 | jcenter()
15 | }
16 |
17 | tasks.withType(JavaCompile) {
18 | sourceCompatibility = "1.7"
19 | targetCompatibility = "1.7"
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
27 | ext {
28 | compileSdkVersion = 25
29 | buildToolsVersion = "25.0.2"
30 | targetSdkVersion = 25
31 | minSdkVersion = 14
32 | targetSdkVersion = 25
33 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | POM_GROUP=com.github.gturedi
2 | POM_ARTIFACT_ID=stateful-layout
3 | POM_VERSION=1.2.1
4 |
5 | POM_NAME=StatefulLayout
6 | POM_PACKAGING=aar
7 | POM_DESCRIPTION=Android layout to show template for loading, empty, error etc. states
8 | POM_URL=https://github.com/gturedi/StatefulLayout
9 |
10 | POM_SCM_URL=https://github.com/gturedi/StatefulLayout
11 | POM_SCM_CONNECTION=https://github.com/gturedi/StatefulLayout.git
12 | POM_SCM_DEV_CONNECTION=https://github.com/gturedi/StatefulLayout.git
13 |
14 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
15 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
16 | POM_LICENCE_DIST=repo
17 |
18 | POM_DEVELOPER_ID=gturedi
19 | POM_DEVELOPER_NAME=Gökhan Türedi
--------------------------------------------------------------------------------
/gradle/mvnPush.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Chris Banes
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | apply plugin: 'maven'
18 | apply plugin: 'signing'
19 |
20 | def isReleaseBuild() {
21 | return POM_VERSION.contains("SNAPSHOT") == false
22 | }
23 |
24 | def getRepositoryUsername() {
25 | return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
26 | }
27 |
28 | def getRepositoryPassword() {
29 | return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
30 | }
31 |
32 | afterEvaluate { project ->
33 | uploadArchives {
34 | repositories {
35 | mavenDeployer {
36 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
37 |
38 | pom.groupId = POM_GROUP
39 | pom.artifactId = POM_ARTIFACT_ID
40 | pom.version = POM_VERSION
41 |
42 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
43 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
44 | }
45 | snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
46 | authentication(userName: getRepositoryUsername(), password: getRepositoryPassword())
47 | }
48 |
49 | pom.project {
50 | name POM_NAME
51 | packaging POM_PACKAGING
52 | description POM_DESCRIPTION
53 | url POM_URL
54 |
55 | scm {
56 | url POM_SCM_URL
57 | connection POM_SCM_CONNECTION
58 | developerConnection POM_SCM_DEV_CONNECTION
59 | }
60 |
61 | licenses {
62 | license {
63 | name POM_LICENCE_NAME
64 | url POM_LICENCE_URL
65 | distribution POM_LICENCE_DIST
66 | }
67 | }
68 |
69 | developers {
70 | developer {
71 | id POM_DEVELOPER_ID
72 | name POM_DEVELOPER_NAME
73 | }
74 | }
75 | }
76 | }
77 | }
78 | }
79 |
80 | signing {
81 | required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") }
82 | sign configurations.archives
83 | }
84 |
85 | task androidJavadocs(type: Javadoc) {
86 | source = android.sourceSets.main.java.srcDirs
87 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
88 |
89 | if (JavaVersion.current().isJava8Compatible()) {
90 | allprojects {
91 | tasks.withType(Javadoc) {
92 | options.addStringOption('Xdoclint:none', '-quiet')
93 | }
94 | }
95 | }
96 | }
97 |
98 | task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
99 | classifier = 'javadoc'
100 | from androidJavadocs.destinationDir
101 | }
102 |
103 | task androidSourcesJar(type: Jar) {
104 | classifier = 'sources'
105 | from android.sourceSets.main.java.sourceFiles
106 | }
107 |
108 | artifacts {
109 | archives androidSourcesJar
110 | archives androidJavadocsJar
111 | }
112 | }
--------------------------------------------------------------------------------
/gradle/quality/checkstyle.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
--------------------------------------------------------------------------------
/gradle/quality/findbugsExludeFilter.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/gradle/quality/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/quality/pmdRuleSet.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/gradle/quality/quality.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'checkstyle'
2 | apply plugin: 'findbugs'
3 | apply plugin: 'pmd'
4 |
5 | def final CONFIG_DIR = "${project.rootDir}/gradle/quality"
6 | def final REPORT_DIR = "${project.buildDir}/reports"
7 | def final IGNORE_ERROR = false
8 | def final SOURCE = "src/main/java"
9 | def final INCLUDE_PATTERN = "**/*.java"
10 | def final EXCLUDE_PATTERN = "**/gen/**"
11 |
12 | android {
13 | lintOptions {
14 | abortOnError !IGNORE_ERROR
15 | xmlReport false
16 | htmlReport true
17 | absolutePaths false
18 | lintConfig file("$CONFIG_DIR/lint.xml")
19 | htmlOutput file("$REPORT_DIR/lintReport.html")
20 | }
21 | }
22 |
23 | task checkstyle(type: Checkstyle) {
24 | showViolations true
25 | configFile file("${CONFIG_DIR}/checkstyle.xml")
26 | ignoreFailures IGNORE_ERROR
27 | source SOURCE
28 | include INCLUDE_PATTERN
29 | exclude EXCLUDE_PATTERN
30 | classpath = files()
31 | reports {
32 | xml.enabled = false
33 | html.enabled = true
34 | html.destination "$REPORT_DIR/checkstyle.html"
35 | }
36 | }
37 |
38 | task findbugs(type: FindBugs) {
39 | effort = "max"
40 | reportLevel = "high"
41 | excludeFilter = new File("$CONFIG_DIR/findbugsExludeFilter.xml")
42 | classes = files("${project.buildDir}/intermediates/classes")
43 | ignoreFailures = IGNORE_ERROR
44 | source SOURCE
45 | include INCLUDE_PATTERN
46 | exclude EXCLUDE_PATTERN
47 | classpath = files()
48 | reports {
49 | xml.enabled = false
50 | html.enabled = true
51 | html.destination "$REPORT_DIR/findbugs.html"
52 | }
53 | }
54 |
55 | task pmd(type: Pmd) {
56 | consoleOutput true
57 | ruleSetFiles = files("$CONFIG_DIR/pmdRuleSet.xml")
58 | ignoreFailures = IGNORE_ERROR
59 | source SOURCE
60 | include INCLUDE_PATTERN
61 | exclude EXCLUDE_PATTERN
62 | reports {
63 | xml.enabled = false
64 | html.enabled = true
65 | html.destination "$REPORT_DIR/pmd.html"
66 | }
67 | }
68 |
69 | // http://vincentbrison.com/2014/07/19/how-to-improve-quality-and-syntax-of-your-android-code
70 | // check.dependsOn 'checkstyle', 'pmd', 'findbugs'
71 | afterEvaluate {
72 | if (project.tasks.findByName('check')) {
73 | check.dependsOn 'lint', 'checkstyle', 'findbugs', 'pmd'
74 | }
75 | }
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gturedi/StatefulLayout/e7ce7c41036a805419120647d40d4cdb7a8a8577/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 07 20:20:28 GMT+03:00 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-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply from: '../gradle/mvnPush.gradle'
3 | apply from: '../gradle/quality/quality.gradle'
4 |
5 | android {
6 | compileSdkVersion project.compileSdkVersion
7 | buildToolsVersion project.buildToolsVersion
8 | resourcePrefix 'stf'
9 |
10 | defaultConfig {
11 | minSdkVersion project.minSdkVersion
12 | targetSdkVersion project.targetSdkVersion
13 | versionCode 1
14 | versionName "1.0"
15 | vectorDrawables.useSupportLibrary = true
16 | }
17 |
18 | lintOptions {
19 | checkReleaseBuilds false
20 | abortOnError false
21 | }
22 | }
23 |
24 | dependencies {
25 | compile 'com.android.support:appcompat-v7:25.1.1'
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/library/src/main/java/com/gturedi/views/CustomAnimationListener.java:
--------------------------------------------------------------------------------
1 | package com.gturedi.views;
2 |
3 | import android.view.animation.Animation;
4 |
5 | /**
6 | * simple class to reduce callback hell
7 | */
8 | @SuppressWarnings("PMD.UncommentedEmptyMethodBody")
9 | public class CustomAnimationListener
10 | implements Animation.AnimationListener {
11 |
12 | @Override
13 | public void onAnimationStart(Animation animation) {
14 | }
15 |
16 | @Override
17 | public void onAnimationEnd(Animation animation) {
18 | }
19 |
20 | @Override
21 | public void onAnimationRepeat(Animation animation) {
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/library/src/main/java/com/gturedi/views/CustomStateOptions.java:
--------------------------------------------------------------------------------
1 | package com.gturedi.views;
2 |
3 | import android.support.annotation.DrawableRes;
4 | import android.view.View;
5 |
6 | import java.io.Serializable;
7 |
8 | /**
9 | * Model builder class to show custom state
10 | * @see com.gturedi.views.StatefulLayout#showCustom(CustomStateOptions)
11 | */
12 | @SuppressWarnings("PMD.AvoidFieldNameMatchingMethodName")
13 | public class CustomStateOptions implements Serializable {
14 |
15 | @DrawableRes private int imageRes;
16 | private boolean isLoading;
17 | private String message;
18 | private String buttonText;
19 | private View.OnClickListener buttonClickListener;
20 |
21 | public CustomStateOptions image(@DrawableRes int val) {
22 | imageRes = val;
23 | return this;
24 | }
25 |
26 | public CustomStateOptions loading() {
27 | isLoading = true;
28 | return this;
29 | }
30 |
31 | public CustomStateOptions message(String val) {
32 | message = val;
33 | return this;
34 | }
35 |
36 | public CustomStateOptions buttonText(String val) {
37 | buttonText = val;
38 | return this;
39 | }
40 |
41 | public CustomStateOptions buttonClickListener(View.OnClickListener val) {
42 | buttonClickListener = val;
43 | return this;
44 | }
45 |
46 | public int getImageRes() {
47 | return imageRes;
48 | }
49 |
50 | public boolean isLoading() {
51 | return isLoading;
52 | }
53 |
54 | public String getMessage() {
55 | return message;
56 | }
57 |
58 | public String getButtonText() {
59 | return buttonText;
60 | }
61 |
62 | public View.OnClickListener getClickListener() {
63 | return buttonClickListener;
64 | }
65 |
66 | }
67 |
--------------------------------------------------------------------------------
/library/src/main/java/com/gturedi/views/StatefulLayout.java:
--------------------------------------------------------------------------------
1 | package com.gturedi.views;
2 |
3 | import android.content.Context;
4 | import android.content.res.TypedArray;
5 | import android.support.annotation.AnimRes;
6 | import android.support.annotation.StringRes;
7 | import android.text.TextUtils;
8 | import android.util.AttributeSet;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.animation.Animation;
12 | import android.view.animation.AnimationUtils;
13 | import android.widget.Button;
14 | import android.widget.ImageView;
15 | import android.widget.LinearLayout;
16 | import android.widget.ProgressBar;
17 | import android.widget.TextView;
18 |
19 | /**
20 | * Android layout to show most common state templates like loading, empty, error etc. To do that all you need to is
21 | * wrap the target area(view) with StatefulLayout. For more information about usage look
22 | * here
23 | */
24 | public class StatefulLayout
25 | extends LinearLayout {
26 |
27 | private static final String MSG_ONE_CHILD = "StatefulLayout must have one child!";
28 | private static final boolean DEFAULT_ANIM_ENABLED = true;
29 | private static final int DEFAULT_IN_ANIM = android.R.anim.fade_in;
30 | private static final int DEFAULT_OUT_ANIM = android.R.anim.fade_out;
31 |
32 | /**
33 | * Indicates whether to place the animation on state changes
34 | */
35 | private boolean animationEnabled;
36 | /**
37 | * Animation started begin of state change
38 | */
39 | private Animation inAnimation;
40 | /**
41 | * Animation started end of state change
42 | */
43 | private Animation outAnimation;
44 | /**
45 | * to synchronize transition animations when animation duration shorter then request of state change
46 | */
47 | private int animCounter;
48 |
49 | private View content;
50 | private LinearLayout stContainer;
51 | private ProgressBar stProgress;
52 | private ImageView stImage;
53 | private TextView stMessage;
54 | private Button stButton;
55 |
56 | public StatefulLayout(Context context) {
57 | this(context, null);
58 | }
59 |
60 | public StatefulLayout(Context context, AttributeSet attrs) {
61 | super(context, attrs, 0);
62 | TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.stfStatefulLayout, 0, 0);
63 | animationEnabled = array.getBoolean(R.styleable.stfStatefulLayout_stfAnimationEnabled, DEFAULT_ANIM_ENABLED);
64 | inAnimation = anim(array.getResourceId(R.styleable.stfStatefulLayout_stfInAnimation, DEFAULT_IN_ANIM));
65 | outAnimation = anim(array.getResourceId(R.styleable.stfStatefulLayout_stfOutAnimation, DEFAULT_OUT_ANIM));
66 | array.recycle();
67 | }
68 |
69 | public boolean isAnimationEnabled() {
70 | return animationEnabled;
71 | }
72 |
73 | public void setAnimationEnabled(boolean animationEnabled) {
74 | this.animationEnabled = animationEnabled;
75 | }
76 |
77 | public Animation getInAnimation() {
78 | return inAnimation;
79 | }
80 |
81 | public void setInAnimation(Animation animation) {
82 | inAnimation = animation;
83 | }
84 |
85 | public void setInAnimation(@AnimRes int anim) {
86 | inAnimation = anim(anim);
87 | }
88 |
89 | public Animation getOutAnimation() {
90 | return outAnimation;
91 | }
92 |
93 | public void setOutAnimation(Animation animation) {
94 | outAnimation = animation;
95 | }
96 |
97 | public void setOutAnimation(@AnimRes int anim) {
98 | outAnimation = anim(anim);
99 | }
100 |
101 | @Override
102 | protected void onFinishInflate() {
103 | super.onFinishInflate();
104 | if (getChildCount() > 1) throw new IllegalStateException(MSG_ONE_CHILD);
105 | if (isInEditMode()) return; // hide state views in designer
106 | setOrientation(VERTICAL);
107 | content = getChildAt(0); // assume first child as content
108 | LayoutInflater.from(getContext()).inflate(R.layout.stf_template, this, true);
109 | stContainer = (LinearLayout) findViewById(R.id.stContainer);
110 | stProgress = (ProgressBar) findViewById(R.id.stProgress);
111 | stImage = (ImageView) findViewById(R.id.stImage);
112 | stMessage = (TextView) findViewById(R.id.stMessage);
113 | stButton = (Button) findViewById(R.id.stButton);
114 | }
115 |
116 | // content //
117 |
118 | public void showContent() {
119 | if (isAnimationEnabled()) {
120 | stContainer.clearAnimation();
121 | content.clearAnimation();
122 | final int animCounterCopy = ++animCounter;
123 | if (stContainer.getVisibility() == VISIBLE) {
124 | outAnimation.setAnimationListener(new CustomAnimationListener() {
125 | @Override
126 | public void onAnimationEnd(Animation animation) {
127 | if (animCounter != animCounterCopy) return;
128 | stContainer.setVisibility(GONE);
129 | content.setVisibility(VISIBLE);
130 | content.startAnimation(inAnimation);
131 | }
132 | });
133 | stContainer.startAnimation(outAnimation);
134 | }
135 | } else {
136 | stContainer.setVisibility(GONE);
137 | content.setVisibility(VISIBLE);
138 | }
139 | }
140 |
141 | // loading //
142 |
143 | public void showLoading() {
144 | showLoading(R.string.stfLoadingMessage);
145 | }
146 |
147 | public void showLoading(@StringRes int resId) {
148 | showLoading(str(resId));
149 | }
150 |
151 | public void showLoading(String message) {
152 | showCustom(new CustomStateOptions()
153 | .message(message)
154 | .loading());
155 | }
156 |
157 | // empty //
158 |
159 | public void showEmpty() {
160 | showEmpty(R.string.stfEmptyMessage);
161 | }
162 |
163 | public void showEmpty(@StringRes int resId) {
164 | showEmpty(str(resId));
165 | }
166 |
167 | public void showEmpty(String message) {
168 | showCustom(new CustomStateOptions()
169 | .message(message)
170 | .image(R.drawable.stf_ic_empty));
171 | }
172 |
173 | // error //
174 |
175 | public void showError(OnClickListener clickListener) {
176 | showError(R.string.stfErrorMessage, clickListener);
177 | }
178 |
179 | public void showError(@StringRes int resId, OnClickListener clickListener) {
180 | showError(str(resId), clickListener);
181 | }
182 |
183 | public void showError(String message, OnClickListener clickListener) {
184 | showCustom(new CustomStateOptions()
185 | .message(message)
186 | .image(R.drawable.stf_ic_error)
187 | .buttonText(str(R.string.stfButtonText))
188 | .buttonClickListener(clickListener));
189 | }
190 |
191 | // offline
192 |
193 | public void showOffline(OnClickListener clickListener) {
194 | showOffline(R.string.stfOfflineMessage, clickListener);
195 | }
196 |
197 | public void showOffline(@StringRes int resId, OnClickListener clickListener) {
198 | showOffline(str(resId), clickListener);
199 | }
200 |
201 | public void showOffline(String message, OnClickListener clickListener) {
202 | showCustom(new CustomStateOptions()
203 | .message(message)
204 | .image(R.drawable.stf_ic_offline)
205 | .buttonText(str(R.string.stfButtonText))
206 | .buttonClickListener(clickListener));
207 | }
208 |
209 | // location off //
210 |
211 | public void showLocationOff(OnClickListener clickListener) {
212 | showLocationOff(R.string.stfLocationOffMessage, clickListener);
213 | }
214 |
215 | public void showLocationOff(@StringRes int resId, OnClickListener clickListener) {
216 | showLocationOff(str(resId), clickListener);
217 | }
218 |
219 | public void showLocationOff(String message, OnClickListener clickListener) {
220 | showCustom(new CustomStateOptions()
221 | .message(message)
222 | .image(R.drawable.stf_ic_location_off)
223 | .buttonText(str(R.string.stfButtonText))
224 | .buttonClickListener(clickListener));
225 | }
226 |
227 | // custom //
228 |
229 | /**
230 | * Shows custom state for given options. If you do not set buttonClickListener, the button will not be shown
231 | *
232 | * @param options customization options
233 | * @see com.gturedi.views.CustomStateOptions
234 | */
235 | public void showCustom(final CustomStateOptions options) {
236 | if (isAnimationEnabled()) {
237 | stContainer.clearAnimation();
238 | content.clearAnimation();
239 | final int animCounterCopy = ++animCounter;
240 | if (stContainer.getVisibility() == GONE) {
241 | outAnimation.setAnimationListener(new CustomAnimationListener() {
242 | @Override
243 | public void onAnimationEnd(Animation animation) {
244 | if (animCounterCopy != animCounter) return;
245 | content.setVisibility(GONE);
246 | stContainer.setVisibility(VISIBLE);
247 | stContainer.startAnimation(inAnimation);
248 | }
249 | });
250 | content.startAnimation(outAnimation);
251 | state(options);
252 | } else {
253 | outAnimation.setAnimationListener(new CustomAnimationListener() {
254 | @Override
255 | public void onAnimationEnd(Animation animation) {
256 | if (animCounterCopy != animCounter)
257 | return;
258 | state(options);
259 | stContainer.startAnimation(inAnimation);
260 | }
261 | });
262 | stContainer.startAnimation(outAnimation);
263 | }
264 | } else {
265 | content.setVisibility(GONE);
266 | stContainer.setVisibility(VISIBLE);
267 | state(options);
268 | }
269 | }
270 |
271 | // helper methods //
272 |
273 | private void state(CustomStateOptions options) {
274 | if (!TextUtils.isEmpty(options.getMessage())) {
275 | stMessage.setVisibility(VISIBLE);
276 | stMessage.setText(options.getMessage());
277 | } else {
278 | stMessage.setVisibility(GONE);
279 | }
280 |
281 | if (options.isLoading()) {
282 | stProgress.setVisibility(VISIBLE);
283 | stImage.setVisibility(GONE);
284 | stButton.setVisibility(GONE);
285 | } else {
286 | stProgress.setVisibility(GONE);
287 | if (options.getImageRes() != 0) {
288 | stImage.setVisibility(VISIBLE);
289 | stImage.setImageResource(options.getImageRes());
290 | } else {
291 | stImage.setVisibility(GONE);
292 | }
293 |
294 | if (options.getClickListener() != null) {
295 | stButton.setVisibility(VISIBLE);
296 | stButton.setOnClickListener(options.getClickListener());
297 | if (!TextUtils.isEmpty(options.getButtonText())) {
298 | stButton.setText(options.getButtonText());
299 | }
300 | } else {
301 | stButton.setVisibility(GONE);
302 | }
303 | }
304 | }
305 |
306 | private String str(@StringRes int resId) {
307 | return getContext().getString(resId);
308 | }
309 |
310 | private Animation anim(@AnimRes int resId) {
311 | return AnimationUtils.loadAnimation(getContext(), resId);
312 | }
313 |
314 | }
315 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/stf_ic_empty.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/stf_ic_error.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/stf_ic_location_off.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/library/src/main/res/drawable/stf_ic_offline.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/library/src/main/res/layout/stf_template.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
13 |
14 |
18 |
19 |
24 |
25 |
30 |
31 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/library/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/library/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 | #FF4081
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 60dp
3 | 80dp
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | An error occurred please try again later
3 | Please check your connection
4 | Please enable location services
5 | There are no items
6 | Loading..
7 | Retry
8 |
--------------------------------------------------------------------------------
/library/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
14 |
15 |
20 |
21 |
29 |
30 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/sample.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gturedi/StatefulLayout/e7ce7c41036a805419120647d40d4cdb7a8a8577/sample.gif
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | include ':library'
3 |
--------------------------------------------------------------------------------