@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_upload_status);

    choiceFormat = new ChoiceFormat(getString(R.string.rate_choice));
    rateNumberFormat = new DecimalFormat(getString(R.string.rate_number_format));

    progressBar = (ProgressBar) findViewById(R.id.progress_bar);
    progressPercent = (TextView) findViewById(R.id.progress_percent);
    uploadRate = (TextView) findViewById(R.id.upload_rate);

    Uri filePath = getFilePath();

    setTitle(getString(R.string.uploading_s, filePath.getLastPathSegment()));

    // First-time start.
    if (UploadStatusObservables.getObservable(filePath) == null && savedInstanceState == null) {
      logger.info("Uploading {}", filePath);

      progressBar.setIndeterminate(true);

      UploadStatusObservables.createSubject(filePath);

      Bundle extras = checkNotNull(getIntent().getExtras());
      if (extras.getBoolean(EXTRA_START_SERVICE, true)) {
        String contentType =
            checkNotNull(
                extras.getString(EXTRA_CONTENT_TYPE), EXTRA_CONTENT_TYPE + " extra is null");
        Intent finishedIntent = checkNotNull((Intent) extras.getParcelable(EXTRA_FINISHED_INTENT));

        Intent serviceIntent =
            UploadService.createMyIntent(this, filePath, contentType, getIntent(), finishedIntent);
        startService(serviceIntent);
      }
    } else {
      logger.info("There's already upload of the same file in progress: {}", filePath);
    }
  }
  @Override
  public void onReceive(Context context, Intent intent) {

    if (intent != null) {
      if (UploadService.getActionBroadcast().equals(intent.getAction())) {
        final int status = intent.getIntExtra(UploadService.STATUS, 0);
        final String uploadId = intent.getStringExtra(UploadService.UPLOAD_ID);
        final int total = intent.getIntExtra(UploadService.TOTAL_ITEMS_TO_UPLOAD, 0);
        final int totalUploaded = intent.getIntExtra(UploadService.TOTAL_ITEMS_UPLOADED, 0);

        switch (status) {
          case UploadService.STATUS_ERROR:
            final Exception exception =
                (Exception) intent.getSerializableExtra(UploadService.ERROR_EXCEPTION);
            onError(uploadId, exception);
            break;

          case UploadService.STATUS_COMPLETED:
            final int responseCode = intent.getIntExtra(UploadService.SERVER_RESPONSE_CODE, 0);
            final String responseMsg = intent.getStringExtra(UploadService.SERVER_RESPONSE_MESSAGE);
            final String tag = intent.getStringExtra(UploadService.TAG_FILENAME);
            final int current = intent.getIntExtra(UploadService.CURRENT, 0);
            final int total2 = intent.getIntExtra(UploadService.TOTAL, 0);
            onCompleted(
                uploadId, responseCode, responseMsg, total, totalUploaded, tag, total2, current);
            break;

          case UploadService.STATUS_IN_PROGRESS:
            final int progress = intent.getIntExtra(UploadService.PROGRESS, 0);
            onProgress(uploadId, progress);
            break;

          default:
            break;
        }
      }
    }
  }
 /**
  * Register this upload receiver. It's recommended to register the receiver in Activity's onResume
  * method.
  *
  * @param activity activity in which to register this receiver
  */
 public void register(final Activity activity) {
   final IntentFilter intentFilter = new IntentFilter();
   intentFilter.addAction(UploadService.getActionBroadcast());
   activity.registerReceiver(this, intentFilter);
 }
示例#4
0
    /**
     * static method to create the object Precondition: If this object is an element, the current or
     * next start element starts this object and any intervening reader events are ignorable If this
     * object is not an element, it is a complex type and the reader is at the event just after the
     * outer start element Postcondition: If this object is an element, the reader is positioned at
     * its end element If this object is a complex type, the reader is positioned at the end element
     * of its outer element
     */
    public static UploadService parse(javax.xml.stream.XMLStreamReader reader)
        throws java.lang.Exception {
      UploadService object = new UploadService();

      int event;
      java.lang.String nillableValue = null;
      java.lang.String prefix = "";
      java.lang.String namespaceuri = "";
      try {

        while (!reader.isStartElement() && !reader.isEndElement()) reader.next();

        if (reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "type") != null) {
          java.lang.String fullTypeName =
              reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "type");
          if (fullTypeName != null) {
            java.lang.String nsPrefix = null;
            if (fullTypeName.indexOf(":") > -1) {
              nsPrefix = fullTypeName.substring(0, fullTypeName.indexOf(":"));
            }
            nsPrefix = nsPrefix == null ? "" : nsPrefix;

            java.lang.String type = fullTypeName.substring(fullTypeName.indexOf(":") + 1);

            if (!"uploadService".equals(type)) {
              // find namespace for the prefix
              java.lang.String nsUri = reader.getNamespaceContext().getNamespaceURI(nsPrefix);
              return (UploadService)
                  org.wso2.carbon.aarservices.xsd.ExtensionMapper.getTypeObject(
                      nsUri, type, reader);
            }
          }
        }

        // Note all attributes that were handled. Used to differ normal attributes
        // from anyAttributes.
        java.util.Vector handledAttributes = new java.util.Vector();

        reader.next();

        java.util.ArrayList list1 = new java.util.ArrayList();

        while (!reader.isStartElement() && !reader.isEndElement()) reader.next();

        if (reader.isStartElement()
            && new javax.xml.namespace.QName(
                    "http://aarservices.carbon.wso2.org", "serviceDataList")
                .equals(reader.getName())) {

          // Process the array and step past its final element's end.

          nillableValue =
              reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "nil");
          if ("true".equals(nillableValue) || "1".equals(nillableValue)) {
            list1.add(null);
            reader.next();
          } else {
            list1.add(org.wso2.carbon.aarservices.xsd.AARServiceData.Factory.parse(reader));
          }
          // loop until we find a start element that is not part of this array
          boolean loopDone1 = false;
          while (!loopDone1) {
            // We should be at the end element, but make sure
            while (!reader.isEndElement()) reader.next();
            // Step out of this element
            reader.next();
            // Step to next element event.
            while (!reader.isStartElement() && !reader.isEndElement()) reader.next();
            if (reader.isEndElement()) {
              // two continuous end elements means we are exiting the xml structure
              loopDone1 = true;
            } else {
              if (new javax.xml.namespace.QName(
                      "http://aarservices.carbon.wso2.org", "serviceDataList")
                  .equals(reader.getName())) {

                nillableValue =
                    reader.getAttributeValue("http://www.w3.org/2001/XMLSchema-instance", "nil");
                if ("true".equals(nillableValue) || "1".equals(nillableValue)) {
                  list1.add(null);
                  reader.next();
                } else {
                  list1.add(org.wso2.carbon.aarservices.xsd.AARServiceData.Factory.parse(reader));
                }
              } else {
                loopDone1 = true;
              }
            }
          }
          // call the converter utility  to convert and set the array

          object.setServiceDataList(
              (org.wso2.carbon.aarservices.xsd.AARServiceData[])
                  org.apache.axis2.databinding.utils.ConverterUtil.convertToArray(
                      org.wso2.carbon.aarservices.xsd.AARServiceData.class, list1));

        } // End of if for expected property start element
        else {

        }

        while (!reader.isStartElement() && !reader.isEndElement()) reader.next();

        if (reader.isStartElement())
          // A start element we are not expecting indicates a trailing invalid property
          throw new org.apache.axis2.databinding.ADBException(
              "Unexpected subelement " + reader.getName());

      } catch (javax.xml.stream.XMLStreamException e) {
        throw new java.lang.Exception(e);
      }

      return object;
    }
示例#5
0
 @Override
 public void dispose() {
   super.dispose();
   UploadService.removeHandler(Upload.this);
   UIUtils.deactivateCallback("upload");
 }
示例#6
0
  // -- v1.1 --//
  @RequestMapping(
      value = PREFIX_API_1_1_COMMENTS + "createWithMedia.json",
      method = RequestMethod.POST)
  @ResponseBody
  public Object createWithMedia_v1_1(
      @RequestParam(value = "videoUrl", required = false) String videoUrl,
      @RequestParam(value = "imageUrl", required = false) String imageUrl,
      @RequestParam(value = "audioUrl", required = false) String audioUrl,
      @RequestParam(value = "audioDuration", required = false) Long audioDuration,
      @RequestParam(value = "videoDuration", required = false) Long videoDuration,
      @RequestParam(value = "text", required = false) String text,
      @RequestParam(value = "postId", required = false) String postId,
      @RequestParam(value = "replyCommentId", required = false) String replyCommentId) {

    if (StringUtils.isBlank(postId) && StringUtils.isBlank(replyCommentId)) {
      return ErrorDto.badRequest("参数postId和replyCommentId不能都为空");
    }

    // 读取附件信息
    FileInfo videoFileInfo = null;
    FileInfo imageFileInfo = null;
    FileInfo audioFileInfo = null;

    // 视频评论
    if (StringUtils.isNotBlank(videoUrl) && StringUtils.isNotBlank(imageUrl)) {

      videoFileInfo = aLiYunStorageService.getTmpFileInfoFromUrl(videoUrl);
      videoFileInfo.setDuration(videoDuration);
      imageFileInfo = aLiYunStorageService.getTmpFileInfoFromUrl(imageUrl);

      try {

        uploadService.checkVideo(videoFileInfo);
        uploadService.checkImage(imageFileInfo);

      } catch (ServiceException e) {

        aLiYunStorageService.delete(videoFileInfo.getTmpKey());
        aLiYunStorageService.delete(imageFileInfo.getTmpKey());

        throw e;
      }
    }

    // 语音评论
    else if (StringUtils.isNotBlank(audioUrl)) {

      audioFileInfo = aLiYunStorageService.getTmpFileInfoFromUrl(audioUrl);
      audioFileInfo.setDuration(audioDuration);

      try {

        uploadService.checkAudio(audioFileInfo);

      } catch (ServiceException e) {

        aLiYunStorageService.delete(audioFileInfo.getTmpKey());

        throw e;
      }
    }

    // 参数错误
    else {
      return ErrorDto.badRequest("参数必须满足这个条件:(videoUrl不为空 && imageUrl不为空) || (audioUrl不为空)");
    }

    return createComment(text, replyCommentId, postId, videoFileInfo, imageFileInfo, audioFileInfo);
  }