zoukankan      html  css  js  c++  java
  • 团队冲刺第二阶段10

    今天做了最后分享的功能,组员之间整合了代码,测试各部分的功能实现。

      public void shareNote (Note note) {
    
        String titleText = note.getTitle();
    
        String contentText = titleText
            + System.getProperty("line.separator")
            + note.getContent();
    
        Intent shareIntent = new Intent();
        // Prepare sharing intent with only text
        if (note.getAttachmentsList().isEmpty()) {
          shareIntent.setAction(Intent.ACTION_SEND);
          shareIntent.setType("text/plain");
    
          // Intent with single image attachment
        } else if (note.getAttachmentsList().size() == 1) {
          shareIntent.setAction(Intent.ACTION_SEND);
          Attachment attachment = note.getAttachmentsList().get(0);
          shareIntent.setType(attachment.getMime_type());
          shareIntent.putExtra(Intent.EXTRA_STREAM, FileProviderHelper.getShareableUri(attachment));
    
          // Intent with multiple images
        } else if (note.getAttachmentsList().size() > 1) {
          shareIntent.setAction(Intent.ACTION_SEND_MULTIPLE);
          ArrayList<Uri> uris = new ArrayList<>();
          // A check to decide the mime type of attachments to share is done here
          HashMap<String, Boolean> mimeTypes = new HashMap<>();
          for (Attachment attachment : note.getAttachmentsList()) {
            uris.add(FileProviderHelper.getShareableUri(attachment));
            mimeTypes.put(attachment.getMime_type(), true);
          }
          // If many mime types are present a general type is assigned to intent
          if (mimeTypes.size() > 1) {
            shareIntent.setType("*/*");
          } else {
            shareIntent.setType((String) mimeTypes.keySet().toArray()[0]);
          }
    
          shareIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        }
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, titleText);
        shareIntent.putExtra(Intent.EXTRA_TEXT, contentText);
    
        startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.share_message_chooser)));
      }

  • 相关阅读:
    系统管理命令之tty
    系统管理命令之id
    idea中使用junit测试时使用Scanner类无法正常测试
    002-字段不为null
    java8中接口中的default方法
    java之接口适配器
    java之对象适配器
    java之类适配器
    java之多态(六)
    java之多态(五)
  • 原文地址:https://www.cnblogs.com/xjmm/p/13085539.html
Copyright © 2011-2022 走看看