Search in sources :

Example 26 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project Signal-Android by signalapp.

the class GroupDescriptionDialog method onCreateDialog.

@Override
@NonNull
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    View dialogView = LayoutInflater.from(getContext()).inflate(R.layout.group_description_dialog, null, false);
    String argumentTitle = requireArguments().getString(ARGUMENT_TITLE, null);
    String argumentDescription = requireArguments().getString(ARGUMENT_DESCRIPTION, null);
    GroupId argumentGroupId = ParcelableGroupId.get(requireArguments().getParcelable(ARGUMENT_GROUP_ID));
    boolean linkify = requireArguments().getBoolean(ARGUMENT_LINKIFY, false);
    LiveGroup liveGroup = argumentGroupId != null ? new LiveGroup(argumentGroupId) : null;
    descriptionText = dialogView.findViewById(R.id.group_description_dialog_text);
    descriptionText.setMovementMethod(LongClickMovementMethod.getInstance(requireContext()));
    MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext(), R.style.Signal_ThemeOverlay_Dialog_Rounded);
    Dialog dialog = builder.setTitle(TextUtils.isEmpty(argumentTitle) ? getString(R.string.GroupDescriptionDialog__group_description) : argumentTitle).setView(dialogView).setPositiveButton(android.R.string.ok, null).create();
    if (argumentDescription != null) {
        GroupDescriptionUtil.setText(requireContext(), descriptionText, argumentDescription, linkify, null);
    } else if (liveGroup != null) {
        liveGroup.getDescription().observe(this, d -> GroupDescriptionUtil.setText(requireContext(), descriptionText, d, linkify, null));
    }
    if (TextUtils.isEmpty(argumentTitle) && liveGroup != null) {
        liveGroup.getTitle().observe(this, dialog::setTitle);
    }
    return dialog;
}
Also used : LiveGroup(org.thoughtcrime.securesms.groups.LiveGroup) FragmentManager(androidx.fragment.app.FragmentManager) Bundle(android.os.Bundle) GroupDescriptionUtil(org.thoughtcrime.securesms.groups.v2.GroupDescriptionUtil) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ParcelableGroupId(org.thoughtcrime.securesms.groups.ParcelableGroupId) LongClickMovementMethod(org.thoughtcrime.securesms.util.LongClickMovementMethod) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) Dialog(android.app.Dialog) TextUtils(android.text.TextUtils) R(org.thoughtcrime.securesms.R) LiveGroup(org.thoughtcrime.securesms.groups.LiveGroup) Nullable(androidx.annotation.Nullable) GroupId(org.thoughtcrime.securesms.groups.GroupId) View(android.view.View) DialogFragment(androidx.fragment.app.DialogFragment) Dialog(android.app.Dialog) EmojiTextView(org.thoughtcrime.securesms.components.emoji.EmojiTextView) View(android.view.View) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ParcelableGroupId(org.thoughtcrime.securesms.groups.ParcelableGroupId) GroupId(org.thoughtcrime.securesms.groups.GroupId) NonNull(androidx.annotation.NonNull)

Example 27 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project Signal-Android by signalapp.

the class ShakeToReport method showPostSubmitDialog.

private void showPostSubmitDialog(@NonNull Activity activity, @NonNull String url) {
    AlertDialog dialog = new MaterialAlertDialogBuilder(activity).setTitle(R.string.ShakeToReport_success).setMessage(url).setNegativeButton(android.R.string.cancel, (d, i) -> {
        d.dismiss();
        enableIfVisible();
    }).setPositiveButton(R.string.ShakeToReport_share, (d, i) -> {
        d.dismiss();
        enableIfVisible();
        activity.startActivity(new ShareIntents.Builder(activity).setText(url).build());
    }).show();
    ((TextView) dialog.findViewById(android.R.id.message)).setTextIsSelectable(true);
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ShakeDetector(org.signal.core.util.ShakeDetector) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) AlertDialog(androidx.appcompat.app.AlertDialog) SubmitDebugLogRepository(org.thoughtcrime.securesms.logsubmit.SubmitDebugLogRepository) NonNull(androidx.annotation.NonNull) SimpleProgressDialog(org.thoughtcrime.securesms.util.views.SimpleProgressDialog) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) ThreadUtil(org.signal.core.util.ThreadUtil) R(org.thoughtcrime.securesms.R) Tracer(org.signal.core.util.tracing.Tracer) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) TextView(android.widget.TextView) Application(android.app.Application) ShareIntents(org.thoughtcrime.securesms.sharing.ShareIntents) Toast(android.widget.Toast) WeakReference(java.lang.ref.WeakReference) Activity(android.app.Activity) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) TextView(android.widget.TextView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 28 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project Signal-Android by signalapp.

the class ShakeToReport method onShakeDetected.

@Override
public void onShakeDetected() {
    if (!SignalStore.internalValues().shakeToReport())
        return;
    Activity activity = weakActivity.get();
    if (activity == null) {
        Log.w(TAG, "No registered activity!");
        return;
    }
    disable();
    new MaterialAlertDialogBuilder(activity).setTitle(R.string.ShakeToReport_shake_detected).setMessage(R.string.ShakeToReport_submit_debug_log).setNegativeButton(android.R.string.cancel, (d, i) -> {
        d.dismiss();
        enableIfVisible();
    }).setPositiveButton(R.string.ShakeToReport_submit, (d, i) -> {
        d.dismiss();
        submitLog(activity);
    }).show();
}
Also used : ShakeDetector(org.signal.core.util.ShakeDetector) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) AlertDialog(androidx.appcompat.app.AlertDialog) SubmitDebugLogRepository(org.thoughtcrime.securesms.logsubmit.SubmitDebugLogRepository) NonNull(androidx.annotation.NonNull) SimpleProgressDialog(org.thoughtcrime.securesms.util.views.SimpleProgressDialog) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) ThreadUtil(org.signal.core.util.ThreadUtil) R(org.thoughtcrime.securesms.R) Tracer(org.signal.core.util.tracing.Tracer) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) TextView(android.widget.TextView) Application(android.app.Application) ShareIntents(org.thoughtcrime.securesms.sharing.ShareIntents) Toast(android.widget.Toast) WeakReference(java.lang.ref.WeakReference) Activity(android.app.Activity) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) Activity(android.app.Activity) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 29 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project Signal-Android by signalapp.

the class BaseRegistrationLockFragment method handleForgottenPin.

private void handleForgottenPin(long timeRemainingMs) {
    int lockoutDays = getLockoutDays(timeRemainingMs);
    new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.RegistrationLockFragment__forgot_your_pin).setMessage(requireContext().getResources().getQuantityString(R.plurals.RegistrationLockFragment__for_your_privacy_and_security_there_is_no_way_to_recover, lockoutDays, lockoutDays)).setPositiveButton(android.R.string.ok, null).setNeutralButton(R.string.PinRestoreEntryFragment_contact_support, (dialog, which) -> sendEmailToSupport()).show();
}
Also used : CircularProgressButtonUtil.setSpinning(org.thoughtcrime.securesms.util.CircularProgressButtonUtil.setSpinning) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) LifecycleDisposable(org.thoughtcrime.securesms.util.LifecycleDisposable) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) R(org.thoughtcrime.securesms.R) Toast(android.widget.Toast) View(android.view.View) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) CircularProgressButton(com.dd.CircularProgressButton) CircularProgressButtonUtil.cancelSpinning(org.thoughtcrime.securesms.util.CircularProgressButtonUtil.cancelSpinning) PinKeyboardType(org.thoughtcrime.securesms.lock.v2.PinKeyboardType) RegistrationViewDelegate.setDebugLogSubmitMultiTapView(org.thoughtcrime.securesms.registration.fragments.RegistrationViewDelegate.setDebugLogSubmitMultiTapView) InputType(android.text.InputType) BaseRegistrationViewModel(org.thoughtcrime.securesms.registration.viewmodel.BaseRegistrationViewModel) CallSuper(androidx.annotation.CallSuper) TokenData(org.thoughtcrime.securesms.pin.TokenData) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) StringRes(androidx.annotation.StringRes) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Disposable(io.reactivex.rxjava3.disposables.Disposable) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) EditorInfo(android.view.inputmethod.EditorInfo) EditText(android.widget.EditText) Resources(android.content.res.Resources) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 30 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project Signal-Android by signalapp.

the class ChatWallpaperFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    viewModel = ViewModelProviders.of(requireActivity()).get(ChatWallpaperViewModel.class);
    AvatarImageView portrait = view.findViewById(R.id.chat_wallpaper_preview_top_bar_portrait);
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    ImageView chatWallpaperPreview = view.findViewById(R.id.chat_wallpaper_preview_background);
    View setWallpaper = view.findViewById(R.id.chat_wallpaper_set_wallpaper);
    SwitchCompat dimInNightMode = view.findViewById(R.id.chat_wallpaper_dark_theme_dims_wallpaper);
    View chatWallpaperDim = view.findViewById(R.id.chat_wallpaper_dim);
    TextView setChatColor = view.findViewById(R.id.chat_wallpaper_set_chat_color);
    TextView resetChatColors = view.findViewById(R.id.chat_wallpaper_reset_chat_colors);
    ImageView sentBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_2);
    ColorizerView colorizerView = view.findViewById(R.id.colorizer);
    TextView resetAllWallpaper = view.findViewById(R.id.chat_wallpaper_reset_all_wallpapers);
    AppCompatImageView recvBubble = view.findViewById(R.id.chat_wallpaper_preview_bubble_1);
    toolbar.setTitle(R.string.preferences__chat_color_and_wallpaper);
    toolbar.setNavigationOnClickListener(nav -> {
        if (!Navigation.findNavController(nav).popBackStack()) {
            requireActivity().finish();
        }
    });
    forceAspectRatioToScreenByAdjustingHeight(chatWallpaperPreview);
    viewModel.getWallpaperPreviewPortrait().observe(getViewLifecycleOwner(), wallpaperPreviewPortrait -> wallpaperPreviewPortrait.applyToAvatarImageView(portrait));
    viewModel.getCurrentWallpaper().observe(getViewLifecycleOwner(), wallpaper -> {
        if (wallpaper.isPresent()) {
            wallpaper.get().loadInto(chatWallpaperPreview);
            ImageViewCompat.setImageTintList(recvBubble, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.conversation_item_wallpaper_bubble_color)));
        } else {
            chatWallpaperPreview.setImageDrawable(null);
            ImageViewCompat.setImageTintList(recvBubble, ColorStateList.valueOf(ContextCompat.getColor(requireContext(), R.color.signal_background_secondary)));
        }
    });
    viewModel.getDimInDarkTheme().observe(getViewLifecycleOwner(), shouldDimInNightMode -> {
        if (shouldDimInNightMode != dimInNightMode.isChecked()) {
            isSettingDimFromViewModel = true;
            dimInNightMode.setChecked(shouldDimInNightMode);
            isSettingDimFromViewModel = false;
        }
        chatWallpaperDim.setAlpha(ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME);
        chatWallpaperDim.setVisibility(shouldDimInNightMode && ThemeUtil.isDarkTheme(requireContext()) ? View.VISIBLE : View.GONE);
    });
    viewModel.getEnableWallpaperControls().observe(getViewLifecycleOwner(), enableWallpaperControls -> {
        dimInNightMode.setEnabled(enableWallpaperControls);
        dimInNightMode.setAlpha(enableWallpaperControls ? 1 : 0.5f);
    });
    chatWallpaperPreview.setOnClickListener(unused -> setWallpaper.performClick());
    setWallpaper.setOnClickListener(unused -> SafeNavigation.safeNavigate(Navigation.findNavController(view), R.id.action_chatWallpaperFragment_to_chatWallpaperSelectionFragment));
    setChatColor.setOnClickListener(unused -> SafeNavigation.safeNavigate(Navigation.findNavController(view), ChatWallpaperFragmentDirections.actionChatWallpaperFragmentToChatColorSelectionFragment(viewModel.getRecipientId())));
    if (viewModel.isGlobal()) {
        resetAllWallpaper.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.ChatWallpaperFragment__reset_wallpaper).setMessage(R.string.ChatWallpaperFragment__would_you_like_to_override_all_wallpapers).setPositiveButton(R.string.ChatWallpaperFragment__reset_default_wallpaper, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.saveWallpaperSelection();
                dialog.dismiss();
            }).setNegativeButton(R.string.ChatWallpaperFragment__reset_all_wallpapers, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.resetAllWallpaper();
                dialog.dismiss();
            }).setNeutralButton(android.R.string.cancel, (dialog, which) -> {
                dialog.dismiss();
            }).show();
        });
        resetChatColors.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.ChatWallpaperFragment__reset_chat_colors).setMessage(R.string.ChatWallpaperFragment__would_you_like_to_override_all_chat_colors).setPositiveButton(R.string.ChatWallpaperFragment__reset_default_colors, (dialog, which) -> {
                viewModel.clearChatColor();
                dialog.dismiss();
            }).setNegativeButton(R.string.ChatWallpaperFragment__reset_all_colors, (dialog, which) -> {
                viewModel.resetAllChatColors();
                dialog.dismiss();
            }).setNeutralButton(android.R.string.cancel, (dialog, which) -> {
                dialog.dismiss();
            }).show();
        });
    } else {
        resetAllWallpaper.setText(R.string.ChatWallpaperFragment__reset_wallpaper);
        resetChatColors.setText(R.string.ChatWallpaperFragment__reset_chat_color);
        resetAllWallpaper.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.ChatWallpaperFragment__reset_wallpaper_question).setPositiveButton(R.string.ChatWallpaperFragment__reset, (dialog, which) -> {
                viewModel.setWallpaper(null);
                viewModel.setDimInDarkTheme(true);
                viewModel.saveWallpaperSelection();
                viewModel.refreshChatColors();
            }).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).show();
        });
        resetChatColors.setOnClickListener(unused -> {
            new MaterialAlertDialogBuilder(requireContext()).setMessage(R.string.ChatWallpaperFragment__reset_chat_color_question).setPositiveButton(R.string.ChatWallpaperFragment__reset, (dialog, which) -> viewModel.clearChatColor()).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss()).show();
        });
    }
    dimInNightMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (!isSettingDimFromViewModel) {
            viewModel.setDimInDarkTheme(isChecked);
        }
    });
    viewModel.getCurrentChatColors().observe(getViewLifecycleOwner(), chatColors -> {
        sentBubble.getDrawable().setColorFilter(chatColors.getChatBubbleColorFilter());
        colorizerView.setBackground(chatColors.getChatBubbleMask());
        Projection projection = Projection.relativeToViewWithCommonRoot(sentBubble, colorizerView, new Projection.Corners(ViewUtil.dpToPx(10)));
        colorizerView.setProjections(Collections.singletonList(projection));
        Drawable colorCircle = chatColors.asCircle();
        colorCircle.setBounds(0, 0, ViewUtil.dpToPx(16), ViewUtil.dpToPx(16));
        TextViewCompat.setCompoundDrawablesRelative(setChatColor, null, null, colorCircle, null);
    });
    sentBubble.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> viewModel.refreshChatColors());
}
Also used : TextViewCompat(androidx.core.widget.TextViewCompat) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ImageView(android.widget.ImageView) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) DisplayMetricsUtil(org.thoughtcrime.securesms.util.DisplayMetricsUtil) ColorStateList(android.content.res.ColorStateList) SafeNavigation(org.thoughtcrime.securesms.util.navigation.SafeNavigation) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ViewModelProviders(androidx.lifecycle.ViewModelProviders) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) ContextCompat(androidx.core.content.ContextCompat) SwitchCompat(androidx.appcompat.widget.SwitchCompat) LayoutInflater(android.view.LayoutInflater) ImageViewCompat(androidx.core.widget.ImageViewCompat) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ThemeUtil(org.thoughtcrime.securesms.util.ThemeUtil) Toolbar(androidx.appcompat.widget.Toolbar) Navigation(androidx.navigation.Navigation) Projection(org.thoughtcrime.securesms.util.Projection) Collections(java.util.Collections) Drawable(android.graphics.drawable.Drawable) Projection(org.thoughtcrime.securesms.util.Projection) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) AvatarImageView(org.thoughtcrime.securesms.components.AvatarImageView) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) Toolbar(androidx.appcompat.widget.Toolbar) SwitchCompat(androidx.appcompat.widget.SwitchCompat)

Aggregations

MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)69 NonNull (androidx.annotation.NonNull)36 View (android.view.View)32 AlertDialog (androidx.appcompat.app.AlertDialog)32 Bundle (android.os.Bundle)29 Nullable (androidx.annotation.Nullable)24 R (org.thoughtcrime.securesms.R)22 Context (android.content.Context)20 TextView (android.widget.TextView)18 Log (org.signal.core.util.logging.Log)16 LayoutInflater (android.view.LayoutInflater)15 Toast (android.widget.Toast)15 DialogInterface (android.content.DialogInterface)14 Intent (android.content.Intent)14 R (org.odk.collect.android.R)14 Dialog (android.app.Dialog)11 DialogFragment (androidx.fragment.app.DialogFragment)11 Resources (android.content.res.Resources)10 SignalStore (org.thoughtcrime.securesms.keyvalue.SignalStore)10 ViewUtil (org.thoughtcrime.securesms.util.ViewUtil)10