Ejemplo n.º 1
0
  @Override
  public boolean handleMessage(Message msg) {

    switch (msg.what) {
      case STATE_WAITING:
        Log.d("debug", "I am waiting!");
        break;

      case STATE_PREPARING:
        // 网络状态判断
        if (ZNetworkStateDetector.isAvailable()
            && ZNetworkStateDetector.isConnected()
            && this.info != null
            && this.info.upRequest != null) {
          // 请求日记结构
          Requester3.createStructure(
              handler,
              this.info.upRequest.diaryid,
              this.info.upRequest.diaryuuid,
              this.info.upRequest.operate_diarytype,
              this.info.upRequest.resourcediaryid,
              this.info.upRequest.resourcediaryuuid,
              this.info.upRequest.tags,
              String.valueOf(TimeHelper.getInstance().now()),
              this.info.upRequest.addresscode,
              this.info.upRequest.position_status,
              this.info.upRequest.isonlymic,
              this.info.upRequest.longitude_real,
              this.info.upRequest.latitude_real,
              this.info.upRequest.position_real,
              this.info.upRequest.longitude,
              this.info.upRequest.latitude,
              this.info.upRequest.position,
              this.info.upRequest.longitude_view,
              this.info.upRequest.latitude_view,
              this.info.upRequest.position_view,
              this.info.upRequest.shoottime,
              this.info.upRequest.attachs);
        } else {
          //				Toast.makeText(ZApplication.getInstance().getApplicationContext(), "网络异常,无法启动该任务!",
          // Toast.LENGTH_LONG).show();
          translateToState(STATE_ERROR);
        }
        break;

      case Requester3.RESPONSE_TYPE_CREATE_STRUCTURE:
        GsonResponse3.createStructureResponse response =
            (GsonResponse3.createStructureResponse) msg.obj;
        if (msg.obj != null
            && response != null
            && response.attachs != null
            && response.status.equals("0")) {
          this.info.diaryid = response.diaryid; // 取得diaryid
          DiaryManager diarymanager = DiaryManager.getInstance();
          MyDiary myLocalDiary = diarymanager.findMyDiaryByUUID(response.diaryuuid);
          MyDiaryList diarylist = diarymanager.findDiaryGroupByUUID(response.diaryuuid);
          if (myLocalDiary != null && diarylist != null) {
            myLocalDiary.diaryid = response.diaryid;
            myLocalDiary.sync_status = 1;
            Log.d(TAG, "diaryid = " + myLocalDiary.diaryid);
            diarylist.diaryid = response.diaryid;
          } else if (this.info.source != 1) {
            Log.d(TAG, "Should Not Be Here!");
            translateToState(STATE_REMOVED);
            return false;
          }

          if (this.info == null
              || this.info.caMedias == null /*|| this.info.caMedias.size() <= 0*/) {
            Log.e(TAG, "Do not click the control button rapidly!");
            return false;
          }

          for (int i = 0; i < response.attachs.length; i++) {
            for (int j = 0; j < this.info.caMedias.size(); j++) {
              Log.d(TAG, "caMedias size = " + this.info.caMedias.size() + "i = " + i + ",j = " + j);
              upMedia tmpmedia = this.info.caMedias.get(j);
              if (tmpmedia == null) {
                Log.d(TAG, "tmpmedia is null");
              }
              if (response.attachs[i] != null
                  && tmpmedia.attachuuid.equals(response.attachs[i].attachuuid)) {
                this.info.caMedias.get(j).attachid = response.attachs[i].attachid; // 取得attachid

                // tmpmf.remotepath = response.attachs[i].path;
                for (int k = 0; k < this.info.caMedias.get(j).attachMedia.size(); k++) {
                  String remoteUrl = this.info.caMedias.get(j).attachMedia.get(k).remotepath;
                  this.info.caMedias.get(j).attachMedia.get(k).remotepath =
                      response.attachs[i].path; // 取得服务器地址
                  // 写入mapping
                  if (response.attachs[i].path != null) {
                    MediaValue tmMV = new MediaValue();
                    tmMV =
                        AccountInfo.getInstance(this.info.userid)
                            .mediamapping
                            .getMedia(this.info.userid, remoteUrl);
                    if (tmMV != null) {
                      Log.d(TAG, "get MediaValue.url=" + tmMV.url);
                      tmMV.url = response.attachs[i].path;
                      AccountInfo.getInstance(this.info.userid)
                          .mediamapping
                          .setMedia(this.info.userid, response.attachs[i].path, tmMV);
                      AccountInfo.getInstance(this.info.userid)
                          .mediamapping
                          .delMedia(this.info.userid, remoteUrl);
                      Log.d(TAG, "set MediaValue.url=" + tmMV.url);
                    }
                  }
                }
              }
            }
            if (this.info.source != 1) {
              // 修改日记结构
              if (myLocalDiary != null && myLocalDiary.attachs != null) {
                DiaryAttach diaryattach = myLocalDiary.attachs;
                // 主
                MainAttach mainattach = diaryattach.levelattach;
                if (mainattach != null) {
                  if (mainattach.attachuuid.equals(response.attachs[i].attachuuid)) {
                    mainattach.attachid = response.attachs[i].attachid;
                    mainattach.attachurl = response.attachs[i].path;
                  }
                }
                // 辅
                AuxAttach[] auxattach = diaryattach.attach;
                if (auxattach != null) {
                  for (int k = 0; k < auxattach.length; k++) {
                    if (auxattach[k].attachuuid.equals(response.attachs[i].attachuuid)) {
                      auxattach[k].attachid = response.attachs[i].attachid;
                      auxattach[k].attachurl = response.attachs[i].path;
                    }
                  }
                }
              }
            }
          }
          if (this.info.source != 1) DiaryManager.getInstance().notifyMyDiaryChanged();

          // 转变正常上传任务
          translateToState(STATE_COMPELETED);
        } else {
          translateToState(ACTION_RETRY);
          return false;
        }
        break;

        // 转变正常上传任务
      case STATE_RUNNING:
        retryTimes = 0;
        break;

      case STATE_PAUSED:
        retryTimes = 0;
        stopThread();
        break;

      case STATE_REMOVED:
        retryTimes = 0;
        stopThread();
        if (taskmanagerListener != null) {
          taskmanagerListener.OnTaskRemoved(this);
        }
        if (mitaskmanagerListener != null) {
          mitaskmanagerListener.OnTaskRemoved(this);
        }
        break;

      case ACTION_RETRY:
        if (retryTimes < 2) {
          retryTimes++;
          ZThread.sleep(500); // 500, 2000, 3500, 5000
          if (getState() == STATE_PAUSED) {
            ZLog.e("Status changed to [" + getState() + "] when retrying!");
            translateToState(STATE_PAUSED);
            break;
          } else if (getState() == STATE_WAITING) {
            ZLog.e("Status changed to [" + getState() + "] when retrying, ignore it!");
            break;
          }
          translateToState(STATE_PREPARING);
          // return是为了不执行 notifyStateChange
          return false;
        } else {
          translateToState(STATE_ERROR);
        }
        break;

        // 转变正常上传任务
      case STATE_COMPELETED:
        retryTimes = 0;
        stopThread();
        Log.d(TAG, "离线任务成功转换成上传任务");
        break;

      case STATE_ERROR:
        break;
    }

    return false;
  }
Ejemplo n.º 2
0
  @Override
  public boolean handleMessage(Message msg) {
    // TODO Auto-generated method stub
    switch (msg.what) {
      case Requester2.RESPONSE_TYPE_MODIFY_TAG:
        Log.d(TAG, "handleMessage  RESPONSE_TYPE_MODIFY_TAG");
        GsonResponse2.modTagsOrPositionResponse tagandpositionResponse =
            (modTagsOrPositionResponse) msg.obj;
        if (tagandpositionResponse != null && "0".equals(tagandpositionResponse.status)) {
          Log.d(TAG, "handleMessage RESPONSE_TYPE_MODIFY_TAG successed");
          DiaryManager diarymanager = DiaryManager.getInstance();
          MyDiary myLocalDiary = diarymanager.findLocalDiaryByUuid(diaryUUID);
          if (myLocalDiary != null) {
            Log.d(TAG, "save myLocalDiary not null");
            myLocalDiary.position = myDiary.position;
            myLocalDiary.tags = getMyDiary().tags;
            DiaryManager.getInstance().diaryDataChanged(myDiary.diaryuuid);
          }
        }
        isTagPositionChangeDone = true;
        saveLocalDiaryAndFinish();
        break;
      case Requester2.RESPONSE_TYPE_CREATE_STRUCTURE:
        Log.d(TAG, "handleMessage RESPONSE_TYPE_CREATE_STRUCTURE");
        structureResponse = (createStructureResponse) msg.obj;

        if (getString(R.string.edit_media_cover).equals(getEditDiaryStyle())) { // 覆盖模式
          if (isDiaryCreated()) {
            if (structureResponse != null && "0".equals(structureResponse.status)) { // 创建日记结构成功
              new CreateDiarySucessedThread().start();
            } else { // 创建日记结构失败
              new CreateDiaryFailedThread().start();
            }
          } else {
            new CreateOfflineDiaryThread().start();
          }
        } else { // 另存为模式
          if (structureResponse != null) { // 创建另存为日记结构成功
            //					Log.d(TAG,"************attachsSize*******" + structureResponse.attachs.length);
            new CreateNewDiaryThread().start();
          }
        }
        break;
      case EditMediaDetailActivity.HANDLER_DISMISS_PROCESS_DIALOG:
        saveLocalDiaryAndFinish();
        break;
      case EditMediaDetailActivity.HANDLER_SOUND_DELETE:
        isDeleteSound = true;
        isAddSoundAttach = false;
        hasShortSound = false;
        checkAuxiliaryAttachEmpty();
        detailMainFragment.processDelShortSoundMsg();
        break;
        /*case DiaryDetailActivity.HANDLER_UPDATE_LONG_RECORD_PLAYER_COMPLETE:
        	isPlaying = false;
        	ivPlay.setImageResource(R.drawable.btn_edit_audio_play);
        	playProcess.setProgress(0);
        	setAudioCurrentTime(0);
        	break;
        case DiaryDetailActivity.HANDLER_UPDATE_LONG_RECORD_PLAYER_PROCESS:
        	if(playProcess!=null) {
        		int progress = (Integer)msg.obj;
        		playProcess.setProgress(progress);
        		setAudioCurrentTime(progress);
        	}
        	break;*/
      case EffectTransCodeUtil.HANDLER_PROCESS_EFFECTS_FINISH:
        Log.d(TAG, "VideoEffectTransCodeUtil.HANDLER_PROCESS_EFFECTS_FINISH");
        if (msg.arg1 == EffectTransCodeUtil.MAIN_AUDIO) {
          if (msg.obj != null) {
            effectAudioPath = (String) msg.obj;
          }
          threadsSignal.countDown();
          Log.d(TAG, "HANDLER_PROCESS_EFFECTS_FINISH SHORT_AUDIO audioPath = " + audioPath);
        } else if (msg.arg1 == EffectTransCodeUtil.SHORT_AUDIO) {
          if (msg.obj != null) {
            audioPath = (String) msg.obj;
          }
          shortAudioSignal.countDown();
          Log.d(TAG, "HANDLER_PROCESS_EFFECTS_FINISH SHORT_AUDIO audioPath = " + audioPath);
        }
        break;
      case EffectTransCodeUtil.HANDLER_PROCESS_EFFECTS_SCHEDULE:
        int percent = msg.arg2;
        Log.d(
            TAG, "VideoEffectTransCodeUtil.HANDLER_PROCESS_EFFECTS_SCHEDULE percent = " + percent);
        if (dialogTitle != null) {
          String titel = "";
          if (msg.arg1 == EffectTransCodeUtil.MAIN_AUDIO) {
            titel = getString(R.string.process_long_record_effect) + " " + percent + "%";
          } else if (msg.arg1 == EffectTransCodeUtil.SHORT_AUDIO) {
            titel = getString(R.string.process_short_record_effect) + " " + percent + "%";
          }
          dialogTitle.setText(titel);
        }
        break;
    }
    return false;
  }