Search in sources :

Example 1 with EMCallBack

use of com.hyphenate.EMCallBack in project SmartCampus by Vegen.

the class EaseChatImagePresenter method handleReceiveMessage.

@Override
protected void handleReceiveMessage(final EMMessage message) {
    super.handleReceiveMessage(message);
    getChatRow().updateView(message);
    message.setMessageStatusCallback(new EMCallBack() {

        @Override
        public void onSuccess() {
            getChatRow().updateView(message);
        }

        @Override
        public void onError(int code, String error) {
            getChatRow().updateView(message);
        }

        @Override
        public void onProgress(int progress, String status) {
            getChatRow().updateView(message);
        }
    });
}
Also used : EMCallBack(com.hyphenate.EMCallBack)

Example 2 with EMCallBack

use of com.hyphenate.EMCallBack in project SmartCampus by Vegen.

the class EaseChatRowPresenter method handleSendMessage.

protected void handleSendMessage(final EMMessage message) {
    EMMessage.Status status = message.status();
    // Update the view according to the message current status.
    getChatRow().updateView(message);
    if (status == EMMessage.Status.SUCCESS || status == EMMessage.Status.FAIL) {
        return;
    }
    message.setMessageStatusCallback(new EMCallBack() {

        @Override
        public void onSuccess() {
            getChatRow().updateView(message);
        }

        @Override
        public void onError(int code, String error) {
            Log.i("EaseChatRowPresenter", "onError: " + code + ", error: " + error);
            getChatRow().updateView(message);
        }

        @Override
        public void onProgress(int progress, String status) {
            getChatRow().updateView(message);
        }
    });
    // Already in progress, do not send again
    if (status == EMMessage.Status.INPROGRESS) {
        return;
    }
    // Send the message
    EMClient.getInstance().chatManager().sendMessage(message);
}
Also used : EMCallBack(com.hyphenate.EMCallBack) EMMessage(com.hyphenate.chat.EMMessage)

Example 3 with EMCallBack

use of com.hyphenate.EMCallBack in project SmartCampus by Vegen.

the class EaseShowNormalFileActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ease_activity_show_file);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    final EMMessage message = getIntent().getParcelableExtra("msg");
    if (!(message.getBody() instanceof EMFileMessageBody)) {
        Toast.makeText(EaseShowNormalFileActivity.this, "Unsupported message body", Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    final File file = new File(((EMFileMessageBody) message.getBody()).getLocalUrl());
    message.setMessageStatusCallback(new EMCallBack() {

        @Override
        public void onSuccess() {
            runOnUiThread(new Runnable() {

                public void run() {
                    FileUtils.openFile(file, EaseShowNormalFileActivity.this);
                    finish();
                }
            });
        }

        @Override
        public void onError(int code, String error) {
            runOnUiThread(new Runnable() {

                public void run() {
                    if (file != null && file.exists() && file.isFile())
                        file.delete();
                    String str4 = getResources().getString(R.string.Failed_to_download_file);
                    Toast.makeText(EaseShowNormalFileActivity.this, str4 + message, Toast.LENGTH_SHORT).show();
                    finish();
                }
            });
        }

        @Override
        public void onProgress(final int progress, String status) {
            runOnUiThread(new Runnable() {

                public void run() {
                    progressBar.setProgress(progress);
                }
            });
        }
    });
    EMClient.getInstance().chatManager().downloadAttachment(message);
}
Also used : EMCallBack(com.hyphenate.EMCallBack) EMFileMessageBody(com.hyphenate.chat.EMFileMessageBody) File(java.io.File) EMMessage(com.hyphenate.chat.EMMessage)

Example 4 with EMCallBack

use of com.hyphenate.EMCallBack 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 5 with EMCallBack

use of com.hyphenate.EMCallBack in project SmartCampus by Vegen.

the class EaseShowVideoActivity method downloadVideo.

/**
 * download video file
 */
private void downloadVideo(EMMessage message) {
    message.setMessageStatusCallback(new EMCallBack() {

        @Override
        public void onSuccess() {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    loadingLayout.setVisibility(View.GONE);
                    progressBar.setProgress(0);
                    showLocalVideo(localFilePath);
                }
            });
        }

        @Override
        public void onProgress(final int progress, String status) {
            Log.d("ease", "video progress:" + progress);
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    progressBar.setProgress(progress);
                }
            });
        }

        @Override
        public void onError(int error, String msg) {
            Log.e("###", "offline file transfer error:" + msg);
            File file = new File(localFilePath);
            if (file.exists()) {
                file.delete();
            }
        }
    });
    EMClient.getInstance().chatManager().downloadAttachment(message);
}
Also used : EMCallBack(com.hyphenate.EMCallBack) File(java.io.File)

Aggregations

EMCallBack (com.hyphenate.EMCallBack)5 EMMessage (com.hyphenate.chat.EMMessage)3 File (java.io.File)3 SuppressLint (android.annotation.SuppressLint)1 ProgressDialog (android.app.ProgressDialog)1 DisplayMetrics (android.util.DisplayMetrics)1 EMFileMessageBody (com.hyphenate.chat.EMFileMessageBody)1