Exemplo n.º 1
0
 /**
  * This method lists files of certain directory by starting a new ListFileTask.
  *
  * @param activityName name of activity, which the ListFileTask attached to
  * @param path the path of certain directory
  * @param listener listener of the ListFileTask
  */
 public void listFiles(String activityName, String path, OperationEventListener listener) {
   LogUtils.d(TAG, "listFiles,activityName = " + activityName + ",path = " + path);
   /*if (isBusy(activityName)) {
        LogUtils.d(TAG, "listFiles,task is busy. ");
        listener.onTaskResult(OperationEventListener.ERROR_CODE_BUSY);
   } else {*/
   if (isBusy(activityName)) {
     LogUtils.d(TAG, "listFiles, cancel other background task...");
     BaseAsyncTask task = getActivityInfo(activityName).getTask();
     if (task != null) {
       task.removeListener();
       task.cancel(true);
     }
   }
   LogUtils.d(TAG, "listFiles,do list.");
   FileInfoManager fileInfoManager = getActivityInfo(activityName).getFileInfoManager();
   int filterType = getActivityInfo(activityName).getFilterType();
   if (fileInfoManager != null) {
     LogUtils.d(TAG, "listFiles fiterType = " + filterType);
     BaseAsyncTask task =
         new ListFileTask(getApplicationContext(), fileInfoManager, listener, path, filterType);
     getActivityInfo(activityName).setTask(task);
     task.execute();
   }
   // }
 }
Exemplo n.º 2
0
 /**
  * This method reconnects to the running task by setting a new listener to the task, when dialog
  * is destroyed and recreated
  *
  * @param activityName name of activity, which the task and dialog attached to
  * @param listener new listener for the task and dialog
  */
 public void reconnected(String activityName, OperationEventListener listener) {
   LogUtils.d(TAG, "reconnected,activityName = " + activityName);
   BaseAsyncTask task = getActivityInfo(activityName).getTask();
   if (task != null) {
     task.setListener(listener);
   }
 }
Exemplo n.º 3
0
 /**
  * This method removes listener from task when service disconnected.
  *
  * @param activityName name of activity, which the task attached to
  */
 public void disconnected(String activityName) {
   LogUtils.d(TAG, "disconnected,activityName = " + activityName);
   BaseAsyncTask task = getActivityInfo(activityName).getTask();
   if (task != null) {
     task.removeListener();
   }
 }
Exemplo n.º 4
0
 /**
  * This method cancel certain task
  *
  * @param activityName name of activity, which the task attached to
  */
 public void cancel(String activityName) {
   LogUtils.d(TAG, " cancel service,activityName = " + activityName);
   BaseAsyncTask task = getActivityInfo(activityName).getTask();
   if (task != null) {
     task.cancel(true);
   }
 }
Exemplo n.º 5
0
 /**
  * This method does paste job by starting a new CutPasteFilesTask or CopyPasteFilesTask according
  * to parameter of type
  *
  * @param activityName name of activity, which the task and operations attached to
  * @param fileInfoList list of files which needs to be paste
  * @param dstFolder destination, which the files should be paste to
  * @param type indicate the previous operation is cut or copy
  * @param listener listener of the started task
  */
 public void pasteFiles(
     String activityName,
     List<FileInfo> fileInfoList,
     String dstFolder,
     int type,
     OperationEventListener listener) {
   LogUtils.d(TAG, " pasteFiles Start,activityName = " + activityName);
   if (isBusy(activityName)) {
     listener.onTaskResult(OperationEventListener.ERROR_CODE_BUSY);
     return;
   }
   if (filterPasteList(fileInfoList, dstFolder) > 0) {
     listener.onTaskResult(OperationEventListener.ERROR_CODE_PASTE_TO_SUB);
   }
   FileInfoManager fileInfoManager = getActivityInfo(activityName).getFileInfoManager();
   if (fileInfoManager == null) {
     LogUtils.w(TAG, "mFileInfoManagerMap.get FileInfoManager = null");
     listener.onTaskResult(OperationEventListener.ERROR_CODE_UNKOWN);
     return;
   }
   BaseAsyncTask task = null;
   if (fileInfoList.size() > 0) {
     switch (type) {
       case FileInfoManager.PASTE_MODE_CUT:
         if (isCutSamePath(fileInfoList, dstFolder)) {
           listener.onTaskResult(OperationEventListener.ERROR_CODE_CUT_SAME_PATH);
           return;
         }
         task =
             new CutPasteFilesTask(
                 fileInfoManager, listener, getApplicationContext(), fileInfoList, dstFolder);
         getActivityInfo(activityName).setTask(task);
         task.execute();
         break;
       case FileInfoManager.PASTE_MODE_COPY:
         task =
             new CopyPasteFilesTask(
                 fileInfoManager, listener, getApplicationContext(), fileInfoList, dstFolder);
         getActivityInfo(activityName).setTask(task);
         task.execute();
         break;
       default:
         listener.onTaskResult(OperationEventListener.ERROR_CODE_UNKOWN);
         return;
     }
   }
 }
Exemplo n.º 6
0
 /**
  * This method gets detail information of a file (or directory) by starting a new DetailInfotask.
  *
  * @param activityName name of activity, which the task and operations attached to
  * @param file a certain file (or directory)
  * @param listener listener of the DetailInfotask
  */
 public void getDetailInfo(String activityName, FileInfo file, OperationEventListener listener) {
   LogUtils.d(TAG, "getDetailInfo,activityName = " + activityName);
   if (isBusy(activityName)) {
     listener.onTaskResult(OperationEventListener.ERROR_CODE_BUSY);
   } else {
     FileInfoManager fileInfoManager = getActivityInfo(activityName).getFileInfoManager();
     if (fileInfoManager != null) {
       BaseAsyncTask task = new DetailInfoTask(fileInfoManager, listener, file);
       getActivityInfo(activityName).setTask(task);
       task.execute();
     }
   }
 }
Exemplo n.º 7
0
 /**
  * This method checks that weather the service is busy or not, which means id any task exist for
  * certain activity
  *
  * @param activityName name of activity, which will be checked
  * @return true for busy, false for not busy
  */
 public boolean isBusy(String activityName) {
   boolean ret = false;
   FileManagerActivityInfo activityInfo = mActivityMap.get(activityName);
   if (activityInfo == null) {
     LogUtils.w(TAG, "isBusy return false,because activityInfo is null!");
     return ret;
   }
   BaseAsyncTask task = activityInfo.getTask();
   if (task != null) {
     return task.isTaskBusy();
   }
   return false;
 }
Exemplo n.º 8
0
 /**
  * This method does delete job by starting a new DeleteFilesTask.
  *
  * @param activityName name of activity, which the operations attached to
  * @param fileInfoList list of files, which needs to be deleted
  * @param listener listener of the DeleteFilesTask
  */
 public void deleteFiles(
     String activityName, List<FileInfo> fileInfoList, OperationEventListener listener) {
   LogUtils.d(TAG, " deleteFiles Start,activityName = " + activityName);
   if (isBusy(activityName)) {
     listener.onTaskResult(OperationEventListener.ERROR_CODE_BUSY);
   } else {
     FileInfoManager fileInfoManager = getActivityInfo(activityName).getFileInfoManager();
     if (fileInfoManager != null) {
       BaseAsyncTask task = new DeleteFilesTask(fileInfoManager, listener, this, fileInfoList);
       getActivityInfo(activityName).setTask(task);
       task.execute();
     }
   }
 }
Exemplo n.º 9
0
 /**
  * This method does create folder job by starting a new CreateFolderTask
  *
  * @param activityName name of activity, which the CreateFolderTask attached to
  * @param destFolder information of file, which needs to be created
  * @param listener listener of CreateFolderTask
  */
 public void createFolder(
     String activityName, String destFolder, OperationEventListener listener) {
   LogUtils.d(TAG, " createFolder Start ");
   if (isBusy(activityName)) {
     listener.onTaskResult(OperationEventListener.ERROR_CODE_BUSY);
   } else {
     FileInfoManager fileInfoManager = getActivityInfo(activityName).getFileInfoManager();
     int filterType = getActivityInfo(activityName).getFilterType();
     if (fileInfoManager != null) {
       BaseAsyncTask task =
           new CreateFolderTask(fileInfoManager, listener, this, destFolder, filterType);
       getActivityInfo(activityName).setTask(task);
       task.execute();
     }
   }
 }
Exemplo n.º 10
0
  /**
   * This method does rename job by starting a new RenameTask
   *
   * @param activityName name of activity, which the operations attached to
   * @param srcFile information of certain file, which needs to be renamed
   * @param dstFile information of new file after rename
   * @param listener listener of RenameTask
   */
  public void rename(
      String activityName, FileInfo srcFile, FileInfo dstFile, OperationEventListener listener) {
    LogUtils.d(TAG, " rename Start,activityName = " + activityName);

    if (isBusy(activityName)) {
      listener.onTaskResult(OperationEventListener.ERROR_CODE_BUSY);
    } else {
      FileInfoManager fileInfoManager = getActivityInfo(activityName).getFileInfoManager();
      int filterType = getActivityInfo(activityName).getFilterType();
      if (fileInfoManager != null) {
        BaseAsyncTask task =
            new RenameTask(fileInfoManager, listener, this, srcFile, dstFile, filterType);
        getActivityInfo(activityName).setTask(task);
        task.execute();
      }
    }
  }
Exemplo n.º 11
0
 /**
  * This method do search job by starting a new search task
  *
  * @param activityName name of activity which starts the search
  * @param searchName the search target
  * @param path the path to limit the search in
  * @param operationEvent the listener corresponds to this search task
  */
 public void search(
     String activityName, String searchName, String path, OperationEventListener operationEvent) {
   LogUtils.d(
       TAG,
       "search, activityName = "
           + activityName
           + ",searchName = "
           + searchName
           + ",path = "
           + path);
   if (isBusy(activityName)) {
     cancel(activityName);
     // operationEvent.onTaskResult(OperationEventListener.ERROR_CODE_BUSY);
   } else {
     FileInfoManager fileInfoManager = getActivityInfo(activityName).getFileInfoManager();
     if (fileInfoManager != null) {
       BaseAsyncTask task =
           new SearchTask(fileInfoManager, operationEvent, searchName, path, getContentResolver());
       getActivityInfo(activityName).setTask(task);
       task.execute();
     }
   }
 }
Exemplo n.º 12
0
 @Override
 public int onStartCommand(Intent intent, int flags, int startId) {
   LogUtils.d(TAG, "onStartCommand...");
   super.onStartCommand(intent, flags, startId);
   return START_NOT_STICKY;
 }