Search in sources :

Example 1 with CloudOperationCallback

use of com.easemob.cloud.CloudOperationCallback in project wechat by motianhuo.

the class ShowVideoActivity method downloadVideo.

/**
 * 下载视频文件
 */
private void downloadVideo(final String remoteUrl, final Map<String, String> header) {
    if (TextUtils.isEmpty(localFilePath)) {
        localFilePath = getLocalFilePath(remoteUrl);
    }
    if (new File(localFilePath).exists()) {
        showLocalVideo(localFilePath);
        return;
    }
    loadingLayout.setVisibility(View.VISIBLE);
    final HttpFileManager httpFileMgr = new HttpFileManager(this, EMChatConfig.getInstance().getStorageUrl());
    final CloudOperationCallback callback = new CloudOperationCallback() {

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

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

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

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

        @Override
        public void onError(String msg) {
            Log.e("###", "offline file transfer error:" + msg);
            File file = new File(localFilePath);
            if (file.exists()) {
                file.delete();
            }
        }
    };
    new Thread(new Runnable() {

        @Override
        public void run() {
            httpFileMgr.downloadFile(remoteUrl, localFilePath, header, callback);
        }
    }).start();
}
Also used : CloudOperationCallback(com.easemob.cloud.CloudOperationCallback) HttpFileManager(com.easemob.cloud.HttpFileManager) File(java.io.File)

Example 2 with CloudOperationCallback

use of com.easemob.cloud.CloudOperationCallback in project wechat by motianhuo.

the class ShowNormalFileActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_show_file);
    progressBar = (ProgressBar) findViewById(R.id.progressBar);
    final FileMessageBody messageBody = getIntent().getParcelableExtra("msgbody");
    file = new File(messageBody.getLocalUrl());
    // set head map
    final Map<String, String> maps = new HashMap<String, String>();
    if (!TextUtils.isEmpty(messageBody.getSecret())) {
        maps.put("share-secret", messageBody.getSecret());
    }
    // 下载文件
    new Thread(new Runnable() {

        public void run() {
            HttpFileManager fileManager = new HttpFileManager(ShowNormalFileActivity.this, EMChatConfig.getInstance().getStorageUrl());
            fileManager.downloadFile(messageBody.getRemoteUrl(), messageBody.getLocalUrl(), maps, new CloudOperationCallback() {

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

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

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

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

                @Override
                public void onError(final String msg) {
                    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(ShowNormalFileActivity.this, str4 + msg, Toast.LENGTH_SHORT).show();
                            finish();
                        }
                    });
                }
            });
        }
    }).start();
}
Also used : CloudOperationCallback(com.easemob.cloud.CloudOperationCallback) HashMap(java.util.HashMap) HttpFileManager(com.easemob.cloud.HttpFileManager) FileMessageBody(com.easemob.chat.FileMessageBody) File(java.io.File)

Example 3 with CloudOperationCallback

use of com.easemob.cloud.CloudOperationCallback in project wechat by motianhuo.

the class ShowBigImage method downloadImage.

/**
 * 下载图片
 *
 * @param remoteFilePath
 */
private void downloadImage(final String remoteFilePath, final Map<String, String> headers) {
    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();
    localFilePath = getLocalFilePath(remoteFilePath);
    final HttpFileManager httpFileMgr = new HttpFileManager(this, EMChatConfig.getInstance().getStorageUrl());
    final CloudOperationCallback callback = new CloudOperationCallback() {

        public void onSuccess(String resultMsg) {
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    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);
                        ImageCache.getInstance().put(localFilePath, bitmap);
                        isDownloaded = true;
                    }
                    if (pd != null) {
                        pd.dismiss();
                    }
                }
            });
        }

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

                @Override
                public void run() {
                    pd.dismiss();
                    image.setImageResource(default_res);
                }
            });
        }

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

                @Override
                public void run() {
                    pd.setMessage(str2 + progress + "%");
                }
            });
        }
    };
    new Thread(new Runnable() {

        @Override
        public void run() {
            httpFileMgr.downloadFile(remoteFilePath, localFilePath, headers, callback);
        }
    }).start();
}
Also used : CloudOperationCallback(com.easemob.cloud.CloudOperationCallback) HttpFileManager(com.easemob.cloud.HttpFileManager) ProgressDialog(android.app.ProgressDialog) DisplayMetrics(android.util.DisplayMetrics) File(java.io.File)

Aggregations

CloudOperationCallback (com.easemob.cloud.CloudOperationCallback)3 HttpFileManager (com.easemob.cloud.HttpFileManager)3 File (java.io.File)3 ProgressDialog (android.app.ProgressDialog)1 DisplayMetrics (android.util.DisplayMetrics)1 FileMessageBody (com.easemob.chat.FileMessageBody)1 HashMap (java.util.HashMap)1