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()));
}
}
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);
}
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();
}
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;
}
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();
}
Aggregations