Java Code Examples for androidx.appcompat.app.AlertDialog#findViewById()

The following examples show how to use androidx.appcompat.app.AlertDialog#findViewById() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HostsActivity.java    From MHViewer with Apache License 2.0 7 votes vote down vote up
protected void put(AlertDialog dialog) {
  TextView host = dialog.findViewById(R.id.host);
  TextView ip = dialog.findViewById(R.id.ip);
  String hostString = host.getText().toString().trim().toLowerCase(Locale.US);
  String ipString = ip.getText().toString().trim();

  if (!Hosts.isValidHost(hostString)) {
    TextInputLayout hostInputLayout = dialog.findViewById(R.id.host_input_layout);
    hostInputLayout.setError(getContext().getString(R.string.invalid_host));
    return;
  }

  if (!Hosts.isValidIp(ipString)) {
    TextInputLayout ipInputLayout = dialog.findViewById(R.id.ip_input_layout);
    ipInputLayout.setError(getContext().getString(R.string.invalid_ip));
    return;
  }

  HostsActivity activity = (HostsActivity) dialog.getOwnerActivity();
  activity.hosts.put(hostString, ipString);
  activity.notifyHostsChanges();

  dialog.dismiss();
}
 
Example 2
Source File: GroupMembersDialog.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public void display() {
  AlertDialog dialog = new AlertDialog.Builder(fragmentActivity)
                                      .setTitle(R.string.ConversationActivity_group_members)
                                      .setIconAttribute(R.attr.group_members_dialog_icon)
                                      .setCancelable(true)
                                      .setView(R.layout.dialog_group_members)
                                      .setPositiveButton(android.R.string.ok, null)
                                      .show();

  GroupMemberListView memberListView = dialog.findViewById(R.id.list_members);

  LiveGroup                                   liveGroup   = new LiveGroup(groupRecipient.requireGroupId());
  LiveData<List<GroupMemberEntry.FullMember>> fullMembers = liveGroup.getFullMembers();

  //noinspection ConstantConditions
  fullMembers.observe(fragmentActivity, memberListView::setMembers);

  dialog.setOnDismissListener(d -> fullMembers.removeObservers(fragmentActivity));

  memberListView.setRecipientClickListener(recipient -> {
    dialog.dismiss();
    contactClick(recipient);
  });
}
 
Example 3
Source File: AboutFragment.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
private void showDonationDialog() {
    AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setView(R.layout.dialog_donate)
            .show();

    String alipayStr = base64Decode("c2V2ZW4zMzJAMTYzLmNvbQ==");
    TextView alipayText = dialog.findViewById(R.id.alipay_text);
    alipayText.setText(alipayStr);
    dialog.findViewById(R.id.alipay_copy).setOnClickListener(v -> copyToClipboard(alipayStr));

    String paypalStr = base64Decode("aHR0cHM6Ly9wYXlwYWwubWUvc2V2ZW4zMzI=");
    TextView paypalText = dialog.findViewById(R.id.paypal_text);
    paypalText.setText(paypalStr);
    dialog.findViewById(R.id.paypal_open).setOnClickListener(v -> openUrl(paypalStr));
    dialog.findViewById(R.id.paypal_copy).setOnClickListener(v -> copyToClipboard(paypalStr));
}
 
Example 4
Source File: HostsActivity.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
protected void put(AlertDialog dialog) {
  TextView host = dialog.findViewById(R.id.host);
  TextView ip = dialog.findViewById(R.id.ip);
  String hostString = host.getText().toString().trim().toLowerCase(Locale.US);
  String ipString = ip.getText().toString().trim();

  if (!Hosts.isValidHost(hostString)) {
    TextInputLayout hostInputLayout = dialog.findViewById(R.id.host_input_layout);
    hostInputLayout.setError(getContext().getString(R.string.invalid_host));
    return;
  }

  if (!Hosts.isValidIp(ipString)) {
    TextInputLayout ipInputLayout = dialog.findViewById(R.id.ip_input_layout);
    ipInputLayout.setError(getContext().getString(R.string.invalid_ip));
    return;
  }

  HostsActivity activity = (HostsActivity) dialog.getOwnerActivity();
  activity.hosts.put(hostString, ipString);
  activity.notifyHostsChanges();

  dialog.dismiss();
}
 
Example 5
Source File: AboutFragment.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
private void showDonationDialog() {
    AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setView(R.layout.dialog_donate)
            .show();

    String alipayStr = base64Decode("c2V2ZW4zMzJAMTYzLmNvbQ==");
    TextView alipayText = dialog.findViewById(R.id.alipay_text);
    alipayText.setText(alipayStr);
    dialog.findViewById(R.id.alipay_copy).setOnClickListener(v -> copyToClipboard(alipayStr));

    String paypalStr = base64Decode("aHR0cHM6Ly9wYXlwYWwubWUvc2V2ZW4zMzI=");
    TextView paypalText = dialog.findViewById(R.id.paypal_text);
    paypalText.setText(paypalStr);
    dialog.findViewById(R.id.paypal_open).setOnClickListener(v -> openUrl(paypalStr));
    dialog.findViewById(R.id.paypal_copy).setOnClickListener(v -> copyToClipboard(paypalStr));
}
 
Example 6
Source File: PrivateActivity.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
private void createFileName() {
    LayoutInflater inflater = getLayoutInflater();
    Bitmap resizedBitmap = Bitmap.createBitmap(favoriteIcon);
    @SuppressLint("InflateParams") View alertLayout = inflater.inflate(R.layout.layout_shortcut, null);
    shortcutNameEditText = alertLayout.findViewById(R.id.shortcut_name_edittext);
    AlertDialog alertDialog = createExitDialog();
    alertDialog.setTitle(R.string.add_home);
    alertDialog.setView(alertLayout);
    alertDialog.show();
    shortcutNameEditText.setHint(webViewTitle);
    ImageView imageShortcut = alertDialog.findViewById(R.id.fav_imageView);
    if (imageShortcut != null) {
        imageShortcut.setImageBitmap(StaticUtils.getCircleBitmap(resizedBitmap));
    }else{
        Log.d("Null", "");
    }
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(Color.LTGRAY);
}
 
Example 7
Source File: MainActivity.java    From SimplicityBrowser with MIT License 6 votes vote down vote up
private void createFileName() {
    LayoutInflater inflater = getLayoutInflater();
    Bitmap resizedBitmap = Bitmap.createBitmap(favoriteIcon);
    @SuppressLint("InflateParams") View alertLayout = inflater.inflate(R.layout.layout_shortcut, null);
    shortcutNameEditText = alertLayout.findViewById(R.id.shortcut_name_edittext);
    AlertDialog alertDialog = createExitDialog();
    alertDialog.setTitle(R.string.add_home);
    alertDialog.setView(alertLayout);
    alertDialog.show();
    shortcutNameEditText.setHint(webViewTitle);
    ImageView imageShortcut = alertDialog.findViewById(R.id.fav_imageView);
    if (imageShortcut != null) {
        imageShortcut.setImageBitmap(StaticUtils.getCircleBitmap(resizedBitmap));
    }else{
        Log.d("Null", "");
    }
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setTextColor(ContextCompat.getColor(this, R.color.md_blue_600));
}
 
Example 8
Source File: MainActivity.java    From HeaderView with MIT License 6 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_info:
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setTitle(getString(R.string.action_info));
            builder.setMessage(fromHtml(getString(R.string.info_message)));
            builder.setPositiveButton(getString(R.string.close), null);
            AlertDialog dialog = builder.create();
            dialog.show();
            TextView textView = dialog.findViewById(android.R.id.message);
            if (textView != null) {
                textView.setMovementMethod(LinkMovementMethod.getInstance());
            }
            return true;
        default:
            return false;
    }
}
 
Example 9
Source File: CrashReportActivity.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(Bundle savedInstanceState) {
    super.init(savedInstanceState);

    ThemePrefs themePrefs = new ThemePrefs(this);

    setTheme(themePrefs.getNewTheme());

    final AlertDialog dialog = new AlertDialog.Builder(this)
            .setTitle(R.string.crash_dialog_title)
            .setView(R.layout.crash_report_dialog)
            .setPositiveButton(R.string.crash_ok, this)
            .setNegativeButton(R.string.crash_cancel, this)
            .create();

    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnDismissListener(this);
    dialog.show();

    comment = dialog.findViewById(android.R.id.input);
    if (savedInstanceState != null) {
        comment.setText(savedInstanceState.getString(STATE_COMMENT));
    }
}
 
Example 10
Source File: MessagePreference.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDialogCreated(AlertDialog dialog) {
    super.onDialogCreated(dialog);

    if (mDialogMessageLinkify) {
        final View messageView = dialog.findViewById(android.R.id.message);
        if (null != messageView && messageView instanceof TextView) {
            ((TextView) messageView).setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
}
 
Example 11
Source File: HostsActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
protected void delete(AlertDialog dialog) {
  TextView host = dialog.findViewById(R.id.host);
  String hostString = host.getText().toString().trim().toLowerCase(Locale.US);

  HostsActivity activity = (HostsActivity) dialog.getOwnerActivity();
  activity.hosts.delete(hostString);
  activity.notifyHostsChanges();

  dialog.dismiss();
}
 
Example 12
Source File: MainActivity.java    From NekoSMS with GNU General Public License v3.0 5 votes vote down vote up
private void showAboutDialog() {
    Spanned html = Html.fromHtml(getString(R.string.format_about_message,
        GITHUB_URL, WIKI_URL));

    AlertDialog dialog = new AlertDialog.Builder(this)
        .setTitle(getString(R.string.app_name) + ' ' + VERSION_NAME)
        .setMessage(html)
        .setPositiveButton(R.string.close, null)
        .show();

    TextView textView = (TextView)dialog.findViewById(android.R.id.message);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
}
 
Example 13
Source File: MainActivity.java    From PermissionUtils with MIT License 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_settings:
            PermissionUtils.openApplicationSettings(MainActivity.this, R.class.getPackage().getName());
            break;
        case R.id.action_fragment_v4:
            Intent fragmentV4 = new Intent(MainActivity.this, FragmentActivity.class);
            fragmentV4.putExtra("IS_FRAGMENT_X", true);
            startActivity(fragmentV4);
            break;
        case R.id.action_fragment:
            Intent fragment = new Intent(MainActivity.this, FragmentActivity.class);
            fragment.putExtra("IS_FRAGMENT_X", false);
            startActivity(fragment);
            break;
        case R.id.action_info:
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setTitle(getString(R.string.action_info));
            builder.setMessage(fromHtml(getString(R.string.info_message)));
            builder.setPositiveButton(getString(R.string.close), null);
            AlertDialog dialog = builder.create();
            dialog.show();
            TextView textView = dialog.findViewById(android.R.id.message);
            if (textView != null) {
                textView.setMovementMethod(LinkMovementMethod.getInstance());
            }
            break;
    }
    return super.onOptionsItemSelected(item);
}
 
Example 14
Source File: Utils.java    From onpc with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Fix dialog icon color after dialog creation. Necessary for older Android Versions
 */
public static void fixIconColor(@NonNull AlertDialog dialog, @AttrRes int resId)
{
    final ImageView imageView = dialog.findViewById(android.R.id.icon);
    if (imageView != null)
    {
        Utils.setImageViewColorAttr(dialog.getContext(), imageView, resId);
    }
}
 
Example 15
Source File: MessagePreference.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDialogCreated(AlertDialog dialog) {
    super.onDialogCreated(dialog);

    if (mDialogMessageLinkify) {
        final View messageView = dialog.findViewById(android.R.id.message);
        if (null != messageView && messageView instanceof TextView) {
            ((TextView) messageView).setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
}
 
Example 16
Source File: HostsActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
protected void delete(AlertDialog dialog) {
  TextView host = dialog.findViewById(R.id.host);
  String hostString = host.getText().toString().trim().toLowerCase(Locale.US);

  HostsActivity activity = (HostsActivity) dialog.getOwnerActivity();
  activity.hosts.delete(hostString);
  activity.notifyHostsChanges();

  dialog.dismiss();
}
 
Example 17
Source File: BackupDialog.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static void showEnableBackupDialog(@NonNull Context context, @NonNull SwitchPreferenceCompat preference) {
  String[]    password = BackupUtil.generateBackupPassphrase();
  AlertDialog dialog   = new AlertDialog.Builder(context)
                                        .setTitle(R.string.BackupDialog_enable_local_backups)
                                        .setView(R.layout.backup_enable_dialog)
                                        .setPositiveButton(R.string.BackupDialog_enable_backups, null)
                                        .setNegativeButton(android.R.string.cancel, null)
                                        .create();

  dialog.setOnShowListener(created -> {
    Button button = ((AlertDialog) created).getButton(AlertDialog.BUTTON_POSITIVE);
    button.setOnClickListener(v -> {
      CheckBox confirmationCheckBox = dialog.findViewById(R.id.confirmation_check);
      if (confirmationCheckBox.isChecked()) {
        BackupPassphrase.set(context, Util.join(password, " "));
        TextSecurePreferences.setBackupEnabled(context, true);
        LocalBackupListener.schedule(context);

        preference.setChecked(true);
        created.dismiss();
      } else {
        Toast.makeText(context, R.string.BackupDialog_please_acknowledge_your_understanding_by_marking_the_confirmation_check_box, Toast.LENGTH_LONG).show();
      }
    });
  });

  dialog.show();

  CheckBox checkBox = dialog.findViewById(R.id.confirmation_check);
  TextView textView = dialog.findViewById(R.id.confirmation_text);

  ((TextView)dialog.findViewById(R.id.code_first)).setText(password[0]);
  ((TextView)dialog.findViewById(R.id.code_second)).setText(password[1]);
  ((TextView)dialog.findViewById(R.id.code_third)).setText(password[2]);

  ((TextView)dialog.findViewById(R.id.code_fourth)).setText(password[3]);
  ((TextView)dialog.findViewById(R.id.code_fifth)).setText(password[4]);
  ((TextView)dialog.findViewById(R.id.code_sixth)).setText(password[5]);

  textView.setOnClickListener(v -> checkBox.toggle());

  dialog.findViewById(R.id.number_table).setOnClickListener(v -> {
    ((ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("text", Util.join(password, " ")));
    Toast.makeText(context, R.string.BackupDialog_copied_to_clipboard, Toast.LENGTH_LONG).show();
  });


}