Created
March 29, 2019 11:47
-
-
Save coolnikhilmaurya/a88e8c4c0d8e3d76f14ad356a4632c09 to your computer and use it in GitHub Desktop.
A simple singletons kotlin class containing methods for displaying and hiding ProgressBar with fullscreen transparent background
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package `in`.test.app.util | |
import android.app.AlertDialog | |
import android.content.Context | |
import android.graphics.Color | |
import android.graphics.drawable.ColorDrawable | |
import android.util.Log | |
import android.view.Window | |
import android.widget.ProgressBar | |
object ProgressUtil{ | |
private lateinit var dialogBuilder:AlertDialog.Builder | |
private lateinit var alertDialog: AlertDialog | |
private lateinit var pDialog: ProgressBar | |
fun showLoadind(ctx:Context){ | |
// instantiating the lateint objects | |
dialogBuilder= AlertDialog.Builder(ctx) | |
pDialog= ProgressBar(ctx) | |
// setting up the dialog | |
dialogBuilder.setCancelable(false) | |
dialogBuilder.setView(pDialog) | |
alertDialog=dialogBuilder.create() | |
// magic of transparent background goes here | |
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); | |
// setting the alertDialog's BackgroundDrawable as the color resource of any color with 1% opacity | |
alertDialog.getWindow()?.setBackgroundDrawable(ColorDrawable(Color.parseColor("#00141414"))) | |
// finally displaying the Alertdialog containging the ProgressBar | |
alertDialog.show() | |
} | |
fun hideLoading(){ | |
try { | |
if(alertDialog.isShowing){ | |
alertDialog.dismiss() | |
} | |
} catch (e: UninitializedPropertyAccessException) { | |
// Log.d("TAG","AlertDialog UninitializedPropertyAccessException") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment