Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1st Activity Intent
- int delay = 10;
- int maxBarValue = 6000;
- showDialog(3);
- in = new Intent(Home.this, CreateMessage.class);
- startActivity(in);
- //Dialog's Code
- protected Dialog onCreateDialog(int id) {
- switch (id) {
- case 3:
- progDialog = new ProgressDialog(Home.this);
- progDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
- progDialog.setMessage("Loading...");
- progThread = new ProgressThread(handler);
- progThread.start();
- return progDialog;
- }
- return null;
- }
- final Handler handler = new Handler() {
- public void handleMessage(Message msg) {
- int total = msg.getData().getInt("total");
- progDialog.setProgress(total);
- if (total <= 0) {
- //dismissDialog(typeBar);
- progDialog.cancel();
- progThread.setState(ProgressThread.DONE);
- }
- }
- };
- private class ProgressThread extends Thread {
- final static int DONE = 0;
- final static int RUNNING = 1;
- Handler mHandler;
- int mState;
- int total;
- ProgressThread(Handler h) {
- mHandler = h;
- }
- @Override
- public void run() {
- mState = RUNNING;
- total = maxBarValue;
- while (mState == RUNNING) {
- try {
- Thread.sleep(delay);
- } catch (InterruptedException e) {
- Log.e("ERROR", "Thread was Interrupted");
- }
- Message msg = mHandler.obtainMessage();
- Bundle b = new Bundle();
- b.putInt("total", total);
- msg.setData(b);
- mHandler.sendMessage(msg);
- total--;
- }
- }
- public void setState(int state) {
- mState = state;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement