Пример #1
0
    public void runInternal() {
      ContentProviderClient client = null;
      try {
        client =
            DocumentsApplication.acquireUnstableProviderOrThrow(
                getContext().getContentResolver(), authority);

        final Uri uri = DocumentsContract.buildRecentDocumentsUri(authority, rootId);
        final Cursor cursor =
            client.query(uri, null, null, null, DirectoryLoader.getQuerySortOrder(mSortOrder));
        mWithRoot = new RootCursorWrapper(authority, rootId, cursor, MAX_DOCS_FROM_ROOT);

      } catch (Exception e) {
        Log.w(TAG, "Failed to load " + authority + ", " + rootId, e);
      } finally {
        ContentProviderClient.releaseQuietly(client);
      }

      set(mWithRoot);

      mFirstPassLatch.countDown();
      /// M: FOR ALPS01480274 @{
      if (mFirstPassDone && !mUiHandler.hasMessages(CONTENT_CHANGE)) {
        mUiHandler.sendEmptyMessage(CONTENT_CHANGE);
      }
      /// @}
    }
Пример #2
0
    @Override
    protected Uri doInBackground(Void... params) {
      final ContentResolver resolver = getContentResolver();
      final DocumentInfo cwd = getCurrentDirectory();

      ContentProviderClient client = null;
      Uri childUri = null;
      try {
        client =
            DocumentsApplication.acquireUnstableProviderOrThrow(
                resolver, cwd.derivedUri.getAuthority());
        childUri =
            DocumentsContract.createDocument(client, cwd.derivedUri, mMimeType, mDisplayName);
      } catch (Exception e) {
        Log.w(TAG, "Failed to create document", e);
      } finally {
        ContentProviderClient.releaseQuietly(client);
      }

      if (childUri != null) {
        saveStackBlocking();
      }

      return childUri;
    }
Пример #3
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    mRoots = DocumentsApplication.getRootsCache(this);

    setResult(Activity.RESULT_CANCELED);
    setContentView(R.layout.activity);

    final Context context = this;
    final Resources res = getResources();
    mShowAsDialog = res.getBoolean(R.bool.show_as_dialog);

    if (mShowAsDialog) {
      // Strongly define our horizontal dimension; we leave vertical as
      // WRAP_CONTENT so that system resizes us when IME is showing.
      final WindowManager.LayoutParams a = getWindow().getAttributes();

      final Point size = new Point();
      getWindowManager().getDefaultDisplay().getSize(size);
      a.width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x);

      getWindow().setAttributes(a);

    } else {
      // Non-dialog means we have a drawer
      mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

      mDrawerToggle =
          new ActionBarDrawerToggle(
              this,
              mDrawerLayout,
              R.drawable.ic_hamburger,
              R.string.drawer_open,
              R.string.drawer_close);

      mDrawerLayout.setDrawerListener(mDrawerListener);

      mRootsDrawer = findViewById(R.id.drawer_roots);
    }

    mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory);

    if (icicle != null) {
      mState = icicle.getParcelable(EXTRA_STATE);
    } else {
      buildDefaultState();
    }

    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setTitleTextAppearance(
        context, android.R.style.TextAppearance_DeviceDefault_Widget_ActionBar_Title);
    /// M: add log to print intent info
    Intent intent = getIntent();
    Log.d(
        TAG,
        "onCreate: intent = "
            + intent
            + ", extra = "
            + (intent != null ? intent.getExtras() : null));

    mToolbarStack = (Spinner) findViewById(R.id.stack);
    mToolbarStack.setOnItemSelectedListener(mStackListener);

    mRootsToolbar = (Toolbar) findViewById(R.id.roots_toolbar);
    if (mRootsToolbar != null) {
      mRootsToolbar.setTitleTextAppearance(
          context, android.R.style.TextAppearance_DeviceDefault_Widget_ActionBar_Title);
    }

    setActionBar(mToolbar);

    // Hide roots when we're managing a specific root
    if (mState.action == ACTION_MANAGE) {
      if (mShowAsDialog) {
        findViewById(R.id.container_roots).setVisibility(View.GONE);
      } else {
        mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
      }
    }

    if (mState.action == ACTION_CREATE) {
      final String mimeType = getIntent().getType();
      final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE);
      SaveFragment.show(getFragmentManager(), mimeType, title);
    } else if (mState.action == ACTION_OPEN_TREE) {
      PickFragment.show(getFragmentManager());
    }

    if (mState.action == ACTION_GET_CONTENT) {
      final Intent moreApps = new Intent(getIntent());
      moreApps.setComponent(null);
      moreApps.setPackage(null);
      RootsFragment.show(getFragmentManager(), moreApps);
    } else if (mState.action == ACTION_OPEN
        || mState.action == ACTION_CREATE
        || mState.action == ACTION_OPEN_TREE) {
      RootsFragment.show(getFragmentManager(), null);
    }

    if (!mState.restored) {
      /// M: If show ad ACTION_MANAGE, hide default title to avoid show to user
      setTitle(null);
      if (mState.action == ACTION_MANAGE) {
        final Uri rootUri = getIntent().getData();
        new RestoreRootTask(rootUri).executeOnExecutor(getCurrentExecutor());
      } else {
        new RestoreStackTask().execute();
      }
    } else {
      onCurrentDirectoryChanged(ANIM_NONE);
    }
    /// M: update action bar when roots are reloaded @{
    mRoots.addCallback(mRootUpdatedListener);
  }