Example usage for android.support.v4.internal.view SupportMenuItem setVisible

List of usage examples for android.support.v4.internal.view SupportMenuItem setVisible

Introduction

In this page you can find the example usage for android.support.v4.internal.view SupportMenuItem setVisible.

Prototype

public MenuItem setVisible(boolean visible);

Source Link

Document

Sets the visibility of the menu item.

Usage

From source file:org.telegram.ui.ChatActivity.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();//from   w  w w.ja  va  2 s.  c  o m
    inflater.inflate(R.menu.chat_menu, menu);
    if (currentEncryptedChat != null && !(currentEncryptedChat instanceof TLRPC.TL_encryptedChat)
            || currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left)) {
        SupportMenuItem item = (SupportMenuItem) menu.findItem(R.id.chat_menu_attach);
        item.setVisible(false);
    }

    SupportMenuItem avatarItem = (SupportMenuItem) menu.findItem(R.id.chat_menu_avatar);
    View avatarLayout = avatarItem.getActionView();
    avatarImageView = (BackupImageView) avatarLayout.findViewById(R.id.chat_avatar_image);

    avatarImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (parentActivity == null) {
                return;
            }
            if (currentUser != null) {
                UserProfileActivity fragment = new UserProfileActivity();
                Bundle args = new Bundle();
                args.putInt("user_id", currentUser.id);
                if (currentEncryptedChat != null) {
                    args.putLong("dialog_id", dialog_id);
                }
                fragment.setArguments(args);
                ((ApplicationActivity) parentActivity).presentFragment(fragment, "user_" + currentUser.id,
                        swipeOpening);
            } else if (currentChat != null) {
                if (info != null) {
                    if (info instanceof TLRPC.TL_chatParticipantsForbidden) {
                        return;
                    }
                    NotificationCenter.Instance.addToMemCache(5, info);
                }
                if (currentChat.participants_count == 0 || currentChat.left
                        || currentChat instanceof TLRPC.TL_chatForbidden) {
                    return;
                }
                ChatProfileActivity fragment = new ChatProfileActivity();
                Bundle args = new Bundle();
                args.putInt("chat_id", currentChat.id);
                fragment.setArguments(args);
                ((ApplicationActivity) parentActivity).presentFragment(fragment, "chat_" + currentChat.id,
                        swipeOpening);
            }
        }
    });

    TLRPC.FileLocation photo = null;
    int placeHolderId = 0;
    if (currentUser != null) {
        if (currentUser.photo != null) {
            photo = currentUser.photo.photo_small;
        }
        placeHolderId = Utilities.getUserAvatarForId(currentUser.id);
    } else if (currentChat != null) {
        if (currentChat.photo != null) {
            photo = currentChat.photo.photo_small;
        }
        placeHolderId = Utilities.getGroupAvatarForId(currentChat.id);
    }
    avatarImageView.setImage(photo, "50_50", placeHolderId);
}