Esempio n. 1
1
  public void onDocumentPicked(DocumentInfo doc) {
    final FragmentManager fm = getFragmentManager();
    if (doc.isDirectory()) {
      mState.stack.push(doc);
      mState.stackTouched = true;
      onCurrentDirectoryChanged(ANIM_DOWN);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
      // Explicit file picked, return
      new ExistingFinishTask(doc.derivedUri).executeOnExecutor(getCurrentExecutor());
    } else if (mState.action == ACTION_CREATE) {
      // Replace selected file
      SaveFragment.get(fm).setReplaceTarget(doc);
    } else if (mState.action == ACTION_MANAGE) {
      // First try managing the document; we expect manager to filter
      // based on authority, so we don't grant.
      final Intent manage = new Intent(DocumentsContract.ACTION_MANAGE_DOCUMENT);
      manage.setData(doc.derivedUri);

      try {
        startActivity(manage);
      } catch (ActivityNotFoundException ex) {
        // Fall back to viewing
        final Intent view = new Intent(Intent.ACTION_VIEW);
        view.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        view.setData(doc.derivedUri);

        try {
          startActivity(view);
        } catch (ActivityNotFoundException ex2) {
          /// M: Show toast with enhance way.
          showToast(R.string.toast_no_application);
        }
      }
    }
  }
Esempio n. 2
0
 @Override
 protected DocumentInfo doInBackground(Void... params) {
   try {
     final Uri uri = DocumentsContract.buildDocumentUri(mRoot.authority, mRoot.documentId);
     return DocumentInfo.fromUri(getContentResolver(), uri);
   } catch (FileNotFoundException e) {
     Log.w(TAG, "Failed to find root", e);
     return null;
   }
 }
  /** Borrowed from TimSort.binarySort(), but modified to sort two column dataset. */
  private static void binarySort(int[] position, String[] value) {
    final int count = position.length;
    for (int start = 1; start < count; start++) {
      final int pivotPosition = position[start];
      final String pivotValue = value[start];

      int left = 0;
      int right = start;

      while (left < right) {
        int mid = (left + right) >>> 1;

        final String lhs = pivotValue;
        final String rhs = value[mid];
        final int compare = DocumentInfo.compareToIgnoreCaseNullable(lhs, rhs);

        if (compare < 0) {
          right = mid;
        } else {
          left = mid + 1;
        }
      }

      int n = start - left;
      switch (n) {
        case 2:
          position[left + 2] = position[left + 1];
          value[left + 2] = value[left + 1];
        case 1:
          position[left + 1] = position[left];
          value[left + 1] = value[left];
          break;
        default:
          System.arraycopy(position, left, position, left + 1, n);
          System.arraycopy(value, left, value, left + 1, n);
      }

      position[left] = pivotPosition;
      value[left] = pivotValue;
    }
  }
  /** Applies the state of fragment to the view components. */
  private void updateView() {
    switch (mAction) {
      case BaseActivity.State.ACTION_OPEN_TREE:
        mPick.setText(R.string.button_select);
        mCancel.setVisibility(View.GONE);
        break;
      case BaseActivity.State.ACTION_OPEN_COPY_DESTINATION:
        mPick.setText(R.string.button_copy);
        mCancel.setVisibility(View.VISIBLE);
        break;
      default:
        mContainer.setVisibility(View.GONE);
        return;
    }

    if (mPickTarget != null
        && (mAction == BaseActivity.State.ACTION_OPEN_TREE || mPickTarget.isCreateSupported())) {
      mContainer.setVisibility(View.VISIBLE);
    } else {
      mContainer.setVisibility(View.GONE);
    }
  }
Esempio n. 5
0
  @Override
  public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    final FragmentManager fm = getFragmentManager();

    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();

    final MenuItem createDir = menu.findItem(R.id.menu_create_dir);
    final MenuItem search = menu.findItem(R.id.menu_search);
    final MenuItem sort = menu.findItem(R.id.menu_sort);
    final MenuItem sortSize = menu.findItem(R.id.menu_sort_size);
    final MenuItem grid = menu.findItem(R.id.menu_grid);
    final MenuItem list = menu.findItem(R.id.menu_list);
    final MenuItem advanced = menu.findItem(R.id.menu_advanced);
    final MenuItem fileSize = menu.findItem(R.id.menu_file_size);

    sort.setVisible(cwd != null);
    grid.setVisible(mState.derivedMode != MODE_GRID);
    list.setVisible(mState.derivedMode != MODE_LIST);

    if (mState.currentSearch != null) {
      // Search uses backend ranking; no sorting
      sort.setVisible(false);

      search.expandActionView();

      mSearchView.setIconified(false);
      mSearchView.clearFocus();
      mSearchView.setQuery(mState.currentSearch, false);
    } else {
      mIgnoreNextClose = true;
      mSearchView.setIconified(true);
      mSearchView.clearFocus();

      mIgnoreNextCollapse = true;
      search.collapseActionView();
    }

    // Only sort by size when visible
    sortSize.setVisible(mState.showSize);

    final boolean searchVisible;
    if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) {
      createDir.setVisible(cwd != null && cwd.isCreateSupported());
      searchVisible = false;

      // No display options in recent directories
      if (cwd == null) {
        grid.setVisible(false);
        list.setVisible(false);
      }

      if (mState.action == ACTION_CREATE) {
        /// M: add to avoid seldom NullPointerException
        SaveFragment saveFragment = SaveFragment.get(fm);
        if (null != saveFragment) {
          saveFragment.setSaveEnabled(cwd != null && cwd.isCreateSupported());
        } else {
          Log.e(TAG, "onPrepareOptionsMenu, SaveFragment is null");
        }
      }
    } else {
      createDir.setVisible(false);

      searchVisible = root != null && ((root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0);
    }

    // TODO: close any search in-progress when hiding
    search.setVisible(searchVisible);

    advanced.setTitle(
        LocalPreferences.getDisplayAdvancedDevices(this)
            ? R.string.menu_advanced_hide
            : R.string.menu_advanced_show);
    fileSize.setTitle(
        LocalPreferences.getDisplayFileSize(this)
            ? R.string.menu_file_size_hide
            : R.string.menu_file_size_show);

    /// M: If in force show advance mode, need hide advance menu
    advanced.setVisible(mState.action != ACTION_MANAGE && !mState.forceAdvanced);
    /// M: If cmd == null and mState.action == ACTION_CREATE, it means show
    /// RecentsCreateFragment, we need hide file size menu to avoid exception
    fileSize.setVisible(
        mState.action != ACTION_MANAGE && !(cwd == null && mState.action == ACTION_CREATE));

    return true;
  }