Java Code Examples for android.app.AlertDialog#dismiss()

The following examples show how to use android.app.AlertDialog#dismiss() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ManageAccountsActivity.java    From evercam-android with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Update shared preference that stores default user's Email
 *
 * @param closeActivity   after updating, close the account manage activity or not
 * @param dialogToDismiss the account manage dialog that is showing
 */
public void updateDefaultUser(final String userEmail, final Boolean closeActivity,
                              final AlertDialog dialogToDismiss) {
    EvercamAccount evercamAccount = new EvercamAccount(this);
    evercamAccount.updateDefaultUser(userEmail);
    AppData.appUsers = evercamAccount.retrieveUserList();

    getMixpanel().identifyUser(AppData.defaultUser.getUsername());
    registerUserWithIntercom(AppData.defaultUser);

    if (closeActivity) {
        if (!AppData.defaultUser.getUsername().equals(oldDefaultUser)) {
            setResult(Constants.RESULT_ACCOUNT_CHANGED);
        }
        ManageAccountsActivity.this.finish();
    } else {
        showAllAccounts();
    }

    if (dialogToDismiss != null && dialogToDismiss.isShowing()) {
        dialogToDismiss.dismiss();
    }
}
 
Example 2
Source File: A2dpDlg.java    From misound with Apache License 2.0 6 votes vote down vote up
private void connectPhone2Bar(final AlertDialog dlg, final Runnable callback){
    final BluetoothDevice bar = mProfile.getBarDevice(mMainActivity);
    if(bar == null) return;
    boolean ok = mProfile.connect(bar, null);
    if(ok && callback != null) {
        runDelay(new Runnable() {
            @Override
            public void run() {
                callback.run();
                runDelay(new Runnable() {
                    @Override
                    public void run() {
                        dlg.dismiss();
                    }
                }, 1000);
            }
        }, 5000);
    }else{
        dlg.dismiss();
    }
}
 
Example 3
Source File: A2dpDlg.java    From misound with Apache License 2.0 6 votes vote down vote up
private void disconnectPhoneFromBar(final AlertDialog dlg, final Runnable callback){
    final BluetoothDevice bar = mProfile.getBarDevice(mMainActivity);
    if(bar == null) return;
    boolean ok = mProfile.disconnect(bar, null);
    mMainActivity.showDefaultEntries(true);
    if(ok && callback != null) {
        runDelay(new Runnable() {
            @Override
            public void run() {
                callback.run();
                runDelay(new Runnable() {
                    @Override
                    public void run() {
                        dlg.dismiss();
                    }
                }, 1000);
            }
        }, 5000);
    }else{
        dlg.dismiss();
    }
}
 
Example 4
Source File: SettingsFragment.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
private void clearData(final boolean clearFavorites) {
    final AlertDialog dialog = new ProgressDialog.Builder(getActivity())
            .setTitle(R.string.title_clearing)
            .setMessage(R.string.message_clearing)
            .setCancelable(false).create();

    final String msgClearingFmt = getString(R.string.message_clearing_fmt);

    final Consumer<Integer> onNextConsumer = ret -> {
        // onNext
        if (ret != 0) {
            dialog.setMessage(String.format(msgClearingFmt, getString(ret)));
        }
    };

    final Consumer<Throwable> onErrorConsumer = err -> { // Failed
        Log.d(TAG, "Failed!" + err.getLocalizedMessage());
        dialog.dismiss();
    };

    final Action onComplete = () -> { // onComplete
        Log.d(TAG, "Dismiss");
        dialog.dismiss();
    };

    compositeDisposable.add(settingsViewModel.clearData(clearFavorites)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(onNextConsumer, onErrorConsumer, onComplete));
    dialog.show();
}
 
Example 5
Source File: SettingsFragment.java    From BackPackTrackII with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();

    running = false;

    for (AlertDialog dialog : dialogs)
        if (dialog.isShowing())
            dialog.dismiss();

    if (db != null)
        db.close();
}
 
Example 6
Source File: DialogFragments.java    From ScreenShift with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    final AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setMessage(R.string.keep_settings_question)
            .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    ((DialogListener) getActivity()).onNegativeButton(KeepSettingsDialog.this);
                }
            })
            .setPositiveButton(R.string.yes, null)
            .setCancelable(false)
            .create();
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);
    final Handler handler = new Handler();
    final Runnable revertRunnable = new Runnable(){
        @Override
        public void run() {
            if(dialog.isShowing()) {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                ((DialogListener) getActivity()).onNegativeButton(KeepSettingsDialog.this);
            }
        }
    };
    handler.postDelayed(revertRunnable, 1000*13);
    return dialog;
}
 
Example 7
Source File: MeasurementView.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
private void prepareInputDialog(final AlertDialog dialog) {
    dialog.setTitle(getName());
    dialog.setIcon(getIcon());

    final View input = getInputView();

    FrameLayout fl = dialog.findViewById(android.R.id.custom);
    fl.removeAllViews();
    fl.addView(input, new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (view == dialog.getButton(DialogInterface.BUTTON_POSITIVE)
                && !validateAndSetInput(input)) {
                return;
            }
            dialog.dismiss();
        }
    };

    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener);
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener(clickListener);

    final MeasurementView next = getNextView();
    if (next != null) {
        dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (validateAndSetInput(input)) {
                    next.prepareInputDialog(dialog);
                }
            }
        });
    }
    else {
        dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(GONE);
    }
}
 
Example 8
Source File: DialogUtilsTest.java    From caffeine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void testQuickDialog(){
    AlertDialog alertDialog = DialogUtils.quickDialog(getActivity(), "Test Message");
    assertTrue(alertDialog.isShowing());
    final TextView textView = (TextView) alertDialog.findViewById(android.R.id.message);
    assertEquals("Test Message", textView.getText().toString());
    alertDialog.dismiss();
    assertFalse(alertDialog.isShowing());
}
 
Example 9
Source File: CheckerFragment.java    From fuckView with GNU Affero General Public License v3.0 4 votes vote down vote up
private void dismiss() {
    for (AlertDialog dialog : dialogs) {
        dialog.dismiss();
    }
}