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