Search in sources :

Example 66 with ClipboardManager

use of android.content.ClipboardManager in project UltimateAndroid by cymcsg.

the class StringUtils method copyToClipBoard.

/**
     * Copy text to system clip board
     *
     * @param context
     * @param text
     * @param success
     */
public static void copyToClipBoard(Context context, String text, String success) {
    ClipData clipData = ClipData.newPlainText("UA", text);
    ClipboardManager manager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    manager.setPrimaryClip(clipData);
    Toast.makeText(context, success, Toast.LENGTH_SHORT).show();
}
Also used : ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

Example 67 with ClipboardManager

use of android.content.ClipboardManager in project FileExplorer by MiCode.

the class FileViewInteractionHub method copy.

private void copy(CharSequence text) {
    ClipboardManager cm = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
    cm.setText(text);
}
Also used : ClipboardManager(android.content.ClipboardManager)

Example 68 with ClipboardManager

use of android.content.ClipboardManager in project routerkeygenAndroid by routerkeygen.

the class NetworkFragment method displayResults.

private void displayResults() {
    if (passwordList.isEmpty()) {
        root.findViewById(R.id.loading_spinner).setVisibility(View.GONE);
        messages.setText(R.string.msg_errnomatches);
    } else {
        final ListView list = (ListView) root.findViewById(R.id.list_keys);
        list.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                final String key = ((TextView) view).getText().toString();
                Toast.makeText(getActivity(), getString(R.string.msg_copied, key), Toast.LENGTH_SHORT).show();
                ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("key", key);
                // Set the clipboard's primary clip.
                clipboard.setPrimaryClip(clip);
                openWifiSettings();
            }
        });
        list.setAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, passwordList));
        root.showNext();
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) ListView(android.widget.ListView) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) ClipData(android.content.ClipData)

Example 69 with ClipboardManager

use of android.content.ClipboardManager in project actor-platform by actorapp.

the class GroupInfoFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    chatId = getArguments().getInt(EXTRA_CHAT_ID);
    groupVM = groups().get(chatId);
    View res = inflater.inflate(R.layout.fragment_group, container, false);
    listView = (RecyclerListView) res.findViewById(R.id.groupList);
    notMemberView = res.findViewById(R.id.notMember);
    res.setBackgroundColor(style.getMainBackgroundColor());
    // listView.setBackgroundColor(style.getMainBackgroundColor());
    notMemberView.setBackgroundColor(style.getMainBackgroundColor());
    ((TextView) notMemberView.findViewById(R.id.not_member_text)).setTextColor(style.getTextPrimaryColor());
    //
    // Header
    //
    // Views
    View header = inflater.inflate(R.layout.fragment_group_header, listView, false);
    TextView title = (TextView) header.findViewById(R.id.title);
    TextView subtitle = (TextView) header.findViewById(R.id.subtitle);
    avatarView = (AvatarView) header.findViewById(R.id.avatar);
    avatarView.init(Screen.dp(48), 22);
    TextView aboutTV = (TextView) header.findViewById(R.id.about);
    View shortNameCont = header.findViewById(R.id.shortNameContainer);
    TextView shortNameView = (TextView) header.findViewById(R.id.shortName);
    TextView shortLinkView = (TextView) header.findViewById(R.id.shortNameLink);
    TextView addMember = (TextView) header.findViewById(R.id.addMemberAction);
    addMember.setText(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.channel_add_member : R.string.group_add_member);
    TextView members = (TextView) header.findViewById(R.id.viewMembersAction);
    TextView leaveAction = (TextView) header.findViewById(R.id.leaveAction);
    TextView administrationAction = (TextView) header.findViewById(R.id.administrationAction);
    View descriptionContainer = header.findViewById(R.id.descriptionContainer);
    SwitchCompat isNotificationsEnabled = (SwitchCompat) header.findViewById(R.id.enableNotifications);
    // Styling
    // ((TextView) header.findViewById(R.id.about_hint)).setTextColor(style.getTextSecondaryColor());
    header.setBackgroundColor(style.getMainBackgroundColor());
    header.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
    title.setTextColor(style.getProfileTitleColor());
    subtitle.setTextColor(style.getProfileSubtitleColor());
    aboutTV.setTextColor(style.getTextPrimaryColor());
    shortNameView.setTextColor(style.getTextPrimaryColor());
    shortLinkView.setTextColor(style.getTextSecondaryColor());
    // settingsHeaderText.setTextColor(style.getSettingsCategoryTextColor());
    ((TintImageView) header.findViewById(R.id.settings_notification_icon)).setTint(style.getSettingsIconColor());
    ((TintImageView) header.findViewById(R.id.settings_about_icon)).setTint(style.getSettingsIconColor());
    ((TextView) header.findViewById(R.id.settings_notifications_title)).setTextColor(style.getTextPrimaryColor());
    ((TextView) header.findViewById(R.id.addMemberAction)).setTextColor(style.getTextPrimaryColor());
    members.setTextColor(style.getTextPrimaryColor());
    administrationAction.setTextColor(style.getTextPrimaryColor());
    leaveAction.setTextColor(style.getTextDangerColor());
    if (groupVM.getGroupType() == GroupType.CHANNEL) {
        leaveAction.setText(R.string.group_leave_channel);
    } else {
        leaveAction.setText(R.string.group_leave);
    }
    header.findViewById(R.id.after_settings_divider).setBackgroundColor(style.getBackyardBackgroundColor());
    //
    // Header
    //
    avatarView.bind(groupVM.getAvatar().get(), groupVM.getName().get(), groupVM.getId());
    avatarView.setOnClickListener(view -> {
        if (groupVM.getAvatar().get() != null) {
            startActivity(ViewAvatarActivity.viewGroupAvatar(chatId, getActivity()));
        }
    });
    bind(groupVM.getName(), name -> {
        title.setText(name);
    });
    bind(groupVM.getMembersCount(), val -> {
        subtitle.setText(messenger().getFormatter().formatGroupMembers(val));
    });
    // About
    bind(groupVM.getAbout(), (about) -> {
        aboutTV.setText(about);
        aboutTV.setVisibility(about != null ? View.VISIBLE : View.GONE);
    });
    bind(groupVM.getShortName(), shortName -> {
        if (shortName != null) {
            shortNameView.setText("@" + shortName);
            String prefix = ActorSDK.sharedActor().getGroupInvitePrefix();
            if (prefix != null) {
                shortLinkView.setText(prefix + shortName);
                shortLinkView.setVisibility(View.VISIBLE);
            } else {
                shortLinkView.setVisibility(View.GONE);
            }
        }
        shortNameCont.setVisibility(shortName != null ? View.VISIBLE : View.GONE);
    });
    final ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    shortNameCont.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String link = shortLinkView.getText().toString();
            clipboard.setPrimaryClip(ClipData.newPlainText(null, (link.contains("://") ? "" : "https://") + link));
            Toast.makeText(getActivity(), getString(R.string.invite_link_copied), Toast.LENGTH_SHORT).show();
        }
    });
    bind(groupVM.getAbout(), groupVM.getShortName(), (about, shortName) -> {
        descriptionContainer.setVisibility(about != null || shortName != null ? View.VISIBLE : View.GONE);
    });
    // Notifications
    isNotificationsEnabled.setChecked(messenger().isNotificationsEnabled(Peer.group(chatId)));
    isNotificationsEnabled.setOnCheckedChangeListener((buttonView, isChecked) -> {
        messenger().changeNotificationsEnabled(Peer.group(chatId), isChecked);
    });
    header.findViewById(R.id.notificationsCont).setOnClickListener(v -> {
        isNotificationsEnabled.setChecked(!isNotificationsEnabled.isChecked());
    });
    // Add Member
    bind(groupVM.getIsCanInviteMembers(), (canInvite) -> {
        if (canInvite) {
            addMember.setVisibility(View.VISIBLE);
        } else {
            addMember.setVisibility(View.GONE);
        }
    });
    addMember.setOnClickListener(view -> {
        startActivity(new Intent(getActivity(), AddMemberActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
    });
    // Administration
    if (groupVM.getIsCanEditAdministration().get() || groupVM.getIsCanDelete().get()) {
        administrationAction.setOnClickListener(view -> {
            startActivity(new Intent(getActivity(), GroupAdminActivity.class).putExtra(Intents.EXTRA_GROUP_ID, chatId));
        });
    } else {
        administrationAction.setVisibility(View.GONE);
    }
    // Async Members
    // Showing member only when members available and async members is enabled
    bind(groupVM.getIsCanViewMembers(), groupVM.getIsAsyncMembers(), (canViewMembers, vm1, isAsync, vm2) -> {
        if (canViewMembers) {
            if (isAsync) {
                members.setVisibility(View.VISIBLE);
                header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
            } else {
                members.setVisibility(View.GONE);
                header.findViewById(R.id.after_settings_divider).setVisibility(View.VISIBLE);
            }
        } else {
            members.setVisibility(View.GONE);
            header.findViewById(R.id.after_settings_divider).setVisibility(View.GONE);
        }
    });
    members.setOnClickListener(view -> {
        startActivity(new Intent(getContext(), MembersActivity.class).putExtra(Intents.EXTRA_GROUP_ID, groupVM.getId()));
    });
    // Leave
    bind(groupVM.getIsCanLeave(), canLeave -> {
        if (canLeave) {
            leaveAction.setVisibility(View.VISIBLE);
            leaveAction.setOnClickListener(view1 -> {
                new AlertDialog.Builder(getActivity()).setMessage(getString(groupVM.getGroupType() == GroupType.CHANNEL ? R.string.alert_leave_channel_message : R.string.alert_leave_group_message).replace("%1$s", groupVM.getName().get())).setPositiveButton(R.string.alert_leave_group_yes, (dialog2, which) -> {
                    execute(messenger().leaveAndDeleteGroup(chatId).then(aVoid -> ActorSDK.returnToRoot(getActivity())));
                }).setNegativeButton(R.string.dialog_cancel, null).show().setCanceledOnTouchOutside(true);
            });
        } else {
            leaveAction.setVisibility(View.GONE);
        }
    });
    listView.addHeaderView(header, null, false);
    //
    // Members
    //
    groupUserAdapter = new MembersAdapter(getActivity(), getArguments().getInt("groupId"));
    listView.setAdapter(groupUserAdapter);
    listView.setOnItemClickListener((parent, view, position, id) -> {
        Object item = parent.getItemAtPosition(position);
        if (item != null && item instanceof GroupMember) {
            GroupMember groupMember = (GroupMember) item;
            if (groupMember.getUid() != myUid()) {
                UserVM userVM = users().get(groupMember.getUid());
                if (userVM != null) {
                    startActivity(Intents.openPrivateDialog(userVM.getId(), true, getActivity()));
                }
            }
        }
    });
    listView.setOnItemLongClickListener((adapterView, view, i, l) -> {
        Object item = adapterView.getItemAtPosition(i);
        if (item != null && item instanceof GroupMember) {
            GroupMember groupMember = (GroupMember) item;
            if (groupMember.getUid() != myUid()) {
                UserVM userVM = users().get(groupMember.getUid());
                if (userVM != null) {
                    groupUserAdapter.onMemberClick(groupVM, userVM, groupMember.isAdministrator(), groupMember.getInviterUid() == myUid(), (BaseActivity) getActivity());
                    return true;
                }
            }
        }
        return false;
    });
    //
    // Scroll handling
    //
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (firstVisibleItem >= 1) {
                updateBar(Integer.MAX_VALUE);
            } else {
                View top = listView.getChildAt(0);
                if (top != null) {
                    updateBar(-top.getTop());
                } else {
                    updateBar(Integer.MAX_VALUE);
                }
            }
        }
    });
    //
    // Placeholder
    //
    bind(groupVM.isMember(), (isMember) -> {
        notMemberView.setVisibility(isMember ? View.GONE : View.VISIBLE);
        getActivity().invalidateOptionsMenu();
    });
    // Menu
    bind(groupVM.getIsCanEditInfo(), canEditInfo -> {
        getActivity().invalidateOptionsMenu();
    });
    return res;
}
Also used : ClipboardManager(android.content.ClipboardManager) AlertDialog(android.app.AlertDialog) BaseFragment(im.actor.sdk.controllers.BaseFragment) Bundle(android.os.Bundle) ViewAvatarActivity(im.actor.sdk.controllers.fragment.preview.ViewAvatarActivity) ActorSDKMessenger.groups(im.actor.sdk.util.ActorSDKMessenger.groups) ActorSDKMessenger.messenger(im.actor.sdk.util.ActorSDKMessenger.messenger) AlertListBuilder(im.actor.sdk.util.AlertListBuilder) ColorDrawable(android.graphics.drawable.ColorDrawable) Screen(im.actor.sdk.util.Screen) PhoneNumberUtil(com.google.i18n.phonenumbers.PhoneNumberUtil) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) ClipboardManager(android.content.ClipboardManager) View(android.view.View) CommandCallback(im.actor.core.viewmodel.CommandCallback) Intents(im.actor.sdk.controllers.Intents) ActorSDKLauncher(im.actor.sdk.ActorSDKLauncher) Void(im.actor.runtime.actors.messages.Void) GroupMember(im.actor.core.entity.GroupMember) UserPhone(im.actor.core.viewmodel.UserPhone) SwitchCompat(android.support.v7.widget.SwitchCompat) ViewGroup(android.view.ViewGroup) ActorBinder(im.actor.sdk.controllers.ActorBinder) AlertDialog(android.app.AlertDialog) TextView(android.widget.TextView) Peer(im.actor.core.entity.Peer) ActorStyle(im.actor.sdk.ActorStyle) Context(android.content.Context) ActorSDKMessenger.myUid(im.actor.sdk.util.ActorSDKMessenger.myUid) TintImageView(im.actor.sdk.view.TintImageView) Intent(android.content.Intent) GroupVM(im.actor.core.viewmodel.GroupVM) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) MembersAdapter(im.actor.sdk.controllers.group.view.MembersAdapter) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) AvatarView(im.actor.sdk.view.avatar.AvatarView) ActionBar(android.support.v7.app.ActionBar) GroupType(im.actor.core.entity.GroupType) ActorSDK(im.actor.sdk.ActorSDK) LayoutInflater(android.view.LayoutInflater) ActorSDKMessenger.users(im.actor.sdk.util.ActorSDKMessenger.users) AbsListView(android.widget.AbsListView) BaseActivity(im.actor.sdk.controllers.activity.BaseActivity) Color(android.graphics.Color) UserVM(im.actor.core.viewmodel.UserVM) R(im.actor.sdk.R) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) Phonenumber(com.google.i18n.phonenumbers.Phonenumber) MembersAdapter(im.actor.sdk.controllers.group.view.MembersAdapter) GroupMember(im.actor.core.entity.GroupMember) TintImageView(im.actor.sdk.view.TintImageView) AbsListView(android.widget.AbsListView) Intent(android.content.Intent) RecyclerListView(im.actor.sdk.view.adapters.RecyclerListView) View(android.view.View) TextView(android.widget.TextView) TintImageView(im.actor.sdk.view.TintImageView) AvatarView(im.actor.sdk.view.avatar.AvatarView) AbsListView(android.widget.AbsListView) UserVM(im.actor.core.viewmodel.UserVM) TextView(android.widget.TextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 70 with ClipboardManager

use of android.content.ClipboardManager in project actor-platform by actorapp.

the class BaseActorSettingsFragment method onCreateView.

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    messenger().onUserVisible(myUid());
    View view = inflater.inflate(R.layout.fragment_settings, container, false);
    shp = getActivity().getSharedPreferences("wallpaper", Context.MODE_PRIVATE);
    baseColor = getResources().getColor(R.color.primary);
    final ActorStyle style = ActorSDK.sharedActor().style;
    final UserVM userModel = users().get(myUid());
    final TextView nameView = (TextView) view.findViewById(R.id.name);
    nameView.setShadowLayer(1, 1, 1, style.getDividerColor());
    nameView.setTextColor(style.getProfileTitleColor());
    bind(nameView, userModel.getName());
    view.findViewById(R.id.notifications).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), NotificationsActivity.class));
        }
    });
    view.findViewById(R.id.helpSettings).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), HelpActivity.class));
        }
    });
    final LinearLayout nickContainer = (LinearLayout) view.findViewById(R.id.nickContainer);
    final LinearLayout contactsContainer = (LinearLayout) view.findViewById(R.id.phoneContainer);
    final LinearLayout about = (LinearLayout) view.findViewById(R.id.about);
    // TODO: Move bindings to onResume
    bind(userModel.getNick(), new ValueChangedListener<String>() {

        @Override
        public void onChanged(final String val, Value<String> Value) {
            final View recordView = inflater.inflate(R.layout.contact_record, nickContainer, false);
            ImageView nickIcon = (ImageView) recordView.findViewById(R.id.recordIcon);
            Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_mention_24_dp));
            drawable.mutate();
            DrawableCompat.setTint(drawable, style.getSettingsIconColor());
            nickIcon.setImageDrawable(drawable);
            String value = (val != null && !val.isEmpty()) ? val : getString(R.string.nickname_empty);
            String title = getString(R.string.nickname);
            TextView nickValue = (TextView) recordView.findViewById(R.id.value);
            nickValue.setText(value);
            nickValue.setTextColor(style.getTextPrimaryColor());
            TextView nickTitle = (TextView) recordView.findViewById(R.id.title);
            nickTitle.setText(title);
            nickTitle.setTextColor(style.getTextSecondaryColor());
            nickContainer.removeAllViews();
            nickContainer.addView(recordView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));
            recordView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    getActivity().startActivity(Intents.editUserNick(getActivity()));
                }
            });
        }
    });
    final TextView aboutTitle = (TextView) about.findViewById(R.id.value);
    ImageView nickIcon = (ImageView) about.findViewById(R.id.recordIcon);
    Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_info_black_24dp));
    drawable.mutate();
    DrawableCompat.setTint(drawable, style.getSettingsIconColor());
    nickIcon.setImageDrawable(drawable);
    aboutTitle.setTextColor(style.getTextPrimaryColor());
    about.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().startActivity(Intents.editUserAbout(getActivity()));
        }
    });
    bind(userModel.getAbout(), new ValueChangedListener<String>() {

        @Override
        public void onChanged(String val, Value<String> valueModel) {
            if (val != null && !val.isEmpty()) {
                aboutTitle.setTextColor(style.getTextPrimaryColor());
                aboutTitle.setText(val);
            } else {
                aboutTitle.setTextColor(style.getTextSecondaryColor());
                aboutTitle.setText(getString(R.string.edit_about_edittext_hint));
            }
        }
    });
    bind(userModel.getPhones(), new ValueChangedListener<ArrayListUserPhone>() {

        @Override
        public void onChanged(ArrayListUserPhone val, Value<ArrayListUserPhone> Value) {
            if (val.size() == 0) {
                noPhones = true;
            } else {
                contactsContainer.setVisibility(View.VISIBLE);
                for (int i = 0; i < val.size(); i++) {
                    final UserPhone record = val.get(i);
                    View recordView = inflater.inflate(R.layout.contact_record, contactsContainer, false);
                    ImageView tintImageView = (ImageView) recordView.findViewById(R.id.recordIcon);
                    if (i == 0) {
                        Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_phone_white_24dp));
                        drawable = drawable.mutate();
                        DrawableCompat.setTint(drawable, style.getSettingsIconColor());
                        tintImageView.setImageDrawable(drawable);
                    } else {
                        tintImageView.setVisibility(View.INVISIBLE);
                    }
                    View divider = recordView.findViewById(R.id.divider);
                    if (i == val.size() - 1 && (userModel.getEmails().get() == null || userModel.getEmails().get().isEmpty())) {
                        divider.setVisibility(View.GONE);
                    } else {
                        divider.setVisibility(View.VISIBLE);
                    }
                    divider.setBackgroundColor(style.getDividerColor());
                    String _phoneNumber;
                    try {
                        Phonenumber.PhoneNumber number = PhoneNumberUtil.getInstance().parse("+" + record.getPhone(), "us");
                        _phoneNumber = PhoneNumberUtil.getInstance().format(number, PhoneNumberUtil.PhoneNumberFormat.INTERNATIONAL);
                    } catch (NumberParseException e) {
                        e.printStackTrace();
                        _phoneNumber = "+" + record.getPhone();
                    }
                    final String phoneNumber = _phoneNumber;
                    TextView value = (TextView) recordView.findViewById(R.id.value);
                    value.setTextColor(style.getTextPrimaryColor());
                    value.setText(phoneNumber);
                    TextView title = (TextView) recordView.findViewById(R.id.title);
                    title.setTextColor(style.getTextSecondaryColor());
                    title.setText(record.getTitle().replace("Mobile phone", getString(R.string.settings_mobile_phone)));
                    contactsContainer.addView(recordView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));
                    recordView.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View 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) }, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    if (which == 0) {
                                        startActivity(new Intent(Intent.ACTION_DIAL).setData(Uri.parse("tel:+" + record.getPhone())));
                                    } else if (which == 1) {
                                        startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse("sms:+" + record.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}", userModel.getName().get())));
                                    } else if (which == 3) {
                                        ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                                        ClipData clip = ClipData.newPlainText("Phone number", phoneNumber);
                                        clipboard.setPrimaryClip(clip);
                                        Toast.makeText(getActivity(), R.string.toast_phone_copied, Toast.LENGTH_SHORT).show();
                                    }
                                }
                            }).show().setCanceledOnTouchOutside(true);
                        }
                    });
                    recordView.setOnLongClickListener(new View.OnLongClickListener() {

                        @Override
                        public boolean onLongClick(View v) {
                            ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("Phone number", "+" + record.getPhone());
                            clipboard.setPrimaryClip(clip);
                            Toast.makeText(getActivity(), R.string.toast_phone_copied, Toast.LENGTH_SHORT).show();
                            return true;
                        }
                    });
                }
            }
        }
    });
    bind(userModel.getEmails(), new ValueChangedListener<ArrayListUserEmail>() {

        @Override
        public void onChanged(ArrayListUserEmail val, Value<ArrayListUserEmail> Value) {
            if (val.size() == 0) {
                noEmails = true;
            } else {
                contactsContainer.setVisibility(View.VISIBLE);
                for (int i = 0; i < val.size(); i++) {
                    final UserEmail record = val.get(i);
                    View recordView = inflater.inflate(R.layout.contact_record, contactsContainer, false);
                    ImageView tintImageView = (ImageView) recordView.findViewById(R.id.recordIcon);
                    if (i == 0) {
                        Drawable drawable = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_email_white_24dp));
                        drawable.mutate();
                        DrawableCompat.setTint(drawable, style.getSettingsIconColor());
                        tintImageView.setImageDrawable(drawable);
                    } else {
                        tintImageView.setVisibility(View.INVISIBLE);
                    }
                    View divider = recordView.findViewById(R.id.divider);
                    if (i != val.size() - 1) {
                        divider.setVisibility(View.VISIBLE);
                    } else {
                        divider.setVisibility(View.GONE);
                    }
                    divider.setBackgroundColor(style.getDividerColor());
                    final String email = record.getEmail();
                    TextView value = (TextView) recordView.findViewById(R.id.value);
                    value.setTextColor(style.getTextPrimaryColor());
                    value.setText(email);
                    TextView title = (TextView) recordView.findViewById(R.id.title);
                    title.setTextColor(style.getTextSecondaryColor());
                    title.setText(record.getTitle());
                    contactsContainer.addView(recordView, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(72)));
                    recordView.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            new AlertDialog.Builder(getActivity()).setItems(new CharSequence[] { getString(R.string.email_menu_email).replace("{0}", email), getString(R.string.phone_menu_copy) }, new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    if (which == 0) {
                                        startActivity(new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", record.getEmail(), null)));
                                    } else if (which == 1) {
                                        ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                                        ClipData clip = ClipData.newPlainText("Email", email);
                                        clipboard.setPrimaryClip(clip);
                                        Toast.makeText(getActivity(), R.string.toast_email_copied, Toast.LENGTH_SHORT).show();
                                    }
                                }
                            }).show().setCanceledOnTouchOutside(true);
                        }
                    });
                    recordView.setOnLongClickListener(new View.OnLongClickListener() {

                        @Override
                        public boolean onLongClick(View v) {
                            ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("Email", "+" + record.getEmail());
                            clipboard.setPrimaryClip(clip);
                            Toast.makeText(getActivity(), R.string.toast_email_copied, Toast.LENGTH_SHORT).show();
                            return true;
                        }
                    });
                }
            }
        }
    });
    view.findViewById(R.id.chatSettings).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), ChatSettingsActivity.class));
        }
    });
    view.findViewById(R.id.encryption).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ActorSDK.sharedActor().startSecuritySettingsActivity(getActivity());
        }
    });
    //        view.findViewById(R.id.encryption).setOnLongClickListener(new View.OnLongClickListener() {
    //            @Override
    //            public boolean onLongClick(View v) {
    //                if (AndroidLogProvider.isSendLogsEnabled()) {
    //                    AndroidLogProvider.setSendLogs(null);
    //                    Toast.makeText(getActivity(), "send logs off", Toast.LENGTH_LONG).show();
    //                } else {
    //
    //                    android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(getActivity());
    //                    builder.setTitle("Send logs integration url");
    //
    //                    LinearLayout ll = new LinearLayout(getActivity());
    //                    ll.setPadding(Screen.dp(20), 0, Screen.dp(20), 0);
    //
    //                    final EditText input = new EditText(getActivity());
    //                    ll.addView(input, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    //                    builder.setView(ll);
    //
    //                    builder.setPositiveButton(getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
    //                        @Override
    //                        public void onClick(DialogInterface dialog, int which) {
    //                            AndroidLogProvider.setSendLogs(input.getText().toString());
    //                            Toast.makeText(getActivity(), "send logs on", Toast.LENGTH_LONG).show();
    //
    //                        }
    //                    });
    //                    builder.setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
    //                        @Override
    //                        public void onClick(DialogInterface dialog, int which) {
    //                            dialog.cancel();
    //                        }
    //                    });
    //
    //                    builder.create().show();
    //
    //
    //                }
    //                return true;
    //            }
    //        });
    view.findViewById(R.id.blockedList).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(getActivity(), BlockedListActivity.class));
        }
    });
    //        view.findViewById(R.id.chatSettings).setOnLongClickListener(new View.OnLongClickListener() {
    //            @Override
    //            public boolean onLongClick(View v) {
    //                Toast.makeText(getActivity(), AndroidLogProvider.toggleWriteLogs() ? "write logs on" : "write logs off", Toast.LENGTH_LONG).show();
    //                return true;
    //            }
    //        });
    View askQuestion = view.findViewById(R.id.askQuestion);
    if (ActorSDK.sharedActor().getHelpPhone() == null || ActorSDK.sharedActor().getHelpPhone().isEmpty()) {
        askQuestion.setVisibility(View.GONE);
        view.findViewById(R.id.divider3).setVisibility(View.GONE);
    }
    askQuestion.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            execute(messenger().findUsers(ActorSDK.sharedActor().getHelpPhone()), R.string.progress_common, new CommandCallback<UserVM[]>() {

                @Override
                public void onResult(UserVM[] res) {
                    if (res.length >= 1) {
                        startActivity(Intents.openPrivateDialog(res[0].getId(), true, getActivity()));
                    }
                }

                @Override
                public void onError(Exception e) {
                }
            });
        }
    });
    //Twitter
    View twitterView = view.findViewById(R.id.twitter);
    if (ActorSDK.sharedActor().getTwitterAcc() == null || ActorSDK.sharedActor().getTwitterAcc().isEmpty()) {
        twitterView.setVisibility(View.GONE);
    }
    twitterView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://twitter.com/" + ActorSDK.sharedActor().getTwitterAcc()));
            startActivity(viewIntent);
        }
    });
    TextView twitterTitle = (TextView) view.findViewById(R.id.settings_twitter);
    twitterTitle.setTextColor(style.getSettingsTitleColor());
    TintImageView twitterIcon = (TintImageView) view.findViewById(R.id.settings_twitter_icon);
    twitterIcon.setTint(style.getSettingsIconColor());
    //Home page
    View homePageView = view.findViewById(R.id.home_page);
    if (ActorSDK.sharedActor().getHomePage() == null || ActorSDK.sharedActor().getHomePage().isEmpty()) {
        homePageView.setVisibility(View.GONE);
    }
    homePageView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(ActorSDK.sharedActor().getHomePage()));
            startActivity(viewIntent);
        }
    });
    TextView homePageTitle = (TextView) view.findViewById(R.id.settings_home_page);
    homePageTitle.setTextColor(style.getSettingsTitleColor());
    TintImageView homePageIcon = (TintImageView) view.findViewById(R.id.settings_home_page_icon);
    homePageIcon.setTint(style.getSettingsIconColor());
    TextView profileHeaderText = (TextView) view.findViewById(R.id.profile_info_header_text);
    profileHeaderText.setTextColor(style.getSettingsCategoryTextColor());
    TextView settingsHeaderText = (TextView) view.findViewById(R.id.settings_header_text);
    settingsHeaderText.setTextColor(style.getSettingsCategoryTextColor());
    TextView aboutHeaderText = (TextView) view.findViewById(R.id.about_header_text);
    aboutHeaderText.setTextColor(style.getSettingsCategoryTextColor());
    TextView settingsNotificationsTitle = (TextView) view.findViewById(R.id.settings_notifications_title);
    settingsNotificationsTitle.setTextColor(style.getSettingsTitleColor());
    TextView settingsChatTitle = (TextView) view.findViewById(R.id.settings_chat_title);
    settingsChatTitle.setTextColor(style.getSettingsTitleColor());
    TextView securityTitle = (TextView) view.findViewById(R.id.settings_security_title);
    securityTitle.setTextColor(style.getSettingsTitleColor());
    TintImageView securityIcon = (TintImageView) view.findViewById(R.id.settings_security_icon);
    securityIcon.setTint(style.getSettingsIconColor());
    TextView blockedListTitle = (TextView) view.findViewById(R.id.settings_blocked_title);
    blockedListTitle.setTextColor(style.getSettingsTitleColor());
    TintImageView blockedListIcon = (TintImageView) view.findViewById(R.id.settings_blocked_icon);
    blockedListIcon.setTint(style.getSettingsIconColor());
    TextView helpTitle = (TextView) view.findViewById(R.id.settings_help_title);
    helpTitle.setTextColor(style.getSettingsTitleColor());
    TintImageView helpIcon = (TintImageView) view.findViewById(R.id.settings_help_icon);
    helpIcon.setTint(style.getSettingsIconColor());
    TextView askTitle = (TextView) view.findViewById(R.id.settings_ask_title);
    askTitle.setTextColor(style.getSettingsTitleColor());
    TintImageView askIcon = (TintImageView) view.findViewById(R.id.settings_ask_icon);
    askIcon.setTint(style.getSettingsIconColor());
    TintImageView notificationsSettingsIcon = (TintImageView) view.findViewById(R.id.settings_notification_icon);
    notificationsSettingsIcon.setTint(style.getSettingsIconColor());
    TintImageView chatSettingsIcon = (TintImageView) view.findViewById(R.id.settings_chat_icon);
    chatSettingsIcon.setTint(style.getSettingsIconColor());
    if (getBeforeNickSettingsView() != null) {
        FrameLayout beforeNick = (FrameLayout) view.findViewById(R.id.before_nick_container);
        beforeNick.addView(getBeforeNickSettingsView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    }
    if (getBeforeNickSettingsView() != null) {
        FrameLayout afterPhone = (FrameLayout) view.findViewById(R.id.after_phone_container);
        afterPhone.addView(getAfterPhoneSettingsView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    }
    if (getSettingsTopView() != null) {
        FrameLayout settingsTop = (FrameLayout) view.findViewById(R.id.settings_top_container);
        settingsTop.addView(getSettingsTopView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    }
    if (getSettingsBottomView() != null) {
        FrameLayout settingsBot = (FrameLayout) view.findViewById(R.id.settings_bottom_container);
        settingsBot.addView(getSettingsBottomView(), FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
    }
    if (getBeforeSettingsCategories() != null) {
        LinearLayout beforeSettings = (LinearLayout) view.findViewById(R.id.before_settings_container);
        addCategories(beforeSettings, getBeforeSettingsCategories(), inflater);
    }
    if (getAfterSettingsCategories() != null) {
        LinearLayout afterSettings = (LinearLayout) view.findViewById(R.id.after_settings_container);
        addCategories(afterSettings, getAfterSettingsCategories(), inflater);
    }
    view.findViewById(R.id.avatarContainer).setBackgroundColor(style.getToolBarColor());
    avatarView = (AvatarView) view.findViewById(R.id.avatar);
    avatarView.init(Screen.dp(96), 44);
    avatarView.bind(users().get(myUid()));
    //Wallpaper
    if (showWallpaperCategory()) {
        ((TextView) view.findViewById(R.id.settings_wallpaper_title)).setTextColor(style.getSettingsCategoryTextColor());
        RecyclerView wallpapers = (RecyclerView) view.findViewById(R.id.wallpapers_list);
        wallpaperAdapter = new HeaderViewRecyclerAdapter(new WallpapersAdapter());
        FrameLayout fl = new FrameLayout(getActivity());
        ImageView icon = new ImageView(getActivity());
        icon.setImageResource(R.drawable.ic_image_black_24dp);
        icon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        icon.setColorFilter(ActorSDK.sharedActor().style.getSettingsIconColor(), PorterDuff.Mode.SRC_IN);
        fl.addView(icon, new FrameLayout.LayoutParams(Screen.dp(72), Screen.dp(85), Gravity.CENTER));
        fl.setLayoutParams(new ViewGroup.LayoutParams(Screen.dp(72), Screen.dp(85)));
        wallpaperAdapter.addHeaderView(fl);
        wallpapers.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
        wallpapers.setAdapter(wallpaperAdapter);
    } else {
        view.findViewById(R.id.wallpapers_list).setVisibility(View.GONE);
        view.findViewById(R.id.settings_wallpaper_title).setVisibility(View.GONE);
    }
    view.findViewById(R.id.avatar).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(ViewAvatarActivity.viewAvatar(myUid(), getActivity()));
        }
    });
    final ScrollView scrollView = ((ScrollView) view.findViewById(R.id.scrollContainer));
    scrollView.setBackgroundColor(style.getMainBackgroundColor());
    scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {

        @Override
        public void onScrollChanged() {
            updateActionBar(scrollView.getScrollY());
        }
    });
    updateActionBar(scrollView.getScrollY());
    return view;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayListUserEmail(im.actor.core.viewmodel.generics.ArrayListUserEmail) TintImageView(im.actor.sdk.view.TintImageView) UserEmail(im.actor.core.viewmodel.UserEmail) ArrayListUserEmail(im.actor.core.viewmodel.generics.ArrayListUserEmail) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ArrayListUserPhone(im.actor.core.viewmodel.generics.ArrayListUserPhone) ActorStyle(im.actor.sdk.ActorStyle) UserPhone(im.actor.core.viewmodel.UserPhone) ArrayListUserPhone(im.actor.core.viewmodel.generics.ArrayListUserPhone) TextView(android.widget.TextView) ImageView(android.widget.ImageView) TintImageView(im.actor.sdk.view.TintImageView) CommandCallback(im.actor.core.viewmodel.CommandCallback) ViewTreeObserver(android.view.ViewTreeObserver) ClipboardManager(android.content.ClipboardManager) ViewGroup(android.view.ViewGroup) 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) TintImageView(im.actor.sdk.view.TintImageView) AvatarView(im.actor.sdk.view.avatar.AvatarView) RecyclerView(android.support.v7.widget.RecyclerView) ScrollView(android.widget.ScrollView) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) UserVM(im.actor.core.viewmodel.UserVM) HeaderViewRecyclerAdapter(im.actor.sdk.view.adapters.HeaderViewRecyclerAdapter) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) NumberParseException(com.google.i18n.phonenumbers.NumberParseException) RecyclerView(android.support.v7.widget.RecyclerView) ClipData(android.content.ClipData) LinearLayout(android.widget.LinearLayout)

Aggregations

ClipboardManager (android.content.ClipboardManager)125 ClipData (android.content.ClipData)82 Intent (android.content.Intent)17 View (android.view.View)15 TextView (android.widget.TextView)13 Context (android.content.Context)10 Paint (android.graphics.Paint)9 DialogInterface (android.content.DialogInterface)7 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 Editable (android.text.Editable)7 TextPaint (android.text.TextPaint)7 ImageView (android.widget.ImageView)6 TargetApi (android.annotation.TargetApi)5 Spanned (android.text.Spanned)5 AlertDialog (android.app.AlertDialog)4 Uri (android.net.Uri)4 ColorDrawable (android.graphics.drawable.ColorDrawable)3 Drawable (android.graphics.drawable.Drawable)3 MenuItem (android.view.MenuItem)3