Search in sources :

Example 21 with EMMessage

use of com.hyphenate.chat.EMMessage in project SmartCampus by Vegen.

the class EaseChatFragment method sendVideoMessage.

protected void sendVideoMessage(String videoPath, String thumbPath, int videoLength) {
    EMMessage message = EMMessage.createVideoSendMessage(videoPath, thumbPath, videoLength, toChatUsername);
    sendMessage(message);
}
Also used : EMMessage(com.hyphenate.chat.EMMessage)

Example 22 with EMMessage

use of com.hyphenate.chat.EMMessage in project SmartCampus by Vegen.

the class EaseShowBigImageActivity method downloadImage.

/**
 * download image
 *
 * @param remoteFilePath
 */
@SuppressLint("NewApi")
private void downloadImage(final String msgId) {
    EMLog.e(TAG, "download with messageId: " + msgId);
    String str1 = getResources().getString(R.string.Download_the_pictures);
    pd = new ProgressDialog(this);
    pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    pd.setCanceledOnTouchOutside(false);
    pd.setMessage(str1);
    pd.show();
    File temp = new File(localFilePath);
    final String tempPath = temp.getParent() + "/temp_" + temp.getName();
    final EMCallBack callback = new EMCallBack() {

        public void onSuccess() {
            EMLog.e(TAG, "onSuccess");
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    new File(tempPath).renameTo(new File(localFilePath));
                    DisplayMetrics metrics = new DisplayMetrics();
                    getWindowManager().getDefaultDisplay().getMetrics(metrics);
                    int screenWidth = metrics.widthPixels;
                    int screenHeight = metrics.heightPixels;
                    bitmap = ImageUtils.decodeScaleImage(localFilePath, screenWidth, screenHeight);
                    if (bitmap == null) {
                        image.setImageResource(default_res);
                    } else {
                        image.setImageBitmap(bitmap);
                        EaseImageCache.getInstance().put(localFilePath, bitmap);
                        isDownloaded = true;
                    }
                    if (isFinishing() || isDestroyed()) {
                        return;
                    }
                    if (pd != null) {
                        pd.dismiss();
                    }
                }
            });
        }

        public void onError(int error, String msg) {
            EMLog.e(TAG, "offline file transfer error:" + msg);
            File file = new File(tempPath);
            if (file.exists() && file.isFile()) {
                file.delete();
            }
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (EaseShowBigImageActivity.this.isFinishing() || EaseShowBigImageActivity.this.isDestroyed()) {
                        return;
                    }
                    image.setImageResource(default_res);
                    pd.dismiss();
                }
            });
        }

        public void onProgress(final int progress, String status) {
            EMLog.d(TAG, "Progress: " + progress);
            final String str2 = getResources().getString(R.string.Download_the_pictures_new);
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    if (EaseShowBigImageActivity.this.isFinishing() || EaseShowBigImageActivity.this.isDestroyed()) {
                        return;
                    }
                    pd.setMessage(str2 + progress + "%");
                }
            });
        }
    };
    EMMessage msg = EMClient.getInstance().chatManager().getMessage(msgId);
    msg.setMessageStatusCallback(callback);
    EMLog.e(TAG, "downloadAttachement");
    EMClient.getInstance().chatManager().downloadAttachment(msg);
}
Also used : EMCallBack(com.hyphenate.EMCallBack) ProgressDialog(android.app.ProgressDialog) File(java.io.File) DisplayMetrics(android.util.DisplayMetrics) EMMessage(com.hyphenate.chat.EMMessage) SuppressLint(android.annotation.SuppressLint)

Example 23 with EMMessage

use of com.hyphenate.chat.EMMessage in project SmartCampus by Vegen.

the class EaseShowVideoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    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.getLocalUrl();
    if (localFilePath != null && new File(localFilePath).exists()) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setDataAndType(Uri.fromFile(new File(localFilePath)), "video/mp4");
        startActivity(intent);
        finish();
    } else {
        EMLog.d(TAG, "download remote video file");
        downloadVideo(message);
    }
}
Also used : Intent(android.content.Intent) EMVideoMessageBody(com.hyphenate.chat.EMVideoMessageBody) File(java.io.File) EMMessage(com.hyphenate.chat.EMMessage)

Example 24 with EMMessage

use of com.hyphenate.chat.EMMessage in project SmartCampus by Vegen.

the class EaseDingMessageHelperTest method createDingAckMessage.

private EMMessage createDingAckMessage(String conversationId, String originalMsgId, String from) {
    EMAMessage _msg = EMAMessage.createSendMessage(from, "", null, EMMessage.ChatType.Chat.ordinal());
    EMMessage msg = new EMMessage(_msg);
    msg.setAttribute(KEY_CONVERSATION_ID, conversationId);
    msg.setAttribute(KEY_DING_ACK, true);
    msg.addBody(new EMCmdMessageBody(originalMsgId));
    return msg;
}
Also used : EMCmdMessageBody(com.hyphenate.chat.EMCmdMessageBody) EMAMessage(com.hyphenate.chat.adapter.message.EMAMessage) EMMessage(com.hyphenate.chat.EMMessage)

Aggregations

EMMessage (com.hyphenate.chat.EMMessage)24 File (java.io.File)4 EMCallBack (com.hyphenate.EMCallBack)3 SuppressLint (android.annotation.SuppressLint)2 EMCmdMessageBody (com.hyphenate.chat.EMCmdMessageBody)2 EMGroup (com.hyphenate.chat.EMGroup)2 EMTextMessageBody (com.hyphenate.chat.EMTextMessageBody)2 EMAMessage (com.hyphenate.chat.adapter.message.EMAMessage)2 EaseAvatarOptions (com.hyphenate.easeui.domain.EaseAvatarOptions)2 EaseImageView (com.hyphenate.easeui.widget.EaseImageView)2 Date (java.util.Date)2 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 DisplayMetrics (android.util.DisplayMetrics)1 TextView (android.widget.TextView)1 EMChatRoom (com.hyphenate.chat.EMChatRoom)1 EMConversation (com.hyphenate.chat.EMConversation)1 EMFileMessageBody (com.hyphenate.chat.EMFileMessageBody)1 EMImageMessageBody (com.hyphenate.chat.EMImageMessageBody)1 EMVideoMessageBody (com.hyphenate.chat.EMVideoMessageBody)1