Search in sources :

Example 6 with Loader

use of android.support.v4.content.Loader in project Reader by TheKeeperOfPie.

the class RecyclerFragmentPagerAdapter method restoreState.

@Override
public void restoreState(Parcelable state, ClassLoader loader) {
    if (state != null) {
        Bundle bundle = (Bundle) state;
        bundle.setClassLoader(loader);
        Parcelable[] fss = bundle.getParcelableArray("states");
        savedStates.clear();
        fragments.clear();
        if (fss != null) {
            for (Parcelable fs : fss) {
                savedStates.add((Fragment.SavedState) fs);
            }
        }
        Iterable<String> keys = bundle.keySet();
        for (String key : keys) {
            if (key.startsWith("f")) {
                int index = Integer.parseInt(key.substring(1));
                FragmentType f = (FragmentType) fragmentManager.getFragment(bundle, key);
                if (f != null) {
                    while (fragments.size() <= index) {
                        fragments.add(null);
                    }
                    f.setMenuVisibility(false);
                    fragments.set(index, f);
                } else {
                    Log.w(TAG, "Bad fragment at key " + key);
                }
            }
        }
    }
}
Also used : Bundle(android.os.Bundle) Parcelable(android.os.Parcelable) Fragment(android.support.v4.app.Fragment)

Example 7 with Loader

use of android.support.v4.content.Loader in project android_frameworks_base by ResurrectionRemix.

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 8 with Loader

use of android.support.v4.content.Loader in project Sunshine-Version-2 by udacity.

the class ForecastFragment method onCreateLoader.

@Override
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
    // This is called when a new Loader needs to be created.  This
    // fragment only uses one loader, so we don't care about checking the id.
    // To only show current and future dates, filter the query to return weather only for
    // dates after or including today.
    // Sort order:  Ascending, by date.
    String sortOrder = WeatherContract.WeatherEntry.COLUMN_DATE + " ASC";
    String locationSetting = Utility.getPreferredLocation(getActivity());
    Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(locationSetting, System.currentTimeMillis());
    return new CursorLoader(getActivity(), weatherForLocationUri, FORECAST_COLUMNS, null, null, sortOrder);
}
Also used : CursorLoader(android.support.v4.content.CursorLoader) Uri(android.net.Uri)

Example 9 with Loader

use of android.support.v4.content.Loader in project Android-DialogFragments by wada811.

the class LoaderSpinnerProgressDialogFragmentExamplesActivity method onLoadFinished.

@Override
public void onLoadFinished(Loader<Object> loader, Object o) {
    Log.i(TAG, "onLoadFinished");
    getSupportLoaderManager().destroyLoader(loader.getId());
    Fragment fragment = getSupportFragmentManager().findFragmentByTag(ProgressDialogFragment.TAG);
    if (fragment != null) {
        ProgressDialogFragment dialogFragment = (ProgressDialogFragment) fragment;
        dialogFragment.dismissAllowingStateLoss();
    }
}
Also used : ProgressDialogFragment(com.wada811.android.dialogfragments.material.ProgressDialogFragment) ProgressDialogFragment(com.wada811.android.dialogfragments.material.ProgressDialogFragment) Fragment(android.support.v4.app.Fragment)

Example 10 with Loader

use of android.support.v4.content.Loader in project Android-DialogFragments by wada811.

the class LoaderSpinnerProgressDialogFragmentExamplesActivity method onLoaderReset.

@Override
public void onLoaderReset(Loader<Object> loader) {
    Log.i(TAG, "onLoaderReset");
    getSupportLoaderManager().destroyLoader(loader.getId());
    Fragment fragment = getSupportFragmentManager().findFragmentByTag(ProgressDialogFragment.TAG);
    if (fragment != null) {
        ProgressDialogFragment dialogFragment = (ProgressDialogFragment) fragment;
        dialogFragment.dismissAllowingStateLoss();
    }
}
Also used : ProgressDialogFragment(com.wada811.android.dialogfragments.material.ProgressDialogFragment) ProgressDialogFragment(com.wada811.android.dialogfragments.material.ProgressDialogFragment) Fragment(android.support.v4.app.Fragment)

Aggregations

Bundle (android.os.Bundle)16 Fragment (android.support.v4.app.Fragment)16 CursorLoader (android.support.v4.content.CursorLoader)11 View (android.view.View)7 Context (android.content.Context)6 Parcelable (android.os.Parcelable)6 RecyclerView (android.support.v7.widget.RecyclerView)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 ActivityManager (android.app.ActivityManager)5 Point (android.graphics.Point)5 AccessibilityNodeInfoCompat (android.support.v4.view.accessibility.AccessibilityNodeInfoCompat)5 GridLayoutManager (android.support.v7.widget.GridLayoutManager)5 SpanSizeLookup (android.support.v7.widget.GridLayoutManager.SpanSizeLookup)5 Recycler (android.support.v7.widget.RecyclerView.Recycler)5 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)5 DocumentClipper (com.android.documentsui.DocumentClipper)5 State (com.android.documentsui.State)5 Selection (com.android.documentsui.dirlist.MultiSelectManager.Selection)5 Cursor (android.database.Cursor)4