Example usage for android.view View setOnClickListener

List of usage examples for android.view View setOnClickListener

Introduction

In this page you can find the example usage for android.view View setOnClickListener.

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:net.phase.wallet.Currency.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    double exchrate = Currency.getRate(context.getActiveCurrency());

    LayoutInflater inflater = LayoutInflater.from(context);

    View v = inflater.inflate(R.layout.walletlayout, null);
    v.setLongClickable(true);//from  w  ww.ja v  a 2s .  c  om
    v.setOnClickListener(context);
    v.setTag(position);

    DecimalFormat df = new DecimalFormat(WalletActivity.decimalString(decimalpoints));

    TextView balanceTextView = (TextView) v.findViewById(R.id.walletBalanceText);
    balanceTextView.setText(df.format(wallets[position].balance / BalanceRetriever.SATOSHIS_PER_BITCOIN));

    TextView curTextView = (TextView) v.findViewById(R.id.walletCurText);
    curTextView.setTextSize(10);

    if (exchrate != 0) {
        curTextView.setText(
                "(" + df.format(wallets[position].balance * exchrate / BalanceRetriever.SATOSHIS_PER_BITCOIN)
                        + context.getActiveCurrency() + ")");
    } else {
        curTextView.setText("");
    }

    balanceTextView.setTextSize(20);
    balanceTextView.setTextColor(Color.GREEN);

    TextView nameTextView = (TextView) v.findViewById(R.id.walletNameText);
    nameTextView.setText(wallets[position].name);
    nameTextView.setTextColor(Color.BLACK);
    nameTextView.setTextSize(16);

    TextView lastUpdatedTextView = (TextView) v.findViewById(R.id.lastUpdatedText);

    lastUpdatedTextView.setTextColor(Color.GRAY);
    lastUpdatedTextView.setTextSize(8);
    lastUpdatedTextView.setText("Last Updated: " + getTimeStampString(wallets[position].lastUpdated));

    TextView infoTextView = (TextView) v.findViewById(R.id.infoText);

    infoTextView.setTextColor(Color.GRAY);
    infoTextView.setTextSize(8);
    infoTextView.setText(
            wallets[position].keys.length + " keys (" + wallets[position].getActiveKeyCount() + " in use)");

    TextView txLastUpdatedTextView = (TextView) v.findViewById(R.id.txLastUpdatedText);
    txLastUpdatedTextView.setTextColor(Color.GRAY);
    txLastUpdatedTextView.setTextSize(8);

    TextView txInfoTextView = (TextView) v.findViewById(R.id.txInfoText);
    txInfoTextView.setTextColor(Color.GRAY);
    txInfoTextView.setTextSize(8);

    if (wallets[position].transactions != null && wallets[position].transactions.length > 0) {
        txLastUpdatedTextView.setText(
                "Last Transaction: " + getTimeStampString(Transaction.latest(wallets[position].transactions)));
        txInfoTextView.setText(wallets[position].transactions.length + " transactions ("
                + Transaction.compressTransactions(wallets[position].transactions).length + " unique)");
    } else {
        txLastUpdatedTextView.setText("");
        txInfoTextView.setText("");
    }

    Button button = (Button) v.findViewById(R.id.updateButton);
    button.setTag(position);
    button.setOnClickListener(context);
    return v;
}

From source file:com.closedevice.fastapp.view.tab.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;//w  w w  .ja v a  2s.co  m

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            if (mTabViewTextViewId != 0) {
                tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);

            }
        }

        ImageView tabIconView = null;
        if (mTabViewIconId != 0 && mIconListener != null) {
            tabIconView = (ImageView) tabView.findViewById(mTabViewIconId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabView != null && i == 1) {
            //mTvMessageCount = (TextView) tabView.findViewById(R.id.tv_unread_count);
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (tabTitleView != null)
            tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        if (tabIconView != null) {
            int icon = mIconListener.getPageIcon(i);
            if (icon != 0)
                tabIconView.setImageResource(icon);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:com.fullteem.yueba.app.adapter.MessageAdapter.java

@Override
@SuppressLint("NewApi")
public View getView(final int position, View convertView, ViewGroup parent) {
    final EMMessage message = getItem(position);
    System.out.println("message.getMsgId()" + message.getMsgId());
    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.head_iv = (CircleImageView) 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_userId = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }/*from   w w w.j  a v  a  2 s  .c om*/

        } 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.head_iv = (CircleImageView) convertView.findViewById(R.id.iv_userhead);
                // 
                holder.tv = (TextView) convertView.findViewById(R.id.tv_chatcontent);
                holder.tv_userId = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
                System.out.println(e.toString());
            }

            // ?
            if (message.getBooleanAttribute(GlobleConstant.MESSAGE_ATTR_IS_VOICE_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.head_iv = (CircleImageView) 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_userId = (TextView) convertView.findViewById(R.id.tv_userid);
                holder.iv_read_status = (ImageView) convertView.findViewById(R.id.iv_unread_voice);
            } catch (Exception e) {
                System.out.println(e.toString());
            }
        } else if (message.getType() == EMMessage.Type.LOCATION) {
            try {
                holder.head_iv = (CircleImageView) 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_userId = (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.head_iv = (CircleImageView) 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_userId = (TextView) convertView.findViewById(R.id.tv_userid);

            } catch (Exception e) {
            }
        } else if (message.getType() == EMMessage.Type.FILE) {
            try {
                holder.head_iv = (CircleImageView) 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_userId = (TextView) convertView.findViewById(R.id.tv_userid);
            } catch (Exception e) {
            }

        }

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

    // ??????
    if (chatType == ChatType.GroupChat && message.direct == EMMessage.Direct.RECEIVE)
        // demousernamenick
        holder.tv_userId.setText(message.getFrom());

    // ??????textview
    if (message.direct == EMMessage.Direct.SEND && chatType != ChatType.GroupChat) {
        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??
        if ((message.getType() == Type.TXT || message.getType() == Type.LOCATION) && !message.isAcked
                && chatType != ChatType.GroupChat) {
            // ??
            if (!message.getBooleanAttribute(GlobleConstant.MESSAGE_ATTR_IS_VOICE_CALL, false)) {
                try {
                    EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                    // ??
                    message.isAcked = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }

    switch (message.getType()) {
    // ??typeitem
    case IMAGE: // 
        handleImageMessage(message, holder, position, convertView);
        break;
    case TXT: // 
        if (!message.getBooleanAttribute(GlobleConstant.MESSAGE_ATTR_IS_VOICE_CALL, false))
            handleTextMessage(message, holder, position);
        else
            // ?
            handleVoiceCallMessage(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, 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);

            }
        });
        // ?
        System.out.println("?:" + appContext.getUserInfo().getUserLogoUrl());
        ImageLoaderUtil.getImageLoader().displayImage(
                DisplayUtils.getAbsolutelyUrl(appContext.getUserInfo().getUserLogoUrl()), holder.head_iv);
        // ?
        holder.head_iv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, PerssonalInfoAcitivity.class);
                intent.putExtra("userId", AppContext.getApplication().getUserInfo().getUserId());
                activity.startActivity(intent);

            }
        });

    } else {
        // ????
        holder.head_iv.setOnLongClickListener(new OnLongClickListener() {

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

        // ?

        String imgUrl = "";
        try {
            imgUrl = message.getStringAttribute("imgurl");
        } catch (EaseMobException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        // ?
        ImageLoaderUtil.getImageLoader().displayImage(DisplayUtils.getAbsolutelyUrl(imgUrl), holder.head_iv);
        // ?mumu?userId
        String username = conversation.getUserName();
        findUserIdByAccount(username, holder.head_iv);

        // ImageLoaderUtil.getImageLoader().displayImage(
        // DisplayUtils.getAbsolutelyUrl(ImageUrl), holder.head_iv);
    }

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

    if (position == 0) {
        timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
        timestamp.setVisibility(View.VISIBLE);
    } else {
        // ???
        if (DateUtils.isCloseEnough(message.getMsgTime(), conversation.getMessage(position - 1).getMsgTime())) {
            timestamp.setVisibility(View.GONE);
        } else {
            timestamp.setText(DateUtils.getTimestampString(new Date(message.getMsgTime())));
            timestamp.setVisibility(View.VISIBLE);
        }
    }
    // System.out.println("message from "+message);
    return convertView;
}

From source file:com.clairvoyant.Components.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;//www  .j  a  v a 2  s .  c o m

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            LinearLayout.LayoutParams loparams = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            loparams.weight = 1;
            //                loparams.height = 50;
            //                loparams.gravity = Gravity.CENTER;
            tabView.setLayoutParams(loparams);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
            tabTitleView.setLayoutParams(
                    new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f));
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
            LinearLayout.LayoutParams loparams = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            loparams.weight = 1;
            //                loparams.height = 50;
            //                loparams.gravity = Gravity.CENTER;
            tabView.setLayoutParams(loparams);
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);

        mTabStrip.addView(tabView);
    }
}

From source file:com.openerp.addons.messages.MessageDetail.java

/**
 * Sets the up list view./*from   w  w  w .  j a  va  2  s.  c  o m*/
 * 
 * @param list
 *            the new up list view
 */
private boolean setupListView(final List<OEListViewRows> list) {
    // Handling List View controls and keys
    String[] from = new String[] { "image", "email_from|name", "email_from|email", "body", "date", "partners",
            "starred", "vote_nb" };
    int[] to = new int[] { R.id.imgUserPicture, R.id.txvMessageAuthor, R.id.txvAuthorEmail,
            R.id.webViewMessageBody, R.id.txvTime, R.id.txvTo, R.id.imgBtnStar, R.id.txvmessageVotenb };

    // Creating instance for listAdapter
    listAdapter = new OEListViewAdapter(scope.context(), R.layout.message_detail_listview_items, list, from, to,
            db);
    listAdapter.toHTML("body", true);
    listAdapter.addImageColumn("image");
    // listAdapter.layoutBackgroundColor("parent_id",
    // Color.parseColor("#aaaaaa"), Color.parseColor("#0099cc"));
    listAdapter.cleanDate("date", scope.User().getTimezone(), "MMM dd, yyyy,  hh:mm a");
    listAdapter.addViewListener(new OEListViewOnCreateListener() {

        @Override
        public View listViewOnCreateListener(final int position, View row_view, OEListViewRows row_data) {
            final int message_id = row_data.getRow_id();
            final HashMap<String, Object> row_values = row_data.getRow_data();
            /* handling vote control */
            final TextView txvVote = (TextView) row_view.findViewById(R.id.txvmessageVotenb);
            final int vote_nb = Integer.parseInt(row_data.getRow_data().get("vote_nb").toString());
            if (vote_nb == 0) {
                txvVote.setText("");
            }
            final boolean hasVoted = Boolean.parseBoolean(row_data.getRow_data().get("has_voted").toString());
            if (!hasVoted) {
                txvVote.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.ic_thumbs_up_unselected_dark_tablet), null, null,
                        null);
                // txvVote.setBackgroundResource(R.drawable.vote_background_selector_gray);
            } else {
                // txvVote.setBackgroundResource(R.drawable.vote_background_selector_blue);
                txvVote.setCompoundDrawablesWithIntrinsicBounds(
                        getResources().getDrawable(R.drawable.ic_thumbs_up_selected_dark_tablet), null, null,
                        null);
            }
            txvVote.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    MessageVoteToggle voteToggle = new MessageVoteToggle(message_id, vote_nb, hasVoted);
                    String newVote = "";
                    boolean btnvoted = false;
                    if (hasVoted) {
                        newVote = (vote_nb - 1) + "";
                        row_values.put("has_voted", "false");
                    } else {
                        btnvoted = true;
                        newVote = (vote_nb + 1) + "";
                        row_values.put("has_voted", "true");
                    }
                    row_values.put("vote_nb", newVote);
                    listAdapter.updateRow(position, new OEListViewRows(message_id, row_values));
                    voteToggle.execute((Void) null);
                    txvVote.setText(newVote);
                    if (!btnvoted) {
                        txvVote.setCompoundDrawablesWithIntrinsicBounds(
                                getResources().getDrawable(R.drawable.ic_thumbs_up_unselected_dark_tablet),
                                null, null, null);
                        // txvVote.setBackgroundResource(R.drawable.vote_background_selector_gray);
                    } else {
                        // txvVote.setBackgroundResource(R.drawable.vote_background_selector_blue);
                        txvVote.setCompoundDrawablesWithIntrinsicBounds(
                                getResources().getDrawable(R.drawable.ic_thumbs_up_selected_dark_tablet), null,
                                null, null);
                    }
                }
            });

            /* handling attachments */
            List<OEListViewRows> attachments = getAttachmentsOfMessage(row_data.getRow_id() + "");
            int index = 0;
            if (attachments.size() > 0) {
                LayoutInflater vi = (LayoutInflater) scope.context().getApplicationContext()
                        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View insertPoint = row_view.findViewById(R.id.gridAttachments);
                ((ViewGroup) insertPoint).removeAllViews();
                for (OEListViewRows row : attachments) {
                    View v = vi.inflate(R.layout.fragment_message_detail_attachment_grid_item, null, true);
                    TextView txvAttachmentName = (TextView) v.findViewById(R.id.txvFileName);

                    txvAttachmentName.setText(row.getRow_data().get("name").toString());
                    TextView txvAttachmentSize = (TextView) v.findViewById(R.id.txvFileSize);
                    long fileSize = Long.parseLong(row.getRow_data().get("file_size").toString());
                    String file_size = OEFileSizeHelper.readableFileSize(fileSize);
                    txvAttachmentSize.setText((file_size.equals("0")) ? " " : file_size);

                    TextView txvAttachmentId = (TextView) v.findViewById(R.id.txvAttachmentId);
                    txvAttachmentId.setText(String.valueOf(row.getRow_id()));
                    ((ViewGroup) insertPoint).addView(v, index, new ViewGroup.LayoutParams(
                            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
                    v.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            int attachment_id = Integer.parseInt(
                                    ((TextView) v.findViewById(R.id.txvAttachmentId)).getText().toString());
                            OEBinaryDownloadHelper binaryDownload = new OEBinaryDownloadHelper();
                            binaryDownload.downloadBinary(attachment_id, db);
                        }
                    });
                    index++;

                }

            } else {
                row_view.findViewById(R.id.layoutMessageAttachments).setVisibility(View.GONE);
            }
            OEContactView oe_contactView = (OEContactView) row_view.findViewById(R.id.imgUserPicture);
            int partner_id = Integer.parseInt(row_data.getRow_data().get("partner_id").toString());
            oe_contactView.assignPartnerId(partner_id);
            return row_view;
        }
    });
    listAdapter.setItemClickListener(R.id.imgBtnReply, new ControlClickEventListener() {

        @Override
        public OEListViewRows controlClicked(int position, OEListViewRows row, View view) {
            Intent composeIntent = new Intent(scope.context(), MessageComposeActivty.class);
            composeIntent.putExtra("message_id", message_id);
            composeIntent.putExtra("send_reply", true);
            startActivityForResult(composeIntent, MESSAGE_REPLY);

            return null;
        }
    });
    // Setting callback handler for boolean field value change.
    listAdapter.setBooleanEventOperation("starred", R.drawable.ic_action_starred,
            R.drawable.ic_action_unstarred, updateStarred);
    GridView lstview = (GridView) rootView.findViewById(R.id.lstMessageDetail);
    // Providing adapter to listview
    lstview.setAdapter(listAdapter);
    return true;
}

From source file:com.easemob.qixin.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 ava2s .  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 == EMMessage.Direct.RECEIVE) {
        //demousername?nick
        holder.tv_usernick.setText(message.getFrom());
    }
    // ??????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
            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, 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);

            }
        });

    } 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;
                }
            });
        }
    }

    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:cm.aptoide.ptdev.adapters.ViewPagerAdapterScreenshots.java

@Override
public Object instantiateItem(ViewGroup container, final int position) {

    final View v = LayoutInflater.from(context).inflate(R.layout.row_item_screenshots_big, null);
    final ProgressBar pb = (ProgressBar) v.findViewById(R.id.screenshots_loading_big);

    String icon;//from   w  w w  .j  a v  a2  s  .  c  o m
    if (hd) {
        Log.d("Aptoide-Screenshots", "Icon is hd: " + url.get(position));

        if (url.get(position).contains("_screen")) {
            icon = url.get(position).split("\\|")[1];
            Log.d("Aptoide-Screenshots", "Icon is : " + icon);
        } else {
            icon = url.get(position);
        }

    } else {
        icon = screenshotToThumb(url.get(position));
    }

    imageLoader.displayImage(icon, (ImageView) v.findViewById(R.id.screenshot_image_big), options,
            new ImageLoadingListener() {

                @Override
                public void onLoadingStarted(String uri, View view) {
                    pb.setVisibility(View.VISIBLE);
                }

                @Override
                public void onLoadingFailed(String uri, View v, FailReason failReason) {
                    ((ImageView) v.findViewById(R.id.screenshot_image_big))
                            .setImageResource(android.R.drawable.ic_delete);
                    pb.setVisibility(View.GONE);
                }

                @Override
                public void onLoadingComplete(String uri, View v, Bitmap loadedImage) {
                    pb.setVisibility(View.GONE);
                }

                @Override
                public void onLoadingCancelled(String uri, View v) {
                }
            });
    container.addView(v);
    if (!hd) {
        v.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                Intent i = new Intent(context, ScreenshotsViewer.class);
                i.putStringArrayListExtra("url", url);
                i.putExtra("position", position);
                i.putExtra("hashCode", hashCode + ".hd");
                context.startActivity(i);
            }
        });
    }
    return v;

}

From source file:com.xpple.jahoqy.adapter.MessageAdapter.java

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(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  www . j a  v  a2 s. c o  m*/

        } else if (message.getType() == 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() == 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() == 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() == 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() == 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
        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(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 == 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() == 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(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;
                }
            });
        }
    }

    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:cgeo.geocaching.cgeocaches.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setTheme();/*from www.j a v a  2 s.  com*/
    setContentView(R.layout.cacheslist_activity);

    // get parameters
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        Object typeObject = extras.get(Intents.EXTRA_LIST_TYPE);
        type = (typeObject instanceof CacheListType) ? (CacheListType) typeObject : CacheListType.OFFLINE;
        coords = extras.getParcelable(Intents.EXTRA_COORDS);
    } else {
        extras = new Bundle();
    }
    if (isInvokedFromAttachment()) {
        type = CacheListType.OFFLINE;
        if (coords == null) {
            coords = new Geopoint(0.0, 0.0);
        }
    }

    // Add the list selection in code. This way we can leave the XML layout of the action bar the same as for other activities.
    final View titleBar = findViewById(R.id.actionbar_title);
    titleBar.setClickable(true);
    titleBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            selectList(v);
        }
    });

    setTitle(title);
    setAdapter();

    prepareFilterBar();

    currentLoader = (AbstractSearchLoader) getSupportLoaderManager().initLoader(type.ordinal(), extras, this);

    // init
    if (CollectionUtils.isNotEmpty(cacheList)) {
        // currentLoader can be null if this activity is created from a map, as onCreateLoader() will return null.
        if (currentLoader != null && currentLoader.isStarted()) {
            showFooterLoadingCaches();
        } else {
            showFooterMoreCaches();
        }
    }

    if (isInvokedFromAttachment()) {
        importGpxAttachement();
    }
}

From source file:com.aibasis.parent.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  www . j a  va2 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, 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);

            }
        });

    } 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;
                }
            });
        }
    }

    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;
}