├── .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 | 15 | 16 | 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 | 36 | 37 | 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 | 19 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 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 | Android States Page Cover 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/v/kobeumut/StateViews.svg)](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 | ![No Connection](/art/no_connection.jpg) 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 | ![No Data](/art/no_data.jpg) 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 |