Search in sources :

Example 81 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RegulatoryInfoDisplayActivity method onCreate.

/**
 * Display the regulatory info graphic in a dialog window.
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Resources resources = getResources();
    if (!resources.getBoolean(R.bool.config_show_regulatory_info)) {
        // no regulatory info to display for this device
        finish();
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.regulatory_labels).setOnDismissListener(this);
    boolean regulatoryInfoDrawableExists = false;
    final String regulatoryInfoFile = getRegulatoryInfoImageFileName();
    final Bitmap regulatoryInfoBitmap = BitmapFactory.decodeFile(regulatoryInfoFile);
    if (regulatoryInfoBitmap != null) {
        regulatoryInfoDrawableExists = true;
    }
    int resId = 0;
    if (!regulatoryInfoDrawableExists) {
        resId = getResourceId();
    }
    if (resId != 0) {
        try {
            Drawable d = getDrawable(resId);
            // set to false if the width or height is <= 2
            // (missing PNG can return an empty 2x2 pixel Drawable)
            regulatoryInfoDrawableExists = (d.getIntrinsicWidth() > 2 && d.getIntrinsicHeight() > 2);
        } catch (Resources.NotFoundException ignored) {
            regulatoryInfoDrawableExists = false;
        }
    }
    CharSequence regulatoryText = resources.getText(R.string.regulatory_info_text);
    if (regulatoryInfoDrawableExists) {
        View view = getLayoutInflater().inflate(R.layout.regulatory_info, null);
        ImageView image = view.findViewById(R.id.regulatoryInfo);
        if (regulatoryInfoBitmap != null) {
            image.setImageBitmap(regulatoryInfoBitmap);
        } else {
            image.setImageResource(resId);
        }
        builder.setView(view);
        builder.show();
    } else if (regulatoryText.length() > 0) {
        builder.setMessage(regulatoryText);
        AlertDialog dialog = builder.show();
        // we have to show the dialog first, or the setGravity() call will throw a NPE
        TextView messageText = (TextView) dialog.findViewById(android.R.id.message);
        messageText.setGravity(Gravity.CENTER);
    } else {
        // neither drawable nor text resource exists, finish activity
        finish();
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Drawable(android.graphics.drawable.Drawable) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Bitmap(android.graphics.Bitmap) TextView(android.widget.TextView) Resources(android.content.res.Resources) ImageView(android.widget.ImageView)

Example 82 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothPairingDialogFragment method createConfirmationDialog.

/**
 * Creates a dialog with UI elements that allow the user to confirm a pairing request.
 */
private AlertDialog createConfirmationDialog() {
    mBuilder.setTitle(getString(R.string.bluetooth_pairing_request, mPairingController.getDeviceName()));
    mBuilder.setView(createView());
    mBuilder.setPositiveButton(getString(R.string.bluetooth_pairing_accept), this);
    mBuilder.setNegativeButton(getString(R.string.bluetooth_pairing_decline), this);
    AlertDialog dialog = mBuilder.create();
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog)

Example 83 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothPairingDialogFragment method createDisplayPasskeyOrPinDialog.

/**
 * Creates a dialog that informs users of a pairing request and shows them the passkey/pin
 * of the device.
 */
private AlertDialog createDisplayPasskeyOrPinDialog() {
    mBuilder.setTitle(getString(R.string.bluetooth_pairing_request, mPairingController.getDeviceName()));
    mBuilder.setView(createView());
    mBuilder.setNegativeButton(getString(android.R.string.cancel), this);
    AlertDialog dialog = mBuilder.create();
    // Tell the controller the dialog has been created.
    mPairingController.notifyDialogDisplayed();
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog)

Example 84 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class BluetoothPairingDialogFragment method createUserEntryDialog.

/**
 * Returns a dialog with UI elements that allow a user to provide input.
 */
private AlertDialog createUserEntryDialog() {
    mBuilder.setTitle(getString(R.string.bluetooth_pairing_request, mPairingController.getDeviceName()));
    mBuilder.setView(createPinEntryView());
    mBuilder.setPositiveButton(getString(android.R.string.ok), this);
    mBuilder.setNegativeButton(getString(android.R.string.cancel), this);
    AlertDialog dialog = mBuilder.create();
    dialog.setOnShowListener(d -> {
        if (TextUtils.isEmpty(getPairingViewText())) {
            mDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
        }
        if (mPairingView != null && mPairingView.requestFocus()) {
            InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.showSoftInput(mPairingView, InputMethodManager.SHOW_IMPLICIT);
            }
        }
    });
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 85 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ZenDeleteRuleDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle arguments = getArguments();
    String ruleName = arguments.getString(EXTRA_ZEN_RULE_NAME);
    String id = arguments.getString(EXTRA_ZEN_RULE_ID);
    final AlertDialog dialog = new AlertDialog.Builder(getContext()).setMessage(getString(R.string.zen_mode_delete_rule_confirmation, ruleName)).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.zen_mode_delete_rule_button, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (arguments != null) {
                mPositiveClickListener.onOk(id);
            }
        }
    }).create();
    final View messageView = dialog.findViewById(android.R.id.message);
    if (messageView != null) {
        messageView.setTextDirection(View.TEXT_DIRECTION_LOCALE);
    }
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) View(android.view.View)

Aggregations

AlertDialog (androidx.appcompat.app.AlertDialog)256 Test (org.junit.Test)89 View (android.view.View)48 DialogInterface (android.content.DialogInterface)40 Button (android.widget.Button)39 TextView (android.widget.TextView)39 Intent (android.content.Intent)30 ShadowAlertDialogCompat (com.android.settings.testutils.shadow.ShadowAlertDialogCompat)30 NonNull (androidx.annotation.NonNull)27 Context (android.content.Context)26 Bundle (android.os.Bundle)20 SuppressLint (android.annotation.SuppressLint)17 EditText (android.widget.EditText)17 ArrayList (java.util.ArrayList)17 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)14 List (java.util.List)12 Activity (android.app.Activity)11 Uri (android.net.Uri)11 LayoutInflater (android.view.LayoutInflater)11 ListView (android.widget.ListView)10