Example usage for android.widget EditText getText

List of usage examples for android.widget EditText getText

Introduction

In this page you can find the example usage for android.widget EditText getText.

Prototype

@Override
    public Editable getText() 

Source Link

Usage

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

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog;/* w  w  w  .jav  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, 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.lewa.crazychapter11.MainActivity.java

private void AddSharedPreBtn() {
    final EditText edit_in = (EditText) findViewById(R.id.edit_in);
    final EditText edit_out = (EditText) findViewById(R.id.edit_out);
    Button btn_read = (Button) findViewById(R.id.btn_read);
    btn_read.setOnClickListener(new OnClickListener() {
        @Override//from   ww  w  . j ava2s.co m
        public void onClick(View v) {
            SharedPreferencesRead();
            // edit_out.setText(read());
            edit_out.setText(ReadFromSdCard());
        }
    });

    Button btn_write = (Button) findViewById(R.id.btn_write);
    btn_write.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd" + "hh:mm:ss");

            editor.putString("time", sdf.format(new Date()));
            editor.putInt("random", (int) (Math.random() * 100));
            editor.commit();

            // write(edit_in.getText().toString());
            WriteToSdCard(edit_in.getText().toString());
            edit_in.setText("");
        }
    });

    Button btn_read_sdcard = (Button) findViewById(R.id.btn_read_sdcard);
    btn_read_sdcard.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            // */
            intent.setClass(MainActivity.this, ReadSdCardActivity.class);
            // */

            startActivity(intent);
        }
    });

    Button btn_dict = (Button) findViewById(R.id.btn_dict);
    btn_dict.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            // */
            intent.setClass(MainActivity.this, DictResolvertTest.class);
            // */
            startActivity(intent);
        }
    });
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Renames a sourceItem//from   www.j  a va  2s. co m
 * @param sourceItem The sourceItem to rename
 */
private void renameItem(final Item sourceItem) {
    final Activity activity = getActivity();
    final EditText newName = new EditText(activity);
    newName.setInputType(InputType.TYPE_CLASS_TEXT);
    newName.setHint(sourceItem.name);
    final AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle(R.string.rename)
            .setIcon(android.R.drawable.ic_menu_edit).setView(newName)
            .setPositiveButton(R.string.rename, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    final ICallback<Item> callback = new DefaultCallback<Item>(getActivity()) {
                        @Override
                        public void success(final Item item) {
                            Toast.makeText(activity,
                                    activity.getString(R.string.renamed_item, sourceItem.name, item.name),
                                    Toast.LENGTH_LONG).show();
                            refresh();
                            dialog.dismiss();
                        }

                        @Override
                        public void failure(final ClientException error) {
                            Toast.makeText(activity, activity.getString(R.string.rename_error, sourceItem.name),
                                    Toast.LENGTH_LONG).show();
                            dialog.dismiss();
                        }
                    };
                    Item updatedItem = new Item();
                    updatedItem.id = sourceItem.id;
                    updatedItem.name = newName.getText().toString();
                    ((BaseApplication) activity.getApplication()).getOneDriveClient().getDrive()
                            .getItems(updatedItem.id).buildRequest().update(updatedItem, callback);
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.cancel();
                }
            }).create();
    alertDialog.show();
}

From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Creates a folder//from ww w .java2 s  .  c o m
 * @param item The parent of the folder to create
 */
private void createFolder(final Item item) {
    final Activity activity = getActivity();
    final EditText newName = new EditText(activity);
    newName.setInputType(InputType.TYPE_CLASS_TEXT);
    newName.setHint(activity.getString(R.string.new_folder_hint));

    final AlertDialog alertDialog = new AlertDialog.Builder(activity).setTitle(R.string.create_folder)
            .setView(newName).setIcon(android.R.drawable.ic_menu_add)
            .setPositiveButton(R.string.create_folder, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    final ICallback<Item> callback = new DefaultCallback<Item>(activity) {
                        @Override
                        public void success(final Item createdItem) {
                            Toast.makeText(activity,
                                    activity.getString(R.string.created_folder, createdItem.name, item.name),
                                    Toast.LENGTH_LONG).show();
                            refresh();
                            dialog.dismiss();
                        }

                        @Override
                        public void failure(final ClientException error) {
                            super.failure(error);
                            Toast.makeText(activity, activity.getString(R.string.new_folder_error, item.name),
                                    Toast.LENGTH_LONG).show();
                            dialog.dismiss();
                        }
                    };

                    final Item newItem = new Item();
                    newItem.name = newName.getText().toString();
                    newItem.folder = new Folder();

                    ((BaseApplication) activity.getApplication()).getOneDriveClient().getDrive()
                            .getItems(mItemId).getChildren().buildRequest().create(newItem, callback);
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    dialog.cancel();
                }
            }).create();
    alertDialog.show();
}

From source file:knayi.delevadriver.JobDetailActivity.java

@Override
public void onClick(View v) {

    Calendar calendar = Calendar.getInstance();
    final long timestamp = System.currentTimeMillis();
    final String token = sPref.getString(Config.TOKEN, null);

    switch (v.getId()) {

    case R.id.job_reject:

        if (job_reject.getText().toString().equals("Reject")) {

            MaterialDialog dialog = new MaterialDialog.Builder(this).titleColor(R.color.white)
                    .customView(R.layout.reject_layout, true).positiveText("REJECT")
                    .positiveColor(R.color.white).positiveColorRes(R.color.white).negativeText("CANCEL")
                    .negativeColorRes(R.color.white).backgroundColorRes(R.color.primary)
                    .typeface("ciclefina.ttf", "ciclegordita.ttf")
                    .callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(final MaterialDialog dialog) {
                            super.onPositive(dialog);

                            EditText et_message = (EditText) dialog.findViewById(R.id.reject_message);

                            if (!et_message.getText().toString().equals("")) {
                                AvaliableJobsAPI.getInstance().getService().rejectJob(jobitem.get_id(), token,
                                        et_message.getText().toString(), "true", new Callback<String>() {
                                            @Override
                                            public void success(String s, Response response) {
                                                Toast.makeText(JobDetailActivity.this,
                                                        "Job is successfully rejected", Toast.LENGTH_SHORT)
                                                        .show();
                                                dialog.dismiss();

                                                //remove job id that is saved to use in locatin update
                                                sPref.edit().putString(Config.TOKEN_JOBID, null).commit();
                                                sPref.edit().putString(Config.TOKEN_DELAY, null).commit();

                                                //check report service is alive
                                                //if alive stop service
                                                if (sPref.getBoolean(Config.TOKEN_SERVICE_ALIVE, false)) {
                                                    Intent intentservice = new Intent(JobDetailActivity.this,
                                                            BackgroundLocationService.class);
                                                    stopService(intentservice);
                                                }

                                                Intent intent = new Intent(JobDetailActivity.this,
                                                        DrawerMainActivity.class);
                                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                                                        | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                                startActivity(intent);
                                                finish();
                                            }

                                            @Override
                                            public void failure(RetrofitError error) {

                                                if (error.getBody() == null) {
                                                    Toast.makeText(JobDetailActivity.this,
                                                            "Cannot connect to server!", Toast.LENGTH_SHORT)
                                                            .show();
                                                } else {

                                                    String errmsg = error.getBody().toString();
                                                    String errcode = "";

                                                    try {
                                                        JSONObject errobj = new JSONObject(errmsg);

                                                        errcode = errobj.getJSONObject("err")
                                                                .getString("message");

                                                        Toast.makeText(JobDetailActivity.this, errcode,
                                                                Toast.LENGTH_SHORT).show();

                                                    } catch (JSONException e) {
                                                        e.printStackTrace();
                                                    }

                                                }

                                                dialog.dismiss();
                                            }
                                        });
                            } else {
                                Toast.makeText(JobDetailActivity.this, "Please enter your message",
                                        Toast.LENGTH_SHORT).show();
                            }//from w w w.j a  va 2  s  . c o  m

                            progress.setVisibility(View.INVISIBLE);
                            progress_background.setVisibility(View.INVISIBLE);

                        }

                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);

                            dialog.dismiss();
                            progress.setVisibility(View.INVISIBLE);
                            progress_background.setVisibility(View.INVISIBLE);

                        }
                    }

                    ).build();

            dialog.show();

            EditText et_message = (EditText) dialog.findViewById(R.id.reject_message);
            et_message.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));

        }
        /*else{
                
            final Dialog msgDialog = new Dialog(JobDetailActivity.this);
                
            msgDialog.setTitle("Why do u reject?");
            msgDialog.setCancelable(true);
            msgDialog.setContentView(R.layout.custom_dialog_reason);
            final EditText message = (EditText) msgDialog.findViewById(R.id.messagebox);
            Button submit = (Button) msgDialog.findViewById(R.id.submitbutton);
                
            msgDialog.show();
                
            submit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                
                    progress.setVisibility(View.VISIBLE);
                
                    progress_background.setVisibility(View.VISIBLE);
                
                    if(message.getText().toString().equals("") && message.getText().toString().equals(null)){
                        Toast.makeText(getApplicationContext(), "Please input message to submit", Toast.LENGTH_SHORT).show();
                    }else{
                        msgDialog.dismiss();
                
                        progress.setVisibility(View.VISIBLE);
                        progress_background.setVisibility(View.VISIBLE);
                        if(token == null){
                            new SweetAlertDialog(JobDetailActivity.this, SweetAlertDialog.WARNING_TYPE)
                                    .setTitleText("")
                                    .setContentText("Please Login again!")
                                    .show();
                            finish();
                            startActivity(new Intent(JobDetailActivity.this, LoginActivity.class));
                
                
                
                        }
                        else{
                            AvaliableJobsAPI.getInstance().getService().rejectJob(jobitem.get_id(), token, location, String.valueOf(timestamp), message.getText().toString(), new Callback<String>() {
                                @Override
                                public void success(String s, Response response) {
                                    progress.setVisibility(View.INVISIBLE);
                                    progress_background.setVisibility(View.INVISIBLE);
                                    startActivity(new Intent(JobDetailActivity.this, TabMainActivity.class));
                                    finish();
                
                                }
                
                                @Override
                                public void failure(RetrofitError error) {
                                    progress.setVisibility(View.INVISIBLE);
                                    progress_background.setVisibility(View.INVISIBLE);
                                    Toast.makeText(getApplicationContext(), "Something Went Wrong!", Toast.LENGTH_SHORT).show();
                                }
                            });
                
                        }
                    }
                
                }
            });
                
        }*/

        break;

    case R.id.job_bid:

        progress.setVisibility(View.VISIBLE);
        progress_background.setVisibility(View.VISIBLE);

        if (token == null) {

            MaterialDialog dialog = new MaterialDialog.Builder(this)
                    .customView(R.layout.custom_message_dialog, false).positiveText("OK")
                    .positiveColor(R.color.white).positiveColorRes(R.color.white)
                    .backgroundColorRes(R.color.primary).typeface("ciclefina.ttf", "ciclegordita.ttf").build();
            dialog.show();

            TextView txt_title = (TextView) dialog.findViewById(R.id.dialog_title);
            TextView txt_message = (TextView) dialog.findViewById(R.id.dialog_message);
            txt_title.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));
            txt_message.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));

            txt_title.setText("Please Login again!");
            txt_message.setText("Server doesn't know this account!");

            Intent intent = new Intent(JobDetailActivity.this, LoginActivity.class);
            startActivity(intent);
            finish();
        }

        if (job_bid.getText().toString().equals("Bid")) {

            final long ts1 = System.currentTimeMillis();

            Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

            if (mLastLocation != null) {
                location = mLastLocation.getLongitude() + "," + mLastLocation.getLatitude();
            }

            acceptJob(token, String.valueOf(ts1), "");

            /*MaterialDialog dialog = new MaterialDialog.Builder(this)
                    .title("Estimate time of arrival to pick up point")
                    .customView(R.layout.estimatetime_layout, true)
                    .positiveText("BID")
                    .positiveColor(R.color.primary)
                    .positiveColorRes(R.color.primary)
                    .negativeText("CANCEL")
                    .negativeColorRes(R.color.primary)
                    .cancelable(false)
                    .callback(new MaterialDialog.ButtonCallback() {
                                  @Override
                                  public void onPositive(MaterialDialog dialog) {
                                      super.onPositive(dialog);
                    
                                      EditText et_estimatetime = (EditText) dialog.findViewById(R.id.estimatetime_et);
                    
                    
                                      if(!et_estimatetime.getText().toString().equals("")) {
                                          acceptJob(token, String.valueOf(ts1), et_estimatetime.getText().toString());
                                      }else{
                                          Toast.makeText(JobDetailActivity.this, "Please Input Fields!", Toast.LENGTH_SHORT).show();
                                          progress.setVisibility(View.INVISIBLE);
                                          progress_background.setVisibility(View.INVISIBLE);
                                      }
                    
                    
                                  }
                    
                                  @Override
                                  public void onNegative(MaterialDialog dialog) {
                                      super.onNegative(dialog);
                    
                                      dialog.dismiss();
                                      progress.setVisibility(View.INVISIBLE);
                                      progress_background.setVisibility(View.INVISIBLE);
                    
                                  }
                              }
                    
                    )
                    .build();
                    
                    
            dialog.show();
                    
            final EditText et_estimatetime = (EditText) dialog.findViewById(R.id.estimatetime_et);
                    
            et_estimatetime.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Calendar mcurrentTime = Calendar.getInstance();
                    int hour = mcurrentTime.get(Calendar.HOUR_OF_DAY);
                    int minute = mcurrentTime.get(Calendar.MINUTE);
                    TimePickerDialog mTimePicker;
                    mTimePicker = new TimePickerDialog(JobDetailActivity.this, new TimePickerDialog.OnTimeSetListener() {
                        @Override
                        public void onTimeSet(TimePicker timePicker, int selectedHour, int selectedMinute) {
                            et_estimatetime.setText( selectedHour + ":" + selectedMinute);
                        }
                    }, hour, minute, true);//Yes 24 hour time
                    mTimePicker.setTitle("Select Time");
                    mTimePicker.show();
                }
            });*/

        }

        else if (job_bid.getText().toString().equals("Agree")) {

            AvaliableJobsAPI.getInstance().getService().agreeJob(jobitem.get_id(), token, "true",
                    new Callback<String>() {
                        @Override
                        public void success(String s, Response response) {
                            Toast.makeText(JobDetailActivity.this, "Success", Toast.LENGTH_SHORT).show();

                            getDataFromServer(job_id);
                        }

                        @Override
                        public void failure(RetrofitError error) {

                            if (error.getBody() == null) {
                                Toast.makeText(JobDetailActivity.this, "Cannot connect to server!",
                                        Toast.LENGTH_SHORT).show();
                            } else {

                                String errmsg = error.getBody().toString();
                                String errcode = "";

                                try {
                                    JSONObject errobj = new JSONObject(errmsg);

                                    errcode = errobj.getJSONObject("err").getString("message");

                                    Toast.makeText(JobDetailActivity.this, errcode, Toast.LENGTH_SHORT).show();

                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }

                            }

                        }
                    });

        }

        else if (job_bid.getText().toString().equals("Finished")) {

            MaterialDialog dialog = new MaterialDialog.Builder(this).titleColor(R.color.white)
                    .customView(R.layout.custom_request_message_dialog, true).positiveText("SEND")
                    .positiveColor(R.color.white).positiveColorRes(R.color.white).negativeText("CANCEL")
                    .negativeColorRes(R.color.white).backgroundColorRes(R.color.primary)
                    .typeface("ciclefina.ttf", "ciclegordita.ttf")
                    .callback(new MaterialDialog.ButtonCallback() {
                        @Override
                        public void onPositive(MaterialDialog dialog) {
                            super.onPositive(dialog);

                            EditText request_secret_code = (EditText) dialog
                                    .findViewById(R.id.request_secret_code);
                            /*EditText request_msg = (EditText) dialog.findViewById(R.id.request_msg);*/

                            if (request_secret_code != null) {

                                if (request_secret_code.getText().toString() != null
                                        && request_secret_code.getText().toString() != "") {

                                    Location mLastLocation = LocationServices.FusedLocationApi
                                            .getLastLocation(mGoogleApiClient);
                                    Long tsLong = System.currentTimeMillis();
                                    String ts = tsLong.toString();

                                    String location = "96,16";

                                    if (mLastLocation != null) {
                                        location = mLastLocation.getLongitude() + ","
                                                + mLastLocation.getLatitude();
                                    }

                                    final long timestamp = System.currentTimeMillis();
                                    JSONObject obj = new JSONObject();
                                    try {
                                        obj.put("location", location);
                                        obj.put("timestamp", String.valueOf(timestamp));
                                        obj.put("secret_code", request_secret_code.getText().toString());
                                        obj.put("message", "");//request_msg.getText().toString());
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }

                                    String json = obj.toString();

                                    try {
                                        TypedInput in = new TypedByteArray("application/json",
                                                json.getBytes("UTF-8"));

                                        progress.setVisibility(View.VISIBLE);
                                        progress_background.setVisibility(View.VISIBLE);

                                        AvaliableJobsAPI.getInstance().getService().jobDone(jobitem.get_id(),
                                                token, in, new Callback<String>() {
                                                    @Override
                                                    public void success(String s, Response response) {

                                                        Toast.makeText(JobDetailActivity.this,
                                                                "Message is sent successfully",
                                                                Toast.LENGTH_SHORT).show();

                                                        sPref.edit().putString(Config.TOKEN_DELAY, null)
                                                                .commit();

                                                        if (sPref.getBoolean(Config.TOKEN_SERVICE_ALIVE,
                                                                false)) {
                                                            Intent intentservice = new Intent(
                                                                    JobDetailActivity.this,
                                                                    BackgroundLocationService.class);
                                                            stopService(intentservice);
                                                        }

                                                        progress.setVisibility(View.INVISIBLE);
                                                        progress_background.setVisibility(View.INVISIBLE);

                                                        bitLayout.setVisibility(View.GONE);

                                                    }

                                                    @Override
                                                    public void failure(RetrofitError error) {

                                                        //Toast.makeText(JobDetailActivity.this, "Failed, Please Try Again!", Toast.LENGTH_SHORT).show();

                                                        if (error.getBody() == null) {
                                                            Toast.makeText(JobDetailActivity.this,
                                                                    "Cannot connect to server!",
                                                                    Toast.LENGTH_SHORT).show();
                                                        } else {

                                                            String errmsg = error.getBody().toString();
                                                            String errcode = "";

                                                            try {
                                                                JSONObject errobj = new JSONObject(errmsg);

                                                                errcode = errobj.getJSONObject("err")
                                                                        .getString("message");

                                                                Toast.makeText(JobDetailActivity.this, errcode,
                                                                        Toast.LENGTH_SHORT).show();

                                                            } catch (JSONException e) {
                                                                e.printStackTrace();
                                                            }

                                                        }

                                                        progress.setVisibility(View.INVISIBLE);
                                                        progress_background.setVisibility(View.INVISIBLE);

                                                    }
                                                });

                                    } catch (UnsupportedEncodingException e) {
                                        e.printStackTrace();
                                    }

                                }

                            }

                            progress.setVisibility(View.INVISIBLE);
                            progress_background.setVisibility(View.INVISIBLE);

                        }

                        @Override
                        public void onNegative(MaterialDialog dialog) {
                            super.onNegative(dialog);

                            dialog.dismiss();
                            progress.setVisibility(View.INVISIBLE);
                            progress_background.setVisibility(View.INVISIBLE);

                        }
                    }

                    ).build();

            dialog.show();

            EditText request_secret_code = (EditText) dialog.findViewById(R.id.request_secret_code);
            /*EditText request_msg = (EditText) dialog.findViewById(R.id.request_msg);*/
            request_secret_code.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));
            /*request_msg.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));*/

        }

        break;

    case R.id.job_report:

        isFirstDialog = true;

        totalprice = Double.parseDouble(jobitem.get_price());

        final MaterialDialog dialog = new MaterialDialog.Builder(this).customView(R.layout.report_layout, true)
                .positiveText("REPORT").positiveColor(R.color.white).positiveColorRes(R.color.white)
                .negativeText("CANCEL").negativeColorRes(R.color.white).backgroundColorRes(R.color.primary)
                .typeface("ciclefina.ttf", "ciclegordita.ttf").callback(new MaterialDialog.ButtonCallback() {
                    @Override
                    public void onPositive(final MaterialDialog dialog) {
                        super.onPositive(dialog);

                        CheckBox cb_weight = (CheckBox) dialog.findViewById(R.id.report_cb_overweight);
                        CheckBox cb_express = (CheckBox) dialog.findViewById(R.id.report_cb_express);
                        CheckBox cb_refrig = (CheckBox) dialog.findViewById(R.id.report_cb_refrigerated);
                        //CheckBox cb_type = (CheckBox) dialog.findViewById(R.id.report_cb_type);

                        final Spinner sp_weight = (Spinner) dialog.findViewById(R.id.report_spinner_overweight);
                        //final Spinner sp_type = (Spinner) dialog.findViewById(R.id.report_spinner_type);

                        EditText et_message = (EditText) dialog.findViewById(R.id.report_et_message);

                        //Refrage

                        if (!et_message.getText().toString().equals("")
                                && et_message.getText().toString() != null) {

                            if (cb_weight.isChecked() || cb_express.isChecked() || cb_refrig.isChecked()) {

                                String message = "";//et_message.getText().toString();

                                if (cb_express.isChecked()) {
                                    message += "true,";
                                } else {
                                    message += "false,";
                                }

                                if (cb_refrig.isChecked()) {
                                    message += "true,";
                                } else {
                                    message += "false,";
                                }

                                if (cb_weight.isChecked()) {
                                    message += weightlist.get(sp_weight.getSelectedItemPosition()) + ",";
                                } else {
                                    message += ",";
                                }

                                AvaliableJobsAPI.getInstance().getService().reportJob(jobitem.get_id(), token,
                                        message, "0", new Callback<String>() {
                                            @Override
                                            public void success(String s, Response response) {
                                                Toast.makeText(JobDetailActivity.this,
                                                        "Your report has successfully sent", Toast.LENGTH_SHORT)
                                                        .show();

                                                dialog.dismiss();
                                            }

                                            @Override
                                            public void failure(RetrofitError error) {
                                                //Toast.makeText(JobDetailActivity.this, "Report is Failed", Toast.LENGTH_SHORT).show();

                                                if (error.getBody() == null) {
                                                    Toast.makeText(JobDetailActivity.this,
                                                            "Cannot connect to server!", Toast.LENGTH_SHORT)
                                                            .show();
                                                } else {

                                                    String errmsg = error.getBody().toString();
                                                    String errcode = "";

                                                    try {
                                                        JSONObject errobj = new JSONObject(errmsg);

                                                        errcode = errobj.getJSONObject("err")
                                                                .getString("message");

                                                        Toast.makeText(JobDetailActivity.this, errcode,
                                                                Toast.LENGTH_SHORT).show();

                                                    } catch (JSONException e) {
                                                        e.printStackTrace();
                                                    }

                                                }

                                                dialog.dismiss();
                                            }
                                        });
                            } else {

                                Toast.makeText(JobDetailActivity.this, "Please select report reason",
                                        Toast.LENGTH_SHORT).show();
                            }

                        } else {
                            Toast.makeText(JobDetailActivity.this, "Please enter your message",
                                    Toast.LENGTH_SHORT).show();
                        }

                        progress.setVisibility(View.INVISIBLE);
                        progress_background.setVisibility(View.INVISIBLE);

                    }

                    @Override
                    public void onNegative(MaterialDialog dialog) {
                        super.onNegative(dialog);

                        dialog.dismiss();
                        progress.setVisibility(View.INVISIBLE);
                        progress_background.setVisibility(View.INVISIBLE);

                    }
                }

                ).build();

        dialog.show();

        final CheckBox cb_weight = (CheckBox) dialog.findViewById(R.id.report_cb_overweight);
        //final CheckBox cb_type = (CheckBox) dialog.findViewById(R.id.report_cb_type);

        CheckBox cb_express = (CheckBox) dialog.findViewById(R.id.report_cb_express);
        CheckBox cb_refrig = (CheckBox) dialog.findViewById(R.id.report_cb_refrigerated);
        EditText et_message = (EditText) dialog.findViewById(R.id.report_et_message);

        et_message.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));
        cb_weight.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));
        cb_express.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));
        cb_refrig.setTypeface(MyTypeFace.get(JobDetailActivity.this, MyTypeFace.NORMAL));

        if (jobitem.getIsExpress().equals("true")) {
            cb_express.setChecked(true);
        }

        if (jobitem.getIsRefrigerated().equals("true")) {
            cb_refrig.setChecked(true);
        }

        //final TextView tv_price = (TextView) dialog.findViewById(R.id.report_price_tag);

        final Spinner sp_weight = (Spinner) dialog.findViewById(R.id.report_spinner_overweight);
        //final Spinner sp_type = (Spinner) dialog.findViewById(R.id.report_spinner_type);

        sp_weight.setEnabled(false);
        //sp_type.setEnabled(false);

        //tv_price.setText("price " + jobitem.get_price());

        sp_weight.setAdapter(new ArrayAdapter<String>(JobDetailActivity.this,
                android.R.layout.simple_spinner_dropdown_item, weightshowlist));
        //sp_type.setAdapter(new ArrayAdapter<String>(JobDetailActivity.this, android.R.layout.simple_spinner_dropdown_item, new String[]{"Other", "Express", "Refrigerated"}));

        sp_weight.setSelection(weightpos);
        //sp_type.setSelection(typepos);

        sp_weight.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                if (!isFirstDialog) {

                    totalprice += weightPricelist.get(sp_weight.getSelectedItemPosition());

                } else {
                    isFirstDialog = false;
                }

                /*if(cb_type.isChecked()){
                    totalprice += typepricelist.get(position);
                }*/

                //                        tv_price.setText("price " + String.valueOf(totalprice));
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        /*sp_type.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                totalprice = Double.parseDouble(jobitem.get_price());
                if (!isFirstDialog) {
                    totalprice += typepricelist.get(position);
                
                } else {
                    isFirstDialog = false;
                }
                
                if (cb_weight.isChecked()) {
                    totalprice += weightPricelist.get(sp_weight.getSelectedItemPosition());
                }
                
                tv_price.setText("price " + String.valueOf(totalprice));
            }
                
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                
            }
        });*/

        cb_weight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    sp_weight.setEnabled(true);

                    totalprice += weightPricelist.get(sp_weight.getSelectedItemPosition());

                } else {
                    sp_weight.setEnabled(false);
                    totalprice -= weightPricelist.get(sp_weight.getSelectedItemPosition());
                }

                //tv_price.setText("price " + String.valueOf(totalprice));
            }
        });

        /*cb_type.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    sp_type.setEnabled(true);
                    totalprice += typepricelist.get(sp_type.getSelectedItemPosition());
                }else{
                    sp_type.setEnabled(false);
                    totalprice -= typepricelist.get(sp_type.getSelectedItemPosition());
                }
                tv_price.setText("price " + String.valueOf(totalprice));
            }
        });*/

        break;

    default:
        Intent intent = new Intent(JobDetailActivity.this, DrawerMainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
        finish();
        break;

    }
}

From source file:com.moonpi.tapunlock.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    // Get pressed item information
    final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();

    // If Rename Tag pressed
    if (item.getTitle().equals(getResources().getString(R.string.rename_context_menu))) {
        // Create new EdiText and configure
        final EditText tagTitle = new EditText(this);
        tagTitle.setSingleLine(true);/*www.j ava 2s.co m*/
        tagTitle.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

        // Set tagTitle maxLength
        int maxLength = 50;
        InputFilter[] array = new InputFilter[1];
        array[0] = new InputFilter.LengthFilter(maxLength);
        tagTitle.setFilters(array);

        // Get tagName text into EditText
        try {
            assert info != null;
            tagTitle.setText(tags.getJSONObject(info.position).getString("tagName"));

        } catch (JSONException e) {
            e.printStackTrace();
        }

        final LinearLayout l = new LinearLayout(this);

        l.setOrientation(LinearLayout.VERTICAL);
        l.addView(tagTitle);

        // Show rename dialog
        new AlertDialog.Builder(this).setTitle(R.string.rename_tag_dialog_title).setView(l)
                .setPositiveButton(R.string.rename_tag_dialog_button, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // 'Rename' pressed, change tagName and store
                        try {
                            JSONObject newTagName = tags.getJSONObject(info.position);
                            newTagName.put("tagName", tagTitle.getText());

                            tags.put(info.position, newTagName);
                            adapter.notifyDataSetChanged();

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        writeToJSON();

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_renamed,
                                Toast.LENGTH_SHORT);
                        toast.show();

                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);

                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        imm.hideSoftInputFromWindow(tagTitle.getWindowToken(), 0);
                    }
                }).show();
        tagTitle.requestFocus();
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

        return true;
    }

    // If Delete Tag pressed
    else if (item.getTitle().equals(getResources().getString(R.string.delete_context_menu))) {
        // Construct dialog message
        String dialogMessage = "";

        assert info != null;
        try {
            dialogMessage = getResources().getString(R.string.delete_context_menu_dialog1) + " '"
                    + tags.getJSONObject(info.position).getString("tagName") + "'?";

        } catch (JSONException e) {
            e.printStackTrace();
            dialogMessage = getResources().getString(R.string.delete_context_menu_dialog2);
        }

        // Show delete dialog
        new AlertDialog.Builder(this).setMessage(dialogMessage)
                .setPositiveButton(R.string.yes_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        JSONArray newArray = new JSONArray();

                        // Copy contents to new array, without the deleted item
                        for (int i = 0; i < tags.length(); i++) {
                            if (i != info.position) {
                                try {
                                    newArray.put(tags.get(i));

                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                            }
                        }

                        // Equal original array to new array
                        tags = newArray;

                        // Write to file
                        try {
                            settings.put("tags", tags);
                            root.put("settings", settings);

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        writeToJSON();

                        adapter.adapterData = tags;
                        adapter.notifyDataSetChanged();

                        updateListViewHeight(listView);

                        // If no tags, show 'Press + to add Tags' textView
                        if (tags.length() == 0)
                            noTags.setVisibility(View.VISIBLE);

                        else
                            noTags.setVisibility(View.INVISIBLE);

                        Toast toast = Toast.makeText(getApplicationContext(), R.string.toast_tag_deleted,
                                Toast.LENGTH_SHORT);
                        toast.show();

                    }
                }).setNegativeButton(R.string.no_button, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Do nothing, close dialog
                    }
                }).show();

        return true;
    }

    return super.onContextItemSelected(item);
}

From source file:com.ezac.gliderlogs.FlightOverviewActivity.java

public void DoServices() {
    // get services.xml view
    LayoutInflater li = LayoutInflater.from(context);
    servicesView = li.inflate(R.layout.services, null);

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

    // set prompts.xml to alertdialog builder
    alertDialogBuilder.setView(servicesView);

    final EditText userInput = (EditText) servicesView.findViewById(R.id.editTextDialogUserInput);

    // set dialog message
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override/*ww  w .  jav  a2  s  .  c o m*/
        public void onClick(DialogInterface dialog, int id) {
            // get user input and set it to result
            if (userInput.getText().toString().equals("To3Myd4T")) {
                Log.d(TAG, "ok, user request to delete all, do it");
                CheckBox csv_ok = (CheckBox) servicesView.findViewById(R.id.service_csv);
                CheckBox db_ok = (CheckBox) servicesView.findViewById(R.id.service_db);
                // make a copy to csv file
                if (csv_ok.isChecked()) {
                    GliderLogToCSV("gliderlogs.db", "ezac");
                    makeToast("Export naar een CSV bestand is uitgevoerd !", 2);
                }
                // make a copy to sqlite database file
                if (db_ok.isChecked()) {
                    GliderLogToDB("com.ezac.gliderlogs", "gliderlogs.db", "ezac");
                    makeToast("Export naar een DB bestand is uitgevoerd !", 2);
                }
                if (csv_ok.isChecked() || db_ok.isChecked()) {
                    sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
                            Uri.parse("file://" + Environment.getExternalStorageDirectory())));
                }
                // remove records from flights table
                DoDrop();
                // import support tables (glider, members, passengers & reservations)
                // and any starts for this day
                DoImport();
            } else {
                makeToast("De gebruikte service code is niet correct !", 0);
                Log.d(TAG, "Fail, user service code error >" + userInput.getText().toString() + "<");
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    // show it
    alertDialog.show();
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@SuppressLint("InflateParams")
private void optionTemplate() {
    final int userId = Util.getUserId(Process.myUid());

    // Build view
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.template, null);
    final Spinner spTemplate = (Spinner) view.findViewById(R.id.spTemplate);
    Button btnRename = (Button) view.findViewById(R.id.btnRename);
    ExpandableListView elvTemplate = (ExpandableListView) view.findViewById(R.id.elvTemplate);

    // Template selector
    final SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    String defaultName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, "0",
            getString(R.string.title_default));
    spAdapter.add(defaultName);/*from ww  w. ja  v  a 2s  .c om*/
    for (int i = 1; i <= 4; i++) {
        String alternateName = PrivacyManager.getSetting(userId, Meta.cTypeTemplateName, Integer.toString(i),
                getString(R.string.title_alternate) + " " + i);
        spAdapter.add(alternateName);
    }
    spTemplate.setAdapter(spAdapter);

    // Template definition
    final TemplateListAdapter templateAdapter = new TemplateListAdapter(this, view, R.layout.templateentry);
    elvTemplate.setAdapter(templateAdapter);
    elvTemplate.setGroupIndicator(null);

    spTemplate.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            templateAdapter.notifyDataSetChanged();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            templateAdapter.notifyDataSetChanged();
        }
    });

    btnRename.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (Util.hasProLicense(ActivityMain.this) == null) {
                // Redirect to pro page
                Util.viewUri(ActivityMain.this, cProUri);
                return;
            }

            final int templateId = spTemplate.getSelectedItemPosition();
            if (templateId == AdapterView.INVALID_POSITION)
                return;

            AlertDialog.Builder dlgRename = new AlertDialog.Builder(spTemplate.getContext());
            dlgRename.setTitle(R.string.title_rename);

            final String original = (templateId == 0 ? getString(R.string.title_default)
                    : getString(R.string.title_alternate) + " " + templateId);
            dlgRename.setMessage(original);

            final EditText input = new EditText(spTemplate.getContext());
            dlgRename.setView(input);

            dlgRename.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String name = input.getText().toString();
                    if (TextUtils.isEmpty(name)) {
                        PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId),
                                null);
                        name = original;
                    } else {
                        PrivacyManager.setSetting(userId, Meta.cTypeTemplateName, Integer.toString(templateId),
                                name);
                    }
                    spAdapter.remove(spAdapter.getItem(templateId));
                    spAdapter.insert(name, templateId);
                    spAdapter.notifyDataSetChanged();
                }
            });

            dlgRename.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing
                }
            });

            dlgRename.create().show();
        }
    });

    // Build dialog
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle(R.string.menu_template);
    alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
    alertDialogBuilder.setView(view);
    alertDialogBuilder.setPositiveButton(getString(R.string.msg_done), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // Do nothing
        }
    });

    // Show dialog
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
}

From source file:com.balakrish.gpstracker.WaypointsListActivity.java

/**
 * Update waypoint in the database//from  w  w w . java 2s .  c o m
 * 
 * @param waypointId
 * @param title
 * @param lat
 * @param lng
 */
protected void updateWaypoint(long waypointId) {

    Context context = this;

    // get waypoint data from db
    final Waypoint wp = Waypoints.get(app.getDatabase(), waypointId);

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.add_waypoint_dialog,
            (ViewGroup) findViewById(R.id.add_waypoint_dialog_layout_root));

    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    builder.setTitle(R.string.edit);
    builder.setView(layout);

    // creating reference to input field in order to use it in onClick
    // handler
    final EditText wpTitle = (EditText) layout.findViewById(R.id.waypointTitleInputText);
    wpTitle.setText(wp.getTitle());

    final EditText wpDescr = (EditText) layout.findViewById(R.id.waypointDescriptionInputText);
    wpDescr.setText(wp.getDescr());

    final EditText wpLat = (EditText) layout.findViewById(R.id.waypointLatInputText);
    wpLat.setText(Double.toString(wp.getLat()));

    final EditText wpLng = (EditText) layout.findViewById(R.id.waypointLngInputText);
    wpLng.setText(Double.toString(wp.getLng()));

    // this event will be overridden in OnShowListener for validation
    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
        }
    });

    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });

    final AlertDialog dialog = builder.create();

    // override setOnShowListener in order to validate dialog without closing it
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {

            Button b = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            b.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {

                    // waypoint title from input dialog

                    if (wpTitle.getText().toString().trim().equals("")) {
                        Toast.makeText(WaypointsListActivity.this, R.string.waypoint_title_required,
                                Toast.LENGTH_SHORT).show();
                        return;
                    }

                    wp.setTitle(wpTitle.getText().toString().trim());
                    wp.setDescr(wpDescr.getText().toString().trim());

                    // validate coordinates
                    try {
                        wp.setLat(Double.parseDouble(wpLat.getText().toString()));
                        wp.setLng(Double.parseDouble(wpLng.getText().toString()));
                    } catch (NumberFormatException e) {
                        Toast.makeText(WaypointsListActivity.this, R.string.incorrect_coordinates,
                                Toast.LENGTH_SHORT).show();
                        return;
                    }

                    try {

                        // update waypoint data in db
                        Waypoints.update(app.getDatabase(), wp);

                        Toast.makeText(WaypointsListActivity.this, R.string.waypoint_updated,
                                Toast.LENGTH_SHORT).show();

                        // cursor.requery();
                        updateWaypointsArray();
                        waypointsArrayAdapter.setItems(waypoints);
                        waypointsArrayAdapter.notifyDataSetChanged();

                    } catch (SQLiteException e) {
                        AppLog.e(WaypointsListActivity.this, "SQLiteException: " + e.getMessage());
                        return;
                    }

                    dialog.dismiss();

                }
            });
        }
    });

    dialog.show();

}

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

@Override
protected Dialog onCreateDialog(int id) {
    final Dialog dialog;
    ProgressDialog pdialog;//  ww  w  .j  av  a2  s .c o  m
    AlertDialog.Builder builder;
    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;
}