FileDocCategorySizeDatePackage
BaseSupportFragment.javaAPI DocAndroid 5.1 API6656Thu Mar 12 22:22:56 GMT 2015android.support.v17.leanback.app

BaseSupportFragment

public class BaseSupportFragment extends android.support.v4.app.Fragment
hide

Fields Summary
private boolean
mEntranceTransitionEnabled
private boolean
mStartEntranceTransitionPending
private Object
mEntranceTransition
static android.support.v17.leanback.transition.TransitionHelper
sTransitionHelper
Constructors Summary
Methods Summary
protected java.lang.ObjectcreateEntranceTransition()
Create entrance transition. Subclass can override to load transition from resource or construct manually. Typically app does not need to override the default transition that browse and details provides.

        return null;
    
voidinternalCreateEntranceTransition()

        mEntranceTransition = createEntranceTransition();
        if (mEntranceTransition == null) {
            return;
        }
        sTransitionHelper.setTransitionListener(mEntranceTransition, new TransitionListener() {
            @Override
            public void onTransitionStart(Object transition) {
                onEntranceTransitionStart();
            }
            @Override
            public void onTransitionEnd(Object transition) {
                mEntranceTransition = null;
                onEntranceTransitionEnd();
            }
        });
    
booleanisEntranceTransitionEnabled()
Return true if entrance transition is enabled and not started yet. Entrance transition can only be executed once and isEntranceTransitionEnabled() is reset to false after entrance transition is started.

        return mEntranceTransitionEnabled;
    
protected voidonEntranceTransitionEnd()
Callback when entrance transition is ended.

    
protected voidonEntranceTransitionStart()
Callback when entrance transition is started.

    
public voidonViewCreated(android.view.View view, android.os.Bundle savedInstanceState)


    
          
        super.onViewCreated(view, savedInstanceState);
        if (mStartEntranceTransitionPending) {
            mStartEntranceTransitionPending = false;
            startEntranceTransition();
        }
    
public voidprepareEntranceTransition()
Enables entrance transition.

Entrance transition is the standard slide-in transition that shows rows of data in browse screen and details screen.

The method is ignored before LOLLIPOP (API21).

This method must be called in or before onCreate(). Typically entrance transition should be enabled when savedInstance is null so that fragment restored from instanceState does not run an extra entrance transition. When the entrance transition is enabled, the fragment will make headers and content hidden initially. When data of rows are ready, app must call {@link #startEntranceTransition()} to kick off the transition, otherwise the rows will be invisible forever.

It is similar to android:windowsEnterTransition and can be considered a late-executed android:windowsEnterTransition controlled by app. There are two reasons that app needs it:

  • Workaround the problem that activity transition is not available between launcher and app. Browse activity must programmatically start the slide-in transition.
  • Separates DetailsOverviewRow transition from other rows transition. So that the DetailsOverviewRow transition can be executed earlier without waiting for all rows to be loaded.
  • Transition object is returned by createEntranceTransition(). Typically the app does not need override the default transition that browse and details provides.

            if (TransitionHelper.systemSupportsEntranceTransitions()) {
                mEntranceTransitionEnabled = true;
            }
        
    protected voidrunEntranceTransition(java.lang.Object entranceTransition)
    Run entrance transition. Subclass may use TransitionManager to perform go(Scene) or beginDelayedTransition(). App should not override the default implementation of browse and details fragment.

        
    public voidstartEntranceTransition()
    When fragment finishes loading data, it should call startEntranceTransition() to execute the entrance transition. startEntranceTransition() will start transition only if both two conditions are satisfied:
  • prepareEntranceTransition() was called.
  • has not executed entrance transition yet.
  • If startEntranceTransition() is called before onViewCreated(), it will be pending and executed when view is created.

            if (!mEntranceTransitionEnabled || mEntranceTransition != null) {
                return;
            }
            // if view is not created yet, delay until onViewCreated()
            if (getView() == null) {
                mStartEntranceTransitionPending = true;
                return;
            }
            // wait till views get their initial position before start transition
            final View view = getView();
            view.getViewTreeObserver().addOnPreDrawListener(
                    new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
                    view.getViewTreeObserver().removeOnPreDrawListener(this);
                    internalCreateEntranceTransition();
                    mEntranceTransitionEnabled = false;
                    runEntranceTransition(mEntranceTransition);
                    return false;
                }
            });
            view.invalidate();