Search in sources :

Example 16 with State

use of com.android.documentsui.State in project platform_frameworks_base by android.

the class DirectoryFragment method onLoadFinished.

@Override
public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
    if (!isAdded())
        return;
    if (mSearchMode) {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SEARCH);
    }
    State state = getDisplayState();
    mAdapter.notifyDataSetChanged();
    mModel.update(result);
    state.derivedSortOrder = result.sortOrder;
    updateLayout(state.derivedMode);
    if (mSelection != null) {
        mSelectionManager.setItemsSelected(mSelection.toList(), true);
        mSelection.clear();
    }
    // Restore any previous instance state
    final SparseArray<Parcelable> container = state.dirState.remove(mStateKey);
    if (container != null && !getArguments().getBoolean(Shared.EXTRA_IGNORE_STATE, false)) {
        getView().restoreHierarchyState(container);
    } else if (mLastSortOrder != state.derivedSortOrder) {
        // The derived sort order takes the user sort order into account, but applies
        // directory-specific defaults when the user doesn't explicitly set the sort
        // order. Scroll to the top if the sort order actually changed.
        mRecView.smoothScrollToPosition(0);
    }
    mLastSortOrder = state.derivedSortOrder;
    mTuner.onModelLoaded(mModel, mType, mSearchMode);
}
Also used : State(com.android.documentsui.State) Parcelable(android.os.Parcelable)

Example 17 with State

use of com.android.documentsui.State in project platform_frameworks_base by android.

the class DirectoryFragment method onStop.

@Override
public void onStop() {
    super.onStop();
    // Remember last scroll location
    final SparseArray<Parcelable> container = new SparseArray<Parcelable>();
    getView().saveHierarchyState(container);
    final State state = getDisplayState();
    state.dirState.put(mStateKey, container);
}
Also used : SparseArray(android.util.SparseArray) State(com.android.documentsui.State) Parcelable(android.os.Parcelable)

Example 18 with State

use of com.android.documentsui.State in project android_frameworks_base by AOSPA.

the class DirectoryFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final Context context = getActivity();
    final State state = getDisplayState();
    // Read arguments when object created for the first time.
    // Restore state if fragment recreated.
    Bundle args = savedInstanceState == null ? getArguments() : savedInstanceState;
    mRoot = args.getParcelable(Shared.EXTRA_ROOT);
    mDocument = args.getParcelable(Shared.EXTRA_DOC);
    mStateKey = buildStateKey(mRoot, mDocument);
    mQuery = args.getString(Shared.EXTRA_QUERY);
    mType = args.getInt(Shared.EXTRA_TYPE);
    final Selection selection = args.getParcelable(Shared.EXTRA_SELECTION);
    mSelection = selection != null ? selection : new Selection();
    mSearchMode = args.getBoolean(Shared.EXTRA_SEARCH_MODE);
    mIconHelper = new IconHelper(context, MODE_GRID);
    mAdapter = new SectionBreakDocumentsAdapterWrapper(this, new ModelBackedDocumentsAdapter(this, mIconHelper));
    mRecView.setAdapter(mAdapter);
    // Switch Access Accessibility API needs an {@link AccessibilityDelegate} to know the proper
    // route when user selects an UI element. It usually guesses this if the element has an
    // {@link OnClickListener}, but since we do not have one for itemView, we will need to
    // manually route it to the right behavior. RecyclerView has its own AccessibilityDelegate,
    // and routes it to its LayoutManager; so we must override the LayoutManager's accessibility
    // methods to route clicks correctly.
    mLayout = new GridLayoutManager(getContext(), mColumnCount) {

        @Override
        public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfoForItem(recycler, state, host, info);
            info.addAction(AccessibilityActionCompat.ACTION_CLICK);
        }

        @Override
        public boolean performAccessibilityActionForItem(RecyclerView.Recycler recycler, RecyclerView.State state, View view, int action, Bundle args) {
            // We are only handling click events; route all other to default implementation
            if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) {
                RecyclerView.ViewHolder vh = mRecView.getChildViewHolder(view);
                if (vh instanceof DocumentHolder) {
                    DocumentHolder dh = (DocumentHolder) vh;
                    if (dh.mEventListener != null) {
                        dh.mEventListener.onActivate(dh);
                        return true;
                    }
                }
            }
            return super.performAccessibilityActionForItem(recycler, state, view, action, args);
        }
    };
    SpanSizeLookup lookup = mAdapter.createSpanSizeLookup();
    if (lookup != null) {
        mLayout.setSpanSizeLookup(lookup);
    }
    mRecView.setLayoutManager(mLayout);
    mGestureDetector = new ListeningGestureDetector(this.getContext(), mDragHelper, new GestureListener());
    mRecView.addOnItemTouchListener(mGestureDetector);
    // TODO: instead of inserting the view into the constructor, extract listener-creation code
    // and set the listener on the view after the fact.  Then the view doesn't need to be passed
    // into the selection manager.
    mSelectionManager = new MultiSelectManager(mRecView, mAdapter, state.allowMultiple ? MultiSelectManager.MODE_MULTIPLE : MultiSelectManager.MODE_SINGLE, null);
    mSelectionManager.addCallback(new SelectionModeListener());
    mModel = new Model();
    mModel.addUpdateListener(mAdapter);
    mModel.addUpdateListener(mModelUpdateListener);
    // Make sure this is done after the RecyclerView is set up.
    mFocusManager = new FocusManager(context, mRecView, mModel);
    mTuner = FragmentTuner.pick(getContext(), state);
    mClipper = new DocumentClipper(context);
    final ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    boolean svelte = am.isLowRamDevice() && (mType == TYPE_RECENT_OPEN);
    mIconHelper.setThumbnailsEnabled(!svelte);
    // Kick off loader at least once
    getLoaderManager().restartLoader(LOADER_ID, null, this);
}
Also used : Selection(com.android.documentsui.dirlist.MultiSelectManager.Selection) ActivityManager(android.app.ActivityManager) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) Context(android.content.Context) Bundle(android.os.Bundle) AccessibilityNodeInfoCompat(android.support.v4.view.accessibility.AccessibilityNodeInfoCompat) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) TextView(android.widget.TextView) Recycler(android.support.v7.widget.RecyclerView.Recycler) Point(android.graphics.Point) SpanSizeLookup(android.support.v7.widget.GridLayoutManager.SpanSizeLookup) DocumentClipper(com.android.documentsui.DocumentClipper) GridLayoutManager(android.support.v7.widget.GridLayoutManager) State(com.android.documentsui.State) RecyclerView(android.support.v7.widget.RecyclerView)

Example 19 with State

use of com.android.documentsui.State in project android_frameworks_base by AOSPA.

the class DirectoryFragment method onCreateLoader.

@Override
public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
    Context context = getActivity();
    State state = getDisplayState();
    Uri contentsUri;
    switch(mType) {
        case TYPE_NORMAL:
            contentsUri = mSearchMode ? DocumentsContract.buildSearchDocumentsUri(mRoot.authority, mRoot.rootId, mQuery) : DocumentsContract.buildChildDocumentsUri(mDocument.authority, mDocument.documentId);
            if (mTuner.managedModeEnabled()) {
                contentsUri = DocumentsContract.setManageMode(contentsUri);
            }
            return new DirectoryLoader(context, mType, mRoot, mDocument, contentsUri, state.userSortOrder, mSearchMode);
        case TYPE_RECENT_OPEN:
            final RootsCache roots = DocumentsApplication.getRootsCache(context);
            return new RecentsLoader(context, roots, state);
        default:
            throw new IllegalStateException("Unknown type " + mType);
    }
}
Also used : Context(android.content.Context) RootsCache(com.android.documentsui.RootsCache) RecentsLoader(com.android.documentsui.RecentsLoader) DirectoryLoader(com.android.documentsui.DirectoryLoader) State(com.android.documentsui.State) Uri(android.net.Uri)

Example 20 with State

use of com.android.documentsui.State in project android_frameworks_base by AOSPA.

the class DirectoryFragment method onLoadFinished.

@Override
public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
    if (!isAdded())
        return;
    if (mSearchMode) {
        Metrics.logUserAction(getContext(), Metrics.USER_ACTION_SEARCH);
    }
    State state = getDisplayState();
    mAdapter.notifyDataSetChanged();
    mModel.update(result);
    state.derivedSortOrder = result.sortOrder;
    updateLayout(state.derivedMode);
    if (mSelection != null) {
        mSelectionManager.setItemsSelected(mSelection.toList(), true);
        mSelection.clear();
    }
    // Restore any previous instance state
    final SparseArray<Parcelable> container = state.dirState.remove(mStateKey);
    if (container != null && !getArguments().getBoolean(Shared.EXTRA_IGNORE_STATE, false)) {
        getView().restoreHierarchyState(container);
    } else if (mLastSortOrder != state.derivedSortOrder) {
        // The derived sort order takes the user sort order into account, but applies
        // directory-specific defaults when the user doesn't explicitly set the sort
        // order. Scroll to the top if the sort order actually changed.
        mRecView.smoothScrollToPosition(0);
    }
    mLastSortOrder = state.derivedSortOrder;
    mTuner.onModelLoaded(mModel, mType, mSearchMode);
}
Also used : State(com.android.documentsui.State) Parcelable(android.os.Parcelable)

Aggregations

State (com.android.documentsui.State)35 Context (android.content.Context)15 Parcelable (android.os.Parcelable)10 ActivityManager (android.app.ActivityManager)5 Cursor (android.database.Cursor)5 Point (android.graphics.Point)5 Uri (android.net.Uri)5 Bundle (android.os.Bundle)5 AccessibilityNodeInfoCompat (android.support.v4.view.accessibility.AccessibilityNodeInfoCompat)5 GridLayoutManager (android.support.v7.widget.GridLayoutManager)5 SpanSizeLookup (android.support.v7.widget.GridLayoutManager.SpanSizeLookup)5 RecyclerView (android.support.v7.widget.RecyclerView)5 Recycler (android.support.v7.widget.RecyclerView.Recycler)5 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)5 SparseArray (android.util.SparseArray)5 LayoutInflater (android.view.LayoutInflater)5 View (android.view.View)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 DirectoryLoader (com.android.documentsui.DirectoryLoader)5