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.safecell.ManageProfile_Activity.java

private void selectLicenseFromDialog() {
    if (licenseProgressDialog.isShowing() == false && scLicenseArrayList.size() > 0) {

        final CharSequence[] items = new CharSequence[scLicenseArrayList.size()];
        for (int i = 0; i < scLicenseArrayList.size(); i++) {
            items[i] = scLicenseArrayList.get(i).getName();
        }//from  w w  w. ja  v a 2 s.co  m

        new AlertDialog.Builder(context).setTitle("Select Licenses")
                .setSingleChoiceItems(items, licensesSelectIndex, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {

                        secondTitleLabelArray[4] = items[item].toString();
                        licensesSelectIndex = item;
                        setListAdapter(new manageProfileListAdapter(ManageProfile_Activity.this));

                        dialog.cancel();
                    }
                }).show();
    }
}

From source file:com.appunite.helpers.EditFragment.java

protected void discardItem() {
    checkState(mIsEdit);//w  ww . ja v a  2 s  .c o m
    new AlertDialog.Builder(getActivity()).setTitle(getDialogDeleteQuestionTitle())
            .setMessage(getDialogDeleteQuestionMessage())
            .setPositiveButton(getDialogDeleteQuestionRemoveButtonTitle(),
                    new DialogInterface.OnClickListener() {

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

                            checkState(mIsEdit);
                            realDiscardItem(mUri);

                            mDiscard = true;
                            FragmentActivity activity = getActivity();
                            activity.setResult(Activity.RESULT_OK);
                            activity.finish();
                        }
                    })
            .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).show();
}

From source file:br.com.sigacon.coletaDados.FragmentParcelasTabsPager.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.fragment_tabs_pager);
    setTitle(R.string.dados_parcela);//from w w  w . j  av  a  2 s  . c  o m
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    mTabHost = (TabHost) findViewById(android.R.id.tabhost);
    mTabHost.setup();

    mViewPager = (ViewPager) findViewById(R.id.pager);

    mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);

    mTabsAdapter.addTab(mTabHost.newTabSpec("maps").setIndicator(getString(R.string.mapa)),
            FragmentParcelasMap.CountingFragment.class, null);
    mTabsAdapter.addTab(mTabHost.newTabSpec("form").setIndicator(getString(R.string.formulario_parcela)),
            FragmentParcelasForm.CountingFragment.class, null);

    if (savedInstanceState != null) {
        mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));
    }

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            String provider = Settings.Secure.getString(getContentResolver(),
                    Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
            //Se vier null ou length == 0    por que o GPS esta desabilitado. 

            Log.e("sigaLog", "provider " + String.valueOf(provider == null) + " ou "
                    + ((provider.contains("gps")) ? provider : "not Gps"));
            if (provider == null || !provider.contains("gps")) {
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                        FragmentParcelasTabsPager.this);
                // Seta o Titulo do Dialog
                alertDialogBuilder.setTitle(R.string.atencao);
                Log.e("sigaLog", "alertDialogBuilder.setTitle");
                // seta a mensagem
                alertDialogBuilder.setMessage(R.string.gps_desativado);
                alertDialogBuilder.setCancelable(false)
                        .setPositiveButton(R.string.sim, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                //Para abrir a tela do menu pode fazer assim:   
                                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                startActivityForResult(intent, 1);
                            }
                        }).setNegativeButton(R.string.nao, new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });

                // Cria o alertDialog com o conteudo do alertDialogBuilder
                AlertDialog alertDialog = alertDialogBuilder.create();
                Log.e("sigaLog", "alertDialog.create");
                // Exibe o Dialog
                alertDialog.show();
                Log.e("sigaLog", "alertDialog.show");
            }
        }
    }, 1000);
}

From source file:com.cloudkick.NodeViewActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.do_connectbot:
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        String user = prefs.getString("sshUser", "root");
        Integer port = new Integer(prefs.getString("sshPort", "22"));
        String uri = "ssh://" + user + "@" + node.ipAddress + ":" + port + "/#" + user;
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        try {/*ww w  .  j a  v  a  2  s.  c  o  m*/
            startActivity(i);
        } catch (ActivityNotFoundException e) {
            // Suggest ConnectBot
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("SSH Client Not Found");
            String mfaMessage = ("The ConnectBot SSH Client is required to complete this operation. "
                    + "Would you like to install ConnectBot from the Android Market now?");
            builder.setMessage(mfaMessage);
            builder.setCancelable(true);
            builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Intent marketActivity = new Intent(Intent.ACTION_VIEW);
                    marketActivity.setData(Uri.parse("market://details?id=org.connectbot"));
                    startActivity(marketActivity);
                }
            });
            builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog mfaDialog = builder.create();
            mfaDialog.show();
        }
        return true;
    default:
        // If its not recognized, do nothing
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.paramedic.mobshaman.fragments.AccionesDetalleServicioFragment.java

private void showUploadPhotoPopup(final boolean isFinishingService) {
    AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
    adb.setTitle("Adjuntar imagen");
    adb.setMessage("Desea adjuntar una imagen al incidente?");
    adb.setPositiveButton("Si", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dispatchTakePictureIntent(isFinishingService);
        }/*from www .j ava2s . c o  m*/
    });
    adb.setNegativeButton("No", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            if (isFinishingService) {
                finishIncident();
            }
            dialog.cancel();
        }
    });

    adb.show();
}

From source file:com.kii.world.MainActivity.java

public void onListItemClick(ListView l, View v, final int position, long id) {

    // build the alert
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Would you like to remove this item?").setCancelable(true)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                // if the user chooses 'yes',
                public void onClick(DialogInterface dialog, int id) {

                    // perform the delete action on the tapped
                    // object
                    MainActivity.this.performDelete(position);
                }//from w w w  .j  a  v a2 s  . co m
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {

                // if the user chooses 'no'
                public void onClick(DialogInterface dialog, int id) {

                    // simply dismiss the dialog
                    dialog.cancel();
                }
            });

    // show the dialog
    builder.create().show();

}

From source file:com.anton.gavel.GavelMain.java

@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) {
    //handles long-press on list item and deletes them
    //this doesn't do anything because Spinners don't support long clicks (last known Dec, 2012)
    AlertDialog.Builder deleteItem = new AlertDialog.Builder(this);
    deleteItem.setTitle("Delete").setMessage("Delete '" + complaintsAdapter.getItem(position) + "'?")
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    complaintsAdapter.remove(complaintsAdapter.getItem(position));
                }//from   ww w  .j a v  a 2 s .  c  o m
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).show();

    return false;
}

From source file:com.example.leandromaguna.myapp.Presentation.PlacesMap.PlacesMapActivity.java

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Your GPS seems to be disabled, do you want to enable it?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                        @SuppressWarnings("unused") final int id) {
                    startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                    mMap.setMyLocationEnabled(true);
                }//www.  java 2s .c o  m
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                    dialog.cancel();
                }
            });
    final AlertDialog alert = builder.create();
    alert.show();
}

From source file:edu.cwru.apo.Home.java

public void onRestRequestComplete(Methods method, JSONObject result) {
    if (method == Methods.phone) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    SharedPreferences.Editor editor = getSharedPreferences(APO.PREF_FILE_NAME, MODE_PRIVATE)
                            .edit();//from  w  ww . ja  v  a 2 s.c  om
                    editor.putLong("updateTime", result.getLong("updateTime"));
                    editor.commit();
                    int numbros = result.getInt("numBros");
                    JSONArray caseID = result.getJSONArray("caseID");
                    JSONArray first = result.getJSONArray("first");
                    JSONArray last = result.getJSONArray("last");
                    JSONArray phone = result.getJSONArray("phone");
                    JSONArray family = result.getJSONArray("family");
                    ContentValues values;
                    for (int i = 0; i < numbros; i++) {
                        values = new ContentValues();
                        values.put("_id", caseID.getString(i));
                        values.put("first", first.getString(i));
                        values.put("last", last.getString(i));
                        values.put("phone", phone.getString(i));
                        values.put("family", family.getString(i));
                        database.replace("phoneDB", null, values);
                    }
                } else if (requestStatus.compareTo("timestamp invalid") == 0) {
                    Toast msg = Toast.makeText(this, "Invalid timestamp.  Please try again.",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("HMAC invalid") == 0) {
                    Auth.loggedIn = false;
                    Toast msg = Toast.makeText(this,
                            "You have been logged out by the server.  Please log in again.", Toast.LENGTH_LONG);
                    msg.show();
                    finish();
                } else {
                    Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } else if (method == Methods.checkAppVersion) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    String appVersion = result.getString("version");
                    String appDate = result.getString("date");
                    final String appUrl = result.getString("url");
                    PackageInfo pinfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
                    ;
                    if (appVersion.compareTo(pinfo.versionName) != 0) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("Upgrade");
                        builder.setMessage("Update available, ready to upgrade?");
                        builder.setIcon(R.drawable.icon);
                        builder.setCancelable(false);
                        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Intent promptInstall = new Intent("android.intent.action.VIEW",
                                        Uri.parse("https://apo.case.edu:8090/app/" + appUrl));
                                startActivity(promptInstall);
                            }
                        });
                        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else {
                        Toast msg = Toast.makeText(this, "No updates found", Toast.LENGTH_LONG);
                        msg.show();
                    }
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NameNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

From source file:app.sunstreak.yourpisd.LoginActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login_new);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);//from w  w  w. ja  v  a  2s  .c o m
    }
    final SharedPreferences sharedPrefs = getPreferences(Context.MODE_PRIVATE);
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    height = size.y;
    mLoginFormView = findViewById(R.id.login_form);
    mLoginStatusView = (LinearLayout) findViewById(R.id.login_status);
    mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message);

    if (DateHelper.isAprilFools()) {
        LinearLayout container = (LinearLayout) mLoginFormView.findViewById(R.id.container);
        ImageView logo = (ImageView) container.findViewById(R.id.logo);
        InputStream is;
        try {
            is = getAssets().open("doge.png");
            logo.setImageBitmap(BitmapFactory.decodeStream(is));
            is.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    mAutoLogin = sharedPrefs.getBoolean("auto_login", false);
    System.out.println(mAutoLogin);

    session = ((YPApplication) getApplication()).session;

    try {
        boolean refresh = getIntent().getExtras().getBoolean("Refresh");

        if (refresh) {
            mEmail = session.getUsername();
            mPassword = session.getPassword();
            showProgress(true);
            mAuthTask = new UserLoginTask();
            mAuthTask.execute((Void) null);

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);
        } else
            mLoginFormView.setVisibility(View.VISIBLE);
    } catch (NullPointerException e) {
        // Keep going.
    }

    if (sharedPrefs.getBoolean("patched", false)) {
        SharedPreferences.Editor editor = sharedPrefs.edit();
        editor.remove("password");
        editor.putBoolean("patched", true);
        editor.commit();
    }

    if (!sharedPrefs.getBoolean("AcceptedUserAgreement", false)) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(getResources().getString(R.string.user_agreement_title));
        builder.setMessage(getResources().getString(R.string.user_agreement));
        // Setting Positive "Yes" Button
        builder.setPositiveButton("Agree", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                sharedPrefs.edit().putBoolean("AcceptedUserAgreement", true).commit();
                dialog.cancel();
            }
        });

        // Setting Negative "NO" Button
        builder.setNegativeButton("Disagree", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                // Write your code here to invoke NO event
                sharedPrefs.edit().putBoolean("AcceptedUserAgreement", false).commit();
                Toast.makeText(LoginActivity.this, "Quitting app", Toast.LENGTH_SHORT).show();
                finish();
            }
        });

        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }

    // Set up the remember_password CheckBox
    mRememberPasswordCheckBox = (CheckBox) findViewById(R.id.remember_password);
    mRememberPasswordCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            mRememberPassword = isChecked;
        }
    });

    mRememberPassword = sharedPrefs.getBoolean("remember_password", false);
    mRememberPasswordCheckBox.setChecked(mRememberPassword);

    // Set up the auto_login CheckBox
    mAutoLoginCheckBox = (CheckBox) findViewById(R.id.auto_login);
    mAutoLoginCheckBox.setChecked(mAutoLogin);
    mAutoLoginCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton button, boolean isChecked) {
            mAutoLogin = isChecked;
            if (isChecked) {
                mRememberPasswordCheckBox.setChecked(true);
            }
        }

    });

    // Set up the login form.
    mEmailView = (EditText) findViewById(R.id.email);

    mPasswordView = (EditText) findViewById(R.id.password);
    mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
            if (id == R.id.login || id == EditorInfo.IME_NULL) {
                attemptLogin();
                return true;
            }
            return false;
        }
    });

    //Load stored username/password
    mEmailView.setText(sharedPrefs.getString("email", mEmail));
    mPasswordView.setText(new String(Base64.decode(sharedPrefs.getString("e_password", ""), Base64.DEFAULT)));
    // If the password was not saved, give focus to the password.
    if (mPasswordView.getText().equals(""))
        mPasswordView.requestFocus();

    mLoginFormView = findViewById(R.id.login_form);
    mLoginStatusView = (LinearLayout) findViewById(R.id.login_status);
    mLoginStatusMessageView = (TextView) findViewById(R.id.login_status_message);

    findViewById(R.id.sign_in_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            attemptLogin();
        }
    });
    findViewById(R.id.sign_in_button).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mPasswordView.getWindowToken(), 0);
            return false;
        }
    });
    mLoginFormView.setVisibility(View.VISIBLE);
    // Login if auto-login is checked.
    if (mAutoLogin)
        attemptLogin();
}