Example usage for android.content DialogInterface cancel

List of usage examples for android.content DialogInterface cancel

Introduction

In this page you can find the example usage for android.content DialogInterface cancel.

Prototype

void cancel();

Source Link

Document

Cancels the dialog, invoking the OnCancelListener .

Usage

From source file:com.cypress.cysmart.HomePageActivity.java

/**
 * Method to create an alert before user exit from the application
 *//*  w  ww .  jav a  2  s  . c  o  m*/
void alertbox() {
    AlertDialog.Builder builder = new AlertDialog.Builder(HomePageActivity.this);
    builder.setMessage(getResources().getString(R.string.alert_message_exit)).setCancelable(false)
            .setTitle(getResources().getString(R.string.app_name))
            .setPositiveButton(getResources().getString(R.string.alert_message_exit_ok),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // Finish the current activity
                            HomePageActivity.this.finish();
                            Intent gattServiceIntent = new Intent(getApplicationContext(),
                                    BluetoothLeService.class);
                            stopService(gattServiceIntent);

                        }
                    })
            .setNegativeButton(getResources().getString(R.string.alert_message_exit_cancel),
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // Cancel the dialog box
                            dialog.cancel();
                        }
                    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.googlecode.networklog.NetworkLog.java

public void confirmExit() {
    Context context = this;

    if (settings.getConfirmExit() == false) {
        finish();//from  ww w. j a  v  a 2 s.  c om
        return;
    }

    StringBuilder message = new StringBuilder(getString(R.string.confirm_exit_text));
    boolean serviceRunning = isServiceRunning(context, NetworkLogService.class.getName());

    if (serviceRunning) {
        message.append("\n\n");
        if (stopServiceAtExit) {
            message.append(getString(R.string.logging_will_stop));
        } else {
            message.append(getString(R.string.logging_will_continue));
        }
    }

    View checkBoxView = View.inflate(this, R.layout.confirm_exit_checkbox, null);
    final CheckBox checkBox = (CheckBox) checkBoxView.findViewById(R.id.confirm_exit_checkbox);
    checkBox.setChecked(false);

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(getString(R.string.confirm_exit_title)).setMessage(message.toString()).setCancelable(true)
            .setView(checkBoxView)
            .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    settings.setConfirmExit(!checkBox.isChecked());
                    finish();
                }
            }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.snt.bt.recon.activities.MainActivity.java

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Your GPS is currently disabled, do you want to manually enable it?")
            .setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }//w w w  . j av  a 2s .  c o m
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    dialog.cancel();
                    //close app
                    finishAffinity();

                }
            });
    final AlertDialog alert = builder.create();
    alert.show();

}

From source file:co.edu.uniajc.vtf.content.ListSitesFragment.java

public Dialog createDialog() {
    LayoutInflater loInflater = this.getActivity().getLayoutInflater();

    AlertDialog.Builder loAlert = new AlertDialog.Builder(getActivity());
    loAlert.setView(loInflater.inflate(R.layout.dialog_search, null));
    loAlert.setPositiveButton(R.string.general_menus_search, new DialogInterface.OnClickListener() {
        @Override// ww w  .  ja v a 2 s.c  o  m
        public void onClick(DialogInterface dialog, int id) {
            OptionsManager loOptions = new OptionsManager(ListSitesFragment.this.getActivity());
            OptionsEntity loOptionsData = loOptions.getOptions();
            EditText loSearchControl = (EditText) ((AlertDialog) dialog).findViewById(R.id.txtSearch);
            loOptionsData.setSearch(loSearchControl.getText().toString());
            loOptions.createOrUpdateOptions(loOptionsData);
            ListSitesFragment.this.cboForceUpdate = true;
            ListSitesFragment.this.loadList(LoadActions.LOAD_DATA);
            dialog.dismiss();
        }
    });

    loAlert.setNegativeButton(R.string.general_menus_cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
            dialog.dismiss();
        }
    });

    loAlert.setNeutralButton(R.string.general_menus_clear, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            OptionsManager loOptions = new OptionsManager(ListSitesFragment.this.getActivity());
            OptionsEntity loOptionsData = loOptions.getOptions();
            loOptionsData.setSearch("");
            loOptions.createOrUpdateOptions(loOptionsData);
            EditText loSearchControl = (EditText) ((AlertDialog) dialog).findViewById(R.id.txtSearch);
            loSearchControl.setText("");
            ListSitesFragment.this.cboForceUpdate = true;
            ListSitesFragment.this.loadList(LoadActions.LOAD_DATA);
            dialog.dismiss();
        }
    });
    loAlert.setCancelable(false);
    return loAlert.create();
}

From source file:arc.noaa.weather.activities.MainActivity.java

private void showLocationSettingsDialog() {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
    alertDialog.setTitle(R.string.location_settings);
    alertDialog.setMessage(R.string.location_settings_message);
    alertDialog.setPositiveButton(R.string.location_settings_button, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            startActivity(intent);/*  w w w.  j a  va 2  s.c  o m*/
        }
    });
    alertDialog.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    alertDialog.show();
}

From source file:org.uoyabause.android.YabauseHandler.java

@Override
public Dialog onCreateDialog(int id, Bundle args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(args.getString("message")).setCancelable(false)
            .setNegativeButton(R.string.exit, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Yabause.this.finish();
                }/*from  w  w  w .j a v  a2  s.  c  o  m*/
            }).setPositiveButton(R.string.ignore, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    return alert;
}

From source file:com.example.android.naradaoffline.DatagramFragment.java

/**
 * Set up the UI and background operations for chat.
 *///  ww  w . ja va2s.c  om
private void setupChat() {
    Log.d(TAG);

    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.message);

    //mConversationView.setAdapter(mConversationArrayAdapter);

    // Initialize the compose field with a listener for the return key
    //        mOutEditText.setOnEditorActionListener(mWriteListener);

    // Initialize the send button with a listener that for click events

    mGetNewsPaper.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view) {

                //                    TextView textView = (TextView) view.findViewById(R.id.edit_text_out);
                DatagramRequest d = new DatagramRequest(DatagramRequestType.GET_NEWSPAPER,
                        mConnectedDeviceName);
                sendDatagramRequest(d);
            }
        }
    });

    // Initialize the send button with a listener that for click events
    mGetEmail.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            View view = getView();
            if (null != view) {
                //                    TextView textView = (TextView) view.findViewById(R.id.edit_text_out);

                Log.i(TAG, "button clicked");

                AlertDialog.Builder builder = new AlertDialog.Builder(DatagramFragment.this.getContext());
                builder.setTitle("Write your email here");

                LinearLayout layout = new LinearLayout(getContext());
                layout.setOrientation(LinearLayout.VERTICAL);

                // Set up the input
                final EditText email = new EditText(DatagramFragment.this.getContext());
                email.setHint("Recipient e-mail address");
                // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
                email.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
                layout.addView(email);
                final EditText input = new EditText(DatagramFragment.this.getContext());
                // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
                input.setHint("Type your e-mail here");
                input.setInputType(InputType.TYPE_CLASS_TEXT);
                layout.addView(input);

                builder.setView(layout);
                // Set up the buttons
                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mEmail = email.getText().toString();
                        mText = input.getText().toString();
                        DatagramRequest d = new DatagramRequest(DatagramRequestType.SEND_EMAIL,
                                mConnectedDeviceName, "", mEmail, mText);
                        sendDatagramRequest(d);

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

                builder.show();

            }
        }
    });

    // Initialize the BluetoothDatagramService to perform bluetooth connections
    mChatService = new BluetoothDatagramService(getActivity(), mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");
}

From source file:com.alivenet.dmvtaxi.fragment.FragmentRateYourRide.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.trip_completed, container, false);

    ratingBar = (RatingBar) view.findViewById(R.id.ratingbar);
    Text_tripcomplete_pickuplocation = (TextView) view.findViewById(R.id.tripcomplete_pickuplocation);
    Text_tripcomplete_dropoff_location = (TextView) view.findViewById(R.id.tripcomplete_dropoff_location);
    mname = (TextView) view.findViewById(R.id.tv_name);
    Text_tripcharged = (TextView) view.findViewById(R.id.tripcharged);
    mlicenceplate = (TextView) view.findViewById(R.id.tv_licenceplate);
    mtaname = (TextView) view.findViewById(R.id.tv_taname);
    mcommentbox = (EditText) view.findViewById(R.id.et_commentbox);
    btntip = (Button) view.findViewById(R.id.btntip);
    btnsubmit = (Button) view.findViewById(R.id.btnsubmit);
    icon = (ImageView) view.findViewById(R.id.tripcompltd_icons);

    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);
    mUserId = mPref.getString("userId", null);
    prgDialog = new ProgressDialog(getActivity());
    prgDialog.setMessage("Please wait...");
    prgDialog.setCancelable(false);/*from ww w.j  a v  a2s .  c o  m*/
    btntip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (MyApplication.RateyourRide == false) {

                LayoutInflater li = LayoutInflater.from(getContext());
                View promptsView = li.inflate(R.layout.prompts, null);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                alertDialogBuilder.setView(promptsView);
                tipValue = (EditText) promptsView.findViewById(R.id.edittip_value);
                // set dialog message
                alertDialogBuilder.setCancelable(false)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // get user input and set it to result
                                // edit text
                                if (tipValue.getText().toString().trim().length() == 0) {

                                } else {
                                    btntip.setText(String.format("Tip: $ %.2f",
                                            Double.valueOf(tipValue.getText().toString())));

                                }
                            }
                        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();

                getToken(mUserId);

            }

        }
    });
    rideDriverComplete = sharedPreference.getDriverRidercompleate(getActivity());
    String rideId = MyApplication.RideId;
    if (rideDriverComplete == null && rideId != null) {

        ValidateRidecomplet(mUserId, rideId);
    }

    if (MyApplication.RateyourRide == true) {
        btnsubmit.setVisibility(View.GONE);
        mcommentbox.setVisibility(View.GONE);
    }

    if (rideDriverComplete != null) {

        if (rideDriverComplete.getPickupaddress() != null && rideDriverComplete.getPickupaddress() != " "
                && rideDriverComplete.getDestinationaddress() != null
                && rideDriverComplete.getDestinationaddress() != " ") {
            Text_tripcomplete_pickuplocation.setText(rideDriverComplete.getPickupaddress());
            Text_tripcomplete_dropoff_location.setText(rideDriverComplete.getDestinationaddress());
        }
        try {

            Picasso.with(getActivity()).load(MyPreferences.getActiveInstance(getActivity()).getImageUrl())
                    .error(R.mipmap.avtar).placeholder(R.mipmap.avtar).into(icon);
        } catch (Exception e) {
            e.printStackTrace();
        }

        mname.setText(rideDriverComplete.driverNameride);
        mlicenceplate.setText(rideDriverComplete.licenseId);
        mtaname.setText(rideDriverComplete.vehicle);
        Text_tripcharged
                .setText("$" + rideDriverComplete.getTotalfare() + "  HAS BEEN CHARGED TO YOUR CREDIT CARD");

        btnsubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String totalStars = "Total Stars:: " + ratingBar.getNumStars();
                String rating = "Rating :: " + ratingBar.getRating();
                String tip = "";
                if (rideDriverComplete != null) {

                    String driverid = rideDriverComplete.getDriverIdride();
                    String rideId = rideDriverComplete.getRideId();
                    if (tipValue != null)
                        tip = tipValue.getText().toString();

                    String comment = mcommentbox.getText().toString();
                    if (driverid != null && rideId != null && totalStars != null && tip != null) {

                        validateRideRating(mUserId, driverid, rideId, totalStars, tip, comment);
                    }

                }
            }
        });
    }

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                // handle back button's click listener

                if (keyCode == KeyEvent.KEYCODE_BACK) {

                    Fragment homeFragment = new FragmentMainScreen();
                    FragmentManager frgManager;
                    frgManager = getFragmentManager();
                    frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit();

                    return true;
                }

                return true;
            }
            return false;
        }
    });

    return view;

}

From source file:ca.etsmtl.applets.etsmobile.ProfileActivity.java

@Override
protected Dialog onCreateDialog(final int id) {
    Dialog d = super.onCreateDialog(id);
    view = getLayoutInflater().inflate(R.layout.login_dialog, null);
    switch (id) {
    case SHOW_LOGIN:
        d = new AlertDialog.Builder(this).setTitle(getString(R.string.login_dialog_title)).setView(view)
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {

                    /**/*from   www .  j  a  v a  2  s  . co  m*/
                     * Login dialog onClick
                     */
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        String codeP;
                        String codeU;
                        switch (which) {
                        case DialogInterface.BUTTON_POSITIVE:
                            codeP = ((TextView) view.findViewById(R.id.login_dialog_code_univesel)).getText()
                                    .toString();
                            codeU = ((TextView) view.findViewById(R.id.login_dialog_mot_passe)).getText()
                                    .toString();
                            creds = new UserCredentials(codeP, codeU);
                            new ProfileTask(handler).execute(creds);
                            break;

                        default:
                            dialog.cancel();
                            dialog.dismiss();
                            break;
                        }
                    }
                }).create();
        break;
    }
    return d;
}

From source file:com.safecell.HomeScreenActivity.java

public void quitDialog(String title, String message) {
    boolean flag = false;
    new AlertDialog.Builder(HomeScreenActivity.this).setMessage(message).setTitle(title)
            .setNeutralButton("Quit", new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int which) {
                    TrackingService.AccountActive = false;
                    dialog.cancel();
                    finish();/*from w  ww . j  av a  2s .  c om*/
                }
            }).show();

}