├── demo ├── .gitignore ├── src │ └── main │ │ ├── res │ │ ├── drawable │ │ │ ├── ic_info.png │ │ │ ├── ic_sad.xml │ │ │ └── ic_launcher_background.xml │ │ ├── font │ │ │ ├── montserrat_bold.ttf │ │ │ ├── montserrat_regular.ttf │ │ │ └── app_font.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 │ │ │ ├── strings.xml │ │ │ ├── dimen.xml │ │ │ ├── colors.xml │ │ │ └── styles.xml │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ ├── layout │ │ │ └── activity_main.xml │ │ └── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ └── com │ │ └── github │ │ └── farzadfarazmand │ │ └── emptystatelibrary │ │ └── MainActivity.kt ├── proguard-rules.pro └── build.gradle ├── emptystate ├── .gitignore ├── src │ └── main │ │ ├── AndroidManifest.xml │ │ ├── res │ │ ├── values │ │ │ ├── strings.xml │ │ │ ├── color.xml │ │ │ ├── dimens.xml │ │ │ └── attrs.xml │ │ └── layout │ │ │ └── empty_state.xml │ │ └── java │ │ └── com │ │ └── github │ │ └── farzadfarazmand │ │ └── emptystate │ │ ├── IconSize.kt │ │ └── EmptyState.kt ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── preview.png ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE.md /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /emptystate/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':demo', ':emptystate' 2 | -------------------------------------------------------------------------------- /emptystate/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/preview.png -------------------------------------------------------------------------------- /emptystate/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | EmptyState 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ic_info.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/drawable/ic_info.png -------------------------------------------------------------------------------- /demo/src/main/res/font/montserrat_bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/font/montserrat_bold.ttf -------------------------------------------------------------------------------- /demo/src/main/res/font/montserrat_regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/font/montserrat_regular.ttf -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/feriousa/EmptyStateLibrary/HEAD/demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /demo/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | EmptyStateLibrary 3 | No Internet Connection 4 | 5 | -------------------------------------------------------------------------------- /emptystate/src/main/java/com/github/farzadfarazmand/emptystate/IconSize.kt: -------------------------------------------------------------------------------- 1 | package com.github.farzadfarazmand.emptystate 2 | 3 | enum class IconSize { 4 | SMALL, 5 | NORMAL, 6 | BIG 7 | } -------------------------------------------------------------------------------- /demo/src/main/res/values/dimen.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 14dp 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | .idea 4 | /local.properties 5 | /.idea/caches 6 | /.idea/libraries 7 | /.idea/modules.xml 8 | /.idea/workspace.xml 9 | /.idea/navEditor.xml 10 | /.idea/assetWizardSettings.xml 11 | .DS_Store 12 | /build 13 | /captures 14 | .externalNativeBuild 15 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Jun 21 10:41:37 IRDT 2019 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-7.3.3-all.zip 7 | -------------------------------------------------------------------------------- /emptystate/src/main/res/values/color.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #333333 5 | #777777 6 | #2196F3 7 | 8 | -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /demo/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FF9800 4 | #F57C00 5 | #CDDC39 6 | 7 | #212121 8 | #009688 9 | 10 | -------------------------------------------------------------------------------- /demo/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /emptystate/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 120dp 5 | 180dp 6 | 250dp 7 | 8 | 16sp 9 | 14sp 10 | 16sp 11 | 12 | 25dp 13 | 14 | -------------------------------------------------------------------------------- /demo/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /demo/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 | -------------------------------------------------------------------------------- /emptystate/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 | -------------------------------------------------------------------------------- /demo/src/main/res/font/app_font.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 15 | 16 | 17 | 25 | 26 | -------------------------------------------------------------------------------- /emptystate/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'kotlin-android' 4 | } 5 | 6 | 7 | android { 8 | compileSdkVersion 31 9 | defaultConfig { 10 | minSdkVersion 14 11 | targetSdkVersion 31 12 | vectorDrawables.useSupportLibrary = true 13 | } 14 | 15 | buildFeatures { 16 | viewBinding = true 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | namespace 'com.github.farzadfarazmand.emptystate' 26 | 27 | } 28 | 29 | dependencies { 30 | implementation fileTree(dir: 'libs', include: ['*.jar']) 31 | //ui 32 | implementation 'androidx.appcompat:appcompat:1.4.1' 33 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3' 34 | implementation 'com.google.android.material:material:1.6.0' 35 | //kotlin 36 | implementation "androidx.core:core-ktx:1.7.0" 37 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10" 38 | } 39 | 40 | repositories { 41 | mavenCentral() 42 | } 43 | -------------------------------------------------------------------------------- /demo/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | } 5 | 6 | android { 7 | compileSdkVersion 31 8 | defaultConfig { 9 | applicationId "com.github.farzadfarazmand.emptystatelibrary" 10 | minSdkVersion 14 11 | targetSdkVersion 31 12 | versionCode 1 13 | versionName "1.0" 14 | vectorDrawables.useSupportLibrary = true 15 | } 16 | 17 | buildFeatures { 18 | viewBinding = true 19 | } 20 | 21 | buildTypes { 22 | release { 23 | minifyEnabled true 24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 25 | } 26 | } 27 | namespace 'com.github.farzadfarazmand.emptystatelibrary' 28 | } 29 | 30 | dependencies { 31 | implementation fileTree(dir: 'libs', include: ['*.jar']) 32 | //kotlin 33 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.10" 34 | implementation 'androidx.core:core-ktx:1.7.0' 35 | //ui 36 | implementation 'androidx.appcompat:appcompat:1.4.1' 37 | implementation 'androidx.constraintlayout:constraintlayout:2.1.3' 38 | implementation project(path: ':emptystate') 39 | } 40 | -------------------------------------------------------------------------------- /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 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /demo/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 25 | 26 | -------------------------------------------------------------------------------- /emptystate/src/main/res/values/attrs.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 | -------------------------------------------------------------------------------- /demo/src/main/java/com/github/farzadfarazmand/emptystatelibrary/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.github.farzadfarazmand.emptystatelibrary 2 | 3 | import android.os.Bundle 4 | import android.os.Handler 5 | import android.view.View 6 | import android.view.animation.OvershootInterpolator 7 | import android.widget.Toast 8 | import androidx.appcompat.app.AppCompatActivity 9 | import androidx.appcompat.app.AppCompatDelegate 10 | import com.github.farzadfarazmand.emptystatelibrary.databinding.ActivityMainBinding 11 | 12 | class MainActivity : AppCompatActivity() { 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | // if want to use svg drawable as empty state icon, add below line and set vectorDrawables.useSupportLibrary to true in defaultConfig 17 | AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) 18 | 19 | val binding = ActivityMainBinding.inflate(layoutInflater) 20 | setContentView(binding.root) 21 | 22 | binding.emptyStateSample.setButtonClickListener(View.OnClickListener { 23 | Toast.makeText( 24 | this@MainActivity, 25 | "button clicked!", 26 | Toast.LENGTH_SHORT 27 | ).show() 28 | }) 29 | // show emptyState with animation 30 | Handler().postDelayed({ binding.emptyStateSample.show(android.R.anim.slide_in_left, OvershootInterpolator()) }, 3000) 31 | // Handler().postDelayed({ emptyStateSample.hide(android.R.anim.slide_out_right, OvershootInterpolator()) }, 6000) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /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 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 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 Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ic_sad.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EmptyStateLibrary 2 | An Android Library for showing different states of a view 3 | 4 | ![Images](https://github.com/farzadfarazmand/EmptyStateLibrary/blob/master/preview.png) 5 | 6 | ## Features 7 | - [x] MinSdk 14 8 | - [x] Support both PNG and SVG as icon 9 | - [x] Could use different custom fonts for title, description and button 10 | - [x] Fullscreen mode 11 | - [x] Easy to use 12 | 13 | ### Add Library 14 | 15 | 1. Add the JitPack repository to your build file 16 | ```groovy 17 | allprojects { 18 | repositories { 19 | maven { url 'https://jitpack.io' } 20 | } 21 | } 22 | ``` 23 | 24 | 2. Add the dependency 25 | ```groovy 26 | dependencies { 27 | . 28 | . 29 | . 30 | implementation 'com.github.farzadfarazmand:EmptyStateLibrary:v1.1.0' 31 | } 32 | ``` 33 | 34 | ### Add EmptyState view 35 | 36 | ```xml 37 | 51 | ``` 52 | ### All xml attributes 53 | Key | Value | Description 54 | --- | ----- | --- 55 | emps_iconSize | SMALL, NORMALL, BIG | size of icon 56 | emps_icon | icon resource id | could be png or vector drawable 57 | emps_fullscreen | Boolean | Show icon in fullscreen mode, icon size is useless in fullscreen 58 | emps_font | Font | custom font resource 59 | emps_title | String | emptyState title, will be gone if not set 60 | emps_titleSize | Dimension | title text size, dp or sp 61 | emps_titleColor | Color | title text color, Hex ot color reference 62 | emps_description | String | emptyState description, will be gone if not set 63 | emps_descriptionSize | Dimension | title text size, dp or sp 64 | emps_descriptionColor | Color | title text color, Hex or color reference 65 | emps_showButton | Boolean | show / hide button 66 | emps_buttonText | String | button's text 67 | emps_buttonTextSize | Dimension | button text size, dp or sp 68 | emps_buttonTextColor | Color | button text color, Hex ot color reference 69 | emps_buttonBackgroundColor | Color | button background color, Hex ot color reference 70 | emps_buttonCorner | Dimension | button corner size in dp 71 | 72 | _**All of these attributes have setters and could be set from code**_ 73 | 74 | ### Show / Hide with animation 75 | You could show or hide emptyState view with animation: 76 | ```kotlin 77 | val emptyStateSample = findViewById(R.id.emptyStateSample) 78 | 79 | //show, default animation is fade in 80 | emptyStateSample.show(android.R.anim.slide_in_left, OvershootInterpolator()) 81 | 82 | 83 | //hide, default animation is fade out 84 | emptyStateSample.hide(android.R.anim.slide_out_right, OvershootInterpolator()) 85 | ``` 86 | 87 | ## Licenses 88 | ``` 89 | Copyright 2019 Farzad Farazmand. 90 | 91 | Licensed to the Apache Software Foundation (ASF) under one or more contributor 92 | license agreements. See the NOTICE file distributed with this work for 93 | additional information regarding copyright ownership. The ASF licenses this 94 | file to you under the Apache License, Version 2.0 (the "License"); you may not 95 | use this file except in compliance with the License. You may obtain a copy of 96 | the License at 97 | 98 | http://www.apache.org/licenses/LICENSE-2.0 99 | 100 | Unless required by applicable law or agreed to in writing, software 101 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 102 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 103 | License for the specific language governing permissions and limitations under 104 | the License. 105 | ``` -------------------------------------------------------------------------------- /emptystate/src/main/res/layout/empty_state.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 19 | 20 | 21 | 25 | 26 | 27 | 40 | 41 | 42 | 54 | 55 | 75 | 76 | 82 | 83 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /demo/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 10 | 12 | 14 | 16 | 18 | 20 | 22 | 24 | 26 | 28 | 30 | 32 | 34 | 36 | 38 | 40 | 42 | 44 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 68 | 70 | 72 | 74 | 75 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ###### Apache License, Version 2.0 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ 2 | 3 | ### TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 4 | 5 | ###### 1. Definitions. 6 | 7 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 8 | 9 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 10 | 11 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 12 | 13 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 14 | 15 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 16 | 17 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 18 | 19 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 20 | 21 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 22 | 23 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 24 | 25 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 26 | 27 | ###### 2. Grant of Copyright License. 28 | 29 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 30 | 31 | ###### 3. Grant of Patent License. 32 | 33 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 34 | 35 | ###### 4. Redistribution. 36 | 37 | You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 38 | 39 | You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 40 | 41 | ###### 5. Submission of Contributions. 42 | 43 | Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 44 | 45 | 6. Trademarks. 46 | 47 | This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 48 | 49 | ###### 7. Disclaimer of Warranty. 50 | 51 | Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 52 | 53 | ###### 8. Limitation of Liability. 54 | 55 | In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 56 | 57 | ###### 9. Accepting Warranty or Additional Liability. 58 | 59 | While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 60 | 61 | ### END OF TERMS AND CONDITIONS 62 | 63 | ### APPENDIX: How to apply the Apache License to your work 64 | 65 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. 66 | 67 | ### Copyright 2018 Aidan Follestad 68 | 69 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 70 | 71 | http://www.apache.org/licenses/LICENSE-2.0 72 | 73 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 74 | -------------------------------------------------------------------------------- /emptystate/src/main/java/com/github/farzadfarazmand/emptystate/EmptyState.kt: -------------------------------------------------------------------------------- 1 | package com.github.farzadfarazmand.emptystate 2 | 3 | import android.content.Context 4 | import android.graphics.Color 5 | import android.graphics.Typeface 6 | import android.text.TextUtils 7 | import android.util.AttributeSet 8 | import android.util.TypedValue 9 | import android.view.LayoutInflater 10 | import android.view.View 11 | import android.view.animation.AccelerateDecelerateInterpolator 12 | import android.view.animation.Animation 13 | import android.view.animation.AnimationUtils 14 | import android.view.animation.Interpolator 15 | import androidx.annotation.* 16 | import androidx.appcompat.app.AppCompatDelegate 17 | import androidx.constraintlayout.widget.ConstraintLayout 18 | import androidx.core.content.ContextCompat 19 | import androidx.core.content.res.ResourcesCompat 20 | import androidx.core.graphics.drawable.DrawableCompat 21 | import com.github.farzadfarazmand.emptystate.databinding.EmptyStateBinding 22 | 23 | /** 24 | * Show different state of views, like noInternetConnection, noListData, notLogin, permissionNotGranted and .... 25 | * @author Farzad Farazmand 26 | * https://github.com/farzadfarazmand/EmptyStateLibrary 27 | */ 28 | class EmptyState : ConstraintLayout { 29 | 30 | private val binding: EmptyStateBinding 31 | 32 | //icon 33 | private var iconSize = IconSize.NORMAL 34 | private var icon = 0 35 | private var isFullScreen = false 36 | 37 | //title 38 | private var title = "" 39 | private var titleSize = resources.getDimensionPixelSize(R.dimen.emps_default_title_size) 40 | private var titleColor = ContextCompat.getColor(context, R.color.emps_default_title_color) 41 | 42 | //description 43 | private var description = "" 44 | private var descriptionSize = 45 | resources.getDimensionPixelSize(R.dimen.emps_default_description_size) 46 | private var descriptionColor = 47 | ContextCompat.getColor(context, R.color.emps_default_description_color) 48 | 49 | //button 50 | private var buttonText = "" 51 | private var showButton = false 52 | private var buttonTextColor = Color.WHITE 53 | private var buttonTextSize = 54 | resources.getDimensionPixelSize(R.dimen.emps_default_button_text_size) 55 | private var buttonBackgroundColor = 56 | ContextCompat.getColor(context, R.color.emps_default_button_color) 57 | private var buttonCornerSize = 58 | resources.getDimensionPixelSize(R.dimen.emps_default_button_corner_size) 59 | private var buttonClickListener: OnClickListener? = null 60 | 61 | private var typeface: Typeface? = null 62 | 63 | constructor(context: Context) : super(context) { 64 | initialView() 65 | } 66 | 67 | constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) { 68 | attrs?.let { handleAttribute(it) } 69 | initialView() 70 | } 71 | 72 | constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super( 73 | context, 74 | attrs, 75 | defStyleAttr 76 | ) { 77 | attrs?.let { handleAttribute(it) } 78 | initialView() 79 | } 80 | 81 | init { 82 | AppCompatDelegate.setCompatVectorFromResourcesEnabled(true) 83 | binding = EmptyStateBinding.inflate(LayoutInflater.from(context), this, true) 84 | } 85 | 86 | private fun handleAttribute(attrs: AttributeSet) { 87 | val typedArray = context.obtainStyledAttributes(attrs, R.styleable.EmptyState) 88 | 89 | //icon 90 | icon = typedArray.getResourceId(R.styleable.EmptyState_emps_icon, 0) 91 | iconSize = IconSize.values()[typedArray.getInt(R.styleable.EmptyState_emps_iconSize, 1)] 92 | isFullScreen = typedArray.getBoolean(R.styleable.EmptyState_emps_fullscreen, false) 93 | 94 | //font 95 | if (typedArray.hasValue(R.styleable.EmptyState_emps_font)) { 96 | val fontId = typedArray.getResourceId(R.styleable.EmptyState_emps_font, -1) 97 | typeface = ResourcesCompat.getFont(context, fontId) 98 | } 99 | 100 | //title 101 | typedArray.getString(R.styleable.EmptyState_emps_title)?.let { title = it } 102 | titleSize = typedArray.getDimensionPixelSize( 103 | R.styleable.EmptyState_emps_titleSize, 104 | resources.getDimensionPixelSize(R.dimen.emps_default_title_size) 105 | ) 106 | titleColor = typedArray.getColor( 107 | R.styleable.EmptyState_emps_titleColor, 108 | ContextCompat.getColor(context, R.color.emps_default_title_color) 109 | ) 110 | //description 111 | typedArray.getString(R.styleable.EmptyState_emps_description)?.let { description = it } 112 | descriptionSize = typedArray.getDimensionPixelSize( 113 | R.styleable.EmptyState_emps_descriptionSize, 114 | resources.getDimensionPixelSize(R.dimen.emps_default_description_size) 115 | ) 116 | descriptionColor = typedArray.getColor( 117 | R.styleable.EmptyState_emps_descriptionColor, 118 | ContextCompat.getColor(context, R.color.emps_default_description_color) 119 | ) 120 | //button 121 | showButton = typedArray.getBoolean(R.styleable.EmptyState_emps_showButton, false) 122 | typedArray.getString(R.styleable.EmptyState_emps_buttonText)?.let { buttonText = it } 123 | buttonTextColor = typedArray.getColor( 124 | R.styleable.EmptyState_emps_buttonTextColor, 125 | Color.WHITE 126 | ) 127 | buttonTextSize = typedArray.getDimensionPixelSize( 128 | R.styleable.EmptyState_emps_buttonTextSize, 129 | resources.getDimensionPixelSize(R.dimen.emps_default_button_text_size) 130 | ) 131 | buttonBackgroundColor = typedArray.getColor( 132 | R.styleable.EmptyState_emps_buttonBackgroundColor, 133 | ContextCompat.getColor(context, R.color.emps_default_button_color) 134 | ) 135 | buttonCornerSize = typedArray.getDimensionPixelSize( 136 | R.styleable.EmptyState_emps_buttonCorner, 137 | resources.getDimensionPixelSize(R.dimen.emps_default_button_corner_size) 138 | ) 139 | typedArray.recycle() 140 | } 141 | 142 | private fun initialView() { 143 | binding.apply { 144 | //icon 145 | setIcon(icon) 146 | 147 | //font 148 | typeface?.let { setTypeface(it) } 149 | 150 | //title 151 | if (!TextUtils.isEmpty(title)) 152 | emptyStateTitle.text = title 153 | else 154 | emptyStateTitle.visibility = View.GONE 155 | emptyStateTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize.toFloat()) 156 | emptyStateTitle.setTextColor(titleColor) 157 | //description 158 | if (!TextUtils.isEmpty(description)) 159 | emptyStateDescription.text = description 160 | else 161 | emptyStateDescription.visibility = View.GONE 162 | emptyStateDescription.setTextSize(TypedValue.COMPLEX_UNIT_PX, descriptionSize.toFloat()) 163 | emptyStateDescription.setTextColor(descriptionColor) 164 | //button 165 | if (showButton) 166 | emptyStateButton.visibility = View.VISIBLE 167 | else 168 | emptyStateButton.visibility = View.GONE 169 | emptyStateButton.text = buttonText 170 | emptyStateButton.setTextColor(buttonTextColor) 171 | emptyStateButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, buttonTextSize.toFloat()) 172 | emptyStateButton.cornerRadius = buttonCornerSize 173 | DrawableCompat.setTint(emptyStateButton.background, buttonBackgroundColor) 174 | 175 | emptyStateButton.setOnClickListener { 176 | if (it.visibility == View.VISIBLE) 177 | buttonClickListener?.onClick(it) 178 | } 179 | } 180 | } 181 | 182 | /** 183 | * set a drawable resource as icon 184 | * @param resourceId get drawable resource, R.drawable.something 185 | * @return instance of emptyState 186 | */ 187 | fun setIcon(@DrawableRes resourceId: Int): EmptyState { 188 | binding.apply { 189 | if (isFullScreen) { 190 | emptyStateBg.setImageResource(resourceId) 191 | emptyStateIcon.visibility = View.INVISIBLE 192 | emptyStateBg.visibility = View.VISIBLE 193 | } else { 194 | emptyStateIcon.setImageResource(resourceId) 195 | emptyStateBg.visibility = View.INVISIBLE 196 | emptyStateIcon.visibility = View.VISIBLE 197 | } 198 | } 199 | return this 200 | } 201 | 202 | /** 203 | * set fullscreen state, must be called before set icon! 204 | * 205 | */ 206 | fun isFullScreen(isFullscreen: Boolean): EmptyState { 207 | this.isFullScreen = isFullscreen 208 | return this 209 | } 210 | 211 | /** 212 | * set icon size type 213 | * @param iconSize get SMALL, NORMALL or BIG 214 | * @return instance of emptyState 215 | */ 216 | fun setIconSize(iconSize: IconSize): EmptyState { 217 | val size = when (iconSize) { 218 | IconSize.BIG -> { 219 | resources.getDimensionPixelSize(R.dimen.emps_default_icon_big_size) 220 | } 221 | IconSize.SMALL -> { 222 | resources.getDimensionPixelSize(R.dimen.emps_default_icon_small_size) 223 | } 224 | else -> { 225 | resources.getDimensionPixelSize(R.dimen.emps_default_icon_normal_size) 226 | } 227 | } 228 | binding.apply { 229 | emptyStateIcon.layoutParams.height = size 230 | emptyStateIcon.layoutParams.width = size 231 | } 232 | return this 233 | } 234 | 235 | /** 236 | * set font 237 | * @param typeface 238 | * @return instance of emptyState 239 | */ 240 | fun setTypeface(typeface: Typeface): EmptyState { 241 | this.typeface = typeface 242 | binding.apply { 243 | emptyStateTitle.typeface = typeface 244 | emptyStateDescription.typeface = typeface 245 | emptyStateButton.typeface = typeface 246 | } 247 | return this 248 | } 249 | 250 | 251 | /** 252 | * set font 253 | * @param fontRes resource 254 | * @return instance of emptyState 255 | */ 256 | fun setTypeface(@FontRes fontRes: Int): EmptyState { 257 | typeface = ResourcesCompat.getFont(context, fontRes) 258 | return typeface?.let { setTypeface(it) } ?: this 259 | } 260 | 261 | /** 262 | * set title resource id 263 | * @param resourceId get a string resource id, R.string.something 264 | * @return instance of emptyState 265 | */ 266 | fun setTitle(@StringRes resourceId: Int): EmptyState { 267 | title = context.getString(resourceId) 268 | binding.apply { 269 | emptyStateTitle.text = title 270 | emptyStateTitle.visibility = View.VISIBLE 271 | } 272 | return this 273 | } 274 | 275 | /** 276 | * set plain title 277 | * @param text get a string, "something" 278 | * @return instance of emptyState 279 | */ 280 | fun setTitle(text: String): EmptyState { 281 | this.title = text 282 | binding.apply { 283 | emptyStateTitle.text = text 284 | emptyStateTitle.visibility = View.VISIBLE 285 | } 286 | return this 287 | } 288 | 289 | /** 290 | * set title color 291 | * @param colorRes get color resource id, R.color.someColor 292 | * @return instance of emptyState 293 | */ 294 | fun setTitleColorResource(@ColorRes colorRes: Int): EmptyState { 295 | titleColor = ContextCompat.getColor(context, colorRes) 296 | binding.emptyStateTitle.setTextColor(titleColor) 297 | return this 298 | } 299 | 300 | /** 301 | * set description color 302 | * @param color get color 303 | * @return instance of emptyState 304 | */ 305 | fun setTitleColor(@ColorInt color: Int): EmptyState { 306 | titleColor = color 307 | binding.emptyStateTitle.setTextColor(color) 308 | return this 309 | } 310 | 311 | /** 312 | * set title size 313 | * @param dimenRes get dimension, R.dimen.someSize 314 | * @return instance of emptyState 315 | */ 316 | fun setTitleSize(@DimenRes dimenRes: Int): EmptyState { 317 | titleSize = resources.getDimensionPixelSize(dimenRes) 318 | binding.emptyStateTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize.toFloat()) 319 | return this 320 | } 321 | 322 | /** 323 | * set description resource id 324 | * @param resourceId get a string resource id, R.string.something 325 | * @return instance of emptyState 326 | */ 327 | fun setDescription(@StringRes resourceId: Int): EmptyState { 328 | description = context.getString(resourceId) 329 | binding.emptyStateDescription.text = description 330 | binding.emptyStateDescription.visibility = View.VISIBLE 331 | return this 332 | } 333 | 334 | /** 335 | * set plain description 336 | * @param text get a string, "something" 337 | * @return instance of emptyState 338 | */ 339 | fun setDescription(text: String): EmptyState { 340 | this.description = text 341 | binding.emptyStateDescription.text = text 342 | binding.emptyStateDescription.visibility = View.VISIBLE 343 | return this 344 | } 345 | 346 | /** 347 | * set description color 348 | * @param colorRes get color resource id, R.color.someColor 349 | * @return instance of emptyState 350 | */ 351 | fun setDescriptionColorResource(@ColorRes colorRes: Int): EmptyState { 352 | descriptionColor = ContextCompat.getColor(context, colorRes) 353 | binding.emptyStateDescription.setTextColor(descriptionColor) 354 | return this 355 | } 356 | 357 | /** 358 | * set description color 359 | * @param color get color 360 | * @return instance of emptyState 361 | */ 362 | fun setDescriptionColor(@ColorInt color: Int): EmptyState { 363 | descriptionColor = color 364 | binding.emptyStateDescription.setTextColor(color) 365 | return this 366 | } 367 | 368 | /** 369 | * set description size 370 | * @param dimenRes get dimension, R.dimen.someSize 371 | * @return instance of emptyState 372 | */ 373 | fun setDescriptionSize(@DimenRes dimenRes: Int): EmptyState { 374 | descriptionSize = resources.getDimensionPixelSize(dimenRes) 375 | binding.emptyStateDescription.setTextSize(TypedValue.COMPLEX_UNIT_PX, descriptionSize.toFloat()) 376 | return this 377 | } 378 | 379 | /** 380 | * set button description resource id 381 | * @param resourceId get a string resource id, R.string.something 382 | * @return instance of emptyState 383 | */ 384 | fun setButtonText(@StringRes resourceId: Int): EmptyState { 385 | buttonText = context.getString(resourceId) 386 | binding.emptyStateDescription.text = description 387 | //because it has description and can't be GONE 388 | showButton = true 389 | binding.emptyStateButton.visibility = View.VISIBLE 390 | return this 391 | } 392 | 393 | /** 394 | * set plain button description 395 | * @param text get a string, "something" 396 | * @return instance of emptyState 397 | */ 398 | fun setButtonText(text: String): EmptyState { 399 | buttonText = text 400 | binding.emptyStateDescription.text = text 401 | //because it has description and can't be GONE 402 | showButton = true 403 | binding.emptyStateButton.visibility = View.VISIBLE 404 | return this 405 | } 406 | 407 | /** 408 | * set button background color 409 | * @param colorRes get color resource id, R.color.someColor 410 | * @return instance of emptyState 411 | */ 412 | fun setButtonBackgroundColorResource(@ColorRes colorRes: Int): EmptyState { 413 | buttonBackgroundColor = ContextCompat.getColor(context, colorRes) 414 | DrawableCompat.setTint(binding.emptyStateButton.background, buttonBackgroundColor) 415 | return this 416 | } 417 | 418 | /** 419 | * set button background color 420 | * @param color get color 421 | * @return instance of emptyState 422 | */ 423 | fun setButtonBackgroundColor(@ColorInt color: Int): EmptyState { 424 | buttonBackgroundColor = color 425 | DrawableCompat.setTint(binding.emptyStateButton.background, buttonBackgroundColor) 426 | return this 427 | } 428 | 429 | /** 430 | * set button description size 431 | * @param dimenRes get dimension, R.dimen.someSize 432 | * @return instance of emptyState 433 | */ 434 | fun setButtonTextSize(@DimenRes dimenRes: Int): EmptyState { 435 | buttonTextSize = resources.getDimensionPixelSize(dimenRes) 436 | binding.emptyStateButton.setTextSize(TypedValue.COMPLEX_UNIT_PX, buttonTextSize.toFloat()) 437 | return this 438 | } 439 | 440 | /** 441 | * set button corner size 442 | * @param dimenRes get dimension, R.dimen.someSize 443 | * @return instance of emptyState 444 | */ 445 | fun setButtonCornerSize(@DimenRes dimenRes: Int): EmptyState { 446 | buttonCornerSize = resources.getDimensionPixelSize(dimenRes) 447 | binding.emptyStateButton.cornerRadius = buttonCornerSize 448 | return this 449 | } 450 | 451 | /** 452 | * set button click listener 453 | * @param clickListener instance of OnClickListener 454 | * @return instance of emptyState 455 | */ 456 | fun setButtonClickListener(clickListener: OnClickListener): EmptyState { 457 | buttonClickListener = clickListener 458 | return this 459 | } 460 | 461 | /** 462 | * showing EmptyState 463 | * @param animRes get animation resource, default is fade_in 464 | * @param interpolator get animation interpolator, default is AccelerateDecelerateInterpolator 465 | */ 466 | fun show( 467 | @AnimRes animRes: Int = android.R.anim.fade_in, 468 | interpolator: Interpolator = AccelerateDecelerateInterpolator() 469 | ) { 470 | val animation = AnimationUtils.loadAnimation(context, animRes) 471 | animation.interpolator = interpolator 472 | animation.setAnimationListener(object : Animation.AnimationListener { 473 | override fun onAnimationRepeat(animation: Animation?) { 474 | } 475 | 476 | override fun onAnimationEnd(animation: Animation?) { 477 | } 478 | 479 | override fun onAnimationStart(animation: Animation?) { 480 | visibility = View.VISIBLE 481 | } 482 | }) 483 | startAnimation(animation) 484 | 485 | } 486 | 487 | /** 488 | * hiding EmptyState 489 | * @param animRes get animations resource, default is fade_out 490 | * @param interpolator get animation interpolator, default is AccelerateDecelerateInterpolator 491 | */ 492 | fun hide( 493 | @AnimRes animRes: Int = android.R.anim.fade_out, 494 | interpolator: Interpolator = AccelerateDecelerateInterpolator() 495 | ) { 496 | val animation = AnimationUtils.loadAnimation(context, animRes) 497 | animation.interpolator = interpolator 498 | animation.setAnimationListener(object : Animation.AnimationListener { 499 | override fun onAnimationRepeat(animation: Animation?) { 500 | } 501 | 502 | override fun onAnimationEnd(animation: Animation?) { 503 | visibility = View.INVISIBLE 504 | } 505 | 506 | override fun onAnimationStart(animation: Animation?) { 507 | } 508 | }) 509 | startAnimation(animation) 510 | } 511 | 512 | } --------------------------------------------------------------------------------