Created
October 1, 2012 09:13
-
-
Save comuttun/3810485 to your computer and use it in GitHub Desktop.
Delayed Progress Dialog
This file contains 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
import java.util.Timer; | |
import java.util.TimerTask; | |
import android.app.Activity; | |
import android.app.ProgressDialog; | |
/** | |
* 一定時間後に表示する {@link ProgressDialog} です | |
* @author skomatsu | |
* | |
*/ | |
public class DelayedProgressDialog { | |
/** アクティビティ */ | |
private Activity activity; | |
/** タイマ {@link Timer} */ | |
private Timer timer; | |
/** {@link ProgressDialog} */ | |
private ProgressDialog dialog; | |
/** | |
* コンストラクタ | |
* | |
* @param activity アクティビティ {@link Activity} | |
*/ | |
public DelayedProgressDialog(Activity activity) { | |
this.activity = activity; | |
timer = new Timer(true); | |
dialog = new ProgressDialog(activity); | |
} | |
/** | |
* {@link ProgressDialog} で表示するメッセージを設定します | |
* @param message 表示するメッセージ | |
*/ | |
public void setMessage(CharSequence message) { | |
dialog.setMessage(message); | |
} | |
/** | |
* {@link ProgressDialog} の indeterminate を設定します | |
* @param indeterminate true/false | |
*/ | |
public void setIndeterminate(boolean indeterminate) { | |
dialog.setIndeterminate(indeterminate); | |
} | |
/** | |
* {@link ProgressDialog} がキャンセル可能かどうかを設定します | |
* @param cancelable キャンセル可能にする場合 true | |
*/ | |
public void setCancellable(boolean cancelable) { | |
dialog.setCancelable(cancelable); | |
} | |
/** | |
* {@link ProgressDialog} のスタイルを設定します | |
* @param style スタイル | |
*/ | |
public void setProgressStyle(int style) { | |
dialog.setProgressStyle(style); | |
} | |
/** | |
* {@link ProgressDialog} を表示します | |
* @param delayInMillis 表示する遅延時間 (ms) | |
*/ | |
public void show(long delayInMillis) { | |
timer.schedule(new TimerTask() { | |
@Override | |
public void run() { | |
activity.runOnUiThread(new Runnable() { | |
@Override | |
public void run() { | |
dialog.show(); | |
} | |
}); | |
} | |
}, delayInMillis); | |
} | |
/** | |
* {@link ProgressDialog} を閉じます | |
*/ | |
public void dismiss() { | |
timer.purge(); | |
timer.cancel(); | |
dialog.dismiss(); | |
} | |
/** | |
* {@link ProgressDialog} を閉じます | |
*/ | |
public void cancel() { | |
timer.purge(); | |
timer.cancel(); | |
dialog.cancel(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment