Search in sources :

Example 1 with WorkTask

use of org.aisen.android.network.task.WorkTask in project AisenWeiBo by wangdan.

the class PictureFragment method downloadImage.

private void downloadImage() {
    new IAction(getActivity(), new SdcardPermissionAction((BaseActivity) getActivity(), null)) {

        @Override
        public void doAction() {
            new WorkTask<Void, Void, String>() {

                @Override
                protected void onPrepare() {
                    super.onPrepare();
                    ViewUtils.createProgressDialog(getActivity(), getString(R.string.msg_save_pic_loading), ThemeUtils.getThemeColor()).show();
                }

                private void notifyFileSys(File file) {
                    SystemUtils.scanPhoto(getActivity(), file);
                }

                @Override
                public String workInBackground(Void... params) throws TaskException {
                    File file = origFile;
                    if (!file.exists())
                        file = BitmapLoader.getInstance().getCacheFile(getImage());
                    String path = SystemUtils.getSdcardPath() + File.separator + AppSettings.getImageSavePath() + File.separator + file.getName();
                    File newFile = new File(path);
                    if (!newFile.exists()) {
                        if (!newFile.getParentFile().exists())
                            newFile.getParentFile().mkdirs();
                        try {
                            FileUtils.copyFile(file, newFile);
                            notifyFileSys(newFile);
                            return newFile.getParentFile().getAbsolutePath();
                        } catch (Exception e) {
                        }
                    } else {
                        notifyFileSys(newFile);
                        return newFile.getParentFile().getAbsolutePath();
                    }
                    return null;
                }

                @Override
                protected void onSuccess(String aBoolean) {
                    super.onSuccess(aBoolean);
                    if (!TextUtils.isEmpty(aBoolean)) {
                        showMessage(String.format(getString(R.string.msg_save_pic_success), aBoolean));
                    } else {
                        showMessage(R.string.msg_save_pic_faild);
                    }
                }

                @Override
                protected void onFinished() {
                    super.onFinished();
                    ViewUtils.dismissProgressDialog();
                }
            }.execute();
        }
    }.run();
}
Also used : IAction(org.aisen.android.support.action.IAction) SdcardPermissionAction(org.aisen.weibo.sina.support.permissions.SdcardPermissionAction) WorkTask(org.aisen.android.network.task.WorkTask) File(java.io.File) TaskException(org.aisen.android.network.task.TaskException)

Aggregations

File (java.io.File)1 TaskException (org.aisen.android.network.task.TaskException)1 WorkTask (org.aisen.android.network.task.WorkTask)1 IAction (org.aisen.android.support.action.IAction)1 SdcardPermissionAction (org.aisen.weibo.sina.support.permissions.SdcardPermissionAction)1