示例#1
0
  private void onCurrentDirectoryChanged(int anim) {
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    final DocumentInfo cwd = getCurrentDirectory();

    mDirectoryContainer.setDrawDisappearingFirst(anim == ANIM_DOWN);

    if (cwd == null) {
      // No directory means recents
      if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) {
        RecentsCreateFragment.show(fm);
      } else {
        DirectoryFragment.showRecentsOpen(fm, anim);

        /// M: When state has stored, we need use store state to init fragment(this may happen when
        // activity
        /// re-create, in this case we need use the userMode store in saveInstance, and only when
        // activity
        /// first created we need follow the below design. {@
        if (!mState.restored) {
          // Start recents in grid when requesting visual things
          final boolean visualMimes =
              MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, mState.acceptMimes);
          mState.userMode = visualMimes ? MODE_GRID : MODE_LIST;
          mState.derivedMode = mState.userMode;
        }
        /// @}
      }
    } else {
      if (mState.currentSearch != null) {
        // Ongoing search
        DirectoryFragment.showSearch(fm, root, mState.currentSearch, anim);
      } else {
        // Normal boring directory
        DirectoryFragment.showNormal(fm, root, cwd, anim);
      }
    }

    // Forget any replacement target
    if (mState.action == ACTION_CREATE) {
      final SaveFragment save = SaveFragment.get(fm);
      if (save != null) {
        save.setReplaceTarget(null);
      }
    }

    if (mState.action == ACTION_OPEN_TREE) {
      final PickFragment pick = PickFragment.get(fm);
      if (pick != null) {
        final CharSequence displayName = (mState.stack.size() <= 1) ? root.title : cwd.displayName;
        pick.setPickTarget(cwd, displayName);
      }
    }

    final RootsFragment roots = RootsFragment.get(fm);
    if (roots != null) {
      roots.onCurrentRootChanged();
    }

    updateActionBar();
    invalidateOptionsMenu();
    dumpStack();
  }
示例#2
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);
  }