Search in sources :

Example 1 with LocationMessageBody

use of com.easemob.chat.LocationMessageBody in project wechat by motianhuo.

the class MessageAdapter method handleLocationMessage.

/**
	 * 处理位置消息
	 * 
	 * @param message
	 * @param holder
	 * @param position
	 * @param convertView
	 */
private void handleLocationMessage(final EMMessage message, final ViewHolder holder, final int position, View convertView) {
    TextView locationView = ((TextView) convertView.findViewById(R.id.tv_location));
    LocationMessageBody locBody = (LocationMessageBody) message.getBody();
    locationView.setText(locBody.getAddress());
    LatLng loc = new LatLng(locBody.getLatitude(), locBody.getLongitude());
    locationView.setOnClickListener(new MapClickListener(loc, locBody.getAddress()));
    locationView.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            activity.startActivityForResult((new Intent(activity, ContextMenu.class)).putExtra("position", position).putExtra("type", EMMessage.Type.LOCATION.ordinal()), ChatActivity.REQUEST_CODE_CONTEXT_MENU);
            return false;
        }
    });
    if (message.direct == EMMessage.Direct.RECEIVE) {
        return;
    }
    // deal with send message
    switch(message.status) {
        case SUCCESS:
            holder.pb.setVisibility(View.GONE);
            holder.staus_iv.setVisibility(View.GONE);
            break;
        case FAIL:
            holder.pb.setVisibility(View.GONE);
            holder.staus_iv.setVisibility(View.VISIBLE);
            break;
        case INPROGRESS:
            holder.pb.setVisibility(View.VISIBLE);
            break;
        default:
            sendMsgInBackground(message, holder);
    }
}
Also used : OnLongClickListener(android.view.View.OnLongClickListener) TextView(android.widget.TextView) Intent(android.content.Intent) ContextMenu(com.juns.wechat.chat.ContextMenu) LatLng(com.easemob.util.LatLng) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LocationMessageBody(com.easemob.chat.LocationMessageBody)

Example 2 with LocationMessageBody

use of com.easemob.chat.LocationMessageBody in project wechat by motianhuo.

the class ChatActivity method sendLocationMsg.

/**
	 * 发送位置信息
	 * 
	 * @param latitude
	 * @param longitude
	 * @param imagePath
	 * @param locationAddress
	 */
private void sendLocationMsg(double latitude, double longitude, String imagePath, String locationAddress) {
    EMMessage message = EMMessage.createSendMessage(EMMessage.Type.LOCATION);
    // 如果是群聊,设置chattype,默认是单聊
    if (chatType == CHATTYPE_GROUP)
        message.setChatType(ChatType.GroupChat);
    LocationMessageBody locBody = new LocationMessageBody(locationAddress, latitude, longitude);
    message.addBody(locBody);
    message.setReceipt(toChatUsername);
    conversation.addMessage(message);
    listView.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    listView.setSelection(listView.getCount() - 1);
    setResult(RESULT_OK);
}
Also used : EMMessage(com.easemob.chat.EMMessage) LocationMessageBody(com.easemob.chat.LocationMessageBody)

Aggregations

LocationMessageBody (com.easemob.chat.LocationMessageBody)2 Intent (android.content.Intent)1 View (android.view.View)1 OnLongClickListener (android.view.View.OnLongClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 EMMessage (com.easemob.chat.EMMessage)1 LatLng (com.easemob.util.LatLng)1 ContextMenu (com.juns.wechat.chat.ContextMenu)1