Example usage for android.widget TextView setVisibility

List of usage examples for android.widget TextView setVisibility

Introduction

In this page you can find the example usage for android.widget TextView setVisibility.

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java

@SuppressLint("SetTextI18n")
public void update(Lyrics lyrics, View layout, boolean animation) {
    File musicFile = null;//  www.  ja  v  a  2  s.c  om
    Bitmap cover = null;
    if (PermissionsChecker.hasPermission(getActivity(), "android.permission.READ_EXTERNAL_STORAGE")) {
        musicFile = Id3Reader.getFile(getActivity(), lyrics.getOriginalArtist(), lyrics.getOriginalTrack());
        cover = Id3Reader.getCover(getActivity(), lyrics.getArtist(), lyrics.getTitle());
    }
    setCoverArt(cover, null);
    boolean artCellDownload = Integer.valueOf(
            PreferenceManager.getDefaultSharedPreferences(getActivity()).getString("pref_artworks", "0")) == 0;
    if (cover == null)
        new CoverArtLoader().execute(lyrics, this.getActivity(),
                artCellDownload || OnlineAccessVerifier.isConnectedWifi(getActivity()));
    getActivity().findViewById(R.id.edit_tags_btn).setEnabled(true);
    getActivity().findViewById(R.id.edit_tags_btn)
            .setVisibility(musicFile == null || !musicFile.canWrite() || lyrics.isLRC()
                    || Id3Reader.getLyrics(getActivity(), lyrics.getArtist(), lyrics.getTitle()) == null
                            ? View.GONE
                            : View.VISIBLE);
    TextSwitcher textSwitcher = ((TextSwitcher) layout.findViewById(R.id.switcher));
    LrcView lrcView = (LrcView) layout.findViewById(R.id.lrc_view);
    View v = getActivity().findViewById(R.id.tracks_msg);
    if (v != null)
        ((ViewGroup) v.getParent()).removeView(v);
    TextView artistTV = (TextView) getActivity().findViewById(R.id.artist);
    TextView songTV = (TextView) getActivity().findViewById(R.id.song);
    final TextView id3TV = (TextView) layout.findViewById(R.id.source_tv);
    TextView writerTV = (TextView) layout.findViewById(R.id.writer_tv);
    TextView copyrightTV = (TextView) layout.findViewById(R.id.copyright_tv);
    RelativeLayout bugLayout = (RelativeLayout) layout.findViewById(R.id.error_msg);
    this.mLyrics = lyrics;
    if (SDK_INT >= ICE_CREAM_SANDWICH)
        beamLyrics(lyrics, this.getActivity());
    new PresenceChecker().execute(this, new String[] { lyrics.getArtist(), lyrics.getTitle(),
            lyrics.getOriginalArtist(), lyrics.getOriginalTrack() });

    if (lyrics.getArtist() != null)
        artistTV.setText(lyrics.getArtist());
    else
        artistTV.setText("");
    if (lyrics.getTitle() != null)
        songTV.setText(lyrics.getTitle());
    else
        songTV.setText("");
    if (lyrics.getCopyright() != null) {
        copyrightTV.setText("Copyright: " + lyrics.getCopyright());
        copyrightTV.setVisibility(View.VISIBLE);
    } else {
        copyrightTV.setText("");
        copyrightTV.setVisibility(View.GONE);
    }
    if (lyrics.getWriter() != null) {
        if (lyrics.getWriter().contains(","))
            writerTV.setText("Writers:\n" + lyrics.getWriter());
        else
            writerTV.setText("Writer:" + lyrics.getWriter());
        writerTV.setVisibility(View.VISIBLE);
    } else {
        writerTV.setText("");
        writerTV.setVisibility(View.GONE);
    }
    if (isActiveFragment)
        ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).show();
    EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics);
    if (newLyrics != null)
        newLyrics.setText("");

    if (lyrics.getFlag() == Lyrics.POSITIVE_RESULT) {
        if (!lyrics.isLRC()) {
            textSwitcher.setVisibility(View.VISIBLE);
            lrcView.setVisibility(View.GONE);
            if (animation)
                textSwitcher.setText(Html.fromHtml(lyrics.getText()));
            else
                textSwitcher.setCurrentText(Html.fromHtml(lyrics.getText()));
        } else {
            textSwitcher.setVisibility(View.GONE);
            lrcView.setVisibility(View.VISIBLE);
            lrcView.setOriginalLyrics(lyrics);
            lrcView.setSourceLrc(lyrics.getText());
            if (isActiveFragment)
                ((ControllableAppBarLayout) getActivity().findViewById(R.id.appbar)).expandToolbar(true);
            updateLRC();
        }

        bugLayout.setVisibility(View.INVISIBLE);
        id3TV.setMovementMethod(LinkMovementMethod.getInstance());
        if ("Storage".equals(lyrics.getSource())) {
            id3TV.setVisibility(View.VISIBLE);
            SpannableString text = new SpannableString(getString(R.string.from_id3));
            text.setSpan(new UnderlineSpan(), 1, text.length() - 1, 0);
            id3TV.setText(text);
            id3TV.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ((MainActivity) getActivity()).id3PopUp(id3TV);
                }
            });
        } else {
            id3TV.setOnClickListener(null);
            id3TV.setVisibility(View.GONE);
        }
        mScrollView.post(new Runnable() {
            @Override
            public void run() {
                mScrollView.scrollTo(0, 0); //only useful when coming from localLyricsFragment
                mScrollView.smoothScrollTo(0, 0);
            }
        });
    } else {
        textSwitcher.setText("");
        textSwitcher.setVisibility(View.INVISIBLE);
        lrcView.setVisibility(View.INVISIBLE);
        bugLayout.setVisibility(View.VISIBLE);
        int message;
        int whyVisibility;
        if (lyrics.getFlag() == Lyrics.ERROR || !OnlineAccessVerifier.check(getActivity())) {
            message = R.string.connection_error;
            whyVisibility = TextView.GONE;
        } else {
            message = R.string.no_results;
            whyVisibility = TextView.VISIBLE;
            updateSearchView(false, lyrics.getTitle(), false);
        }
        TextView whyTextView = ((TextView) bugLayout.findViewById(R.id.bugtext_why));
        ((TextView) bugLayout.findViewById(R.id.bugtext)).setText(message);
        whyTextView.setVisibility(whyVisibility);
        whyTextView.setPaintFlags(whyTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
        id3TV.setVisibility(View.GONE);
    }
    stopRefreshAnimation();
    getActivity().getIntent().setAction("");
    getActivity().invalidateOptionsMenu();
}

From source file:com.easemob.chatui.adapter.MessageAdapter.java

@SuppressLint("NewApi")
public View getView(final int position, View convertView, ViewGroup parent) {
    final EMMessage message = getItem(position);
    ChatType chatType = message.getChatType();
    final ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = createViewByMessage(message, position);
        if (message.getType() == EMMessage.Type.IMAGE) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(R.id.iv_sendPicture));
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.percentage);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }/*from   w  ww . j  a v a 2s  .  c o m*/

        } else if (message.getType() == EMMessage.Type.TXT) {

            try {
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                // 
                holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);

                holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
                holder.tvList = (LinearLayout) convertView.findViewById(R.id.ll_layout);
            } catch (Exception e) {
            }

            // ???
            if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)
                    || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) {
                holder.iv = (ImageView) convertView.findViewById(R.id.iv_call_icon);
                holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent);
            }

        } else if (message.getType() == EMMessage.Type.VOICE) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(R.id.iv_voice));
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.tv_length);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
                holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice);
            } catch (Exception e) {
            }
        } else if (message.getType() == EMMessage.Type.LOCATION) {
            try {
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.tv_location);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }
        } else if (message.getType() == EMMessage.Type.VIDEO) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(R.id.chatting_content_iv));
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.percentage);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.size = (TextView) convertView.findViewById(R.id.chatting_size_iv);
                holder.timeLength = (TextView) convertView.findViewById(R.id.chatting_length_iv);
                holder.playBtn = (ImageView) convertView.findViewById(R.id.chatting_status_btn);
                holder.container_status_btn = (LinearLayout) convertView
                        .findViewById(R.id.container_status_btn);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);

            } catch (Exception e) {
            }
        } else if (message.getType() == EMMessage.Type.FILE) {
            try {
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv_file_name = (TextView) convertView.findViewById(R.id.tv_file_name);
                holder.tv_file_size = (TextView) convertView.findViewById(R.id.tv_file_size);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_file_download_state = (TextView) convertView.findViewById(R.id.tv_file_state);
                holder.ll_container = (LinearLayout) convertView.findViewById(R.id.ll_file_container);
                // 
                holder.tv = (TextView) convertView.findViewById(R.id.percentage);
            } catch (Exception e) {
            }
            try {
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }

        }

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // ??????
    if ((chatType == ChatType.GroupChat || chatType == chatType.ChatRoom) && message.direct == Direct.RECEIVE) {
        //demousername?nick
        //            holder.tv_usernick.setText(message.getFrom());
        /**?userid????*/
        HttpUtils httpUtils = new HttpUtils();
        MyRequestParams params = new MyRequestParams();
        params.addQueryStringParameter("userid", BeewayApplication.getInstance().getmUserid(context));
        params.addQueryStringParameter("friendid", message.getFrom());
        params.addQueryStringParameter("track", 1 + "");
        String url = params.myRequestParams(params);
        httpUtils.send(HttpRequest.HttpMethod.POST, UrlPools.USER_DETAIL + "?" + url,
                new RequestCallBack<String>() {

                    @Override
                    public void onSuccess(ResponseInfo<String> responseInfo) {
                        String result = responseInfo.result;
                        UserDetailBean userDetailBean = UserDetailsActivity.paraseUserDetail(result);
                        holder.tv_usernick.setText(userDetailBean.getData().getFriend().getNickname());
                    }

                    @Override
                    public void onFailure(HttpException e, String s) {
                        LogUtils.e(s);
                        holder.tv_usernick.setText("");
                    }
                });
    }
    // ??????textview
    if (!(chatType == ChatType.GroupChat || chatType == chatType.ChatRoom) && message.direct == Direct.SEND) {
        holder.tv_ack = (TextView) convertView.findViewById(R.id.tv_ack);
        holder.tv_delivered = (TextView) convertView.findViewById(R.id.tv_delivered);
        if (holder.tv_ack != null) {
            if (message.isAcked) {
                if (holder.tv_delivered != null) {
                    holder.tv_delivered.setVisibility(View.INVISIBLE);
                }
                holder.tv_ack.setVisibility(View.VISIBLE);
            } else {
                holder.tv_ack.setVisibility(View.INVISIBLE);

                // check and display msg delivered ack status
                if (holder.tv_delivered != null) {
                    if (message.isDelivered) {
                        holder.tv_delivered.setVisibility(View.VISIBLE);
                    } else {
                        holder.tv_delivered.setVisibility(View.INVISIBLE);
                    }
                }
            }
        }
    } else {
        // ??group messgae,chatroom message??
        if ((message.getType() == EMMessage.Type.TXT || message.getType() == EMMessage.Type.LOCATION)
                && !message.isAcked && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) {
            // ??
            if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) {
                try {
                    EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    // ??
                    message.isAcked = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    //?
    setUserAvatar(message, holder.iv_avatar);

    switch (message.getType()) {
    // ??typeitem
    case IMAGE: // 
        handleImageMessage(message, holder, position, convertView);
        break;
    case TXT: // 
        if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)
                || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false))
            // ?
            handleCallMessage(message, holder, position);
        else if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message))
            //??
            handleRobotMenuMessage(message, holder, position);
        else
            handleTextMessage(message, holder, position);
        break;
    case LOCATION: // ?
        handleLocationMessage(message, holder, position, convertView);
        break;
    case VOICE: // 
        handleVoiceMessage(message, holder, position, convertView);
        break;
    case VIDEO: // 
        handleVideoMessage(message, holder, position, convertView);
        break;
    case FILE: // 
        handleFileMessage(message, holder, position, convertView);
        break;
    default:
        // not supported
    }

    if (message.direct == Direct.SEND) {
        View statusView = convertView.findViewById(R.id.msg_status);
        // ??
        statusView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                // ???alertdialog
                Intent intent = new Intent(activity, AlertDialog.class);
                intent.putExtra("msg", activity.getString(R.string.confirm_resend));
                intent.putExtra("title", activity.getString(R.string.resend));
                intent.putExtra("cancel", true);
                intent.putExtra("position", position);
                if (message.getType() == EMMessage.Type.TXT)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT);
                else if (message.getType() == EMMessage.Type.VOICE)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE);
                else if (message.getType() == EMMessage.Type.IMAGE)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE);
                else if (message.getType() == EMMessage.Type.LOCATION)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION);
                else if (message.getType() == EMMessage.Type.FILE)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE);
                else if (message.getType() == EMMessage.Type.VIDEO)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO);

            }
        });
        /**???*/
        holder.iv_avatar.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, UserDetailsActivity.class);
                intent.putExtra("friendid", EMChatManager.getInstance().getCurrentUser());
                activity.startActivity(intent);
            }
        });
    } else {
        final String st = context.getResources().getString(R.string.Into_the_blacklist);
        if (!((ChatActivity) activity).isRobot && chatType != ChatType.ChatRoom) {
            // ????
            holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    Intent intent = new Intent(activity, AlertDialog.class);
                    intent.putExtra("msg", st);
                    intent.putExtra("cancel", true);
                    intent.putExtra("position", position);
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST);
                    return true;
                }
            });
            /**???*/
            holder.iv_avatar.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(activity, UserDetailsActivity.class);
                    intent.putExtra("friendid", message.getFrom());
                    activity.startActivity(intent);
                }
            });
        }
    }

    TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp);

    if (position == 0) {
        timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
        timestamp.setVisibility(View.VISIBLE);
    } else {
        // ???
        EMMessage prevMessage = getItem(position - 1);
        if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) {
            timestamp.setVisibility(View.GONE);
        } else {
            timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
            timestamp.setVisibility(View.VISIBLE);
        }
    }
    return convertView;
}

From source file:com.shengtao.chat.chatUI.adapter.MessageAdapter.java

@SuppressLint("NewApi")
public View getView(final int position, View convertView, ViewGroup parent) {
    final EMMessage message = getItem(position);
    ChatType chatType = message.getChatType();
    final ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = createViewByMessage(message, position);
        if (message.getType() == Type.IMAGE) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(id.iv_sendPicture));
                holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(id.percentage);
                holder.pb = (ProgressBar) convertView.findViewById(id.progressBar);
                holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid);
            } catch (Exception e) {
            }//from  w  ww  . j a  v  a 2s .  c  o m

        } else if (message.getType() == Type.TXT) {

            try {
                holder.pb = (ProgressBar) convertView.findViewById(id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status);
                holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead);
                // 
                holder.tv = (TextView) convertView.findViewById(id.tv_chatcontent);
                holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid);

                holder.tvTitle = (TextView) convertView.findViewById(id.tvTitle);
                holder.tvList = (LinearLayout) convertView.findViewById(id.ll_layout);
            } catch (Exception e) {
            }

            // ???
            if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)
                    || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) {
                holder.iv = (ImageView) convertView.findViewById(id.iv_call_icon);
                holder.tv = (TextView) convertView.findViewById(id.tv_chatcontent);
            }

        } else if (message.getType() == Type.VOICE) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(id.iv_voice));
                holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(id.tv_length);
                holder.pb = (ProgressBar) convertView.findViewById(id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid);
                holder.iv_read_status = (ImageView) convertView.findViewById(id.iv_unread_voice);
            } catch (Exception e) {
            }
        } else if (message.getType() == Type.LOCATION) {
            try {
                holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(id.tv_location);
                holder.pb = (ProgressBar) convertView.findViewById(id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid);
            } catch (Exception e) {
            }
        } else if (message.getType() == Type.VIDEO) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(id.chatting_content_iv));
                holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(id.percentage);
                holder.pb = (ProgressBar) convertView.findViewById(id.progressBar);
                holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status);
                holder.size = (TextView) convertView.findViewById(id.chatting_size_iv);
                holder.timeLength = (TextView) convertView.findViewById(id.chatting_length_iv);
                holder.playBtn = (ImageView) convertView.findViewById(id.chatting_status_btn);
                holder.container_status_btn = (LinearLayout) convertView.findViewById(id.container_status_btn);
                holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid);

            } catch (Exception e) {
            }
        } else if (message.getType() == Type.FILE) {
            try {
                holder.iv_avatar = (ImageView) convertView.findViewById(id.iv_userhead);
                holder.tv_file_name = (TextView) convertView.findViewById(id.tv_file_name);
                holder.tv_file_size = (TextView) convertView.findViewById(id.tv_file_size);
                holder.pb = (ProgressBar) convertView.findViewById(id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(id.msg_status);
                holder.tv_file_download_state = (TextView) convertView.findViewById(id.tv_file_state);
                holder.ll_container = (LinearLayout) convertView.findViewById(id.ll_file_container);
                // 
                holder.tv = (TextView) convertView.findViewById(id.percentage);
            } catch (Exception e) {
            }
            try {
                holder.tv_usernick = (TextView) convertView.findViewById(id.tv_userid);
            } catch (Exception e) {
            }

        }

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // ??????
    if ((chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == Direct.RECEIVE) {
        //demousername?nick

        UserUtils.setUserNick(message.getFrom(), holder.tv_usernick);
    }
    if (message.direct == Direct.SEND) {
        UserUtils.setCurrentUserNick(holder.tv_usernick);
    }
    // ??????textview
    if (!(chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == Direct.SEND) {
        holder.tv_ack = (TextView) convertView.findViewById(id.tv_ack);
        holder.tv_delivered = (TextView) convertView.findViewById(id.tv_delivered);
        if (holder.tv_ack != null) {
            if (message.isAcked) {
                if (holder.tv_delivered != null) {
                    holder.tv_delivered.setVisibility(View.INVISIBLE);
                }
                holder.tv_ack.setVisibility(View.VISIBLE);
            } else {
                holder.tv_ack.setVisibility(View.INVISIBLE);

                // check and display msg delivered ack status
                if (holder.tv_delivered != null) {
                    if (message.isDelivered) {
                        holder.tv_delivered.setVisibility(View.VISIBLE);
                    } else {
                        holder.tv_delivered.setVisibility(View.INVISIBLE);
                    }
                }
            }
        }
    } else {
        // ??group messgae,chatroom message??
        if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked
                && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) {
            // ??
            if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) {
                try {
                    EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    // ??
                    message.isAcked = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    //?
    setUserAvatar(message, holder.iv_avatar, holder.tv_usernick);

    switch (message.getType()) {
    // ??typeitem
    case IMAGE: // 
        handleImageMessage(message, holder, position, convertView);
        break;
    case TXT: // 
        if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)
                || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false))
            // ?
            handleCallMessage(message, holder, position);
        else if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message))
            //??
            handleRobotMenuMessage(message, holder, position);
        else
            handleTextMessage(message, holder, position);
        break;
    case LOCATION: // ?
        handleLocationMessage(message, holder, position, convertView);
        break;
    case VOICE: // 
        handleVoiceMessage(message, holder, position, convertView);
        break;
    case VIDEO: // 
        handleVideoMessage(message, holder, position, convertView);
        break;
    case FILE: // 
        handleFileMessage(message, holder, position, convertView);
        break;
    default:
        // not supported
    }

    if (message.direct == Direct.SEND) {
        View statusView = convertView.findViewById(id.msg_status);
        // ??
        statusView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                // ???alertdialog
                Intent intent = new Intent(activity, AlertDialog.class);
                intent.putExtra("msg", activity.getString(string.confirm_resend));
                intent.putExtra("title", activity.getString(string.resend));
                intent.putExtra("cancel", true);
                intent.putExtra("position", position);
                if (message.getType() == Type.TXT)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_TEXT);
                else if (message.getType() == Type.VOICE)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VOICE);
                else if (message.getType() == Type.IMAGE)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_PICTURE);
                else if (message.getType() == Type.LOCATION)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_LOCATION);
                else if (message.getType() == Type.FILE)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_FILE);
                else if (message.getType() == Type.VIDEO)
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_VIDEO);

            }
        });

    } else {
        final String st = context.getResources().getString(string.Into_the_blacklist);
        if (!((ChatActivity) activity).isRobot && chatType != ChatType.ChatRoom) {
            // ????
            holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    Intent intent = new Intent(activity, AlertDialog.class);
                    intent.putExtra("msg", st);
                    intent.putExtra("cancel", true);
                    intent.putExtra("position", position);
                    activity.startActivityForResult(intent, ChatActivity.REQUEST_CODE_ADD_TO_BLACKLIST);
                    return true;
                }
            });
        }
    }

    TextView timestamp = (TextView) convertView.findViewById(id.timestamp);

    if (position == 0) {
        timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
        timestamp.setVisibility(View.VISIBLE);
    } else {
        // ???
        EMMessage prevMessage = getItem(position - 1);
        if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) {
            timestamp.setVisibility(View.GONE);
        } else {
            timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
            timestamp.setVisibility(View.VISIBLE);
        }
    }

    return convertView;
}

From source file:de.sourcestream.movieDB.MainActivity.java

/**
 * This method is used in MovieDetails, CastDetails and TVDetails.
 *
 * @param textView the TextView which we hide.
 *//*from   ww  w  .j  av  a  2s. c o  m*/
public void hideTextView(final TextView textView) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            textView.setVisibility(View.GONE);
        }
    });
}

From source file:ca.ualberta.cs.drivr.RequestsListAdapter.java

/**
 * Called when the view holder is wants to bind the request at a certain position in the list.
 * @param viewHolder/*from   w w w  .j  a  v a  2s.  c  om*/
 * @param position
 */
@Override
public void onBindViewHolder(final RequestsListAdapter.ViewHolder viewHolder, final int position) {
    final Request request = requestsToDisplay.get(position);

    // Get the views to update
    final TextView otherUserNameTextView = viewHolder.otherUserNameTextView;
    final TextView descriptionTextView = viewHolder.descriptionTextView;
    final TextView fareTextView = viewHolder.fareTextView;
    final TextView routeTextView = viewHolder.routeTextView;
    final TextView statusTextView = viewHolder.statusTextView;
    final ImageView callImageView = viewHolder.callImageView;
    final ImageView emailImageView = viewHolder.emailImageView;
    final ImageView checkImageView = viewHolder.checkMarkImageView;
    final ImageView deleteImageView = viewHolder.xMarkImageView;

    // Todo Hide Image Views until correct Request State
    if (request.getRequestState() != RequestState.CONFIRMED) {
        checkImageView.setVisibility(View.INVISIBLE);
    }

    if (request.getRequestState() != RequestState.PENDING) {
        deleteImageView.setVisibility(View.INVISIBLE);
    }

    // Show the other person's name
    final DriversList drivers = request.getDrivers();

    // Get the username of the other user
    if (userManager.getUserMode() == UserMode.RIDER) {
        final String multipleDrivers = "Multiple Drivers Accepted";
        final String driverUsername = drivers.size() == 1 ? drivers.get(0).getUsername() : "No Driver Yet";
        otherUserNameTextView.setText(drivers.size() > 1 ? multipleDrivers : driverUsername);
    } else {
        otherUserNameTextView.setText(request.getRider().getUsername());
    }

    // If the request has a description, show it. Otherwise, hide te description
    if (Strings.isNullOrEmpty(request.getDescription()))
        descriptionTextView.setVisibility(View.GONE);
    else
        descriptionTextView.setText(request.getDescription());

    // Show the fare
    fareTextView.setText("$" + request.getFareString());

    // Show the route
    routeTextView.setText(request.getRoute());

    // Driver User
    otherUserNameTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String otherUsername = otherUserNameTextView.getText().toString();
            // there exists drivers
            if (otherUsername != "No Driver Yet") {
                if (otherUsername != "Multiple Drivers Accepted") {
                    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();

                    ElasticSearch elasticSearch = new ElasticSearch(
                            UserManager.getInstance().getConnectivityManager());
                    User user = elasticSearch.loadUser(otherUsername);

                    String driverString = gson.toJson(user, User.class);
                    Intent intent = new Intent(context, DriverProfileActivity.class);
                    intent.putExtra(DriverProfileActivity.DRIVER, driverString);
                    context.startActivity(intent);
                } else {
                    startMultipleDriverIntent(request);
                }
            }
        }
    });

    routeTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
            String requestString = gson.toJson(request, Request.class);
            Intent intent = new Intent(context, RequestActivity.class);
            intent.putExtra("UniqueID", "From_RequestListActivity");
            intent.putExtra(RequestActivity.EXTRA_REQUEST, requestString);
            context.startActivity(intent);
        }
    });

    // Show the status text
    statusTextView.setText(request.getRequestState().toString());

    // Add a listener to the call image
    callImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drivers.size() == 0) {
                Toast.makeText(context, "No driver number available at this time", Toast.LENGTH_SHORT).show();

            }
            // Start Dialer
            else if (drivers.size() == 1) {
                Intent intent = new Intent(Intent.ACTION_CALL);
                String number;
                if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) {
                    number = drivers.get(0).getPhoneNumber();
                } else {
                    number = request.getRider().getPhoneNumber();
                }
                number = "tel:" + number;
                intent.setData(Uri.parse(number));
                if (ActivityCompat.checkSelfPermission(context,
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                    return;
                }
                context.startActivity(intent);

            } else {

                startMultipleDriverIntent(request);
            }
        }
    });

    // Add a listener to the email image
    emailImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drivers.size() == 0) {
                Toast.makeText(context, "No driver email available at this time", Toast.LENGTH_SHORT).show();

            }
            //http://stackoverflow.com/questions/8701634/send-email-intent
            else if (drivers.size() == 1) {

                Intent intent = new Intent();
                ComponentName emailApp = intent.resolveActivity(context.getPackageManager());
                ComponentName unsupportedAction = ComponentName
                        .unflattenFromString("com.android.fallback/.Fallback");
                boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction);
                String email;

                if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) {
                    email = drivers.get(0).getEmail();
                } else {
                    email = request.getRider().getEmail();
                }
                String subject = "Drivr Request: " + request.getId();
                String body = "Drivr user " + drivers.get(0).getUsername();

                if (hasEmailApp) {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                    emailIntent.putExtra(Intent.EXTRA_TEXT, body);
                    context.startActivity(Intent.createChooser(emailIntent, "Chooser Title"));
                } else {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
                    emailIntent.putExtra(Intent.EXTRA_TEXT, "");
                    context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
                }
            } else {
                startMultipleDriverIntent(request);

            }
        }
    });

    // Complete The Request
    checkImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(context, RequestCompletedActivity.class);
            intent.putExtra(RequestCompletedActivity.REQUEST_ID_EXTRA, request.getId());
            context.startActivity(intent);
        }
    });

    deleteImageView.setOnClickListener(new View.OnClickListener() {

        // Todo Delete the Request
        @Override
        public void onClick(View v) {
            v.getContext();
            ElasticSearch elasticSearch = new ElasticSearch(
                    (ConnectivityManager) v.getContext().getSystemService(Context.CONNECTIVITY_SERVICE));
            elasticSearch.deleteRequest(request.getId());
            UserManager userManager = UserManager.getInstance();
            userManager.getRequestsList().removeById(request);
            userManager.notifyObservers();
            requestsToDisplay.remove(request);
            notifyItemRemoved(viewHolder.getAdapterPosition());
        }
    });
}

From source file:com.android.contacts.list.ContactListItemView.java

private void updateHeaderText(TextView headerTextView, String title) {
    setMarqueeText(headerTextView, title);
    headerTextView.setAllCaps(true);/*from   w  w w . j a v a2 s .  c o  m*/
    if (ContactsSectionIndexer.BLANK_HEADER_STRING.equals(title)) {
        headerTextView.setContentDescription(getContext().getString(R.string.description_no_name_header));
    } else {
        headerTextView.setContentDescription(title);
    }
    headerTextView.setVisibility(View.VISIBLE);
}

From source file:com.com.easemob.chatuidemo.adapter.MessageAdapter.java

@SuppressLint("NewApi")
public View getView(final int position, View convertView, ViewGroup parent) {
    final EMMessage message = getItem(position);
    ChatType chatType = message.getChatType();
    final ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
        convertView = createViewByMessage(message, position);
        if (message.getType() == EMMessage.Type.IMAGE) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(R.id.iv_sendPicture));
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.percentage);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }//from w  w  w  .  j a  v a 2  s .  com

        } else if (message.getType() == EMMessage.Type.TXT) {

            try {
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                // 
                holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);

                holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
                holder.tvList = (LinearLayout) convertView.findViewById(R.id.ll_layout);
            } catch (Exception e) {
            }

            // ???
            if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)
                    || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false)) {
                holder.iv = (ImageView) convertView.findViewById(R.id.iv_call_icon);
                holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent);
            }

        } else if (message.getType() == EMMessage.Type.VOICE) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(R.id.iv_voice));
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.tv_length);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
                holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice);
            } catch (Exception e) {
            }
        } else if (message.getType() == EMMessage.Type.LOCATION) {
            try {
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.tv_location);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }
        } else if (message.getType() == EMMessage.Type.VIDEO) {
            try {
                holder.iv = ((ImageView) convertView.findViewById(R.id.chatting_content_iv));
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv = (TextView) convertView.findViewById(R.id.percentage);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.size = (TextView) convertView.findViewById(R.id.chatting_size_iv);
                holder.timeLength = (TextView) convertView.findViewById(R.id.chatting_length_iv);
                holder.playBtn = (ImageView) convertView.findViewById(R.id.chatting_status_btn);
                holder.container_status_btn = (LinearLayout) convertView
                        .findViewById(R.id.container_status_btn);
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);

            } catch (Exception e) {
            }
        } else if (message.getType() == EMMessage.Type.FILE) {
            try {
                holder.iv_avatar = (ImageView) convertView.findViewById(R.id.iv_userhead);
                holder.tv_file_name = (TextView) convertView.findViewById(R.id.tv_file_name);
                holder.tv_file_size = (TextView) convertView.findViewById(R.id.tv_file_size);
                holder.pb = (ProgressBar) convertView.findViewById(R.id.pb_sending);
                holder.staus_iv = (ImageView) convertView.findViewById(R.id.msg_status);
                holder.tv_file_download_state = (TextView) convertView.findViewById(R.id.tv_file_state);
                holder.ll_container = (LinearLayout) convertView.findViewById(R.id.ll_file_container);
                // 
                holder.tv = (TextView) convertView.findViewById(R.id.percentage);
            } catch (Exception e) {
            }
            try {
                holder.tv_usernick = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }

        }

        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    //      // ??????
    //      if ((chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom) && message.direct == EMMessage.Direct.RECEIVE){
    //         //demousername?nick
    //         UserUtils.setUserNick(message.getFrom(), holder.tv_usernick);
    //      }
    //      if(message.direct == EMMessage.Direct.SEND){
    //         UserUtils.setCurrentUserNick(holder.tv_usernick);
    //      }
    // ??????textview
    if (!(chatType == ChatType.GroupChat || chatType == ChatType.ChatRoom)
            && message.direct == EMMessage.Direct.SEND) {
        holder.tv_ack = (TextView) convertView.findViewById(R.id.tv_ack);
        holder.tv_delivered = (TextView) convertView.findViewById(R.id.tv_delivered);
        if (holder.tv_ack != null) {
            if (message.isAcked) {
                if (holder.tv_delivered != null) {
                    holder.tv_delivered.setVisibility(View.INVISIBLE);
                }
                holder.tv_ack.setVisibility(View.VISIBLE);
            } else {
                holder.tv_ack.setVisibility(View.INVISIBLE);

                // check and display msg delivered ack status
                if (holder.tv_delivered != null) {
                    if (message.isDelivered) {
                        holder.tv_delivered.setVisibility(View.VISIBLE);
                    } else {
                        holder.tv_delivered.setVisibility(View.INVISIBLE);
                    }
                }
            }
        }
    } else {
        // ??group messgae,chatroom message??
        if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked
                && chatType != ChatType.GroupChat && chatType != ChatType.ChatRoom) {
            // ??
            if (!message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)) {
                try {
                    EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    // ??
                    message.isAcked = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    //?
    setUserAvatar(message, holder.iv_avatar);

    switch (message.getType()) {
    // ??typeitem
    case IMAGE: // 
        handleImageMessage(message, holder, position, convertView);
        break;
    case TXT: // 
        if (message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VOICE_CALL, false)
                || message.getBooleanAttribute(Constant.MESSAGE_ATTR_IS_VIDEO_CALL, false))
            // ?
            handleCallMessage(message, holder, position);
        else if (((DemoHXSDKHelper) HXSDKHelper.getInstance()).isRobotMenuMessage(message))
            //??
            handleRobotMenuMessage(message, holder, position);
        else
            handleTextMessage(message, holder, position);
        break;
    case LOCATION: // ?
        handleLocationMessage(message, holder, position, convertView);
        break;
    case VOICE: // 
        handleVoiceMessage(message, holder, position, convertView);
        break;
    case VIDEO: // 
        handleVideoMessage(message, holder, position, convertView);
        break;
    case FILE: // 
        handleFileMessage(message, holder, position, convertView);
        break;
    default:
        // not supported
    }

    if (message.direct == EMMessage.Direct.SEND) {
        View statusView = convertView.findViewById(R.id.msg_status);
        // ??
        statusView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                // ???alertdialog
                Intent intent = new Intent(activity, AlertDialog.class);
                intent.putExtra("msg", activity.getString(R.string.confirm_resend));
                intent.putExtra("title", activity.getString(R.string.resend));
                intent.putExtra("cancel", true);
                intent.putExtra("position", position);
                if (message.getType() == EMMessage.Type.TXT)
                    activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_TEXT);
                else if (message.getType() == EMMessage.Type.VOICE)
                    activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_VOICE);
                else if (message.getType() == EMMessage.Type.IMAGE)
                    activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_PICTURE);
                else if (message.getType() == EMMessage.Type.LOCATION)
                    activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_LOCATION);
                else if (message.getType() == EMMessage.Type.FILE)
                    activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_FILE);
                else if (message.getType() == EMMessage.Type.VIDEO)
                    activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_VIDEO);

            }
        });

    } else {
        final String st = context.getResources().getString(R.string.Into_the_blacklist);
        if (!((ChatMessage) activity).isRobot && chatType != ChatType.ChatRoom) {
            // ????
            holder.iv_avatar.setOnLongClickListener(new OnLongClickListener() {

                @Override
                public boolean onLongClick(View v) {
                    Intent intent = new Intent(activity, AlertDialog.class);
                    intent.putExtra("msg", st);
                    intent.putExtra("cancel", true);
                    intent.putExtra("position", position);
                    activity.startActivityForResult(intent, ChatMessage.REQUEST_CODE_ADD_TO_BLACKLIST);
                    return true;
                }
            });
        }
    }

    TextView timestamp = (TextView) convertView.findViewById(R.id.timestamp);

    if (position == 0) {
        timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
        timestamp.setVisibility(View.VISIBLE);
    } else {
        // ???
        EMMessage prevMessage = getItem(position - 1);
        if (prevMessage != null && DateUtils.isCloseEnough(message.getMsgTime(), prevMessage.getMsgTime())) {
            timestamp.setVisibility(View.GONE);
        } else {
            timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
            timestamp.setVisibility(View.VISIBLE);
        }
    }
    return convertView;
}

From source file:com.evandroid.musica.fragment.LyricsViewFragment.java

public void update(Lyrics lyrics, View layout, boolean animation) {

    TextSwitcher textSwitcher = ((TextSwitcher) layout.findViewById(R.id.switcher));
    LrcView lrcView = (LrcView) layout.findViewById(R.id.lrc_view);
    View v = getActivity().findViewById(R.id.tracks_msg);
    if (v != null)
        ((ViewGroup) v.getParent()).removeView(v);

    TextView id3TV = (TextView) layout.findViewById(R.id.id3_tv);
    RelativeLayout bugLayout = (RelativeLayout) layout.findViewById(R.id.error_msg);
    this.mLyrics = lyrics;
    if (SDK_INT >= ICE_CREAM_SANDWICH)
        beamLyrics(lyrics, this.getActivity());
    new PresenceChecker().execute(this, new String[] { lyrics.getArtist(), lyrics.getTrack(),
            lyrics.getOriginalArtist(), lyrics.getOriginalTrack() });

    if (isActiveFragment)
        ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).show();
    EditText newLyrics = (EditText) getActivity().findViewById(R.id.edit_lyrics);
    if (newLyrics != null)
        newLyrics.setText("");

    if (lyrics.getFlag() == Lyrics.POSITIVE_RESULT) {
        if (!lyrics.isLRC()) {
            textSwitcher.setVisibility(View.VISIBLE);
            lrcView.setVisibility(View.GONE);
            if (animation)
                textSwitcher.setText(Html.fromHtml(lyrics.getText()));
            else/*from   w w w  .  ja va  2  s. c  o m*/
                textSwitcher.setCurrentText(Html.fromHtml(lyrics.getText()));
        } else {
            textSwitcher.setVisibility(View.GONE);
            lrcView.setVisibility(View.VISIBLE);
            lrcView.setOriginalLyrics(lyrics);
            lrcView.setSourceLrc(lyrics.getText());
            updateLRC();
        }

        bugLayout.setVisibility(View.INVISIBLE);
        if ("Storage".equals(lyrics.getSource()))
            id3TV.setVisibility(View.VISIBLE);
        else
            id3TV.setVisibility(View.GONE);
        mScrollView.post(new Runnable() {
            @Override
            public void run() {
                mScrollView.scrollTo(0, 0); //only useful when coming from localLyricsFragment
                mScrollView.smoothScrollTo(0, 0);
            }
        });
    } else {
        textSwitcher.setText("");
        textSwitcher.setVisibility(View.INVISIBLE);
        lrcView.setVisibility(View.INVISIBLE);
        bugLayout.setVisibility(View.VISIBLE);
        int message;
        int whyVisibility;
        if (lyrics.getFlag() == Lyrics.ERROR || !OnlineAccessVerifier.check(getActivity())) {
            message = R.string.connection_error;
            whyVisibility = TextView.GONE;
        } else {
            message = R.string.no_results;
            whyVisibility = TextView.VISIBLE;
            updateSearchView(false, lyrics.getTrack(), false);
        }
        TextView whyTextView = ((TextView) bugLayout.findViewById(R.id.bugtext_why));
        ((TextView) bugLayout.findViewById(R.id.bugtext)).setText(message);
        whyTextView.setVisibility(whyVisibility);
        whyTextView.setPaintFlags(whyTextView.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
        id3TV.setVisibility(View.GONE);
    }
    stopRefreshAnimation();
    getActivity().getIntent().setAction("");
    getActivity().invalidateOptionsMenu();
}

From source file:github.popeen.dsub.fragments.SelectDirectoryFragment.java

private void setupTextDisplay(final View header) {

    final TextView titleView = (TextView) header.findViewById(R.id.select_album_title);
    if (playlistName != null) {
        titleView.setText(playlistName);
    } else if (podcastName != null) {
        Collections.reverse(entries);
        titleView.setText(podcastName);//from   www  .j  a v  a  2s  .com
        titleView.setPadding(0, 6, 4, 8);
    } else if (name != null) {
        titleView.setText(name);
        if (artistInfo != null) {
            titleView.setPadding(0, 6, 4, 8);
        }
    } else if (share != null) {
        titleView.setVisibility(View.GONE);
    }

    int songCount = 0;

    Set<String> artists = new HashSet<String>();
    Set<Integer> years = new HashSet<Integer>();
    totalDuration = 0;
    for (Entry entry : entries) {
        if (!entry.isDirectory()) {
            songCount++;
            if (entry.getArtist() != null) {
                artists.add(entry.getArtist());
            }
            if (entry.getYear() != null) {
                years.add(entry.getYear());
            }
            Integer duration = entry.getDuration();
            if (duration != null) {
                totalDuration += duration;
            }
        }
    }
    String artistName = "";
    bookDescription = "Could not collect any info about the book at this time";
    try {

        artistName = artists.iterator().next();
        String endpoint = "getBookDirectory";
        if (Util.isTagBrowsing(context)) {
            endpoint = "getBook";
        }
        SharedPreferences prefs = Util.getPreferences(context);
        String url = Util.getRestUrl(context, endpoint) + "&id=" + directory.getId() + "&f=json";

        Log.w("GetInfo", url);
        String artist, title;
        int year = 0;
        artist = title = "";

        try {
            artist = artists.iterator().next();
        } catch (Exception e) {
            Log.w("GetInfoArtist", e.toString());
        }
        try {
            title = titleView.getText().toString();
        } catch (Exception e) {
            Log.w("GetInfoTitle", e.toString());
        }
        try {
            year = years.iterator().next();
        } catch (Exception e) {
            Log.w("GetInfoYear", e.toString());
        }

        BookInfoAPIParams params = new BookInfoAPIParams(url, artist, title, year);
        bookInfo = new BookInfoAPI(context).execute(params).get();
        bookDescription = bookInfo[0];
        bookReader = bookInfo[1];

    } catch (Exception e) {
        Log.w("GetInfoError", e.toString());
    }
    if (bookDescription.equals("noInfo")) {
        bookDescription = "The server has no description for this book";
    }

    final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist);
    if (podcastDescription != null || artistInfo != null || bookDescription != null) {
        artistView.setVisibility(View.VISIBLE);

        String text = "";
        if (bookDescription != null) {
            text = bookDescription;
        }
        if (podcastDescription != null) {
            text = podcastDescription;
        }
        if (artistInfo != null) {
            text = artistInfo.getBiography();
        }
        Spanned spanned = null;
        if (text != null) {
            String newText = "";
            try {
                if (!artistName.equals("")) {
                    newText += "<b>" + context.getResources().getString(R.string.main_artist) + "</b>: "
                            + artistName + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                if (totalDuration > 0) {
                    newText += "<b>" + context.getResources().getString(R.string.album_book_reader) + "</b>: "
                            + bookReader + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                if (totalDuration > 0) {
                    newText += "<b>" + context.getResources().getString(R.string.album_book_length) + "</b>: "
                            + Util.formatDuration(totalDuration) + "<br/>";
                }
            } catch (Exception e) {
            }
            try {
                newText += text + "<br/>";
            } catch (Exception e) {
            }
            spanned = Html.fromHtml(newText);
        }

        artistView.setText(spanned);
        artistView.setSingleLine(false);
        final int minLines = context.getResources().getInteger(R.integer.TextDescriptionLength);
        artistView.setLines(minLines);
        artistView.setTextAppearance(context, android.R.style.TextAppearance_Small);

        final Spanned spannedText = spanned;
        artistView.setOnClickListener(new View.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
            @Override
            public void onClick(View v) {
                if (artistView.getMaxLines() == minLines) {
                    // Use LeadingMarginSpan2 to try to make text flow around image
                    Display display = context.getWindowManager().getDefaultDisplay();
                    ImageView coverArtView = (ImageView) header.findViewById(R.id.select_album_art);
                    coverArtView.measure(display.getWidth(), display.getHeight());

                    int height, width;
                    ViewGroup.MarginLayoutParams vlp = (ViewGroup.MarginLayoutParams) coverArtView
                            .getLayoutParams();
                    if (coverArtView.getDrawable() != null) {
                        height = coverArtView.getMeasuredHeight() + coverArtView.getPaddingBottom();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    } else {
                        height = coverArtView.getHeight();
                        width = coverArtView.getWidth() + coverArtView.getPaddingRight();
                    }
                    float textLineHeight = artistView.getPaint().getTextSize();

                    int lines = (int) Math.ceil(height / textLineHeight) + 1;

                    SpannableString ss = new SpannableString(spannedText);
                    ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(),
                            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

                    View linearLayout = header.findViewById(R.id.select_album_text_layout);
                    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout
                            .getLayoutParams();
                    int[] rules = params.getRules();
                    rules[RelativeLayout.RIGHT_OF] = 0;
                    params.leftMargin = vlp.rightMargin;

                    artistView.setText(ss);
                    artistView.setMaxLines(100);

                    vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams();
                    vlp.leftMargin = width;
                } else {
                    artistView.setMaxLines(minLines);
                }
            }
        });
        artistView.setMovementMethod(LinkMovementMethod.getInstance());
    } else if (topTracks) {
        artistView.setText(R.string.menu_top_tracks);
        artistView.setVisibility(View.VISIBLE);
    } else if (showAll) {
        artistView.setText(R.string.menu_show_all);
        artistView.setVisibility(View.VISIBLE);
    } else if (artists.size() == 1) {
        String artistText = artists.iterator().next();
        if (years.size() == 1) {
            artistText += " - " + years.iterator().next();
        }
        artistView.setText(artistText);
        artistView.setVisibility(View.VISIBLE);
    } else {
        artistView.setVisibility(View.GONE);
    }

    TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count);
    TextView songLengthView = (TextView) header.findViewById(R.id.select_album_song_length);
    if (podcastDescription != null || artistInfo != null) {
        songCountView.setVisibility(View.GONE);
        songLengthView.setVisibility(View.GONE);
    } else {
        String s = context.getResources().getQuantityString(R.plurals.select_album_n_songs, songCount,
                songCount);

        songCountView.setVisibility(View.GONE);
        songLengthView.setVisibility(View.GONE);
    }
}