Example usage for android.app ProgressDialog ProgressDialog

List of usage examples for android.app ProgressDialog ProgressDialog

Introduction

In this page you can find the example usage for android.app ProgressDialog ProgressDialog.

Prototype

public ProgressDialog(Context context) 

Source Link

Document

Creates a Progress dialog.

Usage

From source file:fm.smart.r1.ItemActivity.java

public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // this should be called once image has been chosen by user
    // using requestCode to pass item id - haven't worked out any other way
    // to do it//from  w w  w  .  j  a v a2  s. c  om
    // if (requestCode == SELECT_IMAGE)
    if (resultCode == Activity.RESULT_OK) {
        // TODO check if user is logged in
        if (LoginActivity.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            // avoid navigation back to this?
            LoginActivity.return_to = ItemActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("item_id", (String) item.getId());
            startActivity(intent);
            // TODO in this case forcing the user to rechoose the image
            // seems a little
            // rude - should probably auto-submit here ...
        } else {
            // Bundle extras = data.getExtras();
            // String sentence_id = (String) extras.get("sentence_id");
            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Uploading image ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread add_image = new Thread() {
                public void run() {
                    // TODO needs to check for interruptibility

                    String sentence_id = Integer.toString(requestCode);
                    Uri selectedImage = data.getData();
                    // Bitmap bitmap = Media.getBitmap(getContentResolver(),
                    // selectedImage);
                    // ByteArrayOutputStream bytes = new
                    // ByteArrayOutputStream();
                    // bitmap.compress(Bitmap.CompressFormat.JPEG, 40,
                    // bytes);
                    // ByteArrayInputStream fileInputStream = new
                    // ByteArrayInputStream(
                    // bytes.toByteArray());

                    // TODO Might have to save to file system first to get
                    // this
                    // to work,
                    // argh!
                    // could think of it as saving to cache ...

                    // add image to sentence
                    FileInputStream is = null;
                    FileOutputStream os = null;
                    File file = null;
                    ContentResolver resolver = getContentResolver();
                    try {
                        Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage);
                        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
                        // ByteArrayInputStream bais = new
                        // ByteArrayInputStream(bytes.toByteArray());

                        // FileDescriptor fd =
                        // resolver.openFileDescriptor(selectedImage,
                        // "r").getFileDescriptor();
                        // is = new FileInputStream(fd);

                        String filename = "test.jpg";
                        File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE);
                        file = new File(dir, filename);
                        os = new FileOutputStream(file);

                        // while (bais.available() > 0) {
                        // / os.write(bais.read());
                        // }
                        os.write(bytes.toByteArray());

                        os.close();

                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (os != null) {
                            try {
                                os.close();
                            } catch (IOException e) {
                            }
                        }
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }

                    // File file = new
                    // File(Uri.decode(selectedImage.toString()));

                    // ensure item is in users default list

                    ItemActivity.add_item_result = new AddItemResult(Main.lookup.addItemToGoal(Main.transport,
                            Main.default_study_goal_id, item.getId(), null));

                    Result result = ItemActivity.add_item_result;

                    if (ItemActivity.add_item_result.success()
                            || ItemActivity.add_item_result.alreadyInList()) {

                        // ensure sentence is in users default goal

                        ItemActivity.add_sentence_goal_result = new AddSentenceResult(
                                Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id,
                                        item.getId(), sentence_id, null));

                        result = ItemActivity.add_sentence_goal_result;
                        if (ItemActivity.add_sentence_goal_result.success()) {

                            String media_entity = "http://test.com/test.jpg";
                            String author = "tansaku";
                            String author_url = "http://smart.fm/users/tansaku";
                            Log.d("DEBUG-IMAGE-URI", selectedImage.toString());
                            ItemActivity.add_image_result = addImage(file, media_entity, author, author_url,
                                    "1", sentence_id, (String) item.getId(), Main.default_study_goal_id);
                            result = ItemActivity.add_image_result;
                        }
                    }
                    final Result display = result;
                    myOtherProgressDialog.dismiss();
                    ItemActivity.this.runOnUiThread(new Thread() {
                        public void run() {
                            final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create();
                            dialog.setTitle(display.getTitle());
                            dialog.setMessage(display.getMessage());
                            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    if (ItemActivity.add_image_result != null
                                            && ItemActivity.add_image_result.success()) {
                                        ItemListActivity.loadItem(ItemActivity.this, item.getId().toString());
                                    }
                                }
                            });

                            dialog.show();
                        }
                    });

                }

            };

            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    add_image.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    add_image.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            closeMenu();
            myOtherProgressDialog.show();
            add_image.start();

        }
    }
}

From source file:com.easemob.chatuidemo.activity.ContactlistFragment.java

/**
 * user???/*from   w  ww . j  a  v  a 2  s .  c  o  m*/
 */
private void moveToBlacklist(final String username) {
    final ProgressDialog pd = new ProgressDialog(getActivity());
    String st1 = getResources().getString(R.string.Is_moved_into_blacklist);
    final String st2 = getResources().getString(R.string.Move_into_blacklist_success);
    final String st3 = getResources().getString(R.string.Move_into_blacklist_failure);
    pd.setMessage(st1);
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    new Thread(new Runnable() {
        public void run() {
            try {
                //???
                EMContactManager.getInstance().addUserToBlackList(username, false);
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getActivity(), st2, Toast.LENGTH_SHORT).show();
                        refresh();
                    }
                });
            } catch (EaseMobException e) {
                e.printStackTrace();
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getActivity(), st3, Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
    }).start();

}

From source file:com.arantius.tivocommander.SeasonPass.java

public void reorderApply(View unusedView) {
    Utils.log("SeasonPass::reorderApply() " + Boolean.toString(mInReorderMode));

    boolean noChange = true;
    ArrayList<String> subIds = new ArrayList<String>();
    for (int i = 0; i < mSubscriptionIds.size(); i++) {
        if (mSubscriptionIds.get(i) != mSubscriptionIdsBeforeReorder.get(i)) {
            noChange = false;/*from   ww w  . ja  va2s.co m*/
        }
        subIds.add(mSubscriptionData.get(i).path("subscriptionId").asText());
    }

    final ProgressDialog d = new ProgressDialog(this);
    final MindRpcResponseListener onReorderComplete = new MindRpcResponseListener() {
        public void onResponse(MindRpcResponse response) {
            if (d.isShowing()) {
                d.dismiss();
            }

            // Flip the buttons.
            findViewById(R.id.reorder_enable).setVisibility(View.VISIBLE);
            findViewById(R.id.reorder_apply).setVisibility(View.GONE);
            // Turn off the drag handles.
            mInReorderMode = false;
            mListAdapter.notifyDataSetChanged();
        }
    };

    if (noChange) {
        // If there was no change, switch the UI back immediately.
        onReorderComplete.onResponse(null);
    } else {
        // Otherwise show a dialog while we do the RPC.
        d.setIndeterminate(true);
        d.setTitle("Saving ...");
        d.setMessage("Saving new season pass order.  " + "Patience please, this takes a while.");
        d.setCancelable(false);
        d.show();

        SubscriptionsReprioritize req = new SubscriptionsReprioritize(subIds);
        MindRpc.addRequest(req, onReorderComplete);
    }
}

From source file:com.andrewshu.android.reddit.reddits.PickSubredditActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;/*  w  ww .  ja va 2s  .c  o  m*/
    ProgressDialog pdialog;

    switch (id) {
    // "Please wait"
    case Constants.DIALOG_LOADING_REDDITS_LIST:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Loading your reddits...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:com.zia.freshdocs.widget.CMISAdapter.java

protected void startProgressDlg(boolean indeterminate) {
    Context context = getContext();
    Resources res = context.getResources();

    if (_progressDlg == null || !_progressDlg.isShowing()) {
        _progressDlg = new ProgressDialog(context);
        _progressDlg.setProgressStyle(/*ww w  .  j  a v a  2s .  co  m*/
                indeterminate ? ProgressDialog.STYLE_SPINNER : ProgressDialog.STYLE_HORIZONTAL);
        _progressDlg.setMessage(res.getString(R.string.loading));
        _progressDlg.setTitle("");
        _progressDlg.setCancelable(true);
        _progressDlg.setIndeterminate(indeterminate);
        _progressDlg.setOnCancelListener(new OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                interrupt();
            }
        });
        _progressDlg.show();
    }
}

From source file:bizapps.com.healthforusPatient.activity.RegisterActivity.java

public void displayProgress() {
    if (progressDialog == null) {
        progressDialog = new ProgressDialog(this);
        progressDialog.getWindow().addFlags(Window.FEATURE_NO_TITLE);
        progressDialog.setMessage("Loading wait...");
    }//from  w  w w. j  a v  a  2  s  . c o  m

    if (!progressDialog.isShowing()) {
        progressDialog.show();
    }
}

From source file:cn.kangeqiu.kq.activity.GroupDetailsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    shareUtil.ssoResult(requestCode, resultCode, data);
    String st1 = getResources().getString(R.string.being_added);
    String st2 = getResources().getString(R.string.is_quit_the_group_chat);
    String st3 = getResources().getString(R.string.chatting_is_dissolution);
    String st4 = getResources().getString(R.string.are_empty_group_of_news);
    String st5 = getResources().getString(R.string.is_modify_the_group_name);
    final String st6 = getResources().getString(R.string.Modify_the_group_name_successful);
    final String st7 = getResources().getString(R.string.change_the_group_name_failed_please);
    String st8 = getResources().getString(R.string.Are_moving_to_blacklist);
    final String st9 = getResources().getString(R.string.failed_to_move_into);

    final String stsuccess = getResources().getString(R.string.Move_into_blacklist_success);
    if (resultCode == RESULT_OK) {
        if (progressDialog == null) {
            progressDialog = new ProgressDialog(GroupDetailsActivity.this);
            progressDialog.setMessage(st1);
            progressDialog.setCanceledOnTouchOutside(false);
        }//from   www .  jav a2s  . c om
        switch (requestCode) {
        case REQUEST_CODE_ADD_USER:// ?
            // final String[] newmembers = data
            // .getStringArrayExtra("newmembers");
            newIds = data.getStringExtra("id");
            progressDialog.setMessage(st1);
            progressDialog.show();
            addMembersToGroup();
            break;
        case REQUEST_CODE_EXIT: // 
            progressDialog.setMessage(st2);
            progressDialog.show();
            exitGrop();
            break;
        case REQUEST_CODE_EXIT_DELETE: // 
            progressDialog.setMessage(st3);
            progressDialog.show();
            deleteGrop();
            break;
        case REQUEST_CODE_CLEAR_ALL_HISTORY:
            // ??
            progressDialog.setMessage(st4);
            progressDialog.show();
            clearGroupHistory();
            break;

        case REQUEST_CODE_EDIT_GROUPNAME: // ??
            final String returnData = data.getStringExtra("data");
            hourse_name.setText(returnData);
            Toast.makeText(getApplicationContext(), st6, 0).show();
            // ((TextView) findViewById(R.id.group_name)).setText(returnData
            // + "("
            // + group.getAffiliationsCount()
            // + st);

            // if (!TextUtils.isEmpty(returnData)) {
            // progressDialog.setMessage(st5);
            // progressDialog.show();
            //
            // new Thread(new Runnable() {
            // public void run() {
            // try {
            // EMGroupManager.getInstance().changeGroupName(
            // groupId, returnData);
            // runOnUiThread(new Runnable() {
            // public void run() {
            // ((TextView) findViewById(R.id.group_name)).setText(returnData
            // + "("
            // + group.getAffiliationsCount()
            // + st);
            // progressDialog.dismiss();
            // Toast.makeText(getApplicationContext(),
            // st6, 0).show();
            // }
            // });
            //
            // } catch (EaseMobException e) {
            // e.printStackTrace();
            // runOnUiThread(new Runnable() {
            // public void run() {
            // progressDialog.dismiss();
            // Toast.makeText(getApplicationContext(),
            // st7, 0).show();
            // }
            // });
            // }
            // }
            // }).start();
            // }
            break;
        case REQUEST_CODE_ADD_TO_BALCKLIST:
            progressDialog.setMessage(st8);
            progressDialog.show();
            new Thread(new Runnable() {
                public void run() {
                    try {
                        EMGroupManager.getInstance().blockUser(groupId, longClickUsername);
                        runOnUiThread(new Runnable() {
                            public void run() {
                                refreshMembers();
                                progressDialog.dismiss();
                                Toast.makeText(getApplicationContext(), stsuccess, 0).show();
                            }
                        });
                    } catch (EaseMobException e) {
                        runOnUiThread(new Runnable() {
                            public void run() {
                                progressDialog.dismiss();
                                Toast.makeText(getApplicationContext(), st9, 0).show();
                            }
                        });
                    }
                }
            }).start();

            break;
        default:
            break;
        }
    } else if (resultCode == 30) {
        try {
            final JSONObject jsonMatch = new JSONObject(data.getStringExtra("match"));
            matchId = jsonMatch.getString("id");
            CPorgressDialog.showProgressDialog(GroupDetailsActivity.this);
            doPullDate(false, "2053", new MCHttpCallBack() {
                @Override
                public void onSuccess(MCHttpResp resp) {
                    super.onSuccess(resp);
                    CPorgressDialog.hideProgressDialog();
                    try {
                        String resultCode = resp.getJson().getString("result_code");
                        if (resultCode.equals("0")) {
                            match_name.setText(jsonMatch.getJSONObject("team1").getString("name") + "VS"
                                    + jsonMatch.getJSONObject("team2").getString("name"));
                        } else {
                            Toast.makeText(GroupDetailsActivity.this, resp.getJson().getString("message"),
                                    Toast.LENGTH_SHORT).show();
                        }
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }

                @Override
                public void onError(MCHttpResp resp) {
                    super.onError(resp);
                    CPorgressDialog.hideProgressDialog();
                }
            });
        } catch (Exception e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

    }
}

From source file:info.guardianproject.otr.app.im.app.WelcomeActivity.java

private void completeShutdown() {
    new AsyncTask<String, Void, String>() {

        private ProgressDialog dialog;

        @Override/*from   w ww. j  a va2 s.co  m*/
        protected void onPreExecute() {
            if (mApp.getActiveConnections().size() > 0) {
                dialog = new ProgressDialog(WelcomeActivity.this);
                dialog.setCancelable(true);
                dialog.setMessage(getString(R.string.signing_out_wait));
                dialog.show();
            }
        }

        @Override
        protected String doInBackground(String... params) {

            boolean stillConnected = true;

            while (stillConnected) {

                try {
                    IImConnection conn = mApp.getActiveConnections().iterator().next();

                    if (conn.getState() == ImConnection.DISCONNECTED
                            || conn.getState() == ImConnection.LOGGING_OUT) {
                        stillConnected = false;
                    } else {
                        conn.logout();
                        stillConnected = true;
                    }

                    Thread.sleep(500);
                } catch (Exception e) {
                }

            }

            return "";
        }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);

            if (dialog != null)
                dialog.dismiss();

            mApp.forceStopImService();

            Imps.clearPassphrase(mApp);

            if (mCacheWord != null) {
                mCacheWord.manuallyLock();
            }

            Intent cacheWordIntent = CacheWordService.getBlankServiceIntent(getApplicationContext());
            stopService(cacheWordIntent);
            finish();
        }
    }.execute();

}

From source file:com.gimranov.zandy.app.ItemActivity.java

protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_NEW:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getResources().getString(R.string.item_type))
                // XXX i18n
                .setItems(Item.ITEM_TYPES_EN, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int pos) {
                        Item item = new Item(getBaseContext(), Item.ITEM_TYPES[pos]);
                        item.dirty = APIRequest.API_DIRTY;
                        item.save(db);/* w ww.j a v  a  2s. c o  m*/
                        if (collectionKey != null) {
                            ItemCollection coll = ItemCollection.load(collectionKey, db);
                            if (coll != null) {
                                coll.loadChildren(db);
                                coll.add(item);
                                coll.saveChildren(db);
                            }
                        }
                        Log.d(TAG, "Loading item data with key: " + item.getKey());
                        // We create and issue a specified intent with the necessary data
                        Intent i = new Intent(getBaseContext(), ItemDataActivity.class);
                        i.putExtra("com.gimranov.zandy.app.itemKey", item.getKey());
                        startActivity(i);
                    }
                });
        AlertDialog dialog = builder.create();
        return dialog;
    case DIALOG_SORT:

        // We generate the sort name list for our current locale
        String[] sorts = new String[SORT_NAMES.length];
        for (int j = 0; j < SORT_NAMES.length; j++) {
            sorts[j] = getResources().getString(SORT_NAMES[j]);
        }

        AlertDialog.Builder builder2 = new AlertDialog.Builder(this);
        builder2.setTitle(getResources().getString(R.string.set_sort_order)).setItems(sorts,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int pos) {
                        Cursor cursor;
                        setSortBy(SORTS[pos]);
                        ItemCollection collection;
                        if (collectionKey != null
                                && (collection = ItemCollection.load(collectionKey, db)) != null) {
                            cursor = getCursor(collection);
                        } else {
                            if (query != null) {
                                cursor = getCursor(query);
                            } else {
                                cursor = getCursor();
                            }
                        }
                        ItemAdapter adapter = (ItemAdapter) getListAdapter();
                        adapter.changeCursor(cursor);
                        Log.d(TAG, "Re-sorting by: " + SORTS[pos]);

                        Persistence.write(SORT_CHOICE, SORTS[pos]);
                    }
                });
        AlertDialog dialog2 = builder2.create();
        return dialog2;
    case DIALOG_PROGRESS:
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        mProgressDialog.setIndeterminate(true);
        mProgressDialog.setMessage(getResources().getString(R.string.identifier_looking_up));
        return mProgressDialog;
    case DIALOG_IDENTIFIER:
        final EditText input = new EditText(this);
        input.setHint(getResources().getString(R.string.identifier_hint));

        final ItemActivity current = this;

        dialog = new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.identifier_message))
                .setView(input).setPositiveButton(getResources().getString(R.string.menu_search),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                Editable value = input.getText();
                                // run search
                                Bundle c = new Bundle();
                                c.putString("mode", "isbn");
                                c.putString("identifier", value.toString());
                                removeDialog(DIALOG_PROGRESS);
                                ItemActivity.this.b = c;
                                showDialog(DIALOG_PROGRESS);
                            }
                        })
                .setNeutralButton(getResources().getString(R.string.scan),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // If we're about to download from Google play, cancel that dialog
                                // and prompt from Amazon if we're on an Amazon device
                                IntentIntegrator integrator = new IntentIntegrator(current);
                                @Nullable
                                AlertDialog producedDialog = integrator.initiateScan();
                                if (producedDialog != null && "amazon".equals(BuildConfig.FLAVOR)) {
                                    producedDialog.dismiss();
                                    AmazonZxingGlue.showDownloadDialog(current);
                                }
                            }
                        })
                .setNegativeButton(getResources().getString(R.string.cancel),
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int whichButton) {
                                // do nothing
                            }
                        })
                .create();
        return dialog;
    default:
        return null;
    }
}