├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── themes.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── mipmap-anydpi-v33
│ │ │ │ └── ic_launcher.xml
│ │ │ ├── layout
│ │ │ │ ├── fragment_test_2.xml
│ │ │ │ ├── activity_test_fragment.xml
│ │ │ │ ├── activity_java_main.xml
│ │ │ │ ├── fragment_test.xml
│ │ │ │ └── activity_main.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── tashila
│ │ │ │ └── pleasewait
│ │ │ │ ├── CustomProgressDialog.kt
│ │ │ │ ├── JavaCustomDialog.java
│ │ │ │ ├── JavaMainActivity.java
│ │ │ │ ├── TestChildFragment.kt
│ │ │ │ ├── TestFragmentActivity.kt
│ │ │ │ ├── TestParentFragment.kt
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── tashila
│ │ │ └── pleasewait
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── tashila
│ │ └── pleasewait
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── library
├── .gitignore
├── consumer-rules.pro
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ │ ├── values
│ │ │ │ └── strings.xml
│ │ │ └── layout
│ │ │ │ └── please_wait_dialog.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── tashila
│ │ │ └── pleasewait
│ │ │ └── PleaseWaitDialog.kt
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── tashila
│ │ │ └── pleasewait
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── tashila
│ │ └── pleasewait
│ │ └── ExampleInstrumentedTest.kt
├── gradle.properties
├── proguard-rules.pro
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/library/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | PleaseWait Library
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tashilapathum/PleaseWait/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v33/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/tashila/pleasewait/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/library/src/test/java/com/tashila/pleasewait/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tashila/pleasewait/CustomProgressDialog.kt:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait
2 |
3 | import android.content.Context
4 | import android.content.DialogInterface
5 | import android.widget.Toast
6 | import android.widget.Toast.LENGTH_SHORT
7 |
8 | class CustomProgressDialog(private val context: Context) : PleaseWaitDialog(context) {
9 | override fun onDismiss(dialog: DialogInterface) {
10 | super.onDismiss(dialog)
11 | Toast.makeText(context, "Dialog dismissed", LENGTH_SHORT).show();
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_test_2.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenLocal()
5 | mavenCentral()
6 | gradlePluginPortal()
7 | }
8 | }
9 | plugins {
10 | id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
11 | }
12 | dependencyResolutionManagement {
13 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
14 | repositories {
15 | google()
16 | mavenCentral()
17 | maven { url 'https://jitpack.io' }
18 | }
19 | }
20 |
21 | rootProject.name = "PleaseWait"
22 | include ':app'
23 | include ':library'
24 |
--------------------------------------------------------------------------------
/library/gradle.properties:
--------------------------------------------------------------------------------
1 | GROUP=com.tashila.pleasewait
2 | VERSION_NAME=0.1.0
3 | VERSION_CODE=1
4 | POM_DESCRIPTION=A lightweight Material 3 replacement for ProgressDialog
5 | POM_URL=https://github.com/tashilapathum/PleaseWait
6 | POM_SCM_URL=https://github.com/tashilapathum/PleaseWait
7 | POM_SCM_CONNECTION=scm:git@github.com:tashilapathum/PleaseWait.git
8 | POM_SCM_DEV_CONNECTION=scm:git@github.com:tashilapathum/PleaseWait.git
9 | POM_LICENCE_NAME=Apache License, Version 2.0
10 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
11 | POM_DEVELOPER_ID=tashilapathum
12 | POM_DEVELOPER_NAME=Tashila Pathum
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_test_fragment.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tashila/pleasewait/JavaCustomDialog.java:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait;
2 |
3 | import static android.widget.Toast.LENGTH_SHORT;
4 |
5 | import android.content.Context;
6 | import android.content.DialogInterface;
7 | import android.widget.Toast;
8 |
9 | public class JavaCustomDialog extends PleaseWaitDialog {
10 | private Context context;
11 |
12 | private JavaCustomDialog() {}
13 |
14 | public JavaCustomDialog(Context context) {
15 | super(context);
16 | this.context = context;
17 | }
18 |
19 | @Override
20 | public void onResume() {
21 | super.onResume();
22 | getDialog().setOnDismissListener(dialog -> Toast.makeText(context, "Dialog dismissed", LENGTH_SHORT).show());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_java_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/tashila/pleasewait/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.tashila.pleasewait", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tashila/pleasewait/JavaMainActivity.java:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait;
2 |
3 | import android.os.Bundle;
4 | import androidx.appcompat.app.AppCompatActivity;
5 |
6 | import com.tashila.pleasewait.sample.databinding.ActivityJavaMainBinding;
7 |
8 | public class JavaMainActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | ActivityJavaMainBinding binding = ActivityJavaMainBinding.inflate(getLayoutInflater());
14 | setContentView(binding.getRoot());
15 |
16 | binding.show.setOnClickListener(view -> showDialog());
17 | }
18 |
19 | private void showDialog() {
20 | JavaCustomDialog dialog = new JavaCustomDialog(this);
21 | dialog.show();
22 | }
23 | }
--------------------------------------------------------------------------------
/app/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
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/tashila/pleasewait/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.tashila.pleasewait.test", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tashila/pleasewait/TestChildFragment.kt:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import com.tashila.pleasewait.sample.databinding.FragmentTest2Binding
9 |
10 | class TestChildFragment : Fragment() {
11 | private lateinit var binding: FragmentTest2Binding
12 |
13 | override fun onCreateView(
14 | inflater: LayoutInflater,
15 | container: ViewGroup?,
16 | savedInstanceState: Bundle?
17 | ): View {
18 | binding = FragmentTest2Binding.inflate(inflater, container, false)
19 | binding.show.setOnClickListener {
20 | (activity as TestFragmentActivity).loadingDialog.show()
21 | }
22 | return binding.root
23 | }
24 |
25 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/tashila/pleasewait/TestFragmentActivity.kt:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait
2 |
3 | import android.os.Bundle
4 | import androidx.activity.enableEdgeToEdge
5 | import androidx.appcompat.app.AppCompatActivity
6 | import com.tashila.pleasewait.sample.databinding.ActivityTestFragmentBinding
7 |
8 | class TestFragmentActivity : AppCompatActivity() {
9 | private lateinit var binding: ActivityTestFragmentBinding
10 | val loadingDialog by lazy { PleaseWaitDialog(this) }
11 |
12 | override fun onCreate(savedInstanceState: Bundle?) {
13 | super.onCreate(savedInstanceState)
14 | binding = ActivityTestFragmentBinding.inflate(layoutInflater)
15 | enableEdgeToEdge()
16 | setContentView(binding.root)
17 | supportActionBar?.setDisplayShowHomeEnabled(true)
18 | supportActionBar?.setDisplayHomeAsUpEnabled(true)
19 | supportFragmentManager
20 | .beginTransaction()
21 | .add(binding.fragmentContainer.id, TestParentFragment())
22 | .commit()
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
21 |
22 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tashila/pleasewait/TestParentFragment.kt:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import com.tashila.pleasewait.sample.databinding.FragmentTestBinding
9 |
10 | class TestParentFragment : Fragment() {
11 | private lateinit var binding: FragmentTestBinding
12 |
13 | override fun onCreateView(
14 | inflater: LayoutInflater,
15 | container: ViewGroup?,
16 | savedInstanceState: Bundle?
17 | ): View {
18 | binding = FragmentTestBinding.inflate(inflater, container, false)
19 | binding.showFragment.setOnClickListener {
20 | childFragmentManager
21 | .beginTransaction()
22 | .add(binding.fragmentContainer.id, TestChildFragment(), "TestChildFragment")
23 | .commit()
24 | }
25 | binding.showDialog.setOnClickListener {
26 | (activity as TestFragmentActivity).loadingDialog.show()
27 | }
28 | return binding.root
29 | }
30 |
31 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
14 |
18 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/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=-Xmx2048m -Dfile.encoding=UTF-8
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 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
24 | org.gradle.parallel=false
25 | android.nonFinalResIds=false
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | }
5 |
6 | android {
7 | namespace 'com.tashila.pleasewait.sample'
8 | compileSdk 36
9 |
10 | defaultConfig {
11 | applicationId "com.tashila.pleasewait"
12 | minSdk 21
13 | targetSdk 36
14 | versionCode 1
15 | versionName "1.0.0"
16 |
17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18 | }
19 |
20 | buildTypes {
21 | release {
22 | minifyEnabled false
23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility JavaVersion.VERSION_17
28 | targetCompatibility JavaVersion.VERSION_17
29 | }
30 | kotlinOptions {
31 | jvmTarget = '17'
32 | }
33 | viewBinding {
34 | enabled = true
35 | }
36 | }
37 |
38 | dependencies {
39 | //implementation project(':library') //for development
40 |
41 | implementation 'androidx.core:core-ktx:1.13.1'
42 | implementation 'androidx.appcompat:appcompat:1.6.1'
43 | implementation 'com.google.android.material:material:1.12.0'
44 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
45 | implementation 'androidx.activity:activity-ktx:1.9.0'
46 | testImplementation 'junit:junit:4.13.2'
47 | androidTestImplementation 'androidx.test.ext:junit:1.1.5'
48 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
49 |
50 | //add the library
51 | implementation 'com.github.tashilapathum:PleaseWait:0.6.5'
52 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea/workspace.xml
42 | .idea/tasks.xml
43 | .idea/gradle.xml
44 | .idea/assetWizardSettings.xml
45 | .idea/dictionaries
46 | .idea/libraries
47 | # Android Studio 3 in .gitignore file.
48 | .idea/caches
49 | .idea/modules.xml
50 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
51 | .idea/navEditor.xml
52 |
53 | # Keystore files
54 | # Uncomment the following lines if you do not want to check your keystore files in.
55 | #*.jks
56 | #*.keystore
57 |
58 | # External native build folder generated in Android Studio 2.2 and later
59 | .externalNativeBuild
60 | .cxx/
61 |
62 | # Google Services (e.g. APIs or Firebase)
63 | # google-services.json
64 |
65 | # Freeline
66 | freeline.py
67 | freeline/
68 | freeline_project_description.json
69 |
70 | # fastlane
71 | fastlane/report.xml
72 | fastlane/Preview.html
73 | fastlane/screenshots
74 | fastlane/test_output
75 | fastlane/readme.md
76 |
77 | # Version control
78 | vcs.xml
79 |
80 | # lint
81 | lint/intermediates/
82 | lint/generated/
83 | lint/outputs/
84 | lint/tmp/
85 | # lint/reports/
86 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'org.jetbrains.kotlin.android'
4 | id 'maven-publish'
5 | }
6 |
7 | android {
8 | namespace 'com.tashila.pleasewait'
9 | compileSdk 36
10 |
11 | defaultConfig {
12 | minSdk 21
13 | targetSdk 36
14 |
15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16 | consumerProguardFiles "consumer-rules.pro"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_17
27 | targetCompatibility JavaVersion.VERSION_17
28 | }
29 | kotlinOptions {
30 | jvmTarget = '17'
31 | }
32 | viewBinding {
33 | enabled = true
34 | }
35 |
36 | publishing {
37 | singleVariant("release") {
38 | withSourcesJar()
39 | withJavadocJar()
40 | }
41 | }
42 | }
43 |
44 | def properties = new Properties()
45 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
46 |
47 | afterEvaluate {
48 | publishing {
49 | publications {
50 | release(MavenPublication) {
51 | from components.release
52 | groupId = 'com.github.tashilapathum'
53 | artifactId = 'PleaseWait'
54 | version = '0.6.4'
55 | }
56 | }
57 | }
58 | }
59 |
60 | dependencies {
61 | implementation 'androidx.core:core-ktx:1.13.1'
62 | implementation 'androidx.appcompat:appcompat:1.6.1'
63 | implementation 'com.google.android.material:material:1.12.0'
64 | testImplementation 'junit:junit:4.13.2'
65 | androidTestImplementation 'androidx.test.ext:junit:1.1.5'
66 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
67 | }
--------------------------------------------------------------------------------
/library/src/main/res/layout/please_wait_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
22 |
23 |
31 |
32 |
39 |
40 |
46 |
47 |
48 |
49 |
50 |
51 |
56 |
57 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PleaseWait
2 | [](https://jitpack.io/#tashilapathum/PleaseWait)
3 |
4 | PleaseWait is a lightweight library that can be used as a drop-in replacement for now-deprecated `android.app.ProgressDialog`.
5 | According to Google, the reason to deprecate the good old `ProgressDialog` is:
6 | > ProgressDialog is a modal dialog, which prevents the user from interacting with the app. Instead of using this class, you should use a progress indicator like ProgressBar, which can be embedded in your app's UI.
7 |
8 | I understand the reasoning but it means we have to do some more work to prevent the user from doing something unexpected before the operation is finished. But come on, using a progress dialog is so much easier. So I made this library to use in my apps to avoid those deprecation warnings everywhere and to improve the look of the progress dialog. Also I wanted to learn the process of publishing a library.
9 |
10 |
11 | ## Preview
12 | | Indeterminate mode | Determinate mode | Dark and light modes |
13 | | --- | --- | --- |
14 | |  |  |  |
15 |
16 |
17 | ## Features
18 | - Supports Material 2 and the latest Material 3 design
19 | - Both determinate and indeterminate progress modes
20 | - Both circular and linear progress bars
21 | - Ability to set a delay before showing
22 | - Ability to set a minimum duration to show the dialog
23 | - Follows Dark and Light modes automatically
24 | - Adapts to your app's theme colors
25 | - Retains state between orientation changes
26 | - Smooth Material animations and transitions
27 | - Lightweight and Easy to implement
28 | - Fully interoperable with Java
29 |
30 |
31 | ## How to use
32 | 1. Add the dependency to the app-level `build.gradle`.
33 |
34 | ```gradle
35 | implementation 'com.github.tashilapathum:PleaseWait:0.6.5'
36 | ```
37 |
38 | 2. Intitialize with `Activity` or `Fragment` context and show.
39 | ```kotlin
40 | val progressDialog = PleaseWaitDialog(context = this)
41 | progressDialog.show()
42 | ```
43 |
44 | 3. Optionally set title and message
45 | ```kotlin
46 | progressDialog.setTitle("Please wait")
47 | progressDialog.setMessage("Loading...")
48 | ```
49 |
50 | 4. Dismiss when the operation is complete
51 | ```
52 | progressDialog.dismiss()
53 | ```
54 |
55 |
56 | ## Additional options
57 |
58 | - Choose progress style: `CIRCULAR`, `LINEAR`, `BOTH` or `NONE`. Default is `CIRCULAR`
59 | ```kotlin
60 | progressDialog.setProgressStyle(PleaseWaitDialog.ProgressStyle.LINEAR)
61 | ```
62 |
63 | - Set determinate or indeterminate mode. Default is `true`.
64 | ```kotlin
65 | progressDialog.setIndeterminate(false) //apply to both progress bars
66 | progressDialog.setIndeterminate(ProgressStyle.LINEAR, false) //apply to a specific progress bar
67 | ```
68 |
69 | - Set progress. You can just set the progress and the progress bars will smoothly animate from indeterminate to determinate mode.
70 | ```kotlin
71 | progressDialog.setProgress(20)
72 | ```
73 |
74 | - Set a delay before showing to avoid flashing the progress dialog for short operations. The dialog won't be shown if you called `dismiss()` before the time has elapsed.
75 | ```kotlin
76 | progressDialog.setShowDelay(2000)
77 | ```
78 |
79 | - Set a delay before dismissing the dialog to show the dialog for a minimum amount of time.
80 | ```kotlin
81 | progressDialog.setDismissDelay(3000)
82 | ```
83 |
84 | - Set title and message by overriding resources on `strings.xml`. There's no title or message by default.
85 | ```xml
86 | Please wait
87 | Loading…
88 | ```
89 |
90 |
91 | ## Java implementation
92 | ```java
93 | PleaseWaitDialog progressDialog = new PleaseWaitDialog(this);
94 | progressDialog.setTitle("Please wait");
95 | progressDialog.setMessage("Loading...");
96 | progressDialog.setCancelable(false);
97 | progressDialog.show();
98 | ```
99 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/java/com/tashila/pleasewait/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.os.Handler
6 | import android.os.Looper
7 | import android.util.Log
8 | import androidx.activity.enableEdgeToEdge
9 | import androidx.appcompat.app.AppCompatActivity
10 | import com.tashila.pleasewait.PleaseWaitDialog.ProgressStyle
11 | import com.tashila.pleasewait.sample.databinding.ActivityMainBinding
12 |
13 | class MainActivity : AppCompatActivity() {
14 | private lateinit var binding: ActivityMainBinding
15 | private lateinit var progressDialog: PleaseWaitDialog
16 | private lateinit var handler: Handler
17 | private lateinit var runnable: Runnable
18 | private var progress = 0
19 |
20 | override fun onCreate(savedInstanceState: Bundle?) {
21 | super.onCreate(savedInstanceState)
22 | binding = ActivityMainBinding.inflate(layoutInflater)
23 | enableEdgeToEdge()
24 | setContentView(binding.root)
25 | init()
26 | }
27 |
28 | private fun init() {
29 | //to show progress
30 | handler = Handler(Looper.getMainLooper())
31 | runnable = object : Runnable {
32 | override fun run() {
33 | if (progress == 100) {
34 | try {
35 | progressDialog.dismiss()
36 | } catch (e: IllegalStateException) {
37 | Log.e(TAG, "DialogFragment not associated with a fragment manager")
38 | }
39 | progress = 0
40 | handler.removeCallbacks(this)
41 | } else {
42 | progress += 10
43 | progressDialog.setProgress(progress)
44 | handler.postDelayed(this, 2000)
45 | }
46 | }
47 | }
48 |
49 | //onClick listeners
50 | binding.apply {
51 | show.setOnClickListener {
52 | showProgressDialog()
53 | updateProgress()
54 | }
55 | showLive.setOnClickListener {
56 | showDialogWithUpdates()
57 | }
58 | showCustom.setOnClickListener {
59 | showCustomDialog()
60 | }
61 | fragment.setOnClickListener {
62 | startActivity(Intent(this@MainActivity, TestFragmentActivity::class.java))
63 | }
64 | javaActivity.setOnClickListener {
65 | startActivity(Intent(this@MainActivity, JavaMainActivity::class.java))
66 | }
67 | }
68 | }
69 |
70 | private fun showProgressDialog() {
71 | handler.removeCallbacks(runnable)
72 |
73 | progressDialog = PleaseWaitDialog(this)
74 | progressDialog.setTitle(getTitleText())
75 | progressDialog.setMessage(getMessageText())
76 | progressDialog.setProgressStyle(getProgressStyle())
77 | progressDialog.setIndeterminate(getIndeterminateProgressStyle(), false)
78 | progressDialog.setShowDelay(getShowDelay())
79 | progressDialog.setDismissDelay(getDismissDelay())
80 | progressDialog.show()
81 | //progressDialog.dismiss() //call dismiss to test DismissDelay
82 | }
83 |
84 | private fun getTitleText(): String {
85 | return binding.title.editText!!.text.toString().trim()
86 | }
87 |
88 | private fun getMessageText(): String {
89 | return binding.message.editText!!.text.toString().trim()
90 | }
91 |
92 | private fun getIndeterminateProgressStyle(): Int {
93 | if (binding.chipBoth.isChecked)
94 | return PleaseWaitDialog.ProgressStyle.BOTH
95 | if (binding.chipCircular.isChecked)
96 | return PleaseWaitDialog.ProgressStyle.CIRCULAR
97 | if (binding.chipLinear.isChecked)
98 | return PleaseWaitDialog.ProgressStyle.LINEAR
99 |
100 | return PleaseWaitDialog.ProgressStyle.NONE
101 | }
102 |
103 | private fun getProgressStyle(): Int {
104 | if (binding.circular.isChecked and binding.linear.isChecked)
105 | return PleaseWaitDialog.ProgressStyle.BOTH
106 | if (binding.circular.isChecked)
107 | return PleaseWaitDialog.ProgressStyle.CIRCULAR
108 | if (binding.linear.isChecked)
109 | return PleaseWaitDialog.ProgressStyle.LINEAR
110 |
111 | return PleaseWaitDialog.ProgressStyle.NONE
112 | }
113 |
114 | private fun getShowDelay(): Long {
115 | val text = binding.showDelay.editText!!.text
116 | return if (text.isNotEmpty())
117 | text.toString().toLong()
118 | else
119 | 0L
120 | }
121 |
122 | private fun getDismissDelay(): Long {
123 | val text = binding.dismissDelay.editText!!.text
124 | return if (text.isNotEmpty())
125 | text.toString().toLong()
126 | else
127 | 0L
128 | }
129 |
130 | private fun updateProgress() {
131 | if (binding.showProgress.isChecked)
132 | handler.postDelayed(runnable, 2000)
133 | }
134 |
135 | private fun showCustomDialog() {
136 | val customDialog = CustomProgressDialog(this)
137 | customDialog.show()
138 | }
139 |
140 | fun showDialogWithUpdates() {
141 | val dialog = PleaseWaitDialog(this).apply {
142 | // Initial setup
143 | setTitle("Initial Title")
144 | setMessage("Initial Message")
145 | setProgressStyle(ProgressStyle.BOTH)
146 | setIndeterminate(true)
147 | setProgress(0)
148 |
149 | // Show the dialog immediately
150 | show()
151 | }
152 |
153 | // Update values while dialog is showing
154 | Handler(Looper.getMainLooper()).postDelayed({
155 | dialog.apply {
156 | setTitle("Updated Title 1")
157 | setMessage("Updated Message 1")
158 | setProgress(25)
159 | setIndeterminate(false)
160 | }
161 | }, 1000)
162 |
163 | // Change progress style and update again
164 | Handler(Looper.getMainLooper()).postDelayed({
165 | dialog.apply {
166 | setProgressStyle(ProgressStyle.LINEAR)
167 | setTitle("Updated Title 2")
168 | setMessage("Updated Message 2")
169 | setProgress(50)
170 | }
171 | }, 2000)
172 |
173 | // Test indeterminate states
174 | Handler(Looper.getMainLooper()).postDelayed({
175 | dialog.apply {
176 | setIndeterminate(ProgressStyle.CIRCULAR, true)
177 | setIndeterminate(ProgressStyle.LINEAR, false)
178 | setProgress(75)
179 | }
180 | }, 3000)
181 |
182 | // Test hiding progress bars completely
183 | Handler(Looper.getMainLooper()).postDelayed({
184 | dialog.apply {
185 | setProgressStyle(ProgressStyle.NONE)
186 | setTitle("Updated Title 3")
187 | setMessage("Updated Message 3")
188 | }
189 | }, 4000)
190 |
191 | // Show progress bars back again
192 | Handler(Looper.getMainLooper()).postDelayed({
193 | dialog.apply {
194 | setProgressStyle(ProgressStyle.BOTH)
195 | }
196 | }, 5000)
197 |
198 | // Hide all the text
199 | Handler(Looper.getMainLooper()).postDelayed({
200 | dialog.apply {
201 | setTitle("")
202 | setMessage("")
203 | }
204 | }, 6000)
205 | }
206 |
207 | companion object {
208 | const val TAG = "MainActivity"
209 | }
210 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
23 |
24 |
30 |
31 |
34 |
35 |
36 |
42 |
43 |
46 |
47 |
48 |
55 |
56 |
60 |
61 |
62 |
69 |
70 |
74 |
75 |
76 |
83 |
84 |
90 |
91 |
97 |
98 |
102 |
103 |
108 |
109 |
114 |
115 |
121 |
122 |
130 |
131 |
138 |
139 |
146 |
147 |
154 |
155 |
156 |
157 |
158 |
165 |
166 |
174 |
175 |
182 |
183 |
190 |
191 |
199 |
200 |
201 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90 | ' "$PWD" ) || exit
91 |
92 | # Use the maximum available, or set MAX_FD != -1 to use that value.
93 | MAX_FD=maximum
94 |
95 | warn () {
96 | echo "$*"
97 | } >&2
98 |
99 | die () {
100 | echo
101 | echo "$*"
102 | echo
103 | exit 1
104 | } >&2
105 |
106 | # OS specific support (must be 'true' or 'false').
107 | cygwin=false
108 | msys=false
109 | darwin=false
110 | nonstop=false
111 | case "$( uname )" in #(
112 | CYGWIN* ) cygwin=true ;; #(
113 | Darwin* ) darwin=true ;; #(
114 | MSYS* | MINGW* ) msys=true ;; #(
115 | NONSTOP* ) nonstop=true ;;
116 | esac
117 |
118 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
119 |
120 |
121 | # Determine the Java command to use to start the JVM.
122 | if [ -n "$JAVA_HOME" ] ; then
123 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
124 | # IBM's JDK on AIX uses strange locations for the executables
125 | JAVACMD=$JAVA_HOME/jre/sh/java
126 | else
127 | JAVACMD=$JAVA_HOME/bin/java
128 | fi
129 | if [ ! -x "$JAVACMD" ] ; then
130 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
131 |
132 | Please set the JAVA_HOME variable in your environment to match the
133 | location of your Java installation."
134 | fi
135 | else
136 | JAVACMD=java
137 | if ! command -v java >/dev/null 2>&1
138 | then
139 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
140 |
141 | Please set the JAVA_HOME variable in your environment to match the
142 | location of your Java installation."
143 | fi
144 | fi
145 |
146 | # Increase the maximum file descriptors if we can.
147 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
148 | case $MAX_FD in #(
149 | max*)
150 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
151 | # shellcheck disable=SC2039,SC3045
152 | MAX_FD=$( ulimit -H -n ) ||
153 | warn "Could not query maximum file descriptor limit"
154 | esac
155 | case $MAX_FD in #(
156 | '' | soft) :;; #(
157 | *)
158 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
159 | # shellcheck disable=SC2039,SC3045
160 | ulimit -n "$MAX_FD" ||
161 | warn "Could not set maximum file descriptor limit to $MAX_FD"
162 | esac
163 | fi
164 |
165 | # Collect all arguments for the java command, stacking in reverse order:
166 | # * args from the command line
167 | # * the main class name
168 | # * -classpath
169 | # * -D...appname settings
170 | # * --module-path (only if needed)
171 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
172 |
173 | # For Cygwin or MSYS, switch paths to Windows format before running java
174 | if "$cygwin" || "$msys" ; then
175 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
176 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
177 |
178 | JAVACMD=$( cygpath --unix "$JAVACMD" )
179 |
180 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
181 | for arg do
182 | if
183 | case $arg in #(
184 | -*) false ;; # don't mess with options #(
185 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
186 | [ -e "$t" ] ;; #(
187 | *) false ;;
188 | esac
189 | then
190 | arg=$( cygpath --path --ignore --mixed "$arg" )
191 | fi
192 | # Roll the args list around exactly as many times as the number of
193 | # args, so each arg winds up back in the position where it started, but
194 | # possibly modified.
195 | #
196 | # NB: a `for` loop captures its iteration list before it begins, so
197 | # changing the positional parameters here affects neither the number of
198 | # iterations, nor the values presented in `arg`.
199 | shift # remove old arg
200 | set -- "$@" "$arg" # push replacement arg
201 | done
202 | fi
203 |
204 |
205 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
206 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
207 |
208 | # Collect all arguments for the java command:
209 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
210 | # and any embedded shellness will be escaped.
211 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
212 | # treated as '${Hostname}' itself on the command line.
213 |
214 | set -- \
215 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
216 | -classpath "$CLASSPATH" \
217 | org.gradle.wrapper.GradleWrapperMain \
218 | "$@"
219 |
220 | # Stop when "xargs" is not available.
221 | if ! command -v xargs >/dev/null 2>&1
222 | then
223 | die "xargs is not available"
224 | fi
225 |
226 | # Use "xargs" to parse quoted args.
227 | #
228 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
229 | #
230 | # In Bash we could simply go:
231 | #
232 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
233 | # set -- "${ARGS[@]}" "$@"
234 | #
235 | # but POSIX shell has neither arrays nor command substitution, so instead we
236 | # post-process each arg (as a line of input to sed) to backslash-escape any
237 | # character that might be a shell metacharacter, then use eval to reverse
238 | # that process (while maintaining the separation between arguments), and wrap
239 | # the whole thing up as a single "set" statement.
240 | #
241 | # This will of course break if any of these variables contains a newline or
242 | # an unmatched quote.
243 | #
244 |
245 | eval "set -- $(
246 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
247 | xargs -n1 |
248 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
249 | tr '\n' ' '
250 | )" '"$@"'
251 |
252 | exec "$JAVACMD" "$@"
253 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/library/src/main/java/com/tashila/pleasewait/PleaseWaitDialog.kt:
--------------------------------------------------------------------------------
1 | package com.tashila.pleasewait
2 |
3 | import android.app.Dialog
4 | import android.content.Context
5 | import android.os.Bundle
6 | import android.os.CountDownTimer
7 | import android.util.Log
8 | import android.view.View.GONE
9 | import android.view.View.VISIBLE
10 | import androidx.appcompat.app.AlertDialog
11 | import androidx.fragment.app.DialogFragment
12 | import androidx.fragment.app.FragmentActivity
13 | import com.google.android.material.dialog.MaterialAlertDialogBuilder
14 | import com.google.android.material.progressindicator.CircularProgressIndicator
15 | import com.google.android.material.progressindicator.LinearProgressIndicator
16 | import com.tashila.pleasewait.databinding.PleaseWaitDialogBinding
17 | import java.util.Timer
18 | import java.util.concurrent.ScheduledExecutorService
19 | import java.util.concurrent.ScheduledThreadPoolExecutor
20 |
21 | public open class PleaseWaitDialog() : DialogFragment() {
22 | private var context: Context? = null
23 | private lateinit var binding: PleaseWaitDialogBinding
24 | private lateinit var dialog: AlertDialog
25 | private lateinit var progressBar: LinearProgressIndicator
26 | private lateinit var progressCircle: CircularProgressIndicator
27 |
28 | //values set by the user
29 | private var title = ""
30 | private var message = ""
31 | private var progress = 0
32 | private var showDelay = 0L
33 | private var dismissDelay = 0L
34 | private var showCalled = false
35 | private var dismissCalled = false
36 | private var isIndeterminate = true
37 | private var isLinearIndeterminate = true
38 | private var isCircularIndeterminate = true
39 | private var progressStyle = ProgressStyle.CIRCULAR
40 |
41 | //timers to track dismiss delay and show delay
42 | private var showTimer: CountDownTimer? = null
43 | private var dismissTimer: CountDownTimer? = null
44 |
45 | constructor(context: Context) : this() {
46 | this.context = context
47 | title = context.getString(R.string.please_wait_dialog_default_title)
48 | message = context.getString(R.string.please_wait_dialog_default_message)
49 | }
50 |
51 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
52 | binding = PleaseWaitDialogBinding.inflate(layoutInflater)
53 |
54 | // Restore saved state
55 | if (savedInstanceState != null) {
56 | title = savedInstanceState.getString(ARG_TITLE) ?: ""
57 | message = savedInstanceState.getString(ARG_MESSAGE) ?: ""
58 | progress = savedInstanceState.getInt(ARG_PROGRESS)
59 | progressStyle = savedInstanceState.getInt(ARG_PROGRESS_STYLE)
60 | isIndeterminate = savedInstanceState.getBoolean(ARG_IS_INDETERMINATE)
61 | isLinearIndeterminate = savedInstanceState.getBoolean(ARG_IS_LINEAR_INDETERMINATE)
62 | isCircularIndeterminate = savedInstanceState.getBoolean(ARG_IS_CIRCULAR_INDETERMINATE)
63 | }
64 |
65 | //build dialog
66 | dialog = MaterialAlertDialogBuilder(requireActivity())
67 | .setView(binding.root)
68 | .create()
69 |
70 | init()
71 | updateTextVisibility()
72 | updateIndeterminateStates()
73 | updateProgressStyle()
74 |
75 | return dialog
76 | }
77 |
78 | private fun init() {
79 | //find views
80 | progressBar = binding.progressBar
81 | progressCircle = binding.progressCircle
82 | if (progress > 0) setProgress(progress) //when called onRestoreSavedInstanceState
83 |
84 | //Hide unnecessary view so the remaining content get centered properly
85 | if (title.isEmpty() and message.isEmpty())
86 | binding.textsLayout.visibility = GONE
87 | if (title.isEmpty())
88 | binding.title.visibility = GONE
89 | if (message.isEmpty())
90 | binding.message.visibility = GONE
91 | }
92 |
93 | private fun isShowing(): Boolean {
94 | return isAdded && ::dialog.isInitialized && dialog.isShowing
95 | }
96 |
97 | private fun updateTextVisibility() {
98 | val titleEmpty = title.isEmpty()
99 | val messageEmpty = message.isEmpty()
100 |
101 | binding.textsLayout.visibility = if (titleEmpty && messageEmpty) GONE else VISIBLE
102 | binding.title.visibility = if (titleEmpty) GONE else VISIBLE
103 | binding.message.visibility = if (messageEmpty) GONE else VISIBLE
104 | }
105 |
106 | private fun updateIndeterminateStates() {
107 | progressBar.isIndeterminate = isIndeterminate
108 | progressCircle.isIndeterminate = isIndeterminate
109 | progressBar.isIndeterminate = isLinearIndeterminate
110 | progressCircle.isIndeterminate = isCircularIndeterminate
111 | }
112 |
113 | private fun updateProgressStyle() {
114 | when (progressStyle) {
115 | ProgressStyle.LINEAR -> {
116 | progressCircle.visibility = GONE
117 | progressBar.visibility = VISIBLE
118 | }
119 | ProgressStyle.BOTH -> {
120 | progressCircle.visibility = VISIBLE
121 | progressBar.visibility = VISIBLE
122 | }
123 | ProgressStyle.NONE -> {
124 | progressCircle.visibility = GONE
125 | progressBar.visibility = GONE
126 | }
127 | else -> { // CIRCULAR
128 | progressCircle.visibility = VISIBLE
129 | progressBar.visibility = GONE
130 | }
131 | }
132 | }
133 |
134 | /* Setters to customize the behaviour and the appearance */
135 |
136 | /**Sets the larger top text*/
137 | public fun setTitle(title: String) {
138 | this.title = title
139 | if (isShowing()) {
140 | binding.title.text = title
141 | updateTextVisibility()
142 | }
143 | }
144 |
145 | /**Sets the smaller bottom text*/
146 | public fun setMessage(message: String) {
147 | this.message = message
148 | if (isShowing()) {
149 | binding.message.text = message
150 | updateTextVisibility()
151 | }
152 | }
153 |
154 | /**Sets a progress value between 0-100 to show the progress on one or both of circular and linear progress bars.
155 | * Use setProgressCompat to smoothly transition from indeterminate mode to determinate mode*/
156 | public fun setProgress(progress: Int) {
157 | this.progress = progress //for savedInstanceState
158 |
159 | if (!isCircularIndeterminate) { //only circular is determinate
160 | progressCircle.setProgressCompat(progress, true)
161 | return
162 | }
163 |
164 | if (!isLinearIndeterminate) { //only linear is determinate
165 | progressBar.setProgressCompat(progress, true)
166 | return
167 | }
168 |
169 | if (!isIndeterminate) { //both are determinate
170 | progressCircle.setProgressCompat(progress, true)
171 | progressBar.setProgressCompat(progress, true)
172 | return
173 | }
174 | }
175 |
176 | /** Sets shown progress bar(s) as indeterminate or not. Default value is true.*/
177 | public fun setIndeterminate(isIndeterminate: Boolean) {
178 | this.isIndeterminate = isIndeterminate
179 | if (isShowing()) {
180 | updateIndeterminateStates()
181 | }
182 | }
183 |
184 | /**Sets the the specifies progressbar(s) as determinate or indeterminate. Both progress bars
185 | * are indeterminate by default.*/
186 | public fun setIndeterminate(which: Int, isIndeterminate: Boolean) {
187 | when (which) {
188 | ProgressStyle.CIRCULAR -> isCircularIndeterminate = isIndeterminate
189 | ProgressStyle.LINEAR -> isLinearIndeterminate = isIndeterminate
190 | ProgressStyle.BOTH -> this.isIndeterminate = isIndeterminate
191 | }
192 | if (isShowing()) {
193 | updateIndeterminateStates()
194 | }
195 | }
196 |
197 | /** Sets the progress bar style. Default value is [ProgressStyle.CIRCULAR].*/
198 | public fun setProgressStyle(progressStyle: Int) {
199 | this.progressStyle = progressStyle
200 | if (isShowing()) {
201 | updateProgressStyle()
202 | }
203 | }
204 |
205 | /**Shows the dialog after the delay specified in milliseconds.
206 | * - If you set this value and called [dismiss] before the [showDelay] has elapsed,
207 | * the dialog won't be shown.
208 | * - The countdown starts after calling [show]*/
209 | public fun setShowDelay(showDelay: Long) {
210 | this.showDelay = showDelay
211 | setShowTimer()
212 | }
213 |
214 | /**Dismisses the dialog after the delay specified in milliseconds.
215 | * - If you set this value and called [dismiss], the dialog won't be dismissed until
216 | * the [dismissDelay] has elapsed.
217 | * - If a [showDelay] has been set, [dismissDelay] timer starts after [showDelay] has finished.
218 | * - The countdown starts after calling [show].*/
219 | public fun setDismissDelay(dismissDelay: Long) {
220 | if (showDelay == 0L)
221 | this.dismissDelay = dismissDelay
222 | else
223 | this.dismissDelay = dismissDelay + showDelay
224 | setDismissTimer()
225 | }
226 |
227 | /** Shows the dialog.
228 | * If a [showDelay] has been set, the dialog isn't shown and the [showTimer] starts.*/
229 | public fun show() {
230 | val fragmentManager = (context as? FragmentActivity)?.supportFragmentManager ?: return
231 | val existing = fragmentManager.findFragmentByTag(TAG) as? DialogFragment
232 | existing?.dismissAllowingStateLoss() // Remove if already shown
233 |
234 | if (showDelay == 0L) {
235 | try {
236 | show(fragmentManager, TAG)
237 | } catch (e: IllegalStateException) {
238 | Log.e(TAG, "show: FragmentManager has been destroyed", e)
239 | }
240 | } else {
241 | showCalled = true
242 | showTimer?.start()
243 | }
244 | }
245 |
246 | /** Dismisses the dialog.
247 | * If a [dismissDelay] has been set, the dialog doesn't get dismissed and the [dismissTimer] starts.*/
248 | override fun dismiss() {
249 | if (dismissDelay == 0L) {
250 | try {
251 | showTimer?.cancel()
252 | dismissTimer?.cancel()
253 | super.dismiss()
254 | } catch (e: IllegalStateException) {
255 | Log.e(TAG, "dismiss: not associated with a fragment manager", e)
256 | }
257 | } else {
258 | dismissCalled = true
259 | dismissTimer?.start()
260 | }
261 | }
262 |
263 | private fun setShowTimer() {
264 | showTimer = object : CountDownTimer(showDelay, 1000) {
265 | override fun onTick(millisUntilFinished: Long) {
266 | Log.i(TAG, "Showing dialog in $millisUntilFinished...")
267 | }
268 |
269 | override fun onFinish() {
270 | showDelay = 0L
271 | if (!dismissCalled) show()
272 | }
273 | }
274 | }
275 |
276 | private fun setDismissTimer() {
277 | dismissTimer = object : CountDownTimer(dismissDelay, 1000) {
278 | override fun onTick(millisUntilFinished: Long) {
279 | Log.i(TAG, "Dismissing dialog in $millisUntilFinished...")
280 | }
281 |
282 | override fun onFinish() {
283 | dismissDelay = 0L
284 | dismiss()
285 | }
286 | }
287 | }
288 |
289 | override fun onSaveInstanceState(outState: Bundle) {
290 | super.onSaveInstanceState(outState)
291 | outState.putString(ARG_TITLE, title)
292 | outState.putString(ARG_MESSAGE, message)
293 | outState.putInt(ARG_PROGRESS, progress)
294 | outState.putSerializable(ARG_PROGRESS_STYLE, progressStyle)
295 | outState.putBoolean(ARG_IS_INDETERMINATE, isIndeterminate)
296 | outState.putBoolean(ARG_IS_LINEAR_INDETERMINATE, isLinearIndeterminate)
297 | outState.putBoolean(ARG_IS_CIRCULAR_INDETERMINATE, isCircularIndeterminate)
298 | }
299 |
300 | companion object {
301 | private const val TAG = "PleaseWaitDialog"
302 | private const val ARG_TITLE = "title"
303 | private const val ARG_MESSAGE = "message"
304 | private const val ARG_PROGRESS = "progress"
305 | private const val ARG_PROGRESS_STYLE = "progressStyle"
306 | private const val ARG_IS_INDETERMINATE = "isIndeterminate"
307 | private const val ARG_IS_LINEAR_INDETERMINATE = "isLinearIndeterminate"
308 | private const val ARG_IS_CIRCULAR_INDETERMINATE = "isCircularIndeterminate"
309 | }
310 |
311 | /** Determines the style of the progress bar shown */
312 | public object ProgressStyle {
313 | /**Shows only the circular progress bar*/
314 | const val CIRCULAR = 0
315 | /**Shows only the linear progress bar*/
316 | const val LINEAR = 1
317 | /**Shows both circular and linear progress bars*/
318 | const val BOTH = 2
319 | /**Hides both progress bars and shows only the title and message texts*/
320 | const val NONE = 3
321 | }
322 |
323 | }
--------------------------------------------------------------------------------