Search in sources :

Example 11 with Builder

use of android.support.v7.app.AlertDialog.Builder in project actor-platform by actorapp.

the class ProfileFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    uid = getArguments().getInt(EXTRA_UID);
    final UserVM user = users().get(uid);
    ArrayList<UserPhone> phones = user.getPhones().get();
    ArrayList<UserEmail> emails = user.getEmails().get();
    String about = user.getAbout().get();
    final String userName = user.getNick().get();
    final View res = inflater.inflate(R.layout.fragment_profile, container, false);
    //
    // Style Background
    //
    res.findViewById(R.id.container).setBackgroundColor(style.getMainBackgroundColor());
    res.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
    //
    // User Avatar
    //
    avatarView = (AvatarView) res.findViewById(R.id.avatar);
    avatarView.init(Screen.dp(48), 22);
    avatarView.bind(user.getAvatar().get(), user.getName().get(), user.getId());
    avatarView.setOnClickListener(v -> {
        startActivity(ViewAvatarActivity.viewAvatar(user.getId(), getActivity()));
    });
    //
    // User Name
    //
    TextView nameText = (TextView) res.findViewById(R.id.name);
    nameText.setTextColor(style.getProfileTitleColor());
    bind(nameText, user.getName());
    //
    // User Last Seen
    //
    TextView lastSeen = (TextView) res.findViewById(R.id.lastSeen);
    lastSeen.setTextColor(style.getProfileSubtitleColor());
    bind(lastSeen, user);
    //
    // Fab
    //
    FloatingActionButton fab = (FloatingActionButton) res.findViewById(R.id.fab);
    fab.setBackgroundTintList(new ColorStateList(new int[][] { new int[] { android.R.attr.state_pressed }, StateSet.WILD_CARD }, new int[] { ActorSDK.sharedActor().style.getFabPressedColor(), ActorSDK.sharedActor().style.getFabColor() }));
    fab.setRippleColor(ActorSDK.sharedActor().style.getFabPressedColor());
    fab.setOnClickListener(v -> startActivity(new Intent(getActivity(), ComposeActivity.class)));
    //
    // Remove Contact
    //
    final View removeContact = res.findViewById(R.id.addContact);
    final TextView addContactTitle = (TextView) removeContact.findViewById(R.id.addContactTitle);
    addContactTitle.setText(getString(R.string.profile_contacts_added));
    addContactTitle.setTextColor(style.getTextPrimaryColor());
    removeContact.setOnClickListener(v -> {
        execute(ActorSDK.sharedActor().getMessenger().removeContact(user.getId()));
    });
    bind(user.isContact(), (isContact, valueModel) -> {
        if (isContact) {
            removeContact.setVisibility(View.VISIBLE);
            //fab
            fab.setImageResource(R.drawable.ic_message_white_24dp);
            fab.setOnClickListener(view -> startActivity(Intents.openPrivateDialog(user.getId(), true, getActivity())));
        } else {
            removeContact.setVisibility(View.GONE);
            //fab
            fab.setImageResource(R.drawable.ic_person_add_white_24dp);
            fab.setOnClickListener(view -> execute(ActorSDK.sharedActor().getMessenger().addContact(user.getId())));
        }
    });
    //
    // New Message
    //
    View newMessageView = res.findViewById(R.id.newMessage);
    ImageView newMessageIcon = (ImageView) newMessageView.findViewById(R.id.newMessageIcon);
    TextView newMessageTitle = (TextView) newMessageView.findViewById(R.id.newMessageText);
    {
        Drawable drawable = getResources().getDrawable(R.drawable.ic_chat_black_24dp);
        drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
        newMessageIcon.setImageDrawable(drawable);
        newMessageTitle.setTextColor(style.getTextPrimaryColor());
    }
    newMessageView.setOnClickListener(v -> {
        startActivity(Intents.openPrivateDialog(user.getId(), true, getActivity()));
    });
    //
    // Voice Call
    //
    View voiceCallDivider = res.findViewById(R.id.voiceCallDivider);
    View voiceCallView = res.findViewById(R.id.voiceCall);
    if (ActorSDK.sharedActor().isCallsEnabled() && !user.isBot()) {
        ImageView voiceViewIcon = (ImageView) voiceCallView.findViewById(R.id.actionIcon);
        TextView voiceViewTitle = (TextView) voiceCallView.findViewById(R.id.actionText);
        Drawable drawable = getResources().getDrawable(R.drawable.ic_phone_white_24dp);
        drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
        voiceViewIcon.setImageDrawable(drawable);
        voiceViewTitle.setTextColor(style.getTextPrimaryColor());
        voiceCallView.setOnClickListener(v -> {
            execute(ActorSDK.sharedActor().getMessenger().doCall(user.getId()));
        });
    } else {
        voiceCallView.setVisibility(View.GONE);
        voiceCallDivider.setVisibility(View.GONE);
    }
    //
    // Video Call
    //
    View videoCallDivider = res.findViewById(R.id.videoCallDivider);
    View videoCallView = res.findViewById(R.id.videoCall);
    if (ActorSDK.sharedActor().isCallsEnabled() && !user.isBot()) {
        ImageView voiceViewIcon = (ImageView) videoCallView.findViewById(R.id.videoCallIcon);
        TextView voiceViewTitle = (TextView) videoCallView.findViewById(R.id.videoCallText);
        Drawable drawable = getResources().getDrawable(R.drawable.ic_videocam_white_24dp);
        drawable.mutate().setColorFilter(style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
        voiceViewIcon.setImageDrawable(drawable);
        voiceViewTitle.setTextColor(style.getTextPrimaryColor());
        videoCallView.setOnClickListener(v -> {
            execute(ActorSDK.sharedActor().getMessenger().doVideoCall(user.getId()));
        });
    } else {
        videoCallView.setVisibility(View.GONE);
        videoCallDivider.setVisibility(View.GONE);
    }
    //
    // Contact Information
    //
    final LinearLayout contactsContainer = (LinearLayout) res.findViewById(R.id.contactsContainer);
    String aboutString = user.getAbout().get();
    boolean isFirstContact = aboutString == null || aboutString.isEmpty();
    //
    // About
    //
    bind(user.getAbout(), new ValueChangedListener<String>() {

        private View userAboutRecord;

        @Override
        public void onChanged(final String newUserAbout, Value<String> valueModel) {
            if (newUserAbout != null && newUserAbout.length() > 0) {
                if (userAboutRecord == null) {
                    userAboutRecord = buildRecordBig(newUserAbout, R.drawable.ic_info_outline_black_24dp, true, false, inflater, contactsContainer);
                } else {
                    ((TextView) userAboutRecord.findViewById(R.id.value)).setText(newUserAbout);
                }
                if (recordFieldWithIcon != null) {
                    recordFieldWithIcon.findViewById(R.id.recordIcon).setVisibility(View.INVISIBLE);
                }
            }
        }
    });
    if (!ActorSDK.sharedActor().isOnClientPrivacyEnabled() || user.isInPhoneBook().get()) {
        for (int i = 0; i < phones.size(); i++) {
            final UserPhone userPhone = phones.get(i);
            // Formatting Phone Number
            String _phoneNumber;
            try {
                Phonenumber.PhoneNumber number = PhoneNumberUtil.getInstance().parse("+" + userPhone.getPhone(), "us");
                _phoneNumber = PhoneNumberUtil.getInstance().format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
            } catch (NumberParseException e) {
                e.printStackTrace();
                _phoneNumber = "+" + userPhone.getPhone();
            }
            final String phoneNumber = _phoneNumber;
            String phoneTitle = userPhone.getTitle();
            // Trying to localize this
            if (phoneTitle.toLowerCase().equals("mobile phone")) {
                phoneTitle = getString(R.string.settings_mobile_phone);
            }
            View view = buildRecord(phoneTitle, phoneNumber, R.drawable.ic_import_contacts_black_24dp, isFirstContact, false, inflater, contactsContainer);
            if (isFirstContact) {
                recordFieldWithIcon = view;
            }
            view.setOnClickListener(v -> {
                new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.phone_menu_call).replace("{0}", phoneNumber), getString(R.string.phone_menu_sms).replace("{0}", phoneNumber), getString(R.string.phone_menu_share).replace("{0}", phoneNumber), getString(R.string.phone_menu_copy) }, (dialog, which) -> {
                    if (which == 0) {
                        startActivity(new Intent(Intent.ACTION_DIAL).setData(Uri.parse("tel:+" + userPhone.getPhone())));
                    } else if (which == 1) {
                        startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("sms:+" + userPhone.getPhone())));
                    } else if (which == 2) {
                        startActivity(new Intent(Intent.ACTION_SEND).setType("text/plain").putExtra(Intent.EXTRA_TEXT, getString(R.string.settings_share_text).replace("{0}", phoneNumber).replace("{1}", user.getName().get())));
                    } else if (which == 3) {
                        ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("Phone number", phoneNumber);
                        clipboard.setPrimaryClip(clip);
                        Snackbar.make(res, R.string.toast_phone_copied, Snackbar.LENGTH_SHORT).show();
                    }
                }).show().setCanceledOnTouchOutside(true);
            });
            view.setOnLongClickListener(v -> {
                ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("Phone number", "+" + userPhone.getPhone());
                clipboard.setPrimaryClip(clip);
                Snackbar.make(res, R.string.toast_phone_copied, Snackbar.LENGTH_SHORT).show();
                return true;
            });
            isFirstContact = false;
        }
        for (int i = 0; i < emails.size(); i++) {
            final UserEmail userEmail = emails.get(i);
            View view = buildRecord(userEmail.getTitle(), userEmail.getEmail(), R.drawable.ic_import_contacts_black_24dp, isFirstContact, false, inflater, contactsContainer);
            if (isFirstContact) {
                recordFieldWithIcon = view;
            }
            view.setOnClickListener(v -> {
                new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.email_menu_email).replace("{0}", userEmail.getEmail()), getString(R.string.phone_menu_copy) }, (dialog, which) -> {
                    if (which == 0) {
                        startActivity(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", userEmail.getEmail(), null)));
                    } else if (which == 1) {
                        ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("Email", userEmail.getEmail());
                        clipboard.setPrimaryClip(clip);
                        Snackbar.make(res, R.string.toast_email_copied, Snackbar.LENGTH_SHORT).show();
                    }
                }).show().setCanceledOnTouchOutside(true);
            });
            view.setOnLongClickListener(v -> {
                ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("Email", "+" + userEmail.getEmail());
                clipboard.setPrimaryClip(clip);
                Snackbar.make(res, R.string.toast_email_copied, Snackbar.LENGTH_SHORT).show();
                return true;
            });
            isFirstContact = false;
        }
    }
    //
    // Username
    //
    final boolean finalIsFirstContact = isFirstContact;
    bind(user.getNick(), new ValueChangedListener<String>() {

        private View userNameRecord;

        @Override
        public void onChanged(final String newUserName, Value<String> valueModel) {
            if (newUserName != null && newUserName.length() > 0) {
                if (userNameRecord == null) {
                    userNameRecord = buildRecord(getString(R.string.nickname), "@" + newUserName, R.drawable.ic_import_contacts_black_24dp, finalIsFirstContact, false, inflater, contactsContainer);
                } else {
                    ((TextView) userNameRecord.findViewById(R.id.value)).setText(newUserName);
                }
                userNameRecord.setOnLongClickListener(v -> {
                    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    ClipData clip = ClipData.newPlainText("Username", newUserName);
                    clipboard.setPrimaryClip(clip);
                    Snackbar.make(res, R.string.toast_nickname_copied, Snackbar.LENGTH_SHORT).show();
                    return true;
                });
                if (finalIsFirstContact) {
                    recordFieldWithIcon = userNameRecord;
                }
            }
        }
    });
    //
    // Settings
    //
    {
        //
        // Notifications
        //
        View notificationContainer = res.findViewById(R.id.notificationsCont);
        View notificationPickerContainer = res.findViewById(R.id.notificationsPickerCont);
        ((TextView) notificationContainer.findViewById(R.id.settings_notifications_title)).setTextColor(style.getTextPrimaryColor());
        final SwitchCompat notificationEnable = (SwitchCompat) res.findViewById(R.id.enableNotifications);
        Peer peer = Peer.user(user.getId());
        notificationEnable.setChecked(messenger().isNotificationsEnabled(peer));
        if (messenger().isNotificationsEnabled(peer)) {
            ViewUtils.showView(notificationPickerContainer, false);
        } else {
            ViewUtils.goneView(notificationPickerContainer, false);
        }
        notificationEnable.setOnCheckedChangeListener((buttonView, isChecked) -> {
            messenger().changeNotificationsEnabled(Peer.user(user.getId()), isChecked);
            if (isChecked) {
                ViewUtils.showView(notificationPickerContainer, false);
            } else {
                ViewUtils.goneView(notificationPickerContainer, false);
            }
        });
        notificationContainer.setOnClickListener(v -> notificationEnable.setChecked(!notificationEnable.isChecked()));
        ImageView iconView = (ImageView) res.findViewById(R.id.settings_notification_icon);
        Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_list_black_24dp));
        drawable.mutate();
        DrawableCompat.setTint(drawable, style.getSettingsIconColor());
        iconView.setImageDrawable(drawable);
        ((TextView) notificationPickerContainer.findViewById(R.id.settings_notifications_picker_title)).setTextColor(style.getTextPrimaryColor());
        notificationPickerContainer.setOnClickListener(view -> {
            Intent intent = new Intent(RingtoneManager.ACTION_RINGTONE_PICKER);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, RingtoneManager.TYPE_NOTIFICATION);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, true);
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
            Uri currentSound = null;
            String defaultPath = null;
            Uri defaultUri = Settings.System.DEFAULT_NOTIFICATION_URI;
            if (defaultUri != null) {
                defaultPath = defaultUri.getPath();
            }
            String path = messenger().getPreferences().getString("userNotificationSound_" + uid);
            if (path == null) {
                path = defaultPath;
            }
            if (path != null && !path.equals("none")) {
                if (path.equals(defaultPath)) {
                    currentSound = defaultUri;
                } else {
                    currentSound = Uri.parse(path);
                }
            }
            intent.putExtra(RingtoneManager.EXTRA_RINGTONE_EXISTING_URI, currentSound);
            startActivityForResult(intent, SOUND_PICKER_REQUEST_CODE);
        });
        //
        // Block
        //
        View blockContainer = res.findViewById(R.id.blockCont);
        final TextView blockTitle = (TextView) blockContainer.findViewById(R.id.settings_block_title);
        blockTitle.setTextColor(style.getTextPrimaryColor());
        bind(user.getIsBlocked(), (val, valueModel) -> {
            blockTitle.setText(val ? R.string.profile_settings_unblock : R.string.profile_settings_block);
        });
        blockContainer.setOnClickListener(v -> {
            if (!user.getIsBlocked().get()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setMessage(getString(R.string.profile_settings_block_confirm).replace("{user}", user.getName().get())).setPositiveButton(R.string.dialog_yes, (dialog, which) -> {
                    execute(messenger().blockUser(user.getId()));
                    dialog.dismiss();
                }).setNegativeButton(R.string.dialog_cancel, (dialog, which) -> {
                    dialog.dismiss();
                }).show();
            } else {
                execute(messenger().unblockUser(user.getId()));
            }
        });
        ImageView blockIconView = (ImageView) res.findViewById(R.id.settings_block_icon);
        Drawable blockDrawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_block_white_24dp));
        drawable.mutate();
        DrawableCompat.setTint(blockDrawable, style.getSettingsIconColor());
        blockIconView.setImageDrawable(blockDrawable);
    }
    //
    // Scroll Coordinate
    //
    final ScrollView scrollView = ((ScrollView) res.findViewById(R.id.scrollContainer));
    scrollView.getViewTreeObserver().addOnScrollChangedListener(() -> updateBar(scrollView.getScrollY()));
    updateBar(scrollView.getScrollY());
    return res;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseFragment(im.actor.sdk.controllers.BaseFragment) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ViewAvatarActivity(im.actor.sdk.controllers.fragment.preview.ViewAvatarActivity) DrawableCompat(android.support.v4.graphics.drawable.DrawableCompat) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) Uri(android.net.Uri) ImageView(android.widget.ImageView) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Screen(im.actor.sdk.util.Screen) ColorStateList(android.content.res.ColorStateList) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) ClipboardManager(android.content.ClipboardManager) View(android.view.View) Intents(im.actor.sdk.controllers.Intents) FloatingActionButton(android.support.design.widget.FloatingActionButton) UserPhone(im.actor.core.viewmodel.UserPhone) SwitchCompat(android.support.v7.widget.SwitchCompat) PorterDuff(android.graphics.PorterDuff) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) StateSet(android.util.StateSet) TextView(android.widget.TextView) UserEmail(im.actor.core.viewmodel.UserEmail) Peer(im.actor.core.entity.Peer) Snackbar(android.support.design.widget.Snackbar) ValueChangedListener(im.actor.runtime.mvvm.ValueChangedListener) Context(android.content.Context) Intent(android.content.Intent) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) ViewUtils(im.actor.sdk.util.ViewUtils) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) AvatarView(im.actor.sdk.view.avatar.AvatarView) Settings(android.provider.Settings) ActionBar(android.support.v7.app.ActionBar) ActorSDK(im.actor.sdk.ActorSDK) ComposeActivity(im.actor.sdk.controllers.compose.ComposeActivity) LayoutInflater(android.view.LayoutInflater) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) Color(android.graphics.Color) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) AlertDialog(android.support.v7.app.AlertDialog) ScrollView(android.widget.ScrollView) RingtoneManager(android.media.RingtoneManager) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) Activity(android.app.Activity) Phonenumber(com.google.i18n.phonenumbers.Phonenumber) Value(im.actor.runtime.mvvm.Value) ColorStateList(android.content.res.ColorStateList) UserEmail(im.actor.core.viewmodel.UserEmail) Uri(android.net.Uri) UserPhone(im.actor.core.viewmodel.UserPhone) FloatingActionButton(android.support.design.widget.FloatingActionButton) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ClipboardManager(android.content.ClipboardManager) Peer(im.actor.core.entity.Peer) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) AvatarView(im.actor.sdk.view.avatar.AvatarView) ScrollView(android.widget.ScrollView) UserVM(im.actor.core.viewmodel.UserVM) ScrollView(android.widget.ScrollView) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) ClipData(android.content.ClipData) LinearLayout(android.widget.LinearLayout) Phonenumber(com.google.i18n.phonenumbers.Phonenumber) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 12 with Builder

use of android.support.v7.app.AlertDialog.Builder in project actor-platform by actorapp.

the class ShortcutActivity method handeleIntent.

private void handeleIntent(Intent i) {
    final Peer p = Peer.fromUniqueId(i.getLongExtra("peer", 0));
    String text = i.getStringExtra("text");
    final String name = users().get(p.getPeerId()).getName().get();
    if (text.contains("{input}") || text.contains("{input/num}")) {
        boolean num = text.contains("{input/num}");
        if (num) {
            text = text.replace("{input/num}", "{input}");
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogStyle);
        String title = text.replace("{input}", "") + " → " + name;
        builder.setTitle(title);
        LinearLayout ll = new LinearLayout(this);
        ll.setPadding(Screen.dp(20), 0, Screen.dp(20), 0);
        input = new EditText(this);
        if (num) {
            input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_SIGNED);
        }
        input.setTextColor(Color.BLACK);
        ll.addView(input, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        builder.setView(ll);
        final String finalText = text;
        builder.setPositiveButton(getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                send(p, finalText.replace("{input}", input.getText().toString()), name);
            }
        });
        builder.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.setOnDismissListener(this);
        AlertDialog ad = builder.create();
        ad.setOnShowListener(new DialogInterface.OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog) {
                InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                input.requestFocus();
                inputMethodManager.showSoftInput(input, 0);
            }
        });
        ad.show();
    } else if (text.contains("{choose}") && text.contains("{/choose}")) {
        final String rawVars = text.substring(text.indexOf("{choose}") + 8, text.indexOf("{/choose}"));
        final String[] vars = rawVars.split("/");
        AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AlertDialogStyle);
        final String rawCommand = text.replace(rawVars, "").replace("{choose}", "").replace("{/choose}", "");
        builder.setTitle(rawCommand + " → " + name);
        textToSend = rawCommand + vars[0];
        builder.setSingleChoiceItems(vars, 0, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                textToSend = rawCommand + vars[which];
            }
        });
        builder.setPositiveButton(getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                send(p, textToSend, name);
            }
        });
        builder.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        builder.setOnDismissListener(this);
        builder.show();
    } else {
        send(p, text, name);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) Peer(im.actor.core.entity.Peer) InputMethodManager(android.view.inputmethod.InputMethodManager) LinearLayout(android.widget.LinearLayout)

Example 13 with Builder

use of android.support.v7.app.AlertDialog.Builder in project material-dialogs by afollestad.

the class DialogInit method init.

@SuppressWarnings("ConstantConditions")
@UiThread
public static void init(final MaterialDialog dialog) {
    final MaterialDialog.Builder builder = dialog.builder;
    // Set cancelable flag and dialog background color
    dialog.setCancelable(builder.cancelable);
    dialog.setCanceledOnTouchOutside(builder.canceledOnTouchOutside);
    if (builder.backgroundColor == 0) {
        builder.backgroundColor = DialogUtils.resolveColor(builder.context, R.attr.md_background_color, DialogUtils.resolveColor(dialog.getContext(), R.attr.colorBackgroundFloating));
    }
    if (builder.backgroundColor != 0) {
        GradientDrawable drawable = new GradientDrawable();
        drawable.setCornerRadius(builder.context.getResources().getDimension(R.dimen.md_bg_corner_radius));
        drawable.setColor(builder.backgroundColor);
        dialog.getWindow().setBackgroundDrawable(drawable);
    }
    // Retrieve color theme attributes
    if (!builder.positiveColorSet) {
        builder.positiveColor = DialogUtils.resolveActionTextColorStateList(builder.context, R.attr.md_positive_color, builder.positiveColor);
    }
    if (!builder.neutralColorSet) {
        builder.neutralColor = DialogUtils.resolveActionTextColorStateList(builder.context, R.attr.md_neutral_color, builder.neutralColor);
    }
    if (!builder.negativeColorSet) {
        builder.negativeColor = DialogUtils.resolveActionTextColorStateList(builder.context, R.attr.md_negative_color, builder.negativeColor);
    }
    if (!builder.widgetColorSet) {
        builder.widgetColor = DialogUtils.resolveColor(builder.context, R.attr.md_widget_color, builder.widgetColor);
    }
    // Retrieve default title/content colors
    if (!builder.titleColorSet) {
        final int titleColorFallback = DialogUtils.resolveColor(dialog.getContext(), android.R.attr.textColorPrimary);
        builder.titleColor = DialogUtils.resolveColor(builder.context, R.attr.md_title_color, titleColorFallback);
    }
    if (!builder.contentColorSet) {
        final int contentColorFallback = DialogUtils.resolveColor(dialog.getContext(), android.R.attr.textColorSecondary);
        builder.contentColor = DialogUtils.resolveColor(builder.context, R.attr.md_content_color, contentColorFallback);
    }
    if (!builder.itemColorSet) {
        builder.itemColor = DialogUtils.resolveColor(builder.context, R.attr.md_item_color, builder.contentColor);
    }
    // Retrieve references to views
    dialog.title = (TextView) dialog.view.findViewById(R.id.md_title);
    dialog.icon = (ImageView) dialog.view.findViewById(R.id.md_icon);
    dialog.titleFrame = dialog.view.findViewById(R.id.md_titleFrame);
    dialog.content = (TextView) dialog.view.findViewById(R.id.md_content);
    dialog.recyclerView = (RecyclerView) dialog.view.findViewById(R.id.md_contentRecyclerView);
    dialog.checkBoxPrompt = (CheckBox) dialog.view.findViewById(R.id.md_promptCheckbox);
    // Button views initially used by checkIfStackingNeeded()
    dialog.positiveButton = (MDButton) dialog.view.findViewById(R.id.md_buttonDefaultPositive);
    dialog.neutralButton = (MDButton) dialog.view.findViewById(R.id.md_buttonDefaultNeutral);
    dialog.negativeButton = (MDButton) dialog.view.findViewById(R.id.md_buttonDefaultNegative);
    // Don't allow the submit button to not be shown for input dialogs
    if (builder.inputCallback != null && builder.positiveText == null) {
        builder.positiveText = builder.context.getText(android.R.string.ok);
    }
    // Set up the initial visibility of action buttons based on whether or not text was set
    dialog.positiveButton.setVisibility(builder.positiveText != null ? View.VISIBLE : View.GONE);
    dialog.neutralButton.setVisibility(builder.neutralText != null ? View.VISIBLE : View.GONE);
    dialog.negativeButton.setVisibility(builder.negativeText != null ? View.VISIBLE : View.GONE);
    // Set up the focus of action buttons
    dialog.positiveButton.setFocusable(true);
    dialog.neutralButton.setFocusable(true);
    dialog.negativeButton.setFocusable(true);
    if (builder.positiveFocus) {
        dialog.positiveButton.requestFocus();
    }
    if (builder.neutralFocus) {
        dialog.neutralButton.requestFocus();
    }
    if (builder.negativeFocus) {
        dialog.negativeButton.requestFocus();
    }
    // Setup icon
    if (builder.icon != null) {
        dialog.icon.setVisibility(View.VISIBLE);
        dialog.icon.setImageDrawable(builder.icon);
    } else {
        Drawable d = DialogUtils.resolveDrawable(builder.context, R.attr.md_icon);
        if (d != null) {
            dialog.icon.setVisibility(View.VISIBLE);
            dialog.icon.setImageDrawable(d);
        } else {
            dialog.icon.setVisibility(View.GONE);
        }
    }
    // Setup icon size limiting
    int maxIconSize = builder.maxIconSize;
    if (maxIconSize == -1) {
        maxIconSize = DialogUtils.resolveDimension(builder.context, R.attr.md_icon_max_size);
    }
    if (builder.limitIconToDefaultSize || DialogUtils.resolveBoolean(builder.context, R.attr.md_icon_limit_icon_to_default_size)) {
        maxIconSize = builder.context.getResources().getDimensionPixelSize(R.dimen.md_icon_max_size);
    }
    if (maxIconSize > -1) {
        dialog.icon.setAdjustViewBounds(true);
        dialog.icon.setMaxHeight(maxIconSize);
        dialog.icon.setMaxWidth(maxIconSize);
        dialog.icon.requestLayout();
    }
    // Setup divider color in case content scrolls
    if (!builder.dividerColorSet) {
        final int dividerFallback = DialogUtils.resolveColor(dialog.getContext(), R.attr.md_divider);
        builder.dividerColor = DialogUtils.resolveColor(builder.context, R.attr.md_divider_color, dividerFallback);
    }
    dialog.view.setDividerColor(builder.dividerColor);
    // Setup title and title frame
    if (dialog.title != null) {
        dialog.setTypeface(dialog.title, builder.mediumFont);
        dialog.title.setTextColor(builder.titleColor);
        dialog.title.setGravity(builder.titleGravity.getGravityInt());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            //noinspection ResourceType
            dialog.title.setTextAlignment(builder.titleGravity.getTextAlignment());
        }
        if (builder.title == null) {
            dialog.titleFrame.setVisibility(View.GONE);
        } else {
            dialog.title.setText(builder.title);
            dialog.titleFrame.setVisibility(View.VISIBLE);
        }
    }
    // Setup content
    if (dialog.content != null) {
        dialog.content.setMovementMethod(new LinkMovementMethod());
        dialog.setTypeface(dialog.content, builder.regularFont);
        dialog.content.setLineSpacing(0f, builder.contentLineSpacingMultiplier);
        if (builder.linkColor == null) {
            dialog.content.setLinkTextColor(DialogUtils.resolveColor(dialog.getContext(), android.R.attr.textColorPrimary));
        } else {
            dialog.content.setLinkTextColor(builder.linkColor);
        }
        dialog.content.setTextColor(builder.contentColor);
        dialog.content.setGravity(builder.contentGravity.getGravityInt());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            //noinspection ResourceType
            dialog.content.setTextAlignment(builder.contentGravity.getTextAlignment());
        }
        if (builder.content != null) {
            dialog.content.setText(builder.content);
            dialog.content.setVisibility(View.VISIBLE);
        } else {
            dialog.content.setVisibility(View.GONE);
        }
    }
    // Setup prompt checkbox
    if (dialog.checkBoxPrompt != null) {
        dialog.checkBoxPrompt.setText(builder.checkBoxPrompt);
        dialog.checkBoxPrompt.setChecked(builder.checkBoxPromptInitiallyChecked);
        dialog.checkBoxPrompt.setOnCheckedChangeListener(builder.checkBoxPromptListener);
        dialog.setTypeface(dialog.checkBoxPrompt, builder.regularFont);
        dialog.checkBoxPrompt.setTextColor(builder.contentColor);
        MDTintHelper.setTint(dialog.checkBoxPrompt, builder.widgetColor);
    }
    // Setup action buttons
    dialog.view.setButtonGravity(builder.buttonsGravity);
    dialog.view.setButtonStackedGravity(builder.btnStackedGravity);
    dialog.view.setStackingBehavior(builder.stackingBehavior);
    boolean textAllCaps;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        textAllCaps = DialogUtils.resolveBoolean(builder.context, android.R.attr.textAllCaps, true);
        if (textAllCaps) {
            textAllCaps = DialogUtils.resolveBoolean(builder.context, R.attr.textAllCaps, true);
        }
    } else {
        textAllCaps = DialogUtils.resolveBoolean(builder.context, R.attr.textAllCaps, true);
    }
    MDButton positiveTextView = dialog.positiveButton;
    dialog.setTypeface(positiveTextView, builder.mediumFont);
    positiveTextView.setAllCapsCompat(textAllCaps);
    positiveTextView.setText(builder.positiveText);
    positiveTextView.setTextColor(builder.positiveColor);
    dialog.positiveButton.setStackedSelector(dialog.getButtonSelector(DialogAction.POSITIVE, true));
    dialog.positiveButton.setDefaultSelector(dialog.getButtonSelector(DialogAction.POSITIVE, false));
    dialog.positiveButton.setTag(DialogAction.POSITIVE);
    dialog.positiveButton.setOnClickListener(dialog);
    dialog.positiveButton.setVisibility(View.VISIBLE);
    MDButton negativeTextView = dialog.negativeButton;
    dialog.setTypeface(negativeTextView, builder.mediumFont);
    negativeTextView.setAllCapsCompat(textAllCaps);
    negativeTextView.setText(builder.negativeText);
    negativeTextView.setTextColor(builder.negativeColor);
    dialog.negativeButton.setStackedSelector(dialog.getButtonSelector(DialogAction.NEGATIVE, true));
    dialog.negativeButton.setDefaultSelector(dialog.getButtonSelector(DialogAction.NEGATIVE, false));
    dialog.negativeButton.setTag(DialogAction.NEGATIVE);
    dialog.negativeButton.setOnClickListener(dialog);
    dialog.negativeButton.setVisibility(View.VISIBLE);
    MDButton neutralTextView = dialog.neutralButton;
    dialog.setTypeface(neutralTextView, builder.mediumFont);
    neutralTextView.setAllCapsCompat(textAllCaps);
    neutralTextView.setText(builder.neutralText);
    neutralTextView.setTextColor(builder.neutralColor);
    dialog.neutralButton.setStackedSelector(dialog.getButtonSelector(DialogAction.NEUTRAL, true));
    dialog.neutralButton.setDefaultSelector(dialog.getButtonSelector(DialogAction.NEUTRAL, false));
    dialog.neutralButton.setTag(DialogAction.NEUTRAL);
    dialog.neutralButton.setOnClickListener(dialog);
    dialog.neutralButton.setVisibility(View.VISIBLE);
    // Setup list dialog stuff
    if (builder.listCallbackMultiChoice != null) {
        dialog.selectedIndicesList = new ArrayList<>();
    }
    if (dialog.recyclerView != null) {
        if (builder.adapter == null) {
            // Determine list type
            if (builder.listCallbackSingleChoice != null) {
                dialog.listType = MaterialDialog.ListType.SINGLE;
            } else if (builder.listCallbackMultiChoice != null) {
                dialog.listType = MaterialDialog.ListType.MULTI;
                if (builder.selectedIndices != null) {
                    dialog.selectedIndicesList = new ArrayList<>(Arrays.asList(builder.selectedIndices));
                    builder.selectedIndices = null;
                }
            } else {
                dialog.listType = MaterialDialog.ListType.REGULAR;
            }
            builder.adapter = new DefaultRvAdapter(dialog, MaterialDialog.ListType.getLayoutForType(dialog.listType));
        } else if (builder.adapter instanceof MDAdapter) {
            // Notify simple list adapter of the dialog it belongs to
            ((MDAdapter) builder.adapter).setDialog(dialog);
        }
    }
    // Setup progress dialog stuff if needed
    setupProgressDialog(dialog);
    // Setup input dialog stuff if needed
    setupInputDialog(dialog);
    // Setup custom views
    if (builder.customView != null) {
        ((MDRootLayout) dialog.view.findViewById(R.id.md_root)).noTitleNoPadding();
        FrameLayout frame = (FrameLayout) dialog.view.findViewById(R.id.md_customViewFrame);
        dialog.customViewFrame = frame;
        View innerView = builder.customView;
        if (innerView.getParent() != null) {
            ((ViewGroup) innerView.getParent()).removeView(innerView);
        }
        if (builder.wrapCustomViewInScroll) {
            /* Apply the frame padding to the content, this allows the ScrollView to draw it's
                   over scroll glow without clipping */
            final Resources r = dialog.getContext().getResources();
            final int framePadding = r.getDimensionPixelSize(R.dimen.md_dialog_frame_margin);
            final ScrollView sv = new ScrollView(dialog.getContext());
            int paddingTop = r.getDimensionPixelSize(R.dimen.md_content_padding_top);
            int paddingBottom = r.getDimensionPixelSize(R.dimen.md_content_padding_bottom);
            sv.setClipToPadding(false);
            if (innerView instanceof EditText) {
                // Setting padding to an EditText causes visual errors, set it to the parent instead
                sv.setPadding(framePadding, paddingTop, framePadding, paddingBottom);
            } else {
                // Setting padding to scroll view pushes the scroll bars out, don't do it if not necessary (like above)
                sv.setPadding(0, paddingTop, 0, paddingBottom);
                innerView.setPadding(framePadding, 0, framePadding, 0);
            }
            sv.addView(innerView, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            innerView = sv;
        }
        frame.addView(innerView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    }
    // Setup user listeners
    if (builder.showListener != null) {
        dialog.setOnShowListener(builder.showListener);
    }
    if (builder.cancelListener != null) {
        dialog.setOnCancelListener(builder.cancelListener);
    }
    if (builder.dismissListener != null) {
        dialog.setOnDismissListener(builder.dismissListener);
    }
    if (builder.keyListener != null) {
        dialog.setOnKeyListener(builder.keyListener);
    }
    // Setup internal show listener
    dialog.setOnShowListenerInternal();
    // Other internal initialization
    dialog.invalidateList();
    dialog.setViewInternal(dialog.view);
    dialog.checkIfListInitScroll();
    // Min height and max width calculations
    WindowManager wm = dialog.getWindow().getWindowManager();
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    final int windowWidth = size.x;
    final int windowHeight = size.y;
    final int windowVerticalPadding = builder.context.getResources().getDimensionPixelSize(R.dimen.md_dialog_vertical_margin);
    final int windowHorizontalPadding = builder.context.getResources().getDimensionPixelSize(R.dimen.md_dialog_horizontal_margin);
    final int maxWidth = builder.context.getResources().getDimensionPixelSize(R.dimen.md_dialog_max_width);
    final int calculatedWidth = windowWidth - (windowHorizontalPadding * 2);
    dialog.view.setMaxHeight(windowHeight - windowVerticalPadding * 2);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = Math.min(maxWidth, calculatedWidth);
    dialog.getWindow().setAttributes(lp);
}
Also used : MDButton(com.afollestad.materialdialogs.internal.MDButton) ArrayList(java.util.ArrayList) WindowManager(android.view.WindowManager) EditText(android.widget.EditText) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) GradientDrawable(android.graphics.drawable.GradientDrawable) IndeterminateHorizontalProgressDrawable(me.zhanghai.android.materialprogressbar.IndeterminateHorizontalProgressDrawable) HorizontalProgressDrawable(me.zhanghai.android.materialprogressbar.HorizontalProgressDrawable) IndeterminateProgressDrawable(me.zhanghai.android.materialprogressbar.IndeterminateProgressDrawable) LinkMovementMethod(android.text.method.LinkMovementMethod) Point(android.graphics.Point) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) GradientDrawable(android.graphics.drawable.GradientDrawable) Point(android.graphics.Point) MDAdapter(com.afollestad.materialdialogs.internal.MDAdapter) ScrollView(android.widget.ScrollView) MDRootLayout(com.afollestad.materialdialogs.internal.MDRootLayout) FrameLayout(android.widget.FrameLayout) Resources(android.content.res.Resources) Display(android.view.Display) UiThread(android.support.annotation.UiThread)

Example 14 with Builder

use of android.support.v7.app.AlertDialog.Builder in project AboutLibraries by mikepenz.

the class LibsFragmentCompat method onCreateView.

public View onCreateView(Context context, LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState, Bundle arguments) {
    if (arguments != null) {
        builder = (LibsBuilder) arguments.getSerializable("data");
    } else {
        Log.e("AboutLibraries", "The AboutLibraries fragment can't be build without the bundle containing the LibsBuilder");
    }
    View view = inflater.inflate(R.layout.fragment_opensource, container, false);
    //allows to modify the view before creating
    if (LibsConfiguration.getInstance().getUiListener() != null) {
        view = LibsConfiguration.getInstance().getUiListener().preOnCreateView(view);
    }
    // init CardView
    RecyclerView mRecyclerView;
    if (view.getId() == R.id.cardListView) {
        mRecyclerView = (RecyclerView) view;
    } else {
        mRecyclerView = (RecyclerView) view.findViewById(R.id.cardListView);
    }
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
    if (LibsConfiguration.getInstance().getItemAnimator() != null) {
        mRecyclerView.setItemAnimator(LibsConfiguration.getInstance().getItemAnimator());
    } else {
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    }
    if (builder != null) {
        mAdapter = new FastAdapter();
        mItemAdapter = new ItemAdapter();
        mRecyclerView.setAdapter(mItemAdapter.wrap(mAdapter));
        mItemAdapter.add(new LoaderItem());
    }
    //allows to modify the view after creating
    if (LibsConfiguration.getInstance().getUiListener() != null) {
        view = LibsConfiguration.getInstance().getUiListener().postOnCreateView(view);
    }
    return view;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) LoaderItem(com.mikepenz.aboutlibraries.ui.item.LoaderItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) ItemAdapter(com.mikepenz.fastadapter.adapters.ItemAdapter)

Example 15 with Builder

use of android.support.v7.app.AlertDialog.Builder in project Timber by naman14.

the class BaseNowplayingFragment method updateRepeatState.

public void updateRepeatState() {
    if (repeat != null && getActivity() != null) {
        MaterialDrawableBuilder builder = MaterialDrawableBuilder.with(getActivity()).setIcon(MaterialDrawableBuilder.IconValue.REPEAT).setSizeDp(30);
        if (getActivity() != null) {
            if (MusicPlayer.getRepeatMode() == 0) {
                builder.setColor(Config.textColorPrimary(getActivity(), ateKey));
            } else
                builder.setColor(Config.accentColor(getActivity(), ateKey));
        }
        repeat.setImageDrawable(builder.build());
        repeat.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                MusicPlayer.cycleRepeat();
                updateRepeatState();
                updateShuffleState();
            }
        });
    }
}
Also used : ImageView(android.widget.ImageView) TimelyView(com.naman14.timber.timely.TimelyView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) MaterialIconView(net.steamcrafted.materialiconlib.MaterialIconView) MaterialDrawableBuilder(net.steamcrafted.materialiconlib.MaterialDrawableBuilder)

Aggregations

AlertDialog (android.support.v7.app.AlertDialog)114 DialogInterface (android.content.DialogInterface)76 View (android.view.View)67 TextView (android.widget.TextView)48 Intent (android.content.Intent)36 RecyclerView (android.support.v7.widget.RecyclerView)27 ListView (android.widget.ListView)23 Dialog (android.app.Dialog)22 LayoutInflater (android.view.LayoutInflater)20 ImageView (android.widget.ImageView)20 EditText (android.widget.EditText)18 SuppressLint (android.annotation.SuppressLint)17 Context (android.content.Context)17 Bundle (android.os.Bundle)15 NonNull (android.support.annotation.NonNull)14 Button (android.widget.Button)13 ArrayList (java.util.ArrayList)12 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)10 OnClickListener (android.content.DialogInterface.OnClickListener)10 ScrollView (android.widget.ScrollView)10