Search in sources :

Example 1 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project CustomActivityOnCrash by Ereza.

the class DefaultErrorActivity method onCreate.

@SuppressLint("PrivateResource")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // This is needed to avoid a crash if the developer has not specified
    // an app-level theme that extends Theme.AppCompat
    TypedArray a = obtainStyledAttributes(R.styleable.AppCompatTheme);
    if (!a.hasValue(R.styleable.AppCompatTheme_windowActionBar)) {
        setTheme(R.style.Theme_AppCompat_Light_DarkActionBar);
    }
    a.recycle();
    setContentView(R.layout.customactivityoncrash_default_error_activity);
    // Close/restart button logic:
    // If a class if set, use restart.
    // Else, use close and just finish the app.
    // It is recommended that you follow this logic if implementing a custom error activity.
    Button restartButton = findViewById(R.id.customactivityoncrash_error_activity_restart_button);
    final CaocConfig config = CustomActivityOnCrash.getConfigFromIntent(getIntent());
    if (config == null) {
        // This should never happen - Just finish the activity to avoid a recursive crash.
        finish();
        return;
    }
    if (config.isShowRestartButton() && config.getRestartActivityClass() != null) {
        restartButton.setText(R.string.customactivityoncrash_error_activity_restart_app);
        restartButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                CustomActivityOnCrash.restartApplication(DefaultErrorActivity.this, config);
            }
        });
    } else {
        restartButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                CustomActivityOnCrash.closeApplication(DefaultErrorActivity.this, config);
            }
        });
    }
    Button moreInfoButton = findViewById(R.id.customactivityoncrash_error_activity_more_info_button);
    if (config.isShowErrorDetails()) {
        moreInfoButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // We retrieve all the error data and show it
                AlertDialog dialog = new AlertDialog.Builder(DefaultErrorActivity.this).setTitle(R.string.customactivityoncrash_error_activity_error_details_title).setMessage(CustomActivityOnCrash.getAllErrorDetailsFromIntent(DefaultErrorActivity.this, getIntent())).setPositiveButton(R.string.customactivityoncrash_error_activity_error_details_close, null).setNeutralButton(R.string.customactivityoncrash_error_activity_error_details_copy, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        copyErrorToClipboard();
                    }
                }).show();
                TextView textView = dialog.findViewById(android.R.id.message);
                if (textView != null) {
                    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.customactivityoncrash_error_activity_error_details_text_size));
                }
            }
        });
    } else {
        moreInfoButton.setVisibility(View.GONE);
    }
    Integer defaultErrorActivityDrawableId = config.getErrorDrawable();
    ImageView errorImageView = findViewById(R.id.customactivityoncrash_error_activity_image);
    if (defaultErrorActivityDrawableId != null) {
        errorImageView.setImageDrawable(ResourcesCompat.getDrawable(getResources(), defaultErrorActivityDrawableId, getTheme()));
    }
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) CaocConfig(cat.ereza.customactivityoncrash.config.CaocConfig) DialogInterface(android.content.DialogInterface) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) Button(android.widget.Button) TypedArray(android.content.res.TypedArray) TextView(android.widget.TextView) ImageView(android.widget.ImageView) SuppressLint(android.annotation.SuppressLint)

Example 2 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project kdeconnect-android by KDE.

the class NotificationFilterActivity method displayAppList.

private void displayAppList() {
    final ListView listView = binding.lvFilterApps;
    AppListAdapter adapter = new AppListAdapter();
    listView.setAdapter(adapter);
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    listView.setLongClickable(true);
    listView.setOnItemClickListener((adapterView, view, i, l) -> {
        if (i == 0) {
            boolean enabled = listView.isItemChecked(0);
            for (int j = 0; j < apps.length; j++) {
                listView.setItemChecked(j, enabled);
            }
            appDatabase.setAllEnabled(enabled);
        } else {
            boolean checked = listView.isItemChecked(i);
            appDatabase.setEnabled(apps[i - 1].pkg, checked);
            apps[i - 1].isEnabled = checked;
        }
    });
    listView.setOnItemLongClickListener((adapterView, view, i, l) -> {
        if (i == 0)
            return true;
        Context context = this;
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        View mView = getLayoutInflater().inflate(R.layout.popup_notificationsfilter, null);
        builder.setMessage(context.getResources().getString(R.string.extra_options));
        ListView lv = mView.findViewById(R.id.extra_options_list);
        final String[] options = new String[] { context.getResources().getString(R.string.privacy_options) };
        ArrayAdapter<String> extra_options_adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, options);
        lv.setAdapter(extra_options_adapter);
        builder.setView(mView);
        AlertDialog ad = builder.create();
        lv.setOnItemClickListener((new_adapterView, new_view, new_i, new_l) -> {
            switch(new_i) {
                case 0:
                    AlertDialog.Builder myBuilder = new AlertDialog.Builder(context);
                    String packageName = apps[i - 1].pkg;
                    View myView = getLayoutInflater().inflate(R.layout.privacy_options, null);
                    CheckBox checkbox_contents = myView.findViewById(R.id.checkbox_contents);
                    checkbox_contents.setChecked(appDatabase.getPrivacy(packageName, AppDatabase.PrivacyOptions.BLOCK_CONTENTS));
                    checkbox_contents.setText(context.getResources().getString(R.string.block_contents));
                    CheckBox checkbox_images = myView.findViewById(R.id.checkbox_images);
                    checkbox_images.setChecked(appDatabase.getPrivacy(packageName, AppDatabase.PrivacyOptions.BLOCK_IMAGES));
                    checkbox_images.setText(context.getResources().getString(R.string.block_images));
                    myBuilder.setView(myView);
                    myBuilder.setTitle(context.getResources().getString(R.string.privacy_options));
                    myBuilder.setPositiveButton(context.getResources().getString(R.string.ok), (dialog, id) -> dialog.dismiss());
                    myBuilder.setMessage(context.getResources().getString(R.string.set_privacy_options));
                    checkbox_contents.setOnCheckedChangeListener((compoundButton, b) -> appDatabase.setPrivacy(packageName, AppDatabase.PrivacyOptions.BLOCK_CONTENTS, compoundButton.isChecked()));
                    checkbox_images.setOnCheckedChangeListener((compoundButton, b) -> appDatabase.setPrivacy(packageName, AppDatabase.PrivacyOptions.BLOCK_IMAGES, compoundButton.isChecked()));
                    ad.cancel();
                    myBuilder.show();
                    break;
            }
        });
        ad.show();
        return true;
    });
    // "Select all" button
    listView.setItemChecked(0, appDatabase.getAllEnabled());
    for (int i = 0; i < apps.length; i++) {
        listView.setItemChecked(i + 1, apps[i].isEnabled);
    }
    listView.setVisibility(View.VISIBLE);
    binding.spinner.setVisibility(View.GONE);
}
Also used : Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) View(android.view.View) CheckedTextView(android.widget.CheckedTextView) ListView(android.widget.ListView) ListView(android.widget.ListView) CheckBox(android.widget.CheckBox) ArrayAdapter(android.widget.ArrayAdapter)

Example 3 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project android by owncloud.

the class ReceiveExternalFilesActivity method showUploadTextDialog.

/**
 * Show a dialog where the user can enter a filename for the file he wants to place the text in.
 */
private void showUploadTextDialog() {
    final AlertDialog.Builder builder = new Builder(this);
    final View dialogView = getLayoutInflater().inflate(R.layout.dialog_upload_text, null);
    builder.setView(dialogView);
    builder.setTitle(R.string.uploader_upload_text_dialog_title);
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.uploader_btn_upload_text, null);
    builder.setNegativeButton(android.R.string.cancel, null);
    final TextInputEditText input = dialogView.findViewById(R.id.inputFileName);
    final TextInputLayout inputLayout = dialogView.findViewById(R.id.inputTextLayout);
    input.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            inputLayout.setError(null);
            inputLayout.setErrorEnabled(false);
        }
    });
    final AlertDialog alertDialog = builder.create();
    setFileNameFromIntent(alertDialog, input);
    alertDialog.setOnShowListener(dialog -> {
        Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        button.setOnClickListener(view -> {
            String fileName = input.getText().toString();
            String error = null;
            if (fileName.length() > MAX_FILENAME_LENGTH) {
                error = String.format(getString(R.string.uploader_upload_text_dialog_filename_error_length_max), MAX_FILENAME_LENGTH);
            } else if (fileName.length() == 0) {
                error = getString(R.string.uploader_upload_text_dialog_filename_error_empty);
            } else {
                fileName += ".txt";
                Uri fileUri = savePlainTextToFile(fileName);
                mStreamsToUpload.clear();
                mStreamsToUpload.add(fileUri);
                uploadFiles();
            }
            inputLayout.setErrorEnabled(error != null);
            inputLayout.setError(error);
        });
    });
    alertDialog.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Builder(androidx.appcompat.app.AlertDialog.Builder) Builder(androidx.appcompat.app.AlertDialog.Builder) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) SortOptionsView(com.owncloud.android.presentation.ui.files.SortOptionsView) Uri(android.net.Uri) Button(android.widget.Button) TextInputEditText(com.google.android.material.textfield.TextInputEditText) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(com.google.android.material.textfield.TextInputLayout)

Example 4 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project kdeconnect-android by KDE.

the class StoragePreferenceDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog dialog = (AlertDialog) super.onCreateDialog(savedInstanceState);
    dialog.setOnShowListener(dialog1 -> {
        AlertDialog alertDialog = (AlertDialog) dialog1;
        positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        positiveButton.setEnabled(enablePositiveButton);
    });
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) NonNull(androidx.annotation.NonNull)

Example 5 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project BigImageViewer by Piasy.

the class LongImageActivity method showDialog.

private AlertDialog showDialog() {
    final ViewGroup container = findViewById(R.id.container);
    final AlertDialog.Builder builder = new AlertDialog.Builder(LongImageActivity.this);
    final View rootView = LayoutInflater.from(LongImageActivity.this).inflate(R.layout.dialog_long_image, container, false);
    builder.setView(rootView);
    final TextView textScan = rootView.findViewById(R.id.action_scan_qr);
    final TextView textSave = rootView.findViewById(R.id.action_save_image);
    textScan.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            decodeQrCode();
            dialog.dismiss();
        }
    });
    textSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            saveImage();
            dialog.dismiss();
        }
    });
    return builder.create();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) BigImageView(com.github.piasy.biv.view.BigImageView) TextView(android.widget.TextView) 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