Here are the examples of the java api com.hyphenate.chat.EMMessage taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
236 Examples
19
Source : EaseChatVoicePresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
private void play(EMMessage message) {
String localPath = ((EMVoiceMessageBody) message.getBody()).getLocalUrl();
File file = new File(localPath);
if (file.exists() && file.isFile()) {
ackMessage(message);
playVoice(message);
// Start the voice play animation.
((EaseChatRowVoice) getChatRow()).startVoicePlayAnimation();
} else {
EMLog.e(TAG, "file not exist");
}
}
19
Source : EaseChatVoicePresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
private void ackMessage(EMMessage message) {
EMMessage.ChatType chatType = message.getChatType();
if (!message.isAcked() && chatType == EMMessage.ChatType.Chat) {
try {
EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
} catch (HyphenateException e) {
e.printStackTrace();
}
}
if (!message.isListened()) {
EMClient.getInstance().chatManager().setVoiceMessageListened(message);
}
}
19
Source : EaseChatVoicePresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
public void onBubbleClick(final EMMessage message) {
String msgId = message.getMsgId();
if (voicePlayer.isPlaying()) {
// Stop the voice play first, no matter the playing voice item is this or others.
voicePlayer.stop();
// Stop the voice play animation.
((EaseChatRowVoice) getChatRow()).stopVoicePlayAnimation();
// If the playing voice item is this item, only need stop play.
String playingId = voicePlayer.getCurrentPlayingId();
if (msgId.equals(playingId)) {
return;
}
}
if (message.direct() == EMMessage.Direct.SEND) {
// Play the voice
String localPath = ((EMVoiceMessageBody) message.getBody()).getLocalUrl();
File file = new File(localPath);
if (file.exists() && file.isFile()) {
playVoice(message);
// Start the voice play animation.
((EaseChatRowVoice) getChatRow()).startVoicePlayAnimation();
} else {
asyncDownloadVoice(message);
}
} else {
final String st = getContext().getResources().getString(R.string.Is_download_voice_click_later);
if (message.status() == EMMessage.Status.SUCCESS) {
if (EMClient.getInstance().getOptions().getAutodownloadThumbnail()) {
play(message);
} else {
EMVoiceMessageBody voiceBody = (EMVoiceMessageBody) message.getBody();
EMLog.i(TAG, "Voice body download status: " + voiceBody.downloadStatus());
switch(voiceBody.downloadStatus()) {
// Download not begin
case PENDING:
case // Download failed
FAILED:
getChatRow().updateView(getMessage());
asyncDownloadVoice(message);
break;
case // During downloading
DOWNLOADING:
Toast.makeText(getContext(), st, Toast.LENGTH_SHORT).show();
break;
case // Download success
SUCCESSED:
play(message);
break;
}
}
} else if (message.status() == EMMessage.Status.INPROGRESS) {
Toast.makeText(getContext(), st, Toast.LENGTH_SHORT).show();
} else if (message.status() == EMMessage.Status.FAIL) {
Toast.makeText(getContext(), st, Toast.LENGTH_SHORT).show();
asyncDownloadVoice(message);
}
}
}
19
Source : EaseChatVoicePresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
private void playVoice(EMMessage msg) {
voicePlayer.play(msg, new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// Stop the voice play animation.
((EaseChatRowVoice) getChatRow()).stopVoicePlayAnimation();
}
});
}
19
Source : EaseChatVoicePresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
private void asyncDownloadVoice(final EMMessage message) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
EMClient.getInstance().chatManager().downloadAttachment(message);
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
getChatRow().updateView(getMessage());
}
}.execute();
}
19
Source : EaseChatTextPresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
protected void handleReceiveMessage(EMMessage message) {
if (!message.isAcked() && message.getChatType() == EMMessage.ChatType.Chat) {
try {
EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
} catch (HyphenateException e) {
e.printStackTrace();
}
return;
}
// Send the group-ack cmd type msg if this msg is a ding-type msg.
EaseDingMessageHelper.get().sendAckMessage(message);
}
19
Source : EaseChatTextPresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
public void onBubbleClick(EMMessage message) {
super.onBubbleClick(message);
if (!EaseDingMessageHelper.get().isDingMessage(message)) {
return;
}
// If this msg is a ding-type msg, click to show a list who has already read this message.
Intent i = new Intent(getContext(), EaseDingAckUserListActivity.clreplaced);
i.putExtra("msg", message);
getContext().startActivity(i);
}
19
Source : EaseChatRowPresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
public void setup(EMMessage msg, int position, EaseChatMessageList.MessageLisreplacedemClickListener itemClickListener, EaseMessageLisreplacedemStyle itemStyle) {
this.message = msg;
this.position = position;
this.itemClickListener = itemClickListener;
chatRow.setUpView(message, position, itemClickListener, this, itemStyle);
handleMessage();
}
19
Source : EaseChatRowPresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
public void onResendClick(final EMMessage message) {
new EaseAlertDialog(getContext(), R.string.resend, R.string.confirm_resend, null, new EaseAlertDialog.AlertDialogUser() {
@Override
public void onResult(boolean confirmed, Bundle bundle) {
if (!confirmed) {
return;
}
message.setStatus(EMMessage.Status.CREATE);
handleSendMessage(message);
}
}, true).show();
}
19
Source : EaseChatRowPresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
protected void handleReceiveMessage(EMMessage message) {
}
19
Source : EaseChatRowPresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
protected void handleSendMessage(final EMMessage message) {
// Update the view according to the message current status.
getChatRow().updateView(message);
if (message.status() == EMMessage.Status.INPROGRESS) {
EMLog.i("handleSendMessage", "Message is INPROGRESS");
if (this.itemClickListener != null) {
this.itemClickListener.onMessageInProgress(message);
}
}
}
19
Source : EaseChatRowPresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
public void onBubbleClick(EMMessage message) {
}
19
Source : EaseChatLocationPresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
protected void handleReceiveMessage(EMMessage message) {
if (!message.isAcked() && message.getChatType() == EMMessage.ChatType.Chat) {
try {
EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
} catch (HyphenateException e) {
e.printStackTrace();
}
}
}
19
Source : EaseChatLocationPresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
public void onBubbleClick(EMMessage message) {
EMLocationMessageBody locBody = (EMLocationMessageBody) message.getBody();
Intent intent = new Intent(getContext(), EaseBaiduMapActivity.clreplaced);
intent.putExtra("lareplacedude", locBody.getLareplacedude());
intent.putExtra("longitude", locBody.getLongitude());
intent.putExtra("address", locBody.getAddress());
getContext().startActivity(intent);
}
19
Source : EaseChatImagePresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
public void onBubbleClick(EMMessage message) {
EMImageMessageBody imgBody = (EMImageMessageBody) message.getBody();
if (EMClient.getInstance().getOptions().getAutodownloadThumbnail()) {
if (imgBody.thumbnailDownloadStatus() == EMFileMessageBody.EMDownloadStatus.FAILED) {
getChatRow().updateView(message);
// retry download with click event of user
EMClient.getInstance().chatManager().downloadThumbnail(message);
}
} else {
if (imgBody.thumbnailDownloadStatus() == EMFileMessageBody.EMDownloadStatus.DOWNLOADING || imgBody.thumbnailDownloadStatus() == EMFileMessageBody.EMDownloadStatus.PENDING || imgBody.thumbnailDownloadStatus() == EMFileMessageBody.EMDownloadStatus.FAILED) {
// retry download with click event of user
EMClient.getInstance().chatManager().downloadThumbnail(message);
getChatRow().updateView(message);
return;
}
}
Intent intent = new Intent(getContext(), EaseShowBigImageActivity.clreplaced);
Uri imgUri = imgBody.getLocalUri();
if (UriUtils.isFileExistByUri(getContext(), imgUri)) {
intent.putExtra("uri", imgUri);
} else {
// The local full size pic does not exist yet.
// ShowBigImage needs to download it from the server
// first
String msgId = message.getMsgId();
intent.putExtra("messageId", msgId);
intent.putExtra("filename", imgBody.getFileName());
}
if (message != null && message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked() && message.getChatType() == EMMessage.ChatType.Chat) {
try {
EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
} catch (Exception e) {
e.printStackTrace();
}
}
getContext().startActivity(intent);
}
19
Source : EaseChatFilePresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
public void onBubbleClick(EMMessage message) {
EMNormalFileMessageBody fileMessageBody = (EMNormalFileMessageBody) message.getBody();
Uri filePath = fileMessageBody.getLocalUri();
String fileLocalPath = UriUtils.getFilePath(getContext(), filePath);
File file = null;
if (!TextUtils.isEmpty(fileLocalPath)) {
file = new File(fileLocalPath);
}
if (file != null && file.exists()) {
// open files if it exist
EaseCompat.openFile(file, (Activity) getContext());
} else if (UriUtils.isFileExistByUri(getContext(), filePath)) {
EaseCompat.openFile(filePath, UriUtils.getFileMimeType(getContext(), filePath), (Activity) getContext());
} else {
// download the file
getContext().startActivity(new Intent(getContext(), EaseShowNormalFileActivity.clreplaced).putExtra("msg", message));
}
if (message.direct() == EMMessage.Direct.RECEIVE && !message.isAcked() && message.getChatType() == EMMessage.ChatType.Chat) {
try {
EMClient.getInstance().chatManager().ackMessageRead(message.getFrom(), message.getMsgId());
} catch (HyphenateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
19
Source : EaseChatBigExpressionPresenter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
protected void handleReceiveMessage(EMMessage message) {
}
19
Source : EaseChatRowVoice.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
protected void onViewUpdate(EMMessage msg) {
super.onViewUpdate(msg);
// Only the received message has the attachment download status.
if (message.direct() == EMMessage.Direct.SEND) {
return;
}
EMVoiceMessageBody voiceBody = (EMVoiceMessageBody) msg.getBody();
if (voiceBody.downloadStatus() == EMFileMessageBody.EMDownloadStatus.DOWNLOADING || voiceBody.downloadStatus() == EMFileMessageBody.EMDownloadStatus.PENDING) {
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.INVISIBLE);
}
}
19
Source : EaseChatRowText.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
protected void onViewUpdate(EMMessage msg) {
switch(msg.status()) {
case CREATE:
onMessageCreate();
break;
case SUCCESS:
onMessageSuccess();
break;
case FAIL:
onMessageError();
break;
case INPROGRESS:
onMessageInProgress();
break;
}
}
19
Source : EaseChatRow.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
public void updateView(final EMMessage msg) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
onViewUpdate(msg);
}
});
}
19
Source : EaseShowVideoActivity.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_replacedLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.ease_showvideo_activity);
loadingLayout = (RelativeLayout) findViewById(R.id.loading_layout);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
final EMMessage message = getIntent().getParcelableExtra("msg");
if (!(message.getBody() instanceof EMVideoMessageBody)) {
Toast.makeText(EaseShowVideoActivity.this, "Unsupported message body", Toast.LENGTH_SHORT).show();
finish();
return;
}
EMVideoMessageBody messageBody = (EMVideoMessageBody) message.getBody();
localFilePath = messageBody.getLocalUri();
EMLog.d(TAG, "localFilePath = " + localFilePath);
EMLog.d(TAG, "local filename = " + messageBody.getFileName());
if (UriUtils.isFileExistByUri(this, localFilePath)) {
showLocalVideo(localFilePath);
} else {
EMLog.d(TAG, "download remote video file");
downloadVideo(message);
}
}
19
Source : EaseShowNormalFileActivity.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
private String getFilePath(EMMessage message) {
Uri localUrlUri = ((EMFileMessageBody) message.getBody()).getLocalUri();
return UriUtils.getFilePath(this, localUrlUri);
}
19
Source : EaseDingMessageHelper.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
private boolean validateMessage(EMMessage message) {
if (message == null) {
return false;
}
if (message.getChatType() != EMMessage.ChatType.GroupChat) {
return false;
}
if (!isDingMessage(message)) {
return false;
}
return true;
}
19
Source : EaseDingMessageHelper.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
/**
* Contains ding msg and ding-ack msg.
*
* @param message
* @return
*/
public boolean isDingMessage(EMMessage message) {
return message.isNeedGroupAck();
}
19
Source : EaseAtMessageHelper.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
public boolean isAtMeMsg(EMMessage message) {
EaseUser user = EaseUserUtils.getUserInfo(message.getFrom());
if (user != null) {
try {
JSONArray jsonArray = message.getJSONArrayAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG);
for (int i = 0; i < jsonArray.length(); i++) {
String username = jsonArray.getString(i);
if (username.equals(EMClient.getInstance().getCurrentUser())) {
return true;
}
}
} catch (Exception e) {
// perhaps is a @ all message
String atUsername = message.getStringAttribute(EaseConstant.MESSAGE_ATTR_AT_MSG, null);
if (atUsername != null) {
if (atUsername.toUpperCase().equals(EaseConstant.MESSAGE_ATTR_VALUE_AT_MSG_ALL)) {
return true;
}
}
return false;
}
}
return false;
}
19
Source : EaseMessageAdapter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
@SuppressLint("NewApi")
public View getView(final int position, View convertView, ViewGroup parent) {
EMMessage message = gereplacedem(position);
EaseChatRowPresenter presenter = null;
if (convertView == null) {
presenter = createChatRowPresenter(message, position);
convertView = presenter.createChatRow(context, message, position, this);
convertView.setTag(presenter);
} else {
presenter = (EaseChatRowPresenter) convertView.getTag();
}
presenter.setup(message, position, itemClickListener, itemStyle);
return convertView;
}
19
Source : EaseMessageAdapter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
/**
* get type of item
*/
public int gereplacedemViewType(int position) {
EMMessage message = gereplacedem(position);
if (message == null) {
return -1;
}
if (customRowProvider != null && customRowProvider.getCustomChatRowType(message) > 0) {
return customRowProvider.getCustomChatRowType(message) + 13;
}
if (message.getType() == EMMessage.Type.TXT) {
if (message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)) {
return message.direct() == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_EXPRESSION : MESSAGE_TYPE_SENT_EXPRESSION;
}
return message.direct() == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_TXT : MESSAGE_TYPE_SENT_TXT;
}
if (message.getType() == EMMessage.Type.IMAGE) {
return message.direct() == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_IMAGE : MESSAGE_TYPE_SENT_IMAGE;
}
if (message.getType() == EMMessage.Type.LOCATION) {
return message.direct() == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_LOCATION : MESSAGE_TYPE_SENT_LOCATION;
}
if (message.getType() == EMMessage.Type.VOICE) {
return message.direct() == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_VOICE : MESSAGE_TYPE_SENT_VOICE;
}
if (message.getType() == EMMessage.Type.VIDEO) {
return message.direct() == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_VIDEO : MESSAGE_TYPE_SENT_VIDEO;
}
if (message.getType() == EMMessage.Type.FILE) {
return message.direct() == EMMessage.Direct.RECEIVE ? MESSAGE_TYPE_RECV_FILE : MESSAGE_TYPE_SENT_FILE;
}
// invalid
return -1;
}
19
Source : EaseMessageAdapter.java
with Apache License 2.0
from y1xian
with Apache License 2.0
from y1xian
protected EaseChatRowPresenter createChatRowPresenter(EMMessage message, int position) {
if (customRowProvider != null && customRowProvider.getCustomChatRow(message, position, this) != null) {
return customRowProvider.getCustomChatRow(message, position, this);
}
EaseChatRowPresenter presenter = null;
EMLog.d(TAG, "message's type = " + message.getType());
switch(message.getType()) {
case TXT:
if (message.getBooleanAttribute(EaseConstant.MESSAGE_ATTR_IS_BIG_EXPRESSION, false)) {
presenter = new EaseChatBigExpressionPresenter();
} else {
presenter = new EaseChatTextPresenter();
}
break;
case LOCATION:
presenter = new EaseChatLocationPresenter();
break;
case FILE:
presenter = new EaseChatFilePresenter();
break;
case IMAGE:
presenter = new EaseChatImagePresenter();
break;
case VOICE:
presenter = new EaseChatVoicePresenter();
break;
case VIDEO:
presenter = new EaseChatVideoPresenter();
break;
case CUSTOM:
presenter = new EaseChatCustomPresenter();
break;
default:
break;
}
return presenter;
}
19
Source : NewCallRecordEventBean.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
/**
* Created by LWK
* TODO 实时通话结束后发送的通知,用于通知聊天界面添加聊天记录
* 2016/12/16
*/
public clreplaced NewCallRecordEventBean {
private String conId;
private EMMessage message;
public NewCallRecordEventBean(EMMessage message) {
this.message = message;
if (message.direct() == EMMessage.Direct.SEND)
this.conId = message.getTo();
else
this.conId = message.getFrom();
}
public String getConId() {
return conId;
}
public void setConId(String conId) {
this.conId = conId;
}
public EMMessage getMessage() {
return message;
}
public void setMessage(EMMessage message) {
this.message = message;
}
}
19
Source : NewCallRecordEventBean.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
public void setMessage(EMMessage message) {
this.message = message;
}
19
Source : HxShortVideoPlayActivity.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
/**
* 短视频播放界面
*/
public clreplaced HxShortVideoPlayActivity extends FCBaseActivity implements HxShortVideoPlayView {
private static final String INTENT_KEY_MESSAGE = "message";
private EMMessage mMessage;
private HxShortVideoPlayPresenter mPresenter;
private View mViewDownload;
private ColorfulRingProgressView mPgvDownload;
private TextView mTvDownload;
private ScalableVideoView mVideoView;
/**
* 跳转到短视频播放界面的公共方法
*
* @param activity 发起跳转的公共方法
* @param message 短视频消息
*/
public static void start(Activity activity, EMMessage message) {
Intent intent = new Intent(activity, HxShortVideoPlayActivity.clreplaced);
intent.putExtra(INTENT_KEY_MESSAGE, message);
activity.startActivity(intent);
}
@Override
protected void beforeOnCreate(Bundle savedInstanceState) {
ScreenUtils.changeStatusBarColor(this, Color.BLACK);
mMessage = getIntent().getParcelableExtra(INTENT_KEY_MESSAGE);
if (mMessage == null) {
showError(R.string.error_shortvideo_play, true);
return;
}
}
@Override
protected int setContentViewId() {
mPresenter = new HxShortVideoPlayPresenter(this);
return R.layout.activity_hx_short_video_play;
}
@Override
protected void initUI() {
CommonActionBar actionBar = findView(R.id.cab_shortvideo);
actionBar.setLeftLayoutAsBack(this);
}
@Override
protected void initData() {
super.initData();
mPresenter.initData(mMessage);
}
@Override
protected void onResume() {
super.onResume();
// 部分机型在播放视频的时候跳转到其他地方再回来时,视频会被拉伸,所以在onResume里设置一次
if (mVideoView != null)
mVideoView.setScalableType(ScalableType.FIT_CENTER);
}
@Override
public void showProgressView() {
ViewStub viewStub = findView(R.id.vs_shortvideo_download_progress);
mViewDownload = viewStub.inflate();
mPgvDownload = findView(R.id.cpgv_download_progress);
mTvDownload = findView(R.id.tv_download_progress);
}
@Override
public void updateDownloadProgress(float progress) {
if (mPgvDownload != null)
mPgvDownload.setPercent(progress);
if (mTvDownload != null)
mTvDownload.setText(new StringBuffer().append(String.valueOf(progress)).append("%"));
}
@Override
public void hideProgressView() {
if (mViewDownload != null)
mViewDownload.setVisibility(View.GONE);
}
@Override
public void startPlayVideo(String path) {
// 这里之所以在需要播放视频的时候才能Inflate
// 是因为:如果直接初始化后,视频却需要下载,下载完后再播放,此时VideoView的TextTureView很可能已经被回收了导致黑屏
ViewStub viewStub = findView(R.id.vs_shortvideo_videoview);
viewStub.inflate();
mVideoView = findView(R.id.svv_shortvideo_play);
try {
mVideoView.setDataSource(path);
mVideoView.setVolume(1f, 1f);
mVideoView.setLooping(true);
mVideoView.prepareAsync(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mVideoView.start();
}
});
} catch (IOException e) {
showError(R.string.error_shortvideo_play, true);
}
}
@Override
public void showError(int errMsgResId, boolean needFinish) {
showLongToast(errMsgResId);
if (needFinish)
finish();
}
@Override
protected void onClick(int id, View v) {
}
@Override
protected void onDestroy() {
mPresenter.onDestory();
super.onDestroy();
}
}
19
Source : HxChatActivity.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public void addNewMessage(EMMessage message, boolean forceScrollToBottom) {
if (mAdapter != null) {
if (forceScrollToBottom) {
mAdapter.addData(message);
scrollToBottom();
} else {
// 判断当前添加消息前最后一条可见消息的位置是不是为最底部的消息,是就在添加新消息后将会话拉到底部
int curLastVisiablePosition = mLayoutManager.findLastVisibleItemPosition();
boolean needScrollToBottom = curLastVisiablePosition == mAdapter.getDatas().size() - 1;
mAdapter.addData(message);
if (needScrollToBottom)
scrollToBottom();
}
}
}
19
Source : HxChatActivity.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public void startToShortVideoPlay(EMMessage message) {
HxShortVideoPlayActivity.start(this, message);
}
19
Source : HxChatActivity.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public void onMessageStatusChanged(EMMessage message) {
if (mAdapter != null) {
int position = mAdapter.getDatas().indexOf(message);
mAdapter.notifyItemChanged(position, message);
}
}
19
Source : HxShortVideoPlayPresenter.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
/**
* 初始化视频数据
*/
public void initData(EMMessage message) {
String msgId = message.getMsgId();
EMVideoMessageBody messageBody = (EMVideoMessageBody) message.getBody();
// 检查文件是否存在本地文件
String localUrl = messageBody.getLocalUrl();
if (new File(localUrl).exists()) {
// 存在就直接播放
mViewImpl.startPlayVideo(localUrl);
return;
}
// 检查是否下载过
ShortVideoBean videoBean = mModel.queryDataByMsgId(msgId);
if (videoBean == null) {
// 没有下载过就直接下载
downLoadRemoteUrlVideo(msgId, messageBody.getRemoteUrl());
} else {
// 下载过就检查文件是否还在
String downLoadUrl = videoBean.getLocal_url();
if (new File(downLoadUrl).exists()) {
// 下载的文件存在就直接播放
mViewImpl.startPlayVideo(downLoadUrl);
} else {
// 下载的文件不存在就重新下载
ShortVideoDao.getInstance().delete(videoBean);
downLoadRemoteUrlVideo(msgId, messageBody.getRemoteUrl());
}
}
}
19
Source : HxChatPresenter.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
/**
* 发送文本消息
*/
public void sendTextMessage(EMConversation.EMConversationType conType, String conId, String message) {
EMMessage emMessage = HxChatHelper.getInstance().createTextMessage(getChatTypeFromConType(conType), conId, message);
emMessage.setAttribute(HxMsgAttrConstant.TXT_ATTR_KEY, HxMsgAttrConstant.NORMAL_TEXT_MSG);
emMessage.setMessageStatusCallback(new MessageStatusCallBack(emMessage));
mViewImpl.addNewMessage(emMessage, true);
HxChatHelper.getInstance().sendMessage(emMessage);
}
19
Source : HxChatPresenter.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
/**
* 发送语音消息
*/
public void sendVoiceMessage(EMConversation.EMConversationType conType, String conId, String filePath, int seconds) {
EMMessage emMessage = HxChatHelper.getInstance().createVoiceMessage(getChatTypeFromConType(conType), conId, filePath, seconds);
emMessage.setMessageStatusCallback(new MessageStatusCallBack(emMessage));
mViewImpl.addNewMessage(emMessage, true);
HxChatHelper.getInstance().sendMessage(emMessage);
}
19
Source : HxChatPresenter.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
/**
* 点击查看短视频
*
* @param message
* @param position
*/
public void clickVideoMessage(EMMessage message, final int position) {
mViewImpl.startToShortVideoPlay(message);
}
19
Source : HxChatPresenter.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
/**
* 发送图片消息
*/
public void sendImageMessage(EMConversation.EMConversationType conType, String conId, String filePath, boolean sendOriginFile) {
EMMessage emMessage = HxChatHelper.getInstance().createImageMessage(getChatTypeFromConType(conType), conId, filePath, sendOriginFile);
emMessage.setMessageStatusCallback(new MessageStatusCallBack(emMessage));
mViewImpl.addNewMessage(emMessage, true);
HxChatHelper.getInstance().sendMessage(emMessage);
}
19
Source : VoiceMessageBaseItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public void setMessageData(RcvHolder holder, final EMMessage emMessage, final int position) {
final EMVoiceMessageBody messageBody = (EMVoiceMessageBody) emMessage.getBody();
final FrameAnimImageView imgLabel = holder.findView(R.id.img_chat_lisreplacedem_voice_content);
TextView tvLength = holder.findView(R.id.tv_chat_lisreplacedem_voice_content);
View vLayout = holder.findView(R.id.fl_chat_lisreplacedem_voice_content);
int voiceLength = messageBody.getLength();
ViewGroup.LayoutParams layoutParams = vLayout.getLayoutParams();
if (voiceLength <= MIN_VOICE_LENGTH)
layoutParams.width = MIN_LAYOUT_WIDTH;
else if (voiceLength >= MAX_VOICE_LENGTH)
layoutParams.width = MAX_LAYOUT_WIDTH;
else
layoutParams.width = MIN_LAYOUT_WIDTH + (MAX_LAYOUT_WIDTH - MIN_LAYOUT_WIDTH) * (voiceLength - MIN_VOICE_LENGTH) / // 5=MAX_VOICE_LENGTH-MIN_VOICE_LENGTH
5;
vLayout.setLayoutParams(layoutParams);
if (mPresenter.getCurPlayVoicePosition() == position) {
if (emMessage.direct() == EMMessage.Direct.SEND)
imgLabel.start(mAnimRight, true, ANIM_DURATION);
else
imgLabel.start(mAnimLeft, true, ANIM_DURATION);
} else {
imgLabel.stop();
if (emMessage.direct() == EMMessage.Direct.SEND)
imgLabel.setImageResource(R.drawable.ic_voice_right03);
else
imgLabel.setImageResource(R.drawable.ic_voice_left03);
}
// 设置时长
String lengthEx = mContext.getResources().getString(R.string.tv_chat_lisreplacedem_voice_length_Ex);
String length = lengthEx.replaceFirst("%%1", String.valueOf(voiceLength));
tvLength.setText(length);
// 是否已听
if (emMessage.direct() == EMMessage.Direct.RECEIVE) {
TextView tvUnlisten = holder.findView(R.id.tv_chat_lisreplacedem_voice_unlisten);
if (emMessage.isListened())
tvUnlisten.setVisibility(View.GONE);
else
tvUnlisten.setVisibility(View.VISIBLE);
}
// 设置点击事件
holder.setClickListener(R.id.fl_chat_lisreplacedem_voice_content, new VoiceClickListener(imgLabel, emMessage, position));
setMessage(holder, emMessage, position);
}
19
Source : VideoMessageBaseItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public void setMessageData(RcvHolder holder, final EMMessage emMessage, final int position) {
SelectableRoundedImageView imgThumb = holder.findView(R.id.img_chat_lisreplacedem_video_content);
TextView tvDuration = holder.findView(R.id.tv_chat_lisreplacedem_video_content_duration);
TextView tvFileLength = holder.findView(R.id.tv_chat_lisreplacedem_video_content_filelength);
EMVideoMessageBody messageBody = (EMVideoMessageBody) emMessage.getBody();
// 缩略图
String localThumb = messageBody.getLocalThumb();
String remoteThumb = messageBody.getThumbnailUrl();
if (StringUtil.isNotEmpty(localThumb) && new File(localThumb).exists())
CommonUtils.getInstance().getImageDisplayer().display(mContext, imgThumb, localThumb, 240, 300);
else
CommonUtils.getInstance().getImageDisplayer().display(mContext, imgThumb, remoteThumb, 240, 300);
// 视频时长
String durationEx = mContext.getResources().getString(R.string.tv_chat_lisreplacedem_video_duration_Ex);
String duration = durationEx.replaceFirst("%%1", String.valueOf(messageBody.getDuration()));
tvDuration.setText(duration);
// 视频大小
tvFileLength.setText(formetFileSize(messageBody.getVideoFileLength()));
// 点击播放
holder.setClickListener(R.id.img_chat_lisreplacedem_video_start, new View.OnClickListener() {
@Override
public void onClick(View v) {
mPresenter.clickVideoMessage(emMessage, position);
}
});
setMessage(holder, emMessage, position);
}
19
Source : RightVoiceRecordItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public void setMessage(RcvHolder holder, EMMessage emMessage, int position) {
}
19
Source : RightVoiceRecordItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public boolean isForViewType(EMMessage item, int position) {
int attr = item.getIntAttribute(HxMsgAttrConstant.TXT_ATTR_KEY, HxMsgAttrConstant.NORMAL_TEXT_MSG);
if (item.direct() == EMMessage.Direct.SEND && item.getType() == EMMessage.Type.TXT && attr == HxMsgAttrConstant.VOICE_CALL_RECORD)
return true;
else
return false;
}
19
Source : RightVoiceMessageItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public boolean isForViewType(EMMessage item, int position) {
if (item.direct() == EMMessage.Direct.SEND && item.getType() == EMMessage.Type.VOICE)
return true;
else
return false;
}
19
Source : RightVideoRecordItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public boolean isForViewType(EMMessage item, int position) {
int attr = item.getIntAttribute(HxMsgAttrConstant.TXT_ATTR_KEY, HxMsgAttrConstant.NORMAL_TEXT_MSG);
if (item.direct() == EMMessage.Direct.SEND && item.getType() == EMMessage.Type.TXT && attr == HxMsgAttrConstant.VIDEO_CALL_RECORD)
return true;
else
return false;
}
19
Source : RightVideoMessageItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public boolean isForViewType(EMMessage item, int position) {
if (item.direct() == EMMessage.Direct.SEND && item.getType() == EMMessage.Type.VIDEO)
return true;
else
return false;
}
19
Source : RightTextMessageItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public boolean isForViewType(EMMessage item, int position) {
int attr = item.getIntAttribute(HxMsgAttrConstant.TXT_ATTR_KEY, HxMsgAttrConstant.NORMAL_TEXT_MSG);
if (item.direct() == EMMessage.Direct.SEND && item.getType() == EMMessage.Type.TXT && attr == HxMsgAttrConstant.NORMAL_TEXT_MSG)
return true;
else
return false;
}
19
Source : RightImageMessageItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public boolean isForViewType(EMMessage item, int position) {
if (item.direct() == EMMessage.Direct.SEND && item.getType() == EMMessage.Type.IMAGE)
return true;
else
return false;
}
19
Source : LeftVoiceRecordItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public boolean isForViewType(EMMessage item, int position) {
int attr = item.getIntAttribute(HxMsgAttrConstant.TXT_ATTR_KEY, HxMsgAttrConstant.NORMAL_TEXT_MSG);
if (item.direct() == EMMessage.Direct.RECEIVE && item.getType() == EMMessage.Type.TXT && attr == HxMsgAttrConstant.VOICE_CALL_RECORD)
return true;
else
return false;
}
19
Source : LeftVoiceMessageItemView.java
with Apache License 2.0
from Vanish136
with Apache License 2.0
from Vanish136
@Override
public boolean isForViewType(EMMessage item, int position) {
if (item.direct() == EMMessage.Direct.RECEIVE && item.getType() == EMMessage.Type.VOICE)
return true;
else
return false;
}
See More Examples