Example usage for android.app ProgressDialog setIndeterminate

List of usage examples for android.app ProgressDialog setIndeterminate

Introduction

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

Prototype

public void setIndeterminate(boolean indeterminate) 

Source Link

Document

Change the indeterminate mode for this ProgressDialog.

Usage

From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java

/** Called when the activity is first created. */
@Override/*from  w  w w.  j a va  2  s .c o m*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_unifiednav);

    detectedAPs = (TextView) findViewById(R.id.detectedAPs);
    textFloor = (TextView) findViewById(R.id.textFloor);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    textDebug = (TextView) findViewById(R.id.textDebug);
    if (AnyplaceAPI.DEBUG_MESSAGES)
        textDebug.setVisibility(View.VISIBLE);

    ActionBar actionBar = getSupportActionBar();
    actionBar.setHomeButtonEnabled(true);

    userData = new AnyUserData();

    SimpleWifiManager.getInstance().startScan();
    sensorsMain = new SensorsMain(getApplicationContext());
    movementDetector = new MovementDetector();
    sensorsMain.addListener(movementDetector);
    sensorsStepCounter = new SensorsStepCounter(getApplicationContext(), sensorsMain);
    lpTracker = new TrackerLogicPlusIMU(movementDetector, sensorsMain, sensorsStepCounter);
    // lpTracker = new TrackerLogic(sensorsMain);
    floorSelector = new Algo1Radiomap(getApplicationContext());

    mAnyplaceCache = AnyplaceCache.getInstance(this);
    visiblePois = new VisiblePois();

    setUpMapIfNeeded();

    // setup the trackme button overlaid in the map
    btnTrackme = (ImageButton) findViewById(R.id.btnTrackme);
    btnTrackme.setImageResource(R.drawable.dark_device_access_location_off);
    isTrackingErrorBackground = true;
    btnTrackme.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final GeoPoint gpsLoc = userData.getLocationGPSorIP();
            if (gpsLoc != null) {
                AnyplaceCache mAnyplaceCache = AnyplaceCache.getInstance(UnifiedNavigationActivity.this);
                mAnyplaceCache.loadWorldBuildings(new FetchBuildingsTaskListener() {

                    @Override
                    public void onSuccess(String result, List<BuildingModel> buildings) {
                        final FetchNearBuildingsTask nearest = new FetchNearBuildingsTask();
                        nearest.run(buildings, gpsLoc.lat, gpsLoc.lng, 200);

                        if (nearest.buildings.size() > 0 && (userData.getSelectedBuildingId() == null
                                || !userData.getSelectedBuildingId().equals(nearest.buildings.get(0).buid))) {
                            floorSelector.Stop();
                            final FloorSelector floorSelectorAlgo1 = new Algo1Server(getApplicationContext());
                            final ProgressDialog floorSelectorDialog = new ProgressDialog(
                                    UnifiedNavigationActivity.this);

                            floorSelectorDialog.setIndeterminate(true);
                            floorSelectorDialog.setTitle("Detecting floor");
                            floorSelectorDialog.setMessage("Please be patient...");
                            floorSelectorDialog.setCancelable(true);
                            floorSelectorDialog.setCanceledOnTouchOutside(false);
                            floorSelectorDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                                @Override
                                public void onCancel(DialogInterface dialog) {
                                    floorSelectorAlgo1.Destoy();
                                    bypassSelectBuildingActivity(nearest.buildings.get(0), "0", false);
                                }
                            });

                            class Callback implements ErrorAnyplaceFloorListener, FloorAnyplaceFloorListener {

                                @Override
                                public void onNewFloor(String floor) {
                                    floorSelectorAlgo1.Destoy();
                                    if (floorSelectorDialog.isShowing()) {
                                        floorSelectorDialog.dismiss();
                                        bypassSelectBuildingActivity(nearest.buildings.get(0), floor, false);
                                    }
                                }

                                @Override
                                public void onFloorError(Exception ex) {
                                    floorSelectorAlgo1.Destoy();
                                    if (floorSelectorDialog.isShowing()) {
                                        floorSelectorDialog.dismiss();
                                        bypassSelectBuildingActivity(nearest.buildings.get(0), "0", false);
                                    }
                                }

                            }
                            Callback callback = new Callback();
                            floorSelectorAlgo1.addListener((FloorAnyplaceFloorListener) callback);
                            floorSelectorAlgo1.addListener((ErrorAnyplaceFloorListener) callback);

                            // Show Dialog
                            floorSelectorDialog.show();
                            floorSelectorAlgo1.Start(gpsLoc.lat, gpsLoc.lng);
                        } else {
                            focusUserLocation();

                            // Clear cancel request
                            lastFloor = null;
                            floorSelector.RunNow();
                            lpTracker.reset();
                        }
                    }

                    @Override
                    public void onErrorOrCancel(String result) {

                    }

                }, UnifiedNavigationActivity.this, false);
            } else {
                focusUserLocation();

                // Clear cancel request
                lastFloor = null;
                floorSelector.RunNow();
                lpTracker.reset();
            }

        }
    });

    btnFloorUp = (ImageButton) findViewById(R.id.btnFloorUp);
    btnFloorUp.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            if (!userData.isFloorSelected()) {
                Toast.makeText(getBaseContext(), "Load a map before tracking can be used!", Toast.LENGTH_SHORT)
                        .show();
                return;
            }

            BuildingModel b = userData.getSelectedBuilding();
            if (b == null) {
                return;
            }

            if (userData.isNavBuildingSelected()) {
                // Move to start/destination poi's floor
                String floor_number;
                List<PoisNav> puids = userData.getNavPois();
                // Check start and destination floor number
                if (!puids.get(puids.size() - 1).floor_number.equals(puids.get(0).floor_number)) {
                    if (userData.getSelectedFloorNumber().equals(puids.get(puids.size() - 1).floor_number)) {
                        floor_number = puids.get(0).floor_number;
                    } else {
                        floor_number = puids.get(puids.size() - 1).floor_number;
                    }

                    FloorModel floor = b.getFloorFromNumber(floor_number);
                    if (floor != null) {
                        bypassSelectBuildingActivity(b, floor);
                        return;
                    }
                }
            }

            // Move one floor up
            int index = b.getSelectedFloorIndex();

            if (b.checkIndex(index + 1)) {
                bypassSelectBuildingActivity(b, b.getFloors().get(index + 1));
            }

        }
    });

    btnFloorDown = (ImageButton) findViewById(R.id.btnFloorDown);
    btnFloorDown.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!userData.isFloorSelected()) {
                Toast.makeText(getBaseContext(), "Load a map before tracking can be used!", Toast.LENGTH_SHORT)
                        .show();
                return;
            }

            BuildingModel b = userData.getSelectedBuilding();
            if (b == null) {
                return;
            }

            if (userData.isNavBuildingSelected()) {
                // Move to start/destination poi's floor
                String floor_number;
                List<PoisNav> puids = userData.getNavPois();
                // Check start and destination floor number
                if (!puids.get(puids.size() - 1).floor_number.equals(puids.get(0).floor_number)) {
                    if (userData.getSelectedFloorNumber().equals(puids.get(puids.size() - 1).floor_number)) {
                        floor_number = puids.get(0).floor_number;
                    } else {
                        floor_number = puids.get(puids.size() - 1).floor_number;
                    }

                    FloorModel floor = b.getFloorFromNumber(floor_number);
                    if (floor != null) {
                        bypassSelectBuildingActivity(b, floor);
                        return;
                    }
                }
            }

            // Move one floor down
            int index = b.getSelectedFloorIndex();

            if (b.checkIndex(index - 1)) {
                bypassSelectBuildingActivity(b, b.getFloors().get(index - 1));
            }
        }

    });

    /*
     * Create a new location client, using the enclosing class to handle callbacks.
     */
    // Create the LocationRequest object
    mLocationRequest = LocationRequest.create();
    // Use high accuracy
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    // Set the update interval to 2 seconds
    mLocationRequest.setInterval(2000);
    // Set the fastest update interval to 1 second
    mLocationRequest.setFastestInterval(1000);
    mLocationClient = new LocationClient(this, this, this);
    // declare that this is the first time this Activity launched so make
    // the automatic building selection
    mAutomaticGPSBuildingSelection = true;

    // get/set settings
    PreferenceManager.setDefaultValues(this, SHARED_PREFS_ANYPLACE, MODE_PRIVATE, R.xml.preferences_anyplace,
            true);
    SharedPreferences preferences = getSharedPreferences(SHARED_PREFS_ANYPLACE, MODE_PRIVATE);
    preferences.registerOnSharedPreferenceChangeListener(this);
    lpTracker.setAlgorithm(preferences.getString("TrackingAlgorithm", "WKNN"));

    // handle the search intent
    handleIntent(getIntent());
}

From source file:in.shick.diode.mail.InboxListActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//  ww w.  ja va2 s.  c  o m
    ProgressDialog pdialog;
    switch (id) {
    case Constants.DIALOG_LOGIN:
        dialog = new LoginDialog(this, mSettings, true) {
            @Override
            public void onLoginChosen(String user, String password) {
                removeDialog(Constants.DIALOG_LOGIN);
                new MyLoginTask(user, password).execute();
            }
        };
        break;

    case Constants.DIALOG_REPLY:
        dialog = new Dialog(this, mSettings.getDialogTheme());
        dialog.setContentView(R.layout.compose_reply_dialog);
        final EditText replyBody = (EditText) dialog.findViewById(R.id.body);
        final Button replySaveButton = (Button) dialog.findViewById(R.id.reply_save_button);
        final Button replyCancelButton = (Button) dialog.findViewById(R.id.reply_cancel_button);
        replySaveButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (mReplyTargetName != null) {
                    new MessageReplyTask(mReplyTargetName).execute(replyBody.getText().toString());
                    removeDialog(Constants.DIALOG_REPLY);
                } else {
                    Common.showErrorToast("Error replying. Please try again.", Toast.LENGTH_SHORT,
                            InboxListActivity.this);
                }
            }
        });
        replyCancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                removeDialog(Constants.DIALOG_REPLY);
            }
        });
        break;
    // "Please wait"
    case Constants.DIALOG_LOGGING_IN:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Logging in...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_REPLYING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Sending reply...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;

    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:com.andrewshu.android.reddit.mail.InboxListActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//ww  w.  j  a  v  a  2 s  .co m
    ProgressDialog pdialog;
    AlertDialog.Builder builder;
    LayoutInflater inflater;
    View layout; // used for inflated views for AlertDialog.Builder.setView()

    switch (id) {
    case Constants.DIALOG_LOGIN:
        dialog = new LoginDialog(this, mSettings, true) {
            @Override
            public void onLoginChosen(String user, String password) {
                removeDialog(Constants.DIALOG_LOGIN);
                new MyLoginTask(user, password).execute();
            }
        };
        break;

    case Constants.DIALOG_REPLY:
        dialog = new Dialog(this, mSettings.getDialogTheme());
        dialog.setContentView(R.layout.compose_reply_dialog);
        final EditText replyBody = (EditText) dialog.findViewById(R.id.body);
        final Button replySaveButton = (Button) dialog.findViewById(R.id.reply_save_button);
        final Button replyCancelButton = (Button) dialog.findViewById(R.id.reply_cancel_button);
        replySaveButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (mReplyTargetName != null) {
                    new MessageReplyTask(mReplyTargetName).execute(replyBody.getText().toString());
                    removeDialog(Constants.DIALOG_REPLY);
                } else {
                    Common.showErrorToast("Error replying. Please try again.", Toast.LENGTH_SHORT,
                            InboxListActivity.this);
                }
            }
        });
        replyCancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                removeDialog(Constants.DIALOG_REPLY);
            }
        });
        break;
    // "Please wait"
    case Constants.DIALOG_LOGGING_IN:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Logging in...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_REPLYING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Sending reply...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;

    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:com.andrewshu.android.reddit.mail.InboxActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//from   ww w .  j a v  a 2s .  c o m
    ProgressDialog pdialog;
    AlertDialog.Builder builder;
    LayoutInflater inflater;
    View layout; // used for inflated views for AlertDialog.Builder.setView()

    switch (id) {
    case Constants.DIALOG_COMPOSE:
        inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        layout = inflater.inflate(R.layout.compose_dialog, null);
        dialog = builder.setView(layout).create();
        final Dialog composeDialog = dialog;

        Common.setTextColorFromTheme(mSettings.getTheme(), getResources(),
                (TextView) layout.findViewById(R.id.compose_destination_textview),
                (TextView) layout.findViewById(R.id.compose_subject_textview),
                (TextView) layout.findViewById(R.id.compose_message_textview),
                (TextView) layout.findViewById(R.id.compose_captcha_textview),
                (TextView) layout.findViewById(R.id.compose_captcha_loading));

        final EditText composeDestination = (EditText) layout.findViewById(R.id.compose_destination_input);
        final EditText composeSubject = (EditText) layout.findViewById(R.id.compose_subject_input);
        final EditText composeText = (EditText) layout.findViewById(R.id.compose_text_input);
        final Button composeSendButton = (Button) layout.findViewById(R.id.compose_send_button);
        final Button composeCancelButton = (Button) layout.findViewById(R.id.compose_cancel_button);
        final EditText composeCaptcha = (EditText) layout.findViewById(R.id.compose_captcha_input);
        composeSendButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                ThingInfo thingInfo = new ThingInfo();

                if (!FormValidation.validateComposeMessageInputFields(InboxActivity.this, composeDestination,
                        composeSubject, composeText, composeCaptcha))
                    return;

                thingInfo.setDest(composeDestination.getText().toString().trim());
                thingInfo.setSubject(composeSubject.getText().toString().trim());
                new MyMessageComposeTask(composeDialog, thingInfo, composeCaptcha.getText().toString().trim(),
                        mCaptchaIden, mSettings, mClient, InboxActivity.this)
                                .execute(composeText.getText().toString().trim());
                removeDialog(Constants.DIALOG_COMPOSE);
            }
        });
        composeCancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                removeDialog(Constants.DIALOG_COMPOSE);
            }
        });
        break;

    case Constants.DIALOG_COMPOSING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Composing message...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//from ww  w  . j a  v  a  2s.c o m
    ProgressDialog pdialog;
    AlertDialog.Builder builder;

    switch (id) {
    case Constants.DIALOG_LOGIN:
        dialog = new LoginDialog(this, mSettings, false) {
            public void onLoginChosen(String user, String password) {
                removeDialog(Constants.DIALOG_LOGIN);
                new MyLoginTask(user, password).execute();
            }
        };
        break;

    case Constants.DIALOG_THREAD_CLICK:
        dialog = new ThreadClickDialog(this, mSettings);
        break;

    case Constants.DIALOG_SORT_BY:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("Sort by:");
        builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_CHOICES, getSelectedSortBy(),
                sortByOnClickListener);
        dialog = builder.create();
        break;
    case Constants.DIALOG_SORT_BY_NEW:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("what's new");
        builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_NEW_CHOICES, getSelectedSortByNew(),
                sortByNewOnClickListener);
        dialog = builder.create();
        break;
    case Constants.DIALOG_SORT_BY_CONTROVERSIAL:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("most controversial");
        builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_CONTROVERSIAL_CHOICES,
                getSelectedSortByControversial(), sortByControversialOnClickListener);
        dialog = builder.create();
        break;
    case Constants.DIALOG_SORT_BY_TOP:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("top scoring");
        builder.setSingleChoiceItems(Constants.ThreadsSort.SORT_BY_TOP_CHOICES, getSelectedSortByTop(),
                sortByTopOnClickListener);
        dialog = builder.create();
        break;

    // "Please wait"
    case Constants.DIALOG_LOGGING_IN:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Logging in...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;

    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:com.andrewshu.android.reddit.user.ProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;/*  ww w.ja va  2  s. c o  m*/
    ProgressDialog pdialog;
    AlertDialog.Builder builder;
    LayoutInflater inflater;
    View layout; // used for inflated views for AlertDialog.Builder.setView()

    switch (id) {
    case Constants.DIALOG_LOGIN:
        dialog = new LoginDialog(this, mSettings, false) {
            @Override
            public void onLoginChosen(String user, String password) {
                removeDialog(Constants.DIALOG_LOGIN);
                new MyLoginTask(user, password).execute();
            }
        };
        break;

    case Constants.DIALOG_COMPOSE:
        inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        layout = inflater.inflate(R.layout.compose_dialog, null);

        Common.setTextColorFromTheme(mSettings.getTheme(), getResources(),
                (TextView) layout.findViewById(R.id.compose_destination_textview),
                (TextView) layout.findViewById(R.id.compose_subject_textview),
                (TextView) layout.findViewById(R.id.compose_message_textview),
                (TextView) layout.findViewById(R.id.compose_captcha_textview),
                (TextView) layout.findViewById(R.id.compose_captcha_loading));

        final EditText composeDestination = (EditText) layout.findViewById(R.id.compose_destination_input);
        final EditText composeSubject = (EditText) layout.findViewById(R.id.compose_subject_input);
        final EditText composeText = (EditText) layout.findViewById(R.id.compose_text_input);
        final Button composeSendButton = (Button) layout.findViewById(R.id.compose_send_button);
        final Button composeCancelButton = (Button) layout.findViewById(R.id.compose_cancel_button);
        final EditText composeCaptcha = (EditText) layout.findViewById(R.id.compose_captcha_input);
        composeDestination.setText(mUsername);

        dialog = builder.setView(layout).create();
        final Dialog composeDialog = dialog;
        composeSendButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                ThingInfo hi = new ThingInfo();

                if (!FormValidation.validateComposeMessageInputFields(ProfileActivity.this, composeDestination,
                        composeSubject, composeText, composeCaptcha))
                    return;

                hi.setDest(composeDestination.getText().toString().trim());
                hi.setSubject(composeSubject.getText().toString().trim());
                new MyMessageComposeTask(composeDialog, hi, composeCaptcha.getText().toString().trim())
                        .execute(composeText.getText().toString().trim());
                removeDialog(Constants.DIALOG_COMPOSE);
            }
        });
        composeCancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                removeDialog(Constants.DIALOG_COMPOSE);
            }
        });
        break;

    case Constants.DIALOG_THREAD_CLICK:
        dialog = new ThreadClickDialog(this, mSettings);
        break;

    // "Please wait"
    case Constants.DIALOG_LOGGING_IN:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Logging in...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_REPLYING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Sending reply...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_COMPOSING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Composing message...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;

    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:com.android.mms.ui.ComposeMessageActivity.java

private void processPickResult(final Intent data) {
    // The EXTRA_PHONE_URIS stores the phone's urls that were selected by user in the
    // multiple phone picker.
    final Parcelable[] uris = data.getParcelableArrayExtra(Intents.EXTRA_PHONE_URIS);

    final int recipientCount = uris != null ? uris.length : 0;

    final int recipientLimit = MmsConfig.getRecipientLimit();
    if (recipientLimit != Integer.MAX_VALUE && recipientCount > recipientLimit) {
        new AlertDialog.Builder(this)
                .setMessage(getString(R.string.too_many_recipients, recipientCount, recipientLimit))
                .setPositiveButton(android.R.string.ok, null).create().show();
        return;/* w w w  .  jav a 2  s  .c om*/
    }

    final Handler handler = new Handler();
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setTitle(getText(R.string.pick_too_many_recipients));
    progressDialog.setMessage(getText(R.string.adding_recipients));
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);

    final Runnable showProgress = new Runnable() {
        @Override
        public void run() {
            progressDialog.show();
        }
    };
    // Only show the progress dialog if we can not finish off parsing the return data in 1s,
    // otherwise the dialog could flicker.
    handler.postDelayed(showProgress, 1000);

    new Thread(new Runnable() {
        @Override
        public void run() {
            final ContactList list;
            try {
                list = ContactList.blockingGetByUris(uris);
            } finally {
                handler.removeCallbacks(showProgress);
                progressDialog.dismiss();
            }
            // TODO: there is already code to update the contact header widget and recipients
            // editor if the contacts change. we can re-use that code.
            final Runnable populateWorker = new Runnable() {
                @Override
                public void run() {
                    mRecipientsEditor.populate(list);
                    updateTitle(list);
                }
            };
            handler.post(populateWorker);
        }
    }, "ComoseMessageActivity.processPickResult").start();
}

From source file:com.andrewshu.android.reddit.profile.ProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;//from   w ww  .  j  a v  a2  s  . c o  m
    ProgressDialog pdialog;
    AlertDialog.Builder builder;
    LayoutInflater inflater;
    View layout; // used for inflated views for AlertDialog.Builder.setView()

    switch (id) {
    case Constants.DIALOG_LOGIN:
        dialog = new LoginDialog(this, mSettings, false) {
            @Override
            public void onLoginChosen(String user, String password) {
                dismissDialog(Constants.DIALOG_LOGIN);
                new MyLoginTask(user, password).execute();
            }
        };
        break;

    case Constants.DIALOG_COMPOSE:
        inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        builder = new AlertDialog.Builder(this);
        layout = inflater.inflate(R.layout.compose_dialog, null);
        final EditText composeDestination = (EditText) layout.findViewById(R.id.compose_destination_input);
        final EditText composeSubject = (EditText) layout.findViewById(R.id.compose_subject_input);
        final EditText composeText = (EditText) layout.findViewById(R.id.compose_text_input);
        final Button composeSendButton = (Button) layout.findViewById(R.id.compose_send_button);
        final Button composeCancelButton = (Button) layout.findViewById(R.id.compose_cancel_button);
        final EditText composeCaptcha = (EditText) layout.findViewById(R.id.compose_captcha_input);
        composeDestination.setText(mUsername);

        dialog = builder.setView(layout).create();
        final Dialog composeDialog = dialog;
        composeSendButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                ThingInfo hi = new ThingInfo();
                // reddit.com performs these sanity checks too.
                if ("".equals(composeDestination.getText().toString().trim())) {
                    Toast.makeText(ProfileActivity.this, "please enter a username", Toast.LENGTH_LONG).show();
                    return;
                }
                if ("".equals(composeSubject.getText().toString().trim())) {
                    Toast.makeText(ProfileActivity.this, "please enter a subject", Toast.LENGTH_LONG).show();
                    return;
                }
                if ("".equals(composeText.getText().toString().trim())) {
                    Toast.makeText(ProfileActivity.this, "you need to enter a message", Toast.LENGTH_LONG)
                            .show();
                    return;
                }
                if (composeCaptcha.getVisibility() == View.VISIBLE
                        && "".equals(composeCaptcha.getText().toString().trim())) {
                    Toast.makeText(ProfileActivity.this, "", Toast.LENGTH_LONG).show();
                    return;
                }
                hi.setDest(composeDestination.getText().toString().trim());
                hi.setSubject(composeSubject.getText().toString().trim());
                new MyMessageComposeTask(composeDialog, hi, composeCaptcha.getText().toString().trim())
                        .execute(composeText.getText().toString().trim());
                dismissDialog(Constants.DIALOG_COMPOSE);
            }
        });
        composeCancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                dismissDialog(Constants.DIALOG_COMPOSE);
            }
        });
        break;

    case Constants.DIALOG_THREAD_CLICK:
        inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        builder = new AlertDialog.Builder(this);
        dialog = builder.setView(inflater.inflate(R.layout.thread_click_dialog, null)).create();
        break;

    // "Please wait"
    case Constants.DIALOG_LOGGING_IN:
        pdialog = new ProgressDialog(this);
        pdialog.setMessage("Logging in...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(false);
        dialog = pdialog;
        break;
    case Constants.DIALOG_REPLYING:
        pdialog = new ProgressDialog(this);
        pdialog.setMessage("Sending reply...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(false);
        dialog = pdialog;
        break;
    case Constants.DIALOG_COMPOSING:
        pdialog = new ProgressDialog(this);
        pdialog.setMessage("Composing message...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(false);
        dialog = pdialog;
        break;

    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    final Dialog dialog;
    ProgressDialog pdialog;
    AlertDialog.Builder builder;/*from  w  ww  .  j  a  v a2s  . c o m*/
    LayoutInflater inflater;

    switch (id) {
    case Constants.DIALOG_LOGIN:
        dialog = new LoginDialog(this, mSettings, false) {
            @Override
            public void onLoginChosen(String user, String password) {
                removeDialog(Constants.DIALOG_LOGIN);
                new MyLoginTask(user, password).execute();
            }
        };
        break;

    case Constants.DIALOG_COMMENT_CLICK:
        dialog = new CommentClickDialog(this, mSettings);
        break;

    case Constants.DIALOG_REPLY: {
        dialog = new Dialog(this, mSettings.getDialogTheme());
        dialog.setContentView(R.layout.compose_reply_dialog);
        final EditText replyBody = (EditText) dialog.findViewById(R.id.body);
        final Button replySaveButton = (Button) dialog.findViewById(R.id.reply_save_button);
        final Button replyCancelButton = (Button) dialog.findViewById(R.id.reply_cancel_button);

        replySaveButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mReplyTargetName != null) {
                    new CommentReplyTask(mReplyTargetName).execute(replyBody.getText().toString());
                    dialog.dismiss();
                } else {
                    Common.showErrorToast("Error replying. Please try again.", Toast.LENGTH_SHORT,
                            CommentsListActivity.this);
                }
            }
        });
        replyCancelButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mVoteTargetThing.setReplyDraft(replyBody.getText().toString());
                dialog.cancel();
            }
        });
        dialog.setCancelable(false); // disallow the BACK key
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                replyBody.setText("");
            }
        });
        break;
    }

    case Constants.DIALOG_EDIT: {
        dialog = new Dialog(this, mSettings.getDialogTheme());
        dialog.setContentView(R.layout.compose_reply_dialog);
        final EditText replyBody = (EditText) dialog.findViewById(R.id.body);
        final Button replySaveButton = (Button) dialog.findViewById(R.id.reply_save_button);
        final Button replyCancelButton = (Button) dialog.findViewById(R.id.reply_cancel_button);

        replyBody.setText(mEditTargetBody);

        replySaveButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                if (mReplyTargetName != null) {
                    new EditTask(mReplyTargetName).execute(replyBody.getText().toString());
                    dialog.dismiss();
                } else {
                    Common.showErrorToast("Error editing. Please try again.", Toast.LENGTH_SHORT,
                            CommentsListActivity.this);
                }
            }
        });
        replyCancelButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                dialog.cancel();
            }
        });
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                replyBody.setText("");
            }
        });
        break;
    }

    case Constants.DIALOG_DELETE:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("Really delete this?");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                removeDialog(Constants.DIALOG_DELETE);
                new DeleteTask(mDeleteTargetKind).execute(mReplyTargetName);
            }
        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        dialog = builder.create();
        break;

    case Constants.DIALOG_SORT_BY:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("Sort by:");
        int selectedSortBy = -1;
        for (int i = 0; i < Constants.CommentsSort.SORT_BY_URL_CHOICES.length; i++) {
            if (Constants.CommentsSort.SORT_BY_URL_CHOICES[i].equals(mSettings.getCommentsSortByUrl())) {
                selectedSortBy = i;
                break;
            }
        }
        builder.setSingleChoiceItems(Constants.CommentsSort.SORT_BY_CHOICES, selectedSortBy,
                sortByOnClickListener);
        dialog = builder.create();
        break;

    case Constants.DIALOG_REPORT:
        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setTitle("Really report this?");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                removeDialog(Constants.DIALOG_REPORT);
                new ReportTask(mReportTargetName.toString()).execute();
            }
        }).setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
        dialog = builder.create();
        break;

    // "Please wait"
    case Constants.DIALOG_DELETING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Deleting...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_EDITING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Submitting edit...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_LOGGING_IN:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Logging in...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_REPLYING:
        pdialog = new ProgressDialog(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        pdialog.setMessage("Sending reply...");
        pdialog.setIndeterminate(true);
        pdialog.setCancelable(true);
        dialog = pdialog;
        break;
    case Constants.DIALOG_FIND:
        inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View content = inflater.inflate(R.layout.dialog_find, null);
        final EditText find_box = (EditText) content.findViewById(R.id.input_find_box);
        //          final CheckBox wrap_box = (CheckBox) content.findViewById(R.id.find_wrap_checkbox);

        builder = new AlertDialog.Builder(new ContextThemeWrapper(this, mSettings.getDialogTheme()));
        builder.setView(content);
        builder.setTitle(R.string.find).setPositiveButton(R.string.find, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String search_text = find_box.getText().toString().toLowerCase();
                //               findCommentText(search_text, wrap_box.isChecked(), false);
                findCommentText(search_text, true, false);
            }
        }).setNegativeButton("Cancel", null);
        dialog = builder.create();
        break;
    default:
        throw new IllegalArgumentException("Unexpected dialog id " + id);
    }
    return dialog;
}