├── .gitignore
├── .idea
├── codeStyles
│ └── Project.xml
├── gradle.xml
├── markdown-navigator.xml
├── markdown-navigator
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
├── runConfigurations.xml
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── umutbey
│ │ └── stateviews
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── umutbey
│ │ │ └── stateviews
│ │ │ └── Samples
│ │ │ ├── App.java
│ │ │ └── MainActivity.java
│ └── res
│ │ ├── drawable-hdpi
│ │ └── caution.png
│ │ ├── drawable-mdpi
│ │ └── caution.png
│ │ ├── drawable-xhdpi
│ │ └── caution.png
│ │ ├── drawable-xxhdpi
│ │ └── caution.png
│ │ ├── drawable-xxxhdpi
│ │ └── caution.png
│ │ ├── drawable
│ │ ├── fingerprint.xml
│ │ ├── magnify.xml
│ │ ├── photos_archive.xml
│ │ └── search.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── umutbey
│ └── stateviews
│ └── ExampleUnitTest.java
├── art
├── StatusPage.jpg
├── no_connection.jpg
└── no_data.jpg
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── project.properties
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── umutbey
│ │ └── stateviews
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── umutbey
│ │ │ └── stateviews
│ │ │ ├── StateModel.kt
│ │ │ ├── StateView.kt
│ │ │ └── StateViewsBuilder.kt
│ └── res
│ │ ├── drawable
│ │ └── ic_server_error.xml
│ │ ├── layout
│ │ ├── state_custom.xml
│ │ └── state_loading.xml
│ │ └── values
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── themes.xml
│ └── test
│ └── java
│ └── com
│ └── umutbey
│ └── stateviews
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | local.properties
10 | .externalNativeBuild
11 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.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 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator.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 |
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 |
--------------------------------------------------------------------------------
/.idea/markdown-navigator/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/misc.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 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2018 Mehdi Sakout
2 | Copyright (c) 2018 Mustafa Umut ADALI.
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.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # State Views for Android (BETA version)
2 | Create & Show progress, data or error views, the easy way!
3 |
4 |
5 |
6 |
7 | StateViews is based on ViewSwitcher mechanism and allows to handle the different app states, from loading... to displaying
8 | data and error views, the library is tiny and fully customizable.
9 |
10 | This repo has been developed from https://github.com/medyo/StateViews.
11 |
12 | Different features of original repo:
13 | - Codes converted to Kotlin
14 | - Fixed some memory leaks
15 | - Icons colors can be customized separately
16 | - Added showing state status
17 |
18 | ```xml
19 |
23 |
24 |
29 |
30 |
31 | ```
32 | Then Call the appropriate state:
33 |
34 | ```java
35 | mStatusPage.displayLoadingState();
36 | ```
37 |
38 | ```java
39 | mStatusPage.displayState("TAG_NAME");
40 | ```
41 |
42 | ```java
43 | mStatusPage.hideStates();
44 | ```
45 |
46 |
47 |
48 | ## Setup
49 | [](https://jitpack.io/#kobeumut/StateViews)
50 |
51 | ```
52 | allprojects {
53 | repositories {
54 | ...
55 | maven { url 'https://jitpack.io' }
56 | }
57 | }
58 | ```
59 |
60 | ```
61 | implementation 'com.github.kobeumut:StateViews:0.5'
62 | ```
63 |
64 | ## Usage
65 |
66 | ### 1. Available attributes for PageStatus Builder
67 |
68 | | Function | Description |
69 | | ------------- |:-------------:|
70 | | setState(params) | Create a new state. Params are tag, title, description, icon, spesific icon color, button text, clicklistener|
71 | | setIconColor(Int) | Set Icon color for all icons(Same color) |
72 | | setIconSize(Int) | Set Icon Size |
73 | | setTextColor(Int) | set Title and description colors|
74 | | setFontFace(String) | Set Custom font |
75 | | setButtonBackgroundColor(Int) | Set Button Background color|
76 | | setButtonTextColor(String) | Set Button Text color|
77 |
78 | ### 2. Available attributes for PageStatesView
79 |
80 |
81 | | Function | Description |
82 | | ------------- |:-------------:|
83 | | displayState(String) | Display a state by his tag name. If you want to send displayState("hide") parameter, state will hide |
84 | | hideStates() | Hide all states and display data|
85 | | displayLoadingState() | Display the loading state|
86 | | addCustomState(Intent) | Create a new state only available for the current activity, fragment...|
87 | | setOnStateButtonClicked(View.OnClickListener) | Click listener for the state button|
88 | | applyGravity(Int) | Set View Gravity |
89 |
90 | ### 3. Samples
91 | #### Display an Error View
92 |
93 | 
94 |
95 | ```java
96 | setState(
97 | "TAG_ERROR",
98 | "No Connection",
99 | "Error retrieving information from server.",
100 | AppCompatResources.getDrawable(this, R.drawable.ic_server_error),
101 | Color.Black,
102 | "Retry"
103 | );
104 |
105 | mStatusPage.displayState("TAG_ERROR");
106 | ```
107 |
108 | #### Display a "no Data" View
109 |
110 | 
111 |
112 | ```java
113 | setState(
114 | "TAG_NO_RESULTS",
115 | "No Results Found",
116 | "Unfortunately I could not find any results matching your search",
117 | AppCompatResources.getDrawable(this, R.drawable.search), ,null, null
118 | )
119 |
120 | mStatusPage.displayState("TAG_NO_RESULTS");
121 | ```
122 |
123 | ## Contribute
124 | Contributions are welcome!
125 |
126 | ## ProGuard
127 | Nothing to include
128 |
129 | ## License
130 |
131 | ~~~
132 | Copyright (c) 2018 Mehdi Sakout
133 | Copyright (c) 2018 Mustafa Umut ADALI.
134 |
135 | Licensed under the Apache License, Version 2.0 (the "License");
136 | you may not use this file except in compliance with the License.
137 | You may obtain a copy of the License at
138 |
139 | http://www.apache.org/licenses/LICENSE-2.0
140 |
141 | Unless required by applicable law or agreed to in writing, software
142 | distributed under the License is distributed on an "AS IS" BASIS,
143 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
144 | See the License for the specific language governing permissions and
145 | limitations under the License.
146 | ~~~
147 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 |
5 | compileSdkVersion 28
6 | buildToolsVersion '28.0.3'
7 |
8 | defaultConfig {
9 | applicationId "com.umutbey.stateviews.Samples"
10 | minSdkVersion 15
11 | targetSdkVersion 28
12 | versionCode 2
13 | versionName "0.3"
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | vectorDrawables.useSupportLibrary = true
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | implementation fileTree(dir: 'libs', include: ['*.jar'])
27 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.1-alpha01', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | implementation 'androidx.appcompat:appcompat:1.0.2'
31 | testImplementation 'junit:junit:4.12'
32 | implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
33 | implementation 'com.google.android.material:material:1.1.0-alpha01'
34 | implementation project(path: ':library')
35 | }
36 | repositories {
37 | mavenCentral()
38 | }
39 |
--------------------------------------------------------------------------------
/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 /Users/medyo/Library/Android/sdk/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 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/umutbey/stateviews/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.umutbey.stateviews;
2 |
3 | import android.content.Context;
4 | import androidx.test.InstrumentationRegistry;
5 | import androidx.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.umutbey.stateviews", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/umutbey/stateviews/Samples/App.java:
--------------------------------------------------------------------------------
1 | package com.umutbey.stateviews.Samples;
2 |
3 | import android.app.Application;
4 | import android.graphics.Color;
5 |
6 | import com.umutbey.stateviews.StateViewsBuilder;
7 |
8 | import androidx.appcompat.content.res.AppCompatResources;
9 |
10 | /**
11 | * Created by medyo on 11/20/17.
12 | * Developed by kobeumut on 11/04/18
13 | */
14 |
15 | public class App extends Application {
16 |
17 | @Override
18 | public void onCreate() {
19 | super.onCreate();
20 |
21 | StateViewsBuilder.Companion
22 | .init()
23 | .setState("error",
24 | "No Connection",
25 | "Error retrieving information from server.",
26 | AppCompatResources.getDrawable(this, R.drawable.ic_server_error),
27 | Color.RED,
28 | "Retry", null
29 | )
30 |
31 | .setState(
32 | "archive",
33 | "Clear the clutter",
34 | "Archived items will be kept here. They'll still show in albums " +
35 | "& search results.",
36 | AppCompatResources.getDrawable(this, R.drawable.photos_archive),
37 | Color.BLUE,
38 | "LEARN MORE", null
39 | )
40 |
41 | .setState("search",
42 | "No Results Found",
43 | "Unfortunately I could not find any results matching your search",
44 | AppCompatResources.getDrawable(this, R.drawable.search), null, null, null)
45 | .setState("custom",
46 | "Custom State",
47 | "This is a custom state, made in 5 seconds \nClick to hide status ",
48 | AppCompatResources.getDrawable(this, R.drawable.caution),
49 | null,
50 | "HIDE STATE", null)
51 | .setButtonBackgroundColor(Color.parseColor("#317DED"))
52 | .setButtonTextColor(Color.parseColor("#FFFFFF"))
53 | .setIconSize(getResources().getDimensionPixelSize(R.dimen.state_views_icon_size));
54 |
55 | StateViewsBuilder.Companion
56 | .init()
57 | .setState("custom",
58 | "Custom 1 State",
59 | "This is a 1 custom state, made in 5 seconds \nClick to hide status ",
60 | AppCompatResources.getDrawable(this, R.drawable.caution),
61 | null,
62 | "HIDE STATE", null)
63 | .setButtonBackgroundColor(Color.parseColor("#317DED"))
64 | .setButtonTextColor(Color.parseColor("#FFFFFF"))
65 | .setIconSize(getResources().getDimensionPixelSize(R.dimen.state_views_icon_size));
66 | }
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/umutbey/stateviews/Samples/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.umutbey.stateviews.Samples;
2 |
3 | import android.os.Bundle;
4 | import android.view.View;
5 | import android.widget.Button;
6 | import android.widget.Toast;
7 |
8 | import com.umutbey.stateviews.StateView;
9 |
10 | import androidx.appcompat.app.AppCompatActivity;
11 |
12 | public class MainActivity extends AppCompatActivity implements View.OnClickListener {
13 |
14 | StateView mStatusPage;
15 | Button mLoading, mError, mCustom, mSearch, mHide;
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | setContentView(R.layout.activity_main);
21 |
22 | mLoading = findViewById(R.id.button_loading);
23 | mError = findViewById(R.id.button_error);
24 | mCustom = findViewById(R.id.button_custom);
25 | mSearch = findViewById(R.id.button_search);
26 | mHide = findViewById(R.id.button_hide);
27 |
28 | mLoading.setOnClickListener(this);
29 | mError.setOnClickListener(this);
30 | mCustom.setOnClickListener(this);
31 | mSearch.setOnClickListener(this);
32 | mHide.setOnClickListener(this);
33 |
34 | mStatusPage = findViewById(R.id.status_page);
35 | mStatusPage.setOnStateButtonClicked(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View view) {
38 | switch (view.getTag().toString()){
39 | case "custom":
40 | mStatusPage.hideStates();
41 | Toast.makeText(MainActivity.this, "Is State Showing: "+mStatusPage.isStateShowing(), Toast.LENGTH_SHORT).show();
42 | break;
43 | default: Toast.makeText(MainActivity.this, "Button Clicked " + mStatusPage.getShowingState(), Toast.LENGTH_SHORT).show();
44 | }
45 | }
46 | });
47 |
48 | }
49 |
50 | @Override
51 | public void onClick(View view) {
52 | switch (view.getId()) {
53 | case R.id.button_loading:
54 | mStatusPage.displayLoadingState();
55 | break;
56 | case R.id.button_error:
57 | mStatusPage.displayState("error");
58 | break;
59 | case R.id.button_custom:
60 | mStatusPage.displayState("custom");
61 | break;
62 | case R.id.button_search: {
63 | mStatusPage.displayState("search");
64 | break;
65 | }
66 | case R.id.button_hide: {
67 | mStatusPage.displayState("hide");
68 | break;
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/caution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/drawable-hdpi/caution.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/caution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/drawable-mdpi/caution.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/caution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/drawable-xhdpi/caution.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/caution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/drawable-xxhdpi/caution.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxxhdpi/caution.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/drawable-xxxhdpi/caution.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/fingerprint.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/magnify.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/photos_archive.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
14 |
15 |
16 |
19 |
20 |
21 |
24 |
25 |
26 |
27 |
28 |
31 |
32 |
33 |
36 |
37 |
38 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/search.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
12 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
13 |
14 |
19 |
20 |
25 |
30 |
31 |
36 |
37 |
42 |
43 |
44 |
48 |
49 |
54 |
55 |
56 |
57 |
58 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/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/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 | 150dp
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PageStatus
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/com/umutbey/stateviews/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.umutbey.stateviews;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/art/StatusPage.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/art/StatusPage.jpg
--------------------------------------------------------------------------------
/art/no_connection.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/art/no_connection.jpg
--------------------------------------------------------------------------------
/art/no_data.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/art/no_data.jpg
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.10'
5 |
6 | repositories {
7 | google()
8 | jcenter()
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.2.1'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 |
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | google()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | android.enableJetifier=true
10 | android.useAndroidX=true
11 | org.gradle.jvmargs=-Xmx1536m
12 | # When configured, Gradle will run in incubating parallel mode.
13 | # This option should only be used with decoupled projects. More details, visit
14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
15 | # org.gradle.parallel=true
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kobeumut/StateViews/838736a6d0e0f8e1981f00978ccd3c28bcd68872/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Nov 14 18:03:31 WET 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.10-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/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 |
6 | compileSdkVersion 28
7 |
8 | defaultConfig {
9 | minSdkVersion 15
10 | targetSdkVersion 28
11 | versionCode 13
12 | versionName "0.3"
13 |
14 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15 | vectorDrawables.useSupportLibrary = true
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | }
26 |
27 | dependencies {
28 | implementation fileTree(dir: 'libs', include: ['*.jar'])
29 |
30 | implementation 'androidx.appcompat:appcompat:1.0.2'
31 | testImplementation 'junit:junit:4.12'
32 | androidTestImplementation 'androidx.test:runner:1.1.1-alpha01'
33 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1-alpha01'
34 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
35 | }
36 | repositories {
37 | mavenCentral()
38 | }
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/library/project.properties:
--------------------------------------------------------------------------------
1 | #project
2 | project.name=state-views
3 | project.description=Create and Show progress, data or error views, the easy way!
4 | project.groupId=com.github.medyo
5 | project.artifactId=state-views
6 | project.packaging=aar
7 | project.siteUrl=https://github.com/medyo/StateViews
8 | project.gitUrl=https://github.com/medyo/StateViews.git
9 | project.licenceName=MIT
10 | project.licenceUrl=http://opensource.org/licenses/MIT
11 | #javadoc
12 | javadoc.name=state-views
13 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/umutbey/stateviews/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.umutbey.stateviews;
2 |
3 | import android.content.Context;
4 | import androidx.test.InstrumentationRegistry;
5 | import androidx.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.assertEquals;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("sakout.mehdi.pagestatus.library.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/library/src/main/java/com/umutbey/stateviews/StateModel.kt:
--------------------------------------------------------------------------------
1 | package com.umutbey.stateviews
2 |
3 | import android.graphics.drawable.Drawable
4 | import android.view.View
5 |
6 | /*
7 | * Created by medyo on 11/15/17.
8 | * Developed by kobeumut on 11/04/18
9 | */
10 |
11 | class StateModel {
12 |
13 | var tag: String? = null
14 | var title: String? = null
15 | var description: String? = null
16 | var icon: Drawable? = null
17 | var iconColor: Int? = null
18 | var buttonTitle: String? = null
19 | var layoutId: Int? = null
20 | var view: View? = null
21 | var custom: Boolean? = false
22 | var clickListener: View.OnClickListener? = null
23 | }
24 |
--------------------------------------------------------------------------------
/library/src/main/java/com/umutbey/stateviews/StateView.kt:
--------------------------------------------------------------------------------
1 | package com.umutbey.stateviews
2 |
3 | import android.content.Context
4 | import android.graphics.PorterDuff
5 | import android.graphics.Typeface
6 | import android.graphics.drawable.Drawable
7 | import android.text.TextUtils
8 | import android.util.AttributeSet
9 | import android.util.Log
10 | import android.util.TypedValue
11 | import android.view.Gravity
12 | import android.view.LayoutInflater
13 | import android.view.View
14 | import android.widget.*
15 | import java.util.*
16 |
17 | /*
18 | * Created by medyo on 11/15/17.
19 | * Developed by kobeumut on 11/04/18
20 | */
21 | class StateView : ViewFlipper {
22 |
23 | private val TAG = "PageStatusView"
24 | /**
25 | * Data States
26 | */
27 |
28 | private var mBuilder: StateViewsBuilder? = null
29 | private lateinit var mInflater: LayoutInflater
30 | private var mOnClickListener: View.OnClickListener? = null
31 | private var showingState: String? = ""
32 |
33 | constructor(context: Context) : super(context) {
34 | setupView(null)
35 | }
36 |
37 | constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
38 | setupView(attrs)
39 | }
40 |
41 | private fun setupView(attrs: AttributeSet?) {
42 |
43 | // TODO: Add support of dynamic styles
44 |
45 | if (isInEditMode) {
46 | return
47 | }
48 |
49 | handleStates()
50 | }
51 |
52 | private fun handleStates() {
53 |
54 | mInflater = LayoutInflater.from(context)
55 |
56 | /**
57 | * Append new state values
58 | */
59 |
60 | addView(getViewByLayoutId(R.layout.state_loading, STATES.LOADING.name), 0)
61 |
62 | if (hasPrivateConfiguration()) {
63 | applyCustomStyle(mBuilder, mBuilder!!.states)
64 | } else if (StateViewsBuilder.instance != null) {
65 | applyCustomStyle(StateViewsBuilder.instance, StateViewsBuilder.instance!!.states)
66 | }
67 |
68 | hideStates()
69 |
70 | }
71 |
72 | fun addCustomState(tag: String, title: String, description: String, icon: Drawable, buttonTitle: String) {
73 |
74 | var builder = mBuilder
75 | if (builder == null) {
76 | builder = StateViewsBuilder.instance
77 | }
78 |
79 | val view = mInflater.inflate(R.layout.state_custom, null, false) as LinearLayout
80 |
81 | setTitleValue(view, title, builder!!.textColor, builder.font)
82 | setDescriptionValue(view, description, builder.textColor, builder.font)
83 | setIcon(view, icon, builder.iconColor, builder.iconSize!!)
84 | setButtonStyle(view, buttonTitle, builder.font, builder.buttonBackgroundColor, builder.buttonTextColor)
85 |
86 | view.tag = tag
87 | addView(view, childCount)
88 | }
89 |
90 | private fun applyCustomStyle(builder: StateViewsBuilder?, states: List) {
91 |
92 | /*
93 | * Load Views
94 | */
95 |
96 | for (i in states.indices) {
97 | val state = states[i]
98 | val position = i + 1
99 | if (state.custom!!) {
100 |
101 | if (state.view != null) {
102 | val view = state.view
103 | view!!.tag = state.tag
104 | addView(view, position)
105 |
106 | } else if (state.layoutId != null) {
107 | val view = mInflater.inflate(state.layoutId!!, null, false)
108 | view.tag = state.tag
109 | addView(view, position)
110 | }
111 | } else {
112 | val view = mInflater.inflate(R.layout.state_custom, null, false) as LinearLayout
113 |
114 | setTitleValue(view, state.title, builder!!.textColor, builder.font)
115 | setDescriptionValue(view, state.description, builder.textColor, builder.font)
116 | setIcon(view, state.icon, state.iconColor?:builder.iconColor, builder.iconSize!!)
117 | setButtonStyle(view, state.buttonTitle, builder.font, builder.buttonBackgroundColor, builder.buttonTextColor)
118 |
119 | view.tag = state.tag
120 | addView(view, position)
121 | }
122 | }
123 |
124 | }
125 |
126 | fun applyGravity(gravity: Int?) {
127 |
128 | var builder = mBuilder
129 | StateViewsBuilder.instance?.let {
130 | builder = it
131 | }
132 |
133 | if (builder == null) {
134 | return
135 | }
136 |
137 | val states = builder!!.states
138 | val inlineStates = arrayOfNulls(states.size)
139 |
140 | for (i in states.indices) {
141 | inlineStates[i] = states[i].tag
142 | }
143 |
144 | for (i in 0 until childCount) {
145 | val view = getChildAt(i)
146 |
147 | if (view.tag != null && Arrays.asList(*inlineStates).contains(view.tag.toString())) {
148 |
149 | if (view is LinearLayout) {
150 | view.gravity = gravity!!
151 | }
152 |
153 | }
154 | }
155 |
156 |
157 | }
158 |
159 | private fun hasPrivateConfiguration(): Boolean {
160 | return mBuilder != null
161 | }
162 |
163 | fun setPrivateConfiguration(builder: StateViewsBuilder) {
164 | this.mBuilder = builder
165 | }
166 |
167 | /**
168 | * Display the show progress View
169 | */
170 | fun displayLoadingState() {
171 | displayedChild = 0
172 | }
173 | fun isStateShowing():Boolean{
174 | return !showingState.isNullOrEmpty()
175 | }
176 | fun getShowingState():String?{
177 | return showingState?:"none"
178 | }
179 | fun displayState(tagName: String) {
180 | if(tagName == "hide"){
181 | hideStates()
182 | return
183 | }
184 |
185 | var found: Boolean? = false
186 | for (i in 0 until childCount) {
187 | val view = getChildAt(i)
188 |
189 | if (view.tag != null && view.tag.toString().equals(tagName, ignoreCase = true)) {
190 | displayedChild = i
191 | showingState = tagName
192 | found = true
193 | }
194 | }
195 |
196 | if (!(found)!!) {
197 | Log.e(TAG, "Tag name Incorrect or not found")
198 | }
199 | }
200 |
201 | fun hideStates() {
202 |
203 | for (i in 0 until childCount) {
204 | if (getChildAt(i).tag == null) {
205 | displayedChild = i
206 | showingState = null
207 | }
208 |
209 | }
210 | }
211 |
212 | /**
213 | * Return a view based on layout id
214 | *
215 | * @param layout Layout Id
216 | * @param tag Layout Tag
217 | * @return View
218 | */
219 | private fun getViewByLayoutId(layout: Int, tag: String): View {
220 |
221 | val view = mInflater.inflate(layout, null, false)
222 | view.tag = tag
223 | view.visibility = View.GONE
224 |
225 | return view!!
226 | }
227 |
228 | private fun setTitleValue(view: View, value: String?, color: Int?, typeface: Typeface?) {
229 | val mTextView = view.findViewById(R.id.state_title)
230 | mTextView.gravity = Gravity.CENTER_HORIZONTAL
231 | setTextColor(mTextView, color)
232 | setTextFont(mTextView, typeface)
233 | if (!TextUtils.isEmpty(value)) {
234 | mTextView.text = value
235 | mTextView.visibility = View.VISIBLE
236 | } else {
237 | mTextView.visibility = View.GONE
238 | }
239 | }
240 |
241 | private fun setTextFont(mTextView: TextView, typeface: Typeface?) {
242 | if (typeface != null) {
243 | mTextView.typeface = typeface
244 | }
245 | }
246 |
247 | private fun setTextColor(textView: TextView, color: Int?) {
248 |
249 | if (color != null) {
250 | textView.setTextColor(color)
251 | }
252 | }
253 |
254 | private fun setDescriptionValue(view: View, value: String?, color: Int?, typeface: Typeface?) {
255 | val mTextView = view.findViewById(R.id.state_description)
256 | mTextView.gravity = Gravity.CENTER_HORIZONTAL
257 | setTextColor(mTextView, color)
258 | setTextFont(mTextView, typeface)
259 | if (!TextUtils.isEmpty(value)) {
260 | mTextView.text = value
261 | mTextView.visibility = View.VISIBLE
262 | } else {
263 | mTextView.visibility = View.GONE
264 | }
265 | }
266 |
267 | fun setOnStateButtonClicked(clickListener: View.OnClickListener) {
268 | mOnClickListener = clickListener
269 |
270 | for (i in 0 until childCount) {
271 | if (getChildAt(i).tag != null) {
272 |
273 | val view = getChildAt(i)
274 |
275 | if (view.findViewById(R.id.state_button) != null) {
276 | val button = view.findViewById