Friday, August 8, 2014

Android Dialog With timeout

This would be good for you


package com.sanghwa.nettychatting.dialog;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Handler;

public class CustomDialog {

static ProgressDialog pDialog =  null;

static int TIME_OUT =  5000;

static Handler handler = new Handler();

public static void showCustomDialog(Activity context){
if(pDialog == null){
pDialog  = new ProgressDialog(context);
pDialog.setCancelable(false);
pDialog.setMessage("loading..");
}

if(pDialog.isShowing()){
return;
}

pDialog.show();
handler.postDelayed(new Runnable() {

@Override
public void run() {
if(pDialog.isShowing()){
pDialog.dismiss();
}
}
}, TIME_OUT);


}

public static void close(){
if(pDialog == null){
return;
}
handler.postDelayed(new Runnable() {

@Override
public void run() {
if(pDialog.isShowing()){
pDialog.dismiss();
}
}
}, 0);
}
}

No comments:

Post a Comment