Example usage for android.app AlertDialog.Builder create

List of usage examples for android.app AlertDialog.Builder create

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder create.

Prototype

public void create() 

Source Link

Document

Forces immediate creation of the dialog.

Usage

From source file:com.dattasmoon.pebble.plugin.ConvertPreference.java

@Override
protected void onBindDialogView(View view) {
    Button btnAdd = (Button) view.findViewById(R.id.btnAdd);
    etFrom = (EditText) view.findViewById(R.id.etFrom);
    etTo = (EditText) view.findViewById(R.id.etTo);
    lvConvert = (ListView) view.findViewById(R.id.lvConvert);
    lvConvert.setEmptyView(view.findViewById(android.R.id.empty));
    lvConvert.setAdapter(arrayAdapter);/*from   ww  w . j  av a  2 s.  com*/
    lvConvert.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
            AdapterView.AdapterContextMenuInfo contextInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
            int position = contextInfo.position;
            long id = contextInfo.id;
            // the child view who's info we're viewing (should be equal to v)
            View v = contextInfo.targetView;
            AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());

            final int arrayPosition = (Integer) v.getTag();
            final String text = ((TextView) v.findViewById(R.id.tvItem)).getText().toString();
            builder.setMessage(
                    getContext().getResources().getString(R.string.confirm_delete) + " '" + text + "' ?")
                    .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            JSONArray temp = new JSONArray();
                            for (int i = 0; i < arrayAdapter.getJSONArray().length(); i++) {
                                if (i == arrayPosition) {
                                    continue;
                                }
                                try {
                                    temp.put(arrayAdapter.getJSONArray().getJSONObject(i));
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                            arrayAdapter.setJSONArray(temp);

                            arrayAdapter.notifyDataSetChanged();
                        }
                    }).setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // User cancelled the dialog
                        }
                    });
            builder.create().show();
        }
    });

    btnAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            JSONObject item = new JSONObject();
            try {
                item.put("from", etFrom.getText().toString());
                item.put("to", etTo.getText().toString());
                arrayAdapter.getJSONArray().put(item);
                etFrom.setText("");
                etTo.setText("");
                arrayAdapter.notifyDataSetChanged();
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    });
    super.onBindDialogView(view);
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private void sendRegistrationRequest(final String email) {
    final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage(getString(R.string.registration_sending_email, email));
    progressDialog.setCancelable(true);/*ww w . ja  va 2  s .c om*/
    progressDialog.show();
    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            progressDialog.dismiss();
            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
            builder.setMessage(R.string.error_please_try_again);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    };
    final String timestamp = "" + mWiz.getTimestamp();
    final String registrationId = mWiz.getRegistrationId();
    final String deviceId = mWiz.getDeviceId();

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "2";
            String requestSignature = Security.sha256(version + email + " " + timestamp + " " + deviceId + " "
                    + registrationId + " " + CloudConstants.REGISTRATION_EMAIL_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_REQUEST_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("email", email));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("request_signature", requestSignature));
                nameValuePairs.add(new BasicNameValuePair("install_id", mWiz.getInstallationId()));
                nameValuePairs.add(new BasicNameValuePair("request_id", UUID.randomUUID().toString()));
                nameValuePairs.add(new BasicNameValuePair("language", Locale.getDefault().getLanguage()));
                nameValuePairs.add(new BasicNameValuePair("country", Locale.getDefault().getCountry()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);

                int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode == 200) {
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            mWiz.setEmail(email);
                            mWiz.save();
                            progressDialog.dismiss();
                            mWiz.proceedToNextPage();
                            showNotification();
                        }
                    });
                } else if (statusCode == 502) {

                    final HttpEntity entity = response.getEntity();
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            progressDialog.dismiss();
                            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);

                            boolean stringSet = false;
                            if (entity != null) {
                                @SuppressWarnings("unchecked")
                                final Map<String, Object> responseMap = (Map<String, Object>) org.json.simple.JSONValue
                                        .parse(new InputStreamReader(entity.getContent()));

                                if (responseMap != null) {
                                    String result = (String) responseMap.get("result");
                                    if (result != null) {
                                        builder.setMessage(result);
                                        stringSet = true;
                                    }
                                }
                            }

                            if (!stringSet) {
                                builder.setMessage(R.string.registration_email_not_valid);
                            }

                            builder.setPositiveButton(R.string.rogerthat, null);
                            AlertDialog dialog = builder.create();
                            dialog.show();
                        }
                    });
                } else {
                    mUIHandler.post(showErrorDialog);
                }

            } catch (ClientProtocolException e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            } catch (IOException e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });
}

From source file:de.quadrillenschule.azocamsynca.job.JobProcessor.java

public void processingLoop() {

    if (getRequestStatus() == ProcessorStatus.PAUSED) {
        setStatus(ProcessorStatus.PAUSED);
        return;/*w  w w .  j a  va 2 s  .  c  o  m*/
    }
    setStatus(ProcessorStatus.PROCESSING);
    TriggerPhotoSerie currentJobT = null;
    for (TriggerPhotoSerie j : jobs) {
        if (j.getTriggerStatus() != TriggerPhotoSerie.TriggerJobStatus.FINISHED_TRIGGERING) {
            currentJobT = j;
            if ((j.getTriggerStatus() == PhotoSerie.TriggerJobStatus.WAITFORUSER)
                    && ((alertDialog != null) && (alertDialog.isShowing()))) {
                return;
            }
            if ((j.getTriggerStatus() == PhotoSerie.TriggerJobStatus.WAITFORUSER)) {
                currentJobT.setTriggerStatus(PhotoSerie.TriggerJobStatus.NEW);
            }
            break;
        }
    }
    if (currentJobT == null) {
        setStatus(ProcessorStatus.PAUSED);
        return;
    }

    final TriggerPhotoSerie currentJob = currentJobT;
    final NikonIR camera = ((AzoTriggerServiceApplication) getActivity().getApplication()).getCamera();

    if (currentJob.getTriggerStatus() == PhotoSerie.TriggerJobStatus.NEW) {
        currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.WAITFORUSER);
        if (currentJob.getSeriesName().equals(PhotoSerie.TESTSHOTS)) {
            doTestShots(currentJob);
            return;
        }
        AlertDialog.Builder ad = new AlertDialog.Builder(getActivity(), R.style.dialog);
        ad.setTitle(currentJob.getProject() + ": " + currentJob.getSeriesName());
        ad.setMessage(
                currentJob.getNumber() + " x " + (int) (currentJob.getExposure() / 1000) + "s\n\n"
                        + "Delay after each exposure:" + currentJob.getDelayAfterEachExposure() / 1000 + "s\n"
                        + "Camera controls time: " + camera.isExposureSetOnCamera(currentJob.getExposure())
                        + "\n" + "Total time: "
                        + ((currentJob.getNumber()
                                * (currentJob.getExposure() + currentJob.getDelayAfterEachExposure())) / 1000)
                        + "s");

        ad.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface arg0, int arg1) {
                currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.PREPARED);
                processingLoop();
            }
        });
        ad.setNegativeButton("Pause", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface arg0, int arg1) {
                currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.NEW);
                pause();
            }
        });

        MediaPlayer mediaPlayer = MediaPlayer.create(activity, R.raw.oida_peda);
        mediaPlayer.start();
        ad.create();
        alertDialog = ad.show();

    }

    final Handler handler = new Handler();

    if ((currentJob.getTriggerStatus() == PhotoSerie.TriggerJobStatus.PREPARED
            || currentJob.getTriggerStatus() == PhotoSerie.TriggerJobStatus.RUNNING)) {
        handler.postDelayed(new Runnable() {

            public void run() {
                if ((((AzoTriggerServiceApplication) getActivity().getApplication()).getJobProcessor()
                        .getStatus() == ProcessorStatus.PAUSED) && (!currentJob.isToggleIsOpen())) {

                    return;
                }
                camera.trigger();
                for (JobProgressListener j : jobProgressListeners) {
                    j.jobProgressed(currentJob);
                }
                if (currentJob.getFirstTriggerTime() == 0) {
                    currentJob.setFirstTriggerTime(System.currentTimeMillis());
                }
                currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.RUNNING);

                if (!camera.isExposureSetOnCamera(currentJob.getExposure())) {
                    if (!currentJob.isToggleIsOpen()) {
                        currentJob.setToggleIsOpen(!currentJob.isToggleIsOpen());

                        currentJob.setLastTriggerTime(System.currentTimeMillis());
                    } else {
                        currentJob.setToggleIsOpen(!currentJob.isToggleIsOpen());
                        currentJob.setTriggered(currentJob.getTriggered() + 1);

                    }
                } else {

                    currentJob.setTriggered(currentJob.getTriggered() + 1);

                }
                if (currentJob.getTriggered() < currentJob.getNumber()) {
                    long time;
                    if (camera.isExposureSetOnCamera(currentJob.getExposure())) {
                        time = currentJob.getExposure() + currentJob.getDelayAfterEachExposure();
                    } else {
                        if (currentJob.isToggleIsOpen()) {
                            time = currentJob.getExposure();
                        } else {
                            time = currentJob.getDelayAfterEachExposure();
                        }
                    }
                    handler.postDelayed(this, time);
                } else {
                    currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.FINISHED_TRIGGERING);
                    processingLoop();
                }
            }
        }, currentJob.getInitialDelay());
    } else {
    }

}

From source file:com.f16gaming.pathofexilestatistics.PoeEntry.java

public AlertDialog getInfoDialog(Activity activity, Resources res) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    LayoutInflater inflater = activity.getLayoutInflater();
    View view = inflater.inflate(R.layout.info, null);
    String nameFormat = res.getString(R.string.info_name);
    String accountFormat = res.getString(R.string.info_account);
    String rankFormat = res.getString(R.string.info_rank);
    String levelFormat = res.getString(R.string.info_level);
    String classFormat = res.getString(R.string.info_class);
    String experienceFormat = res.getString(R.string.info_experience);
    ((TextView) view.findViewById(R.id.info_name)).setText(String.format(nameFormat, name));
    ((TextView) view.findViewById(R.id.info_account)).setText(String.format(accountFormat, account));
    ((TextView) view.findViewById(R.id.info_rank)).setText(String.format(rankFormat, rank));
    ((TextView) view.findViewById(R.id.info_level)).setText(String.format(levelFormat, level));
    ((TextView) view.findViewById(R.id.info_class)).setText(String.format(classFormat, className));
    ((TextView) view.findViewById(R.id.info_experience)).setText(String.format(experienceFormat, experience));

    TextView status = (TextView) view.findViewById(R.id.info_status);
    status.setText(online ? R.string.online : R.string.offline);
    status.setTextColor(online ? res.getColor(R.color.online) : res.getColor(R.color.offline));

    builder.setTitle(R.string.info_title).setView(view).setPositiveButton(android.R.string.ok,
            new DialogInterface.OnClickListener() {
                @Override/*  www  .jav  a 2s .c o  m*/
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    return builder.create();
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private void onPinEntered() {

    final String pin = mEnterPinEditText.getText().toString();
    // Validate pin code
    if (!RegexPatterns.PIN.matcher(pin).matches()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
        builder.setMessage(R.string.registration_invalid_pin);
        builder.setPositiveButton(R.string.rogerthat, null);
        AlertDialog dialog = builder.create();
        dialog.show();//from w  w  w .  j a  v a  2 s.c o  m
        return;
    }
    // Make call to Rogerthat webfarm
    final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog
            .setMessage(getString(R.string.registration_activating_account, getString(R.string.app_name)));
    progressDialog.setCancelable(false);
    progressDialog.show();
    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            progressDialog.dismiss();
            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
            builder.setMessage(R.string.registration_sending_pin_error);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    };
    final String email = mWiz.getEmail();
    final String timestamp = "" + mWiz.getTimestamp();
    final String registrationId = mWiz.getRegistrationId();
    final String deviceId = mWiz.getDeviceId();

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "2";
            String pinSignature = Security.sha256(version + " " + email + " " + timestamp + " " + deviceId + " "
                    + registrationId + " " + pin + CloudConstants.REGISTRATION_PIN_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_PIN_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("email", email));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("pin_code", pin));
                nameValuePairs.add(new BasicNameValuePair("pin_signature", pinSignature));
                nameValuePairs.add(new BasicNameValuePair("request_id", UUID.randomUUID().toString()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                nameValuePairs.add(
                        new BasicNameValuePair("use_xmpp_kick", CloudConstants.USE_XMPP_KICK_CHANNEL + ""));
                nameValuePairs.add(new BasicNameValuePair("GCM_registration_id", mGCMRegistrationId));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);
                int statusCode = response.getStatusLine().getStatusCode();
                HttpEntity entity = response.getEntity();
                if (statusCode != 200 || entity == null) {
                    mUIHandler.post(showErrorDialog);
                    return;
                }
                @SuppressWarnings("unchecked")
                final Map<String, Object> responseMap = (Map<String, Object>) org.json.simple.JSONValue
                        .parse(new InputStreamReader(entity.getContent()));
                if ("success".equals(responseMap.get("result"))) {

                    JSONObject account = (JSONObject) responseMap.get("account");
                    final RegistrationInfo info = new RegistrationInfo(email,
                            new Credentials((String) account.get("account"), (String) account.get("password")));

                    mAgeAndGenderSet = (Boolean) responseMap.get("age_and_gender_set");
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            hideNotification();
                            tryConnect(progressDialog, 1, getString(R.string.registration_establish_connection,
                                    email, getString(R.string.app_name)) + " ", info);
                        }
                    });
                } else {

                    final long attempts_left = (Long) responseMap.get("attempts_left");
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            progressDialog.dismiss();
                            if (attempts_left > 0) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(
                                        RegistrationActivity2.this);
                                builder.setMessage(getString(R.string.registration_incorrect_pin, email));
                                builder.setTitle(getString(R.string.registration_incorrect_pin_dialog_title));
                                builder.setPositiveButton(R.string.rogerthat, null);
                                AlertDialog dialog = builder.create();
                                dialog.show();
                                mEnterPinEditText.setText("");
                            } else {
                                hideNotification();
                                new AlertDialog.Builder(RegistrationActivity2.this)
                                        .setMessage(getString(R.string.registration_no_attempts_left))
                                        .setCancelable(true).setPositiveButton(R.string.try_again, null)
                                        .create().show();
                                mWiz.reInit();
                                mWiz.goBackToPrevious();
                                return;
                            }
                        }
                    });

                }
            } catch (Exception e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });

}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private void registerWithAccessToken(final String accessToken) {
    final String timestamp = "" + mWiz.getTimestamp();
    final String deviceId = mWiz.getDeviceId();
    final String registrationId = mWiz.getRegistrationId();
    final String installId = mWiz.getInstallationId();
    // Make call to Rogerthat webfarm
    final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog/*from   w w  w .jav  a 2s.c  om*/
            .setMessage(getString(R.string.registration_activating_account, getString(R.string.app_name)));
    progressDialog.setCancelable(false);
    progressDialog.show();
    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            progressDialog.dismiss();
            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
            builder.setMessage(R.string.registration_facebook_error);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    };

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "1";
            String signature = Security.sha256(version + " " + installId + " " + timestamp + " " + deviceId
                    + " " + registrationId + " " + accessToken + CloudConstants.REGISTRATION_MAIN_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_FACEBOOK_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(8);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("signature", signature));
                nameValuePairs.add(new BasicNameValuePair("install_id", installId));
                nameValuePairs.add(new BasicNameValuePair("access_token", accessToken));
                nameValuePairs.add(new BasicNameValuePair("language", Locale.getDefault().getLanguage()));
                nameValuePairs.add(new BasicNameValuePair("country", Locale.getDefault().getCountry()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                nameValuePairs.add(
                        new BasicNameValuePair("use_xmpp_kick", CloudConstants.USE_XMPP_KICK_CHANNEL + ""));
                nameValuePairs.add(new BasicNameValuePair("GCM_registration_id", mGCMRegistrationId));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);

                int statusCode = response.getStatusLine().getStatusCode();
                HttpEntity entity = response.getEntity();

                if (entity == null) {
                    mUIHandler.post(showErrorDialog);
                    return;
                }

                @SuppressWarnings("unchecked")
                final Map<String, Object> responseMap = (Map<String, Object>) JSONValue
                        .parse(new InputStreamReader(entity.getContent()));

                if (statusCode != 200 || responseMap == null) {
                    if (statusCode == 500 && responseMap != null) {
                        final String errorMessage = (String) responseMap.get("error");
                        if (errorMessage != null) {
                            mUIHandler.post(new SafeRunnable() {
                                @Override
                                protected void safeRun() throws Exception {
                                    T.UI();
                                    progressDialog.dismiss();
                                    AlertDialog.Builder builder = new AlertDialog.Builder(
                                            RegistrationActivity2.this);
                                    builder.setMessage(errorMessage);
                                    builder.setPositiveButton(R.string.rogerthat, null);
                                    AlertDialog dialog = builder.create();
                                    dialog.show();
                                }
                            });
                            return;
                        }
                    }
                    mUIHandler.post(showErrorDialog);
                    return;
                }
                JSONObject account = (JSONObject) responseMap.get("account");
                final String email = (String) responseMap.get("email");
                mAgeAndGenderSet = (Boolean) responseMap.get("age_and_gender_set");
                final RegistrationInfo info = new RegistrationInfo(email,
                        new Credentials((String) account.get("account"), (String) account.get("password")));
                mUIHandler.post(new SafeRunnable() {
                    @Override
                    protected void safeRun() throws Exception {
                        T.UI();
                        mWiz.setEmail(email);
                        mWiz.save();
                        hideNotification();
                        tryConnect(progressDialog, 1, getString(R.string.registration_establish_connection,
                                email, getString(R.string.app_name)) + " ", info);
                    }
                });

            } catch (Exception e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });
}

From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if (id == R.id.action_view_as_grid) {
        Intent i = new Intent(POIMapActivity.this, POIGridActivity.class);

        i.putExtra("playOn", mActionPlay);

        i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        // finish();
        overridePendingTransition(0, 0);

        startActivityForResult(i, 1);//from www .j  a  v  a2s.c o m
        overridePendingTransition(0, 0);

    } else if (id == R.id.action_directions) {

        if (mActionDirections == 1) { // cancel directions action
            item.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        } else if (mActionDirections == 0) { // set directions action on

            item.setIcon(R.drawable.ic_action_directions_pressed);
            mActionDirections = 1;

            gmm.handleMapWarningMessages(POIMapActivity.this, tvMapMessage);
            if (gmm.myLocationEnabled && gmm.internetEnabled) {
                Toast.makeText(POIMapActivity.this,
                        POIMapActivity.this.getResources().getString(R.string.tap_route_destination),
                        Toast.LENGTH_SHORT).show();

            } else {
                tvMapMessage.setBackgroundColor(
                        POIMapActivity.this.getResources().getColor(R.color.red_transparent));

                item.setIcon(R.drawable.ic_action_directions);
                mActionDirections = 0;
                tvMapDirectionsInfo.setVisibility(View.INVISIBLE);

            }
        } else { // mActionDirections == 3
            item.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        }

    } else if (id == R.id.action_play) {

        if (mActionPlay) { // cancel play mode
            gmm.addAllMarkers(POIMapActivity.this);
            item.setIcon(R.drawable.ic_action_play);
            mActionPlay = false;

            miDirections.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        } else {
            gmm.addPlayMarkers(POIMapActivity.this);
            item.setIcon(R.drawable.ic_action_pause_red);
            if (gmm.activePOIMarker != null) {
                drawUserDestRoute(gmm.activePOIMarker.getPosition());
            }
            mActionPlay = true;

        }

    } else if (id == R.id.action_google_map_type) {
        // get google map type names
        String[] googleMapTypeNames = getResources().getStringArray(R.array.google_map_type_names);

        // creating and Building the Dialog
        AlertDialog.Builder builderMapType = new AlertDialog.Builder(this);
        builderMapType.setTitle(getResources().getString(R.string.action_google_map_type));
        builderMapType.setSingleChoiceItems(googleMapTypeNames, selectedMapType,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {

                        if (item != selectedMapType) {
                            switchGoogleMapType(item);
                            // save selected type in settings
                            SharedPreferences preferences = PreferenceManager
                                    .getDefaultSharedPreferences(POIMapActivity.this);
                            SharedPreferences.Editor editor = preferences.edit();
                            editor.putString("googleMapType", String.valueOf(item));
                            editor.commit();
                        }
                        mapTypeDialog.dismiss();
                    }
                });
        mapTypeDialog = builderMapType.create();
        mapTypeDialog.show();

    } else if (id == R.id.action_legal_notices) {

        String licenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
        AlertDialog.Builder licenseDialog = new AlertDialog.Builder(POIMapActivity.this);
        licenseDialog.setTitle(getString(R.string.action_legal_notices));
        licenseDialog.setMessage(licenseInfo);
        licenseDialog.show();

    } else if (id == R.id.action_scan_qr_code) {

        handleQRcodeScanRequest();

    } else if (id == R.id.action_about) {
        String about = getString(R.string.about_application);
        AlertDialog alertDialog;
        alertDialog = new AlertDialog.Builder(POIMapActivity.this).create();

        alertDialog.setTitle(getString(R.string.action_about));
        alertDialog.setMessage(Html.fromHtml(about));

        alertDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        alertDialog.show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java

public void showAlertDialog() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Manual Location");
    builder.setMessage(/*from ww  w. j  ava  2  s  . c  om*/
            "Note that this will not allow Repeater.MY to auto-detect location.\n\nDisable Location Service now?"); // Want
    // to
    // enable?

    // if yes - bring user to enable Location Service settings
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialogInterface, int i) {

            Intent intent = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            getApplicationContext().startActivity(intent);
        }
    });

    // if no - bring user to selecting Static Location Activity
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();

        }

    });
    builder.create().show();

}

From source file:com.nexes.manager.EventHandler.java

/**
 * This method, handles the button presses of the top buttons found in the
 * Main activity.//from  ww w.j  a  v a2s  .com
 */
@Override
public void onClick(View v) {

    switch (v.getId()) {

    case R.id.back_button:
        if (mFileMang.getCurrentDir() != "/") {
            if (multi_select_flag) {
                mDelegate.killMultiSelect(true);
                Toast.makeText(mContext, "Multi-select is now off", Toast.LENGTH_SHORT).show();
            }

            stopThumbnailThread();
            updateDirectory(mFileMang.getPreviousDir());
            if (mPathLabel != null)
                mPathLabel.setText(mFileMang.getCurrentDir());
        }
        break;

    case R.id.home_button:
        if (multi_select_flag) {
            mDelegate.killMultiSelect(true);
            Toast.makeText(mContext, "Multi-select is now off", Toast.LENGTH_SHORT).show();
        }

        stopThumbnailThread();
        updateDirectory(mFileMang.setHomeDir("/sdcard"));
        if (mPathLabel != null)
            mPathLabel.setText(mFileMang.getCurrentDir());
        break;

    case R.id.info_button:
        Intent info = new Intent(mContext, DirectoryInfo.class);
        info.putExtra("PATH_NAME", mFileMang.getCurrentDir());
        mContext.startActivity(info);
        break;

    case R.id.help_button:
        Intent help = new Intent(mContext, HelpManager.class);
        mContext.startActivity(help);
        break;

    case R.id.manage_button:
        display_dialog(MANAGE_DIALOG);
        break;

    case R.id.multiselect_button:
        if (multi_select_flag) {
            mDelegate.killMultiSelect(true);

        } else {
            LinearLayout hidden_lay = (LinearLayout) ((Activity) mContext).findViewById(R.id.hidden_buttons);

            multi_select_flag = true;
            hidden_lay.setVisibility(LinearLayout.VISIBLE);
        }
        break;

    /*
     * three hidden buttons for multiselect
     */
    case R.id.hidden_attach:
        /* check if user selected objects before going further */
        if (mMultiSelectData == null || mMultiSelectData.isEmpty()) {
            mDelegate.killMultiSelect(true);
            break;
        }

        ArrayList<Uri> uris = new ArrayList<Uri>();
        int length = mMultiSelectData.size();
        Intent mail_int = new Intent();

        mail_int.setAction(android.content.Intent.ACTION_SEND_MULTIPLE);
        mail_int.setType("application/mail");
        mail_int.putExtra(Intent.EXTRA_BCC, "");
        mail_int.putExtra(Intent.EXTRA_SUBJECT, " ");

        for (int i = 0; i < length; i++) {
            File file = new File(mMultiSelectData.get(i));
            uris.add(Uri.fromFile(file));
        }

        mail_int.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        mContext.startActivity(Intent.createChooser(mail_int, "Email using..."));

        mDelegate.killMultiSelect(true);
        break;

    case R.id.hidden_move:
    case R.id.hidden_copy:
        /* check if user selected objects before going further */
        if (mMultiSelectData == null || mMultiSelectData.isEmpty()) {
            mDelegate.killMultiSelect(true);
            break;
        }

        if (v.getId() == R.id.hidden_move)
            delete_after_copy = true;

        mInfoLabel.setText("Holding " + mMultiSelectData.size() + " file(s)");

        mDelegate.killMultiSelect(false);
        break;

    case R.id.hidden_delete:
        /* check if user selected objects before going further */
        if (mMultiSelectData == null || mMultiSelectData.isEmpty()) {
            mDelegate.killMultiSelect(true);
            break;
        }

        final String[] data = new String[mMultiSelectData.size()];
        int at = 0;

        for (String string : mMultiSelectData)
            data[at++] = string;

        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(
                "Are you sure you want to delete " + data.length + " files? This cannot be " + "undone.");
        builder.setCancelable(false);
        builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                new BackgroundWork(DELETE_TYPE).execute(data);
                mDelegate.killMultiSelect(true);
            }
        });
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mDelegate.killMultiSelect(true);
                dialog.cancel();
            }
        });

        builder.create().show();
        break;
    }
}

From source file:kr.co.cashqc.MainActivity.java

@Override
protected Dialog onCreateDialog(int i) {
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

    LayoutInflater inflater = MainActivity.this.getLayoutInflater();

    final View view = inflater.inflate(R.layout.dialog_custom_login, null);

    builder.setView(view);/*from w w  w . j a v  a  2  s. co m*/
    builder.setPositiveButton("login", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            EditText passwordEditText = (EditText) view.findViewById(R.id.password);
            // EditText distanceEditText = (EditText)
            // view.findViewById(R.id.distance);

            if (passwordEditText.getText().toString().equals("1599")) {
                adminFlag = true;
                Toast.makeText(mContext, "?", Toast.LENGTH_SHORT).show();
                // try {
                // mDistance =
                // Integer.parseInt(distanceEditText.getText().toString());
                // } catch (NumberFormatException e) {
                // e.printStackTrace();
                // mDistance = 3;
                // }
                mManualTextView.setVisibility(View.VISIBLE);
            } else {
                adminFlag = false;
                mDistance = 3;
                // mManualTextView.setVisibility(View.GONE);
            }

        }
    });

    return builder.create();
}