Android 4.4 Email 附件查看

Android 4.4 Email 点击视频附件查看的简单流程

4.4中附件的view是在 MessageAttachmentBar 中进行显示的。

1.当点击附件的时候调用onClick方法。

        if (res == R.id.preview_attachment) {
            previewAttachment();
        } else if (res == R.id.save_attachment) {//点击保存
            if (mAttachment.canSave()) {//判断是否可以保存,判断是不是已经下载
                mActionHandler.startDownloadingAttachment(AttachmentDestination.EXTERNAL);//开始下载,下载到外部,
                mSaveClicked = true;

                Analytics.getInstance().sendEvent(
                        "save_attachment", Utils.normalizeMimeType(mAttachment.getContentType()),
                        "attachment_bar", mAttachment.size);
            }
        } else if (res == R.id.download_again) {//再次下载
            if (mAttachment.isPresentLocally()) {//判断是不是该附件已经保存
                mActionHandler.showDownloadingDialog();
                mActionHandler.startRedownloadingAttachment(mAttachment);

                Analytics.getInstance().sendEvent("redownload_attachment",
                        Utils.normalizeMimeType(mAttachment.getContentType()), "attachment_bar",
                        mAttachment.size);
            }
        } else if (res == R.id.cancel_attachment) {//取消下载
            mActionHandler.cancelAttachment();
            mSaveClicked = false;

            Analytics.getInstance().sendEvent(
                    "cancel_attachment", Utils.normalizeMimeType(mAttachment.getContentType()),
                    "attachment_bar", mAttachment.size);
        。。。。。
        } else {
           。。。。
            // view or play.
            else if (MimeType.isViewable(
                    getContext(), mAttachment.contentUri, mAttachment.getContentType())) {//此附件开始查看
                mActionHandler.showAttachment(AttachmentDestination.CACHE);

                action = "attachment_bar";
            }
            。。。。
          

            if (action != null) {
                Analytics.getInstance()
                        .sendEvent("view_attachment", mime, action, mAttachment.size);
            }
        }

        return true;
2.附件可以下载的时候调用
mActionHandler.showAttachment(AttachmentDestination.CACHE);
 name="code" class="html">AttachmentDestination.CACHE:表示下载到内部存储。
mActionHander 是AttachmentActionHandler
  public void showAttachment(int destination) {
        if (mView == null) {
            return;
        }

        
        if (mAttachment.isPresentLocally() &&
                (destination == AttachmentDestination.CACHE ||
                        mAttachment.destination == destination)) {//判断此附件是不是已经下载,若已经下载可以直接就行查看。
            mView.viewAttachment();
        } else {
            showDownloadingDialog();//显示下载的对话框
            startDownloadingAttachment(destination);//开始下载附件,更新数据库
        }
    }

3.查看附件调用了startDownloadingAttachment,实现如下:

    private void startDownloadingAttachment(
            Attachment attachment, int destination, int rendition, int additionalPriority,
            boolean delayDownload) {
        final ContentValues params = new ContentValues(5);
        params.put(AttachmentColumns.STATE, AttachmentState.DOWNLOADING);//更新状态
        params.put(AttachmentColumns.DESTINATION, destination);//下载的方向
        params.put(AttachmentContentValueKeys.RENDITION, rendition);
        params.put(AttachmentContentValueKeys.ADDITIONAL_PRIORITY, additionalPriority);
        params.put(AttachmentContentValueKeys.DELAY_DOWNLOAD, delayDownload);//是否延迟下载

        mCommandHandler.sendCommand(attachment.uri, params);
    }
4.mCommandHandler.sendCommand(attachment.uri, params); 是一个异步更新数据库的操作,最后将更新数据库。调用了EmailProvider。

5.EmailProvider中对于Attachment数据库进行更新操作之后,将会触发对于Attachment表格的监听。

    private final AttachmentService DEFAULT_ATTACHMENT_SERVICE = new AttachmentService() {
        @Override
        public void attachmentChanged(Context context, long id, int flags) {
            // The default implementation delegates to the real service.
            AttachmentDownloadService.attachmentChanged(context, id, flags);//启动下载的服务
        }
    };

6.AttachmentDownloadService 是对于邮件附件下载的service。

 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值