Search in sources :

Example 36 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project Signal-Android by WhisperSystems.

the class DeviceProvisioningActivity method onCreate.

@Override
protected void onCreate(Bundle bundle, boolean ready) {
    AlertDialog dialog = new AlertDialog.Builder(this).setTitle(getString(R.string.DeviceProvisioningActivity_link_a_signal_device)).setMessage(getString(R.string.DeviceProvisioningActivity_it_looks_like_youre_trying_to_link_a_signal_device_using_a_3rd_party_scanner)).setPositiveButton(R.string.DeviceProvisioningActivity_continue, (dialog1, which) -> {
        Intent intent = new Intent(DeviceProvisioningActivity.this, DeviceActivity.class);
        intent.putExtra("add", true);
        startActivity(intent);
        finish();
    }).setNegativeButton(android.R.string.cancel, (dialog12, which) -> {
        dialog12.dismiss();
        finish();
    }).setOnDismissListener(dialog13 -> finish()).create();
    dialog.setIcon(getResources().getDrawable(R.drawable.icon_dialog));
    dialog.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Log(org.signal.core.util.logging.Log) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) Intent(android.content.Intent) Window(android.view.Window) Intent(android.content.Intent)

Example 37 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project Signal-Android by WhisperSystems.

the class SimpleProgressDialog method showDelayed.

/**
 * Shows the dialog after {@param delayMs} ms.
 * <p>
 * To dismiss, call {@link DismissibleDialog#dismiss()} on the result. If dismiss is called before
 * the delay has elapsed, the dialog will not show at all.
 * <p>
 * Dismiss can be called on any thread.
 *
 * @param minimumShowTimeMs If the dialog does display, then it will be visible for at least this duration.
 *                          This is to prevent flicker.
 */
@AnyThread
@NonNull
public static DismissibleDialog showDelayed(@NonNull Context context, int delayMs, int minimumShowTimeMs) {
    AtomicReference<AlertDialog> dialogAtomicReference = new AtomicReference<>();
    AtomicLong shownAt = new AtomicLong();
    Runnable showRunnable = () -> {
        Log.i(TAG, "Taking some time. Showing a progress dialog.");
        shownAt.set(System.currentTimeMillis());
        dialogAtomicReference.set(show(context));
    };
    ThreadUtil.runOnMainDelayed(showRunnable, delayMs);
    return new DismissibleDialog() {

        @Override
        public void dismiss() {
            ThreadUtil.cancelRunnableOnMain(showRunnable);
            ThreadUtil.runOnMain(() -> {
                AlertDialog alertDialog = dialogAtomicReference.getAndSet(null);
                if (alertDialog != null) {
                    long beenShowingForMs = System.currentTimeMillis() - shownAt.get();
                    long remainingTimeMs = minimumShowTimeMs - beenShowingForMs;
                    if (remainingTimeMs > 0) {
                        ThreadUtil.runOnMainDelayed(alertDialog::dismiss, remainingTimeMs);
                    } else {
                        alertDialog.dismiss();
                    }
                }
            });
        }

        @Override
        public void dismissNow() {
            ThreadUtil.cancelRunnableOnMain(showRunnable);
            ThreadUtil.runOnMain(() -> {
                AlertDialog alertDialog = dialogAtomicReference.getAndSet(null);
                if (alertDialog != null) {
                    alertDialog.dismiss();
                }
            });
        }
    };
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicReference(java.util.concurrent.atomic.AtomicReference) NonNull(androidx.annotation.NonNull) AnyThread(androidx.annotation.AnyThread)

Example 38 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project Signal-Android by WhisperSystems.

the class SimpleProgressDialog method show.

@MainThread
@NonNull
public static AlertDialog show(@NonNull Context context) {
    AlertDialog dialog = new AlertDialog.Builder(context).setView(R.layout.progress_dialog).setCancelable(false).create();
    dialog.show();
    dialog.getWindow().setLayout(context.getResources().getDimensionPixelSize(R.dimen.progress_dialog_size), context.getResources().getDimensionPixelSize(R.dimen.progress_dialog_size));
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) MainThread(androidx.annotation.MainThread) NonNull(androidx.annotation.NonNull)

Example 39 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project Signal-Android by WhisperSystems.

the class EnableCallNotificationSettingsDialog method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    MaterialAlertDialogBuilder dialogBuilder = new MaterialAlertDialogBuilder(requireContext(), R.style.Signal_ThemeOverlay_Dialog_Rounded);
    Runnable action = null;
    switch(getCallNotificationSettingsBitmask(requireContext())) {
        case NOTIFICATIONS_DISABLED:
            dialogBuilder.setTitle(R.string.EnableCallNotificationSettingsDialog__enable_call_notifications).setMessage(R.string.EnableCallNotificationSettingsDialog__to_receive_call_notifications_tap_settings_and_turn_on_show_notifications).setPositiveButton(R.string.EnableCallNotificationSettingsDialog__settings, null);
            action = this::showNotificationSettings;
            break;
        case CALL_CHANNEL_INVALID:
            dialogBuilder.setTitle(R.string.EnableCallNotificationSettingsDialog__enable_call_notifications).setMessage(R.string.EnableCallNotificationSettingsDialog__to_receive_call_notifications_tap_settings_and_turn_on_notifications).setPositiveButton(R.string.EnableCallNotificationSettingsDialog__settings, null);
            action = this::showNotificationChannelSettings;
            break;
        case BACKGROUND_RESTRICTED:
            dialogBuilder.setTitle(R.string.EnableCallNotificationSettingsDialog__enable_background_activity).setMessage(R.string.EnableCallNotificationSettingsDialog__to_receive_call_notifications_tap_settings_and_enable_background_activity_in_battery_settings).setPositiveButton(R.string.EnableCallNotificationSettingsDialog__settings, null);
            action = this::showAppSettings;
            break;
        default:
            dialogBuilder.setTitle(R.string.EnableCallNotificationSettingsDialog__enable_call_notifications).setView(createView()).setPositiveButton(android.R.string.ok, null);
            break;
    }
    dialogBuilder.setNegativeButton(android.R.string.cancel, null);
    AlertDialog dialog = dialogBuilder.create();
    if (action != null) {
        final Runnable localAction = action;
        dialog.setOnShowListener(d -> dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> localAction.run()));
    }
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) NonNull(androidx.annotation.NonNull) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) Uri(android.net.Uri) ConversationFragment(org.thoughtcrime.securesms.conversation.ConversationFragment) Dialog(android.app.Dialog) Intent(android.content.Intent) DeviceProperties(org.thoughtcrime.securesms.util.DeviceProperties) R(org.thoughtcrime.securesms.R) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) SuppressLint(android.annotation.SuppressLint) NotificationChannels(org.thoughtcrime.securesms.notifications.NotificationChannels) Toast(android.widget.Toast) View(android.view.View) Settings(android.provider.Settings) Build(android.os.Build) TargetApi(android.annotation.TargetApi) DialogInterface(android.content.DialogInterface) FragmentManager(androidx.fragment.app.FragmentManager) LayoutInflater(android.view.LayoutInflater) Log(org.signal.core.util.logging.Log) TextView(android.widget.TextView) DialogFragment(androidx.fragment.app.DialogFragment) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 40 with AlertDialog

use of androidx.appcompat.app.AlertDialog in project Signal-Android by WhisperSystems.

the class WallpaperCropActivity method setWallpaper.

private void setWallpaper() {
    EditorModel model = imageEditor.getModel();
    Point size = new Point(imageEditor.getWidth(), imageEditor.getHeight());
    AlertDialog dialog = SimpleProgressDialog.show(this);
    viewModel.render(this, model, size, new AsynchronousCallback.MainThread<ChatWallpaper, WallpaperCropViewModel.Error>() {

        @Override
        public void onComplete(@Nullable ChatWallpaper result) {
            dialog.dismiss();
            setResult(RESULT_OK, new Intent().putExtra(ChatWallpaperPreviewActivity.EXTRA_CHAT_WALLPAPER, result));
            finish();
        }

        @Override
        public void onError(@Nullable WallpaperCropViewModel.Error error) {
            dialog.dismiss();
            Toast.makeText(WallpaperCropActivity.this, R.string.WallpaperCropActivity__error_setting_wallpaper, Toast.LENGTH_SHORT).show();
        }
    }.toWorkerCallback());
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) EditorModel(org.signal.imageeditor.core.model.EditorModel) ChatWallpaper(org.thoughtcrime.securesms.wallpaper.ChatWallpaper) Intent(android.content.Intent) Point(android.graphics.Point) Nullable(androidx.annotation.Nullable)

Aggregations

AlertDialog (androidx.appcompat.app.AlertDialog)261 Test (org.junit.Test)89 View (android.view.View)49 DialogInterface (android.content.DialogInterface)42 TextView (android.widget.TextView)40 Button (android.widget.Button)39 Intent (android.content.Intent)30 ShadowAlertDialogCompat (com.android.settings.testutils.shadow.ShadowAlertDialogCompat)30 NonNull (androidx.annotation.NonNull)28 Context (android.content.Context)26 Bundle (android.os.Bundle)20 EditText (android.widget.EditText)18 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)18 SuppressLint (android.annotation.SuppressLint)17 ArrayList (java.util.ArrayList)17 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