RowPresenter.java revision cb04695965b44b6ff633a773426df286d3bfaad9
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14package android.support.v17.leanback.widget;
15
16import android.support.v17.leanback.app.HeadersFragment;
17import android.support.v17.leanback.graphics.ColorOverlayDimmer;
18import android.view.View;
19import android.view.ViewGroup;
20
21/**
22 * An abstract {@link Presenter} that renders a {@link Row}.
23 *
24 * <h3>Customize UI widgets</h3>
25 * When a subclass of RowPresenter adds UI widgets, it should subclass
26 * {@link RowPresenter.ViewHolder} and override {@link #createRowViewHolder(ViewGroup)}
27 * and {@link #initializeRowViewHolder(ViewHolder)}. The subclass must use layout id
28 * "row_content" for the widget that will be aligned to the title of any {@link HeadersFragment}
29 * that may exist in the parent fragment. RowPresenter contains an optional and
30 * replaceable {@link RowHeaderPresenter} that renders the header. You can disable
31 * the default rendering or replace the Presenter with a new header presenter
32 * by calling {@link #setHeaderPresenter(RowHeaderPresenter)}.
33 *
34 * <h3>UI events from fragments</h3>
35 * RowPresenter receives calls from its parent (typically a Fragment) when:
36 * <ul>
37 * <li>
38 * A row is selected via {@link #setRowViewSelected(Presenter.ViewHolder, boolean)}.  The event
39 * is triggered immediately when there is a row selection change before the selection
40 * animation is started.  Selected status may control activated status of the row (see
41 * "Activated status" below).
42 * Subclasses of RowPresenter may override {@link #onRowViewSelected(ViewHolder, boolean)}.
43 * </li>
44 * <li>
45 * A row is expanded to full height via {@link #setRowViewExpanded(Presenter.ViewHolder, boolean)}
46 * when BrowseFragment hides fast lane on the left.
47 * The event is triggered immediately before the expand animation is started.
48 * Row title is shown when row is expanded.  Expanded status may control activated status
49 * of the row (see "Activated status" below).
50 * Subclasses of RowPresenter may override {@link #onRowViewExpanded(ViewHolder, boolean)}.
51 * </li>
52 * </ul>
53 *
54 * <h3>Activated status</h3>
55 * The activated status of a row is applied to the row view and it's children via
56 * {@link View#setActivated(boolean)}.
57 * The activated status is typically used to control {@link BaseCardView} info region visibility.
58 * The row's activated status can be controlled by selected status and/or expanded status.
59 * Call {@link #setSyncActivatePolicy(int)} and choose one of the four policies:
60 * <ul>
61 * <li>{@link #SYNC_ACTIVATED_TO_EXPANDED} Activated status is synced with row expanded status</li>
62 * <li>{@link #SYNC_ACTIVATED_TO_SELECTED} Activated status is synced with row selected status</li>
63 * <li>{@link #SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED} Activated status is set to true
64 *     when both expanded and selected status are true</li>
65 * <li>{@link #SYNC_ACTIVATED_CUSTOM} Activated status is not controlled by selected status
66 *     or expanded status, application can control activated status by its own.
67 *     Application should call {@link RowPresenter.ViewHolder#setActivated(boolean)} to change
68 *     activated status of row view.
69 * </li>
70 * </ul>
71 *
72 * <h3>User events</h3>
73 * RowPresenter provides {@link OnItemSelectedListener} and {@link OnItemClickedListener}.
74 * If a subclass wants to add its own {@link View.OnFocusChangeListener} or
75 * {@link View.OnClickListener}, it must do that in {@link #createRowViewHolder(ViewGroup)}
76 * to be properly chained by the library.  Adding View listeners after
77 * {@link #createRowViewHolder(ViewGroup)} is undefined and may result in
78 * incorrect behavior by the library's listeners.
79 *
80 * <h3>Selection animation</h3>
81 * <p>
82 * When a user scrolls through rows, a fragment will initiate animation and call
83 * {@link #setSelectLevel(Presenter.ViewHolder, float)} with float value between
84 * 0 and 1.  By default, the RowPresenter draws a dim overlay on top of the row
85 * view for views that are not selected. Subclasses may override this default effect
86 * by having {@link #isUsingDefaultSelectEffect()} return false and overriding
87 * {@link #onSelectLevelChanged(ViewHolder)} to apply a different selection effect.
88 * </p>
89 * <p>
90 * Call {@link #setSelectEffectEnabled(boolean)} to enable/disable the select effect,
91 * This will not only enable/disable the default dim effect but also subclasses must
92 * respect this flag as well.
93 * </p>
94 */
95public abstract class RowPresenter extends Presenter {
96
97    /**
98     * Don't synchronize row view activated status with selected status or expanded status,
99     * application will do its own through {@link RowPresenter.ViewHolder#setActivated(boolean)}.
100     */
101    public static final int SYNC_ACTIVATED_CUSTOM = 0;
102
103    /**
104     * Synchronizes row view's activated status to expand status of the row view holder.
105     */
106    public static final int SYNC_ACTIVATED_TO_EXPANDED = 1;
107
108    /**
109     * Synchronizes row view's activated status to selected status of the row view holder.
110     */
111    public static final int SYNC_ACTIVATED_TO_SELECTED = 2;
112
113    /**
114     * Sets the row view's activated status to true when both expand and selected are true.
115     */
116    public static final int SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED = 3;
117
118    static class ContainerViewHolder extends Presenter.ViewHolder {
119        /**
120         * wrapped row view holder
121         */
122        final ViewHolder mRowViewHolder;
123
124        public ContainerViewHolder(RowContainerView containerView, ViewHolder rowViewHolder) {
125            super(containerView);
126            containerView.addRowView(rowViewHolder.view);
127            if (rowViewHolder.mHeaderViewHolder != null) {
128                containerView.addHeaderView(rowViewHolder.mHeaderViewHolder.view);
129            }
130            mRowViewHolder = rowViewHolder;
131            mRowViewHolder.mContainerViewHolder = this;
132        }
133    }
134
135    /**
136     * A view holder for a {@link Row}.
137     */
138    public static class ViewHolder extends Presenter.ViewHolder {
139        private static final int ACTIVATED_NOT_ASSIGNED = 0;
140        private static final int ACTIVATED = 1;
141        private static final int NOT_ACTIVATED = 2;
142
143        ContainerViewHolder mContainerViewHolder;
144        RowHeaderPresenter.ViewHolder mHeaderViewHolder;
145        Row mRow;
146        int mActivated = ACTIVATED_NOT_ASSIGNED;
147        boolean mSelected;
148        boolean mExpanded;
149        boolean mInitialzed;
150        float mSelectLevel = 0f; // initially unselected
151        protected final ColorOverlayDimmer mColorDimmer;
152
153        /**
154         * Constructor for ViewHolder.
155         *
156         * @param view The View bound to the Row.
157         */
158        public ViewHolder(View view) {
159            super(view);
160            mColorDimmer = ColorOverlayDimmer.createDefault(view.getContext());
161        }
162
163        /**
164         * Returns the Row bound to the View in this ViewHolder.
165         */
166        public final Row getRow() {
167            return mRow;
168        }
169
170        /**
171         * Returns whether the Row is in its expanded state.
172         *
173         * @return true if the Row is expanded, false otherwise.
174         */
175        public final boolean isExpanded() {
176            return mExpanded;
177        }
178
179        /**
180         * Returns whether the Row is selected.
181         *
182         * @return true if the Row is selected, false otherwise.
183         */
184        public final boolean isSelected() {
185            return mSelected;
186        }
187
188        /**
189         * Returns the current selection level of the Row.
190         */
191        public final float getSelectLevel() {
192            return mSelectLevel;
193        }
194
195        /**
196         * Returns the view holder for the Row header for this Row.
197         */
198        public final RowHeaderPresenter.ViewHolder getHeaderViewHolder() {
199            return mHeaderViewHolder;
200        }
201
202        /**
203         * Sets the row view's activated status.  The status will be applied to children through
204         * {@link #syncActivatedStatus(View)}.  Application should only call this function
205         * when {@link RowPresenter#getSyncActivatePolicy()} is
206         * {@link RowPresenter#SYNC_ACTIVATED_CUSTOM}; otherwise the value will
207         * be overwritten when expanded or selected status changes.
208         */
209        public final void setActivated(boolean activated) {
210            mActivated = activated ? ACTIVATED : NOT_ACTIVATED;
211        }
212
213        /**
214         * Synchronizes the activated status of view to the last value passed through
215         * {@link RowPresenter.ViewHolder#setActivated(boolean)}. No operation if
216         * {@link RowPresenter.ViewHolder#setActivated(boolean)} is never called.  Normally
217         * application does not need to call this method,  {@link ListRowPresenter} automatically
218         * calls this method when a child is attached to list row.   However if
219         * application writes its own custom RowPresenter, it should call this method
220         * when attaches a child to the row view.
221         */
222        public final void syncActivatedStatus(View view) {
223            if (mActivated == ACTIVATED) {
224                view.setActivated(true);
225            } else if (mActivated == NOT_ACTIVATED) {
226                view.setActivated(false);
227            }
228        }
229    }
230
231    private RowHeaderPresenter mHeaderPresenter = new RowHeaderPresenter();
232    private OnItemSelectedListener mOnItemSelectedListener;
233    private OnItemClickedListener mOnItemClickedListener;
234    private OnItemViewSelectedListener mOnItemViewSelectedListener;
235    private OnItemViewClickedListener mOnItemViewClickedListener;
236
237    boolean mSelectEffectEnabled = true;
238    int mSyncActivatePolicy = SYNC_ACTIVATED_TO_EXPANDED;
239
240    /**
241     * Constructs a RowPresenter.
242     */
243    public RowPresenter() {
244        mHeaderPresenter.setNullItemVisibilityGone(true);
245    }
246
247    @Override
248    public final Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
249        ViewHolder vh = createRowViewHolder(parent);
250        vh.mInitialzed = false;
251        Presenter.ViewHolder result;
252        if (needsRowContainerView()) {
253            RowContainerView containerView = new RowContainerView(parent.getContext());
254            if (mHeaderPresenter != null) {
255                vh.mHeaderViewHolder = (RowHeaderPresenter.ViewHolder)
256                        mHeaderPresenter.onCreateViewHolder((ViewGroup) vh.view);
257            }
258            result = new ContainerViewHolder(containerView, vh);
259        } else {
260            result = vh;
261        }
262        initializeRowViewHolder(vh);
263        if (!vh.mInitialzed) {
264            throw new RuntimeException("super.initializeRowViewHolder() must be called");
265        }
266        return result;
267    }
268
269    /**
270     * Called to create a ViewHolder object for a Row. Subclasses will override
271     * this method to return a different concrete ViewHolder object.
272     *
273     * @param parent The parent View for the Row's view holder.
274     * @return A ViewHolder for the Row's View.
275     */
276    protected abstract ViewHolder createRowViewHolder(ViewGroup parent);
277
278    /**
279     * Called after a {@link RowPresenter.ViewHolder} is created for a Row.
280     * Subclasses may override this method and start by calling
281     * super.initializeRowViewHolder(ViewHolder).
282     *
283     * @param vh The ViewHolder to initialize for the Row.
284     */
285    protected void initializeRowViewHolder(ViewHolder vh) {
286        vh.mInitialzed = true;
287        // set clip children to false for slide transition
288        if (vh.view instanceof ViewGroup) {
289            ((ViewGroup) vh.view).setClipChildren(false);
290        }
291        if (vh.mContainerViewHolder != null) {
292            ((ViewGroup) vh.mContainerViewHolder.view).setClipChildren(false);
293        }
294    }
295
296    /**
297     * Set the Presenter used for rendering the header. Can be null to disable
298     * header rendering. The method must be called before creating any Row Views.
299     */
300    public final void setHeaderPresenter(RowHeaderPresenter headerPresenter) {
301        mHeaderPresenter = headerPresenter;
302    }
303
304    /**
305     * Get the Presenter used for rendering the header, or null if none has been
306     * set.
307     */
308    public final RowHeaderPresenter getHeaderPresenter() {
309        return mHeaderPresenter;
310    }
311
312    /**
313     * Get the {@link RowPresenter.ViewHolder} from the given Presenter
314     * ViewHolder.
315     */
316    public final ViewHolder getRowViewHolder(Presenter.ViewHolder holder) {
317        if (holder instanceof ContainerViewHolder) {
318            return ((ContainerViewHolder) holder).mRowViewHolder;
319        } else {
320            return (ViewHolder) holder;
321        }
322    }
323
324    /**
325     * Set the expanded state of a Row view.
326     *
327     * @param holder The Row ViewHolder to set expanded state on.
328     * @param expanded True if the Row is expanded, false otherwise.
329     */
330    public final void setRowViewExpanded(Presenter.ViewHolder holder, boolean expanded) {
331        ViewHolder rowViewHolder = getRowViewHolder(holder);
332        rowViewHolder.mExpanded = expanded;
333        onRowViewExpanded(rowViewHolder, expanded);
334    }
335
336    /**
337     * Set the selected state of a Row view.
338     *
339     * @param holder The Row ViewHolder to set expanded state on.
340     * @param selected True if the Row is expanded, false otherwise.
341     */
342    public final void setRowViewSelected(Presenter.ViewHolder holder, boolean selected) {
343        ViewHolder rowViewHolder = getRowViewHolder(holder);
344        rowViewHolder.mSelected = selected;
345        onRowViewSelected(rowViewHolder, selected);
346    }
347
348    /**
349     * Subclass may override this to respond to expanded state changes of a Row.
350     * The default implementation will hide/show the header view. Subclasses may
351     * make visual changes to the Row View but must not create animation on the
352     * Row view.
353     */
354    protected void onRowViewExpanded(ViewHolder vh, boolean expanded) {
355        updateHeaderViewVisibility(vh);
356        updateActivateStatus(vh, vh.view);
357    }
358
359    /**
360     * Update view's activate status according to {@link #getSyncActivatePolicy()} and the
361     * selected status and expanded status of the RowPresenter ViewHolder.
362     */
363    private void updateActivateStatus(ViewHolder vh, View view) {
364        switch (mSyncActivatePolicy) {
365            case SYNC_ACTIVATED_TO_EXPANDED:
366                vh.setActivated(vh.isExpanded());
367                break;
368            case SYNC_ACTIVATED_TO_SELECTED:
369                vh.setActivated(vh.isSelected());
370                break;
371            case SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED:
372                vh.setActivated(vh.isExpanded() && vh.isSelected());
373                break;
374        }
375        vh.syncActivatedStatus(view);
376    }
377
378    /**
379     * Sets policy of updating row view activated status.  Can be one of:
380     * <li> Default value {@link #SYNC_ACTIVATED_TO_EXPANDED}
381     * <li> {@link #SYNC_ACTIVATED_TO_SELECTED}
382     * <li> {@link #SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED}
383     * <li> {@link #SYNC_ACTIVATED_CUSTOM}
384     */
385    public final void setSyncActivatePolicy(int syncActivatePolicy) {
386        mSyncActivatePolicy = syncActivatePolicy;
387    }
388
389    /**
390     * Returns policy of updating row view activated status.  Can be one of:
391     * <li> Default value {@link #SYNC_ACTIVATED_TO_EXPANDED}
392     * <li> {@link #SYNC_ACTIVATED_TO_SELECTED}
393     * <li> {@link #SYNC_ACTIVATED_TO_EXPANDED_AND_SELECTED}
394     * <li> {@link #SYNC_ACTIVATED_CUSTOM}
395     */
396    public final int getSyncActivatePolicy() {
397        return mSyncActivatePolicy;
398    }
399
400
401    /**
402     * The method is only called from onRowViewSelecetd().
403     * Default behavior is signaling row selected events with null item. Subclass of RowPresenter
404     * having child items should override this method and dispatch events with item information.
405     */
406    protected void dispatchItemSelectedListener(ViewHolder vh, boolean selected) {
407        if (selected) {
408            if (mOnItemViewSelectedListener != null) {
409                mOnItemViewSelectedListener.onItemSelected(null, null, vh, vh.getRow());
410            }
411            if (mOnItemSelectedListener != null) {
412                mOnItemSelectedListener.onItemSelected(null, vh.getRow());
413            }
414        }
415    }
416
417    /**
418     * Subclass may override this to respond to selected state changes of a Row.
419     * Subclass may make visual changes to Row view but must not create
420     * animation on the Row view.
421     */
422    protected void onRowViewSelected(ViewHolder vh, boolean selected) {
423        dispatchItemSelectedListener(vh, selected);
424        updateHeaderViewVisibility(vh);
425        updateActivateStatus(vh, vh.view);
426    }
427
428    private void updateHeaderViewVisibility(ViewHolder vh) {
429        if (mHeaderPresenter != null && vh.mHeaderViewHolder != null) {
430            RowContainerView containerView = ((RowContainerView) vh.mContainerViewHolder.view);
431            containerView.showHeader(vh.isExpanded());
432        }
433    }
434
435    /**
436     * Set the current select level to a value between 0 (unselected) and 1 (selected).
437     * Subclasses may override {@link #onSelectLevelChanged(ViewHolder)} to
438     * respond to changes in the selected level.
439     */
440    public final void setSelectLevel(Presenter.ViewHolder vh, float level) {
441        ViewHolder rowViewHolder = getRowViewHolder(vh);
442        rowViewHolder.mSelectLevel = level;
443        onSelectLevelChanged(rowViewHolder);
444    }
445
446    /**
447     * Get the current select level. The value will be between 0 (unselected)
448     * and 1 (selected).
449     */
450    public final float getSelectLevel(Presenter.ViewHolder vh) {
451        return getRowViewHolder(vh).mSelectLevel;
452    }
453
454    /**
455     * Callback when select level is changed. The default implementation applies
456     * the select level to {@link RowHeaderPresenter#setSelectLevel(RowHeaderPresenter.ViewHolder, float)}
457     * when {@link #getSelectEffectEnabled()} is true. Subclasses may override
458     * this function and implement a different select effect. In this case, you
459     * should also override {@link #isUsingDefaultSelectEffect()} to disable
460     * the default dimming effect applied by the library.
461     */
462    protected void onSelectLevelChanged(ViewHolder vh) {
463        if (getSelectEffectEnabled()) {
464            vh.mColorDimmer.setActiveLevel(vh.mSelectLevel);
465            if (vh.mHeaderViewHolder != null) {
466                mHeaderPresenter.setSelectLevel(vh.mHeaderViewHolder, vh.mSelectLevel);
467            }
468            if (isUsingDefaultSelectEffect()) {
469                ((RowContainerView) vh.mContainerViewHolder.view).setForegroundColor(
470                        vh.mColorDimmer.getPaint().getColor());
471            }
472        }
473    }
474
475    /**
476     * Enables or disables the row selection effect.
477     * This will not only affect the default dim effect, but subclasses must
478     * respect this flag as well.
479     */
480    public final void setSelectEffectEnabled(boolean applyDimOnSelect) {
481        mSelectEffectEnabled = applyDimOnSelect;
482    }
483
484    /**
485     * Returns true if the row selection effect is enabled.
486     * This value not only determines whether the default dim implementation is
487     * used, but subclasses must also respect this flag.
488     */
489    public final boolean getSelectEffectEnabled() {
490        return mSelectEffectEnabled;
491    }
492
493    /**
494     * Return whether this RowPresenter is using the default dimming effect
495     * provided by the library.  Subclasses may(most likely) return false and
496     * override {@link #onSelectLevelChanged(ViewHolder)}.
497     */
498    public boolean isUsingDefaultSelectEffect() {
499        return true;
500    }
501
502    final boolean needsDefaultSelectEffect() {
503        return isUsingDefaultSelectEffect() && getSelectEffectEnabled();
504    }
505
506    final boolean needsRowContainerView() {
507        return mHeaderPresenter != null || needsDefaultSelectEffect();
508    }
509
510    /**
511     * Return true if the Row view can draw outside its bounds.
512     */
513    public boolean canDrawOutOfBounds() {
514        return false;
515    }
516
517    @Override
518    public final void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
519        onBindRowViewHolder(getRowViewHolder(viewHolder), item);
520    }
521
522    protected void onBindRowViewHolder(ViewHolder vh, Object item) {
523        vh.mRow = (Row) item;
524        if (vh.mHeaderViewHolder != null) {
525            mHeaderPresenter.onBindViewHolder(vh.mHeaderViewHolder, item);
526        }
527    }
528
529    @Override
530    public final void onUnbindViewHolder(Presenter.ViewHolder viewHolder) {
531        onUnbindRowViewHolder(getRowViewHolder(viewHolder));
532    }
533
534    protected void onUnbindRowViewHolder(ViewHolder vh) {
535        if (vh.mHeaderViewHolder != null) {
536            mHeaderPresenter.onUnbindViewHolder(vh.mHeaderViewHolder);
537        }
538        vh.mRow = null;
539    }
540
541    @Override
542    public final void onViewAttachedToWindow(Presenter.ViewHolder holder) {
543        onRowViewAttachedToWindow(getRowViewHolder(holder));
544    }
545
546    protected void onRowViewAttachedToWindow(ViewHolder vh) {
547        if (vh.mHeaderViewHolder != null) {
548            mHeaderPresenter.onViewAttachedToWindow(vh.mHeaderViewHolder);
549        }
550    }
551
552    @Override
553    public final void onViewDetachedFromWindow(Presenter.ViewHolder holder) {
554        onRowViewDetachedFromWindow(getRowViewHolder(holder));
555    }
556
557    protected void onRowViewDetachedFromWindow(ViewHolder vh) {
558        if (vh.mHeaderViewHolder != null) {
559            mHeaderPresenter.onViewDetachedFromWindow(vh.mHeaderViewHolder);
560        }
561        cancelAnimationsRecursive(vh.view);
562    }
563
564    /**
565     * Set the listener for item or row selection. A RowPresenter fires a row
566     * selection event with a null item. Subclasses (e.g. {@link ListRowPresenter})
567     * can fire a selection event with the selected item.
568     */
569    public final void setOnItemSelectedListener(OnItemSelectedListener listener) {
570        mOnItemSelectedListener = listener;
571    }
572
573    /**
574     * Get the listener for item or row selection.
575     */
576    public final OnItemSelectedListener getOnItemSelectedListener() {
577        return mOnItemSelectedListener;
578    }
579
580    /**
581     * Set the listener for item click events. A RowPresenter does not use this
582     * listener, but a subclass may fire an item click event if it has the concept
583     * of an item. The {@link OnItemClickedListener} will override any
584     * {@link View.OnClickListener} that an item's Presenter sets during
585     * {@link Presenter#onCreateViewHolder(ViewGroup)}. So in general, you
586     * should choose to use an OnItemClickedListener or a {@link
587     * View.OnClickListener}, but not both.
588     */
589    public final void setOnItemClickedListener(OnItemClickedListener listener) {
590        mOnItemClickedListener = listener;
591    }
592
593    /**
594     * Get the listener for item click events.
595     */
596    public final OnItemClickedListener getOnItemClickedListener() {
597        return mOnItemClickedListener;
598    }
599
600    /**
601     * Set listener for item or row selection.  RowPresenter fires row selection
602     * event with null item, subclass of RowPresenter e.g. {@link ListRowPresenter} can
603     * fire a selection event with selected item.
604     */
605    public final void setOnItemViewSelectedListener(OnItemViewSelectedListener listener) {
606        mOnItemViewSelectedListener = listener;
607    }
608
609    /**
610     * Get listener for item or row selection.
611     */
612    public final OnItemViewSelectedListener getOnItemViewSelectedListener() {
613        return mOnItemViewSelectedListener;
614    }
615
616    /**
617     * Set listener for item click event.  RowPresenter does nothing but subclass of
618     * RowPresenter may fire item click event if it does have a concept of item.
619     * OnItemViewClickedListener will override {@link View.OnClickListener} that
620     * item presenter sets during {@link Presenter#onCreateViewHolder(ViewGroup)}.
621     * So in general,  developer should choose one of the listeners but not both.
622     */
623    public final void setOnItemViewClickedListener(OnItemViewClickedListener listener) {
624        mOnItemViewClickedListener = listener;
625    }
626
627    /**
628     * Set listener for item click event.
629     */
630    public final OnItemViewClickedListener getOnItemViewClickedListener() {
631        return mOnItemViewClickedListener;
632    }
633
634    /**
635     * Freeze/Unfreeze the row, typically used when transition starts/ends.
636     * This method is called by fragment, app should not call it directly.
637     */
638    public void freeze(ViewHolder holder, boolean freeze) {
639    }
640
641    /**
642     * Change visibility of views, entrance transition will be run against the views that
643     * change visibilities.  Subclass may override and begin with calling
644     * super.setEntranceTransitionState().  This method is called by fragment,
645     * app should not call it directly.
646     */
647    public void setEntranceTransitionState(ViewHolder holder, boolean afterTransition) {
648        if (holder.mHeaderViewHolder != null &&
649                holder.mHeaderViewHolder.view.getVisibility() != View.GONE) {
650            holder.mHeaderViewHolder.view.setVisibility(afterTransition ?
651                    View.VISIBLE : View.INVISIBLE);
652        }
653    }
654}
655