BaseRowSupportFragment.java revision 99ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0d
16193c12a1897723c87b41f4e304a8cd04deef2dcDake Gu/* This file is auto-generated from BaseRowFragment.java.  DO NOT MODIFY. */
26193c12a1897723c87b41f4e304a8cd04deef2dcDake Gu
361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu/*
461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Copyright (C) 2014 The Android Open Source Project
561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu *
661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * in compliance with the License. You may obtain a copy of the License at
861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu *
961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * http://www.apache.org/licenses/LICENSE-2.0
1061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu *
1161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Unless required by applicable law or agreed to in writing, software distributed under the License
1261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
1361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * or implied. See the License for the specific language governing permissions and limitations under
1461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * the License.
1561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */
1661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gupackage android.support.v17.leanback.app;
1761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
1861905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v4.app.Fragment;
1961905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.os.Bundle;
2061905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.ItemBridgeAdapter;
2161905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.ListRow;
222f5ebf3f6f7bb6a24856f389e369b247118ba119susnataimport android.support.v17.leanback.widget.ObjectAdapter;
230246318f27a905a31df5a8af445cfe67d31dfb68Dake Guimport android.support.v17.leanback.widget.OnChildViewHolderSelectedListener;
242f5ebf3f6f7bb6a24856f389e369b247118ba119susnataimport android.support.v17.leanback.widget.PresenterSelector;
252f5ebf3f6f7bb6a24856f389e369b247118ba119susnataimport android.support.v17.leanback.widget.Row;
262f5ebf3f6f7bb6a24856f389e369b247118ba119susnataimport android.support.v17.leanback.widget.VerticalGridView;
270246318f27a905a31df5a8af445cfe67d31dfb68Dake Guimport android.support.v7.widget.RecyclerView;
2861905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.LayoutInflater;
2961905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.View;
3061905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.ViewGroup;
3161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
3261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu/**
3361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * An internal base class for a fragment containing a list of rows.
3461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */
3561905b0b52c50018dcaebcd79699c39b8f28d622Dake Guabstract class BaseRowSupportFragment extends Fragment {
36fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak    private static final String CURRENT_SELECTED_POSITION = "currentSelectedPosition";
3761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private ObjectAdapter mAdapter;
3899ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    VerticalGridView mVerticalGridView;
3961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private PresenterSelector mPresenterSelector;
4099ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    ItemBridgeAdapter mBridgeAdapter;
4199ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    int mSelectedPosition = -1;
42902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu    private boolean mPendingTransitionPrepare;
43bb0a680c10b84b83833a59634373140f8bd0750csusnata    private LateSelectionObserver mLateSelectionObserver = new LateSelectionObserver();
4461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
4542752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    abstract int getLayoutResourceId();
4661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
470246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu    private final OnChildViewHolderSelectedListener mRowSelectedListener =
480246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu            new OnChildViewHolderSelectedListener() {
490246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                @Override
500246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                public void onChildViewHolderSelected(RecyclerView parent,
510246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                        RecyclerView.ViewHolder view, int position, int subposition) {
520d841b3454f896da58deb506ca22730bfd04f34fDake Gu                    mSelectedPosition = position;
530246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                    onRowSelected(parent, view, position, subposition);
540246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                }
550246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu            };
5661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
570246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu    void onRowSelected(RecyclerView parent, RecyclerView.ViewHolder view,
580246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu            int position, int subposition) {
5961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
6061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
6161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
6261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public View onCreateView(LayoutInflater inflater, ViewGroup container,
6361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            Bundle savedInstanceState) {
6461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        View view = inflater.inflate(getLayoutResourceId(), container, false);
6561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mVerticalGridView = findGridViewFromRoot(view);
66902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu        if (mPendingTransitionPrepare) {
67902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu            mPendingTransitionPrepare = false;
68902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu            onTransitionPrepare();
69902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu        }
7061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        return view;
7161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
7261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
7342752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    VerticalGridView findGridViewFromRoot(View view) {
7461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        return (VerticalGridView) view;
7561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
7661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
7761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
7861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public void onViewCreated(View view, Bundle savedInstanceState) {
79fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak        if (savedInstanceState != null) {
80fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak            mSelectedPosition = savedInstanceState.getInt(CURRENT_SELECTED_POSITION, -1);
81fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak        }
8261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (mBridgeAdapter != null) {
83bb0a680c10b84b83833a59634373140f8bd0750csusnata            setAdapterAndSelection();
84bb0a680c10b84b83833a59634373140f8bd0750csusnata        }
85bb0a680c10b84b83833a59634373140f8bd0750csusnata        mVerticalGridView.setOnChildViewHolderSelectedListener(mRowSelectedListener);
86bb0a680c10b84b83833a59634373140f8bd0750csusnata    }
87bb0a680c10b84b83833a59634373140f8bd0750csusnata
88bb0a680c10b84b83833a59634373140f8bd0750csusnata    /**
89bb0a680c10b84b83833a59634373140f8bd0750csusnata     * This class waits for the adapter to be updated before setting the selected
90bb0a680c10b84b83833a59634373140f8bd0750csusnata     * row.
91bb0a680c10b84b83833a59634373140f8bd0750csusnata     */
92bb0a680c10b84b83833a59634373140f8bd0750csusnata    private class LateSelectionObserver extends RecyclerView.AdapterDataObserver {
93bb0a680c10b84b83833a59634373140f8bd0750csusnata        boolean mIsLateSelection = false;
94bb0a680c10b84b83833a59634373140f8bd0750csusnata
9599ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas        LateSelectionObserver() {
9699ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas        }
9799ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas
9815375aa6fd54b036f97f99229aefab2822c8a1c9Aurimas Liutikas        @Override
99bb0a680c10b84b83833a59634373140f8bd0750csusnata        public void onChanged() {
100bb0a680c10b84b83833a59634373140f8bd0750csusnata            performLateSelection();
101bb0a680c10b84b83833a59634373140f8bd0750csusnata        }
102bb0a680c10b84b83833a59634373140f8bd0750csusnata
10315375aa6fd54b036f97f99229aefab2822c8a1c9Aurimas Liutikas        @Override
104bb0a680c10b84b83833a59634373140f8bd0750csusnata        public void onItemRangeInserted(int positionStart, int itemCount) {
105bb0a680c10b84b83833a59634373140f8bd0750csusnata            performLateSelection();
106bb0a680c10b84b83833a59634373140f8bd0750csusnata        }
107bb0a680c10b84b83833a59634373140f8bd0750csusnata
108bb0a680c10b84b83833a59634373140f8bd0750csusnata        void startLateSelection() {
109bb0a680c10b84b83833a59634373140f8bd0750csusnata            mIsLateSelection = true;
110bb0a680c10b84b83833a59634373140f8bd0750csusnata            mBridgeAdapter.registerAdapterDataObserver(this);
111bb0a680c10b84b83833a59634373140f8bd0750csusnata        }
112bb0a680c10b84b83833a59634373140f8bd0750csusnata
113bb0a680c10b84b83833a59634373140f8bd0750csusnata        void performLateSelection() {
114bb0a680c10b84b83833a59634373140f8bd0750csusnata            clear();
115bb0a680c10b84b83833a59634373140f8bd0750csusnata            if (mVerticalGridView != null) {
11661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                mVerticalGridView.setSelectedPosition(mSelectedPosition);
11761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
11861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
119bb0a680c10b84b83833a59634373140f8bd0750csusnata
120bb0a680c10b84b83833a59634373140f8bd0750csusnata        void clear() {
121bb0a680c10b84b83833a59634373140f8bd0750csusnata            if (mIsLateSelection) {
122bb0a680c10b84b83833a59634373140f8bd0750csusnata                mIsLateSelection = false;
123bb0a680c10b84b83833a59634373140f8bd0750csusnata                mBridgeAdapter.unregisterAdapterDataObserver(this);
124bb0a680c10b84b83833a59634373140f8bd0750csusnata            }
125bb0a680c10b84b83833a59634373140f8bd0750csusnata        }
126bb0a680c10b84b83833a59634373140f8bd0750csusnata    }
127bb0a680c10b84b83833a59634373140f8bd0750csusnata
128bb0a680c10b84b83833a59634373140f8bd0750csusnata    void setAdapterAndSelection() {
129bb0a680c10b84b83833a59634373140f8bd0750csusnata        mVerticalGridView.setAdapter(mBridgeAdapter);
130bb0a680c10b84b83833a59634373140f8bd0750csusnata        // We don't set the selected position unless we've data in the adapter.
131bb0a680c10b84b83833a59634373140f8bd0750csusnata        boolean lateSelection = mBridgeAdapter.getItemCount() == 0 && mSelectedPosition >= 0;
132bb0a680c10b84b83833a59634373140f8bd0750csusnata        if (lateSelection) {
133bb0a680c10b84b83833a59634373140f8bd0750csusnata            mLateSelectionObserver.startLateSelection();
134bb0a680c10b84b83833a59634373140f8bd0750csusnata        } else if (mSelectedPosition >= 0) {
135bb0a680c10b84b83833a59634373140f8bd0750csusnata            mVerticalGridView.setSelectedPosition(mSelectedPosition);
136bb0a680c10b84b83833a59634373140f8bd0750csusnata        }
13761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
13861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
13961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
14061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public void onDestroyView() {
14161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        super.onDestroyView();
142bb0a680c10b84b83833a59634373140f8bd0750csusnata        mLateSelectionObserver.clear();
14361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mVerticalGridView = null;
14461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
14561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
146fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak    @Override
147fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak    public void onSaveInstanceState(Bundle outState) {
148fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak        super.onSaveInstanceState(outState);
149fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak        outState.putInt(CURRENT_SELECTED_POSITION, mSelectedPosition);
150fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak    }
151fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak
15261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    /**
15361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     * Set the presenter selector used to create and bind views.
15461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     */
15561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public final void setPresenterSelector(PresenterSelector presenterSelector) {
15661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mPresenterSelector = presenterSelector;
15761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        updateAdapter();
15861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
15961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
16061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    /**
16161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     * Get the presenter selector used to create and bind views.
16261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     */
16361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public final PresenterSelector getPresenterSelector() {
16461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        return mPresenterSelector;
16561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
16661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
16761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    /**
16861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     * Sets the adapter for the fragment.
16961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     */
17061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public final void setAdapter(ObjectAdapter rowsAdapter) {
17161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mAdapter = rowsAdapter;
17261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        updateAdapter();
17361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
17461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
17561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    /**
17661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     * Returns the list of rows.
17761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     */
17861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public final ObjectAdapter getAdapter() {
17961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        return mAdapter;
18061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
18161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
18261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    /**
18361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     * Returns the bridge adapter.
18461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     */
18542752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    final ItemBridgeAdapter getBridgeAdapter() {
18661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        return mBridgeAdapter;
18761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
18861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
18961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    /**
1903f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu     * Sets the selected row position with smooth animation.
19161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu     */
19261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public void setSelectedPosition(int position) {
1933f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu        setSelectedPosition(position, true);
1943f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu    }
1953f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu
1963f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu    /**
1970d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu     * Gets position of currently selected row.
1980d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu     * @return Position of currently selected row.
1990d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu     */
2002f1bd591e01fe93f605844d4a10cde7116315b7cDake Gu    public int getSelectedPosition() {
2010d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu        return mSelectedPosition;
2020d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu    }
2030d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu
2040d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu    /**
2053f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu     * Sets the selected row position.
2063f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu     */
2073f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu    public void setSelectedPosition(int position, boolean smooth) {
2080d841b3454f896da58deb506ca22730bfd04f34fDake Gu        if (mSelectedPosition == position) {
2090d841b3454f896da58deb506ca22730bfd04f34fDake Gu            return;
2100d841b3454f896da58deb506ca22730bfd04f34fDake Gu        }
21161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mSelectedPosition = position;
21261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if(mVerticalGridView != null && mVerticalGridView.getAdapter() != null) {
213bb0a680c10b84b83833a59634373140f8bd0750csusnata            if (mLateSelectionObserver.mIsLateSelection) {
214bb0a680c10b84b83833a59634373140f8bd0750csusnata                return;
215bb0a680c10b84b83833a59634373140f8bd0750csusnata            }
2163f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu            if (smooth) {
2173f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu                mVerticalGridView.setSelectedPositionSmooth(position);
2183f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu            } else {
2193f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu                mVerticalGridView.setSelectedPosition(position);
2203f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu            }
22161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
22261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
22361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
22461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    final VerticalGridView getVerticalGridView() {
22561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        return mVerticalGridView;
22661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
22761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
22842752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    void updateAdapter() {
229e71207666a1a915e5a5bdf7503bd936f4d87b48bDake Gu        if (mBridgeAdapter != null) {
230e71207666a1a915e5a5bdf7503bd936f4d87b48bDake Gu            // detach observer from ObjectAdapter
231bb0a680c10b84b83833a59634373140f8bd0750csusnata            mLateSelectionObserver.clear();
232e71207666a1a915e5a5bdf7503bd936f4d87b48bDake Gu            mBridgeAdapter.clear();
233e71207666a1a915e5a5bdf7503bd936f4d87b48bDake Gu            mBridgeAdapter = null;
234e71207666a1a915e5a5bdf7503bd936f4d87b48bDake Gu        }
23561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
23661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (mAdapter != null) {
23761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // If presenter selector is null, adapter ps will be used
23861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            mBridgeAdapter = new ItemBridgeAdapter(mAdapter, mPresenterSelector);
23961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
24061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (mVerticalGridView != null) {
241bb0a680c10b84b83833a59634373140f8bd0750csusnata            setAdapterAndSelection();
24261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
24361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
24461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
24542752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    Object getItem(Row row, int position) {
24661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (row instanceof ListRow) {
24761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            return ((ListRow) row).getAdapter().get(position);
24861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        } else {
24961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            return null;
25061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
25161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
25261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
2532f5ebf3f6f7bb6a24856f389e369b247118ba119susnata    public boolean onTransitionPrepare() {
25461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (mVerticalGridView != null) {
25561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            mVerticalGridView.setAnimateChildLayout(false);
256902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu            mVerticalGridView.setScrollEnabled(false);
257902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu            return true;
25861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
259902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu        mPendingTransitionPrepare = true;
260902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu        return false;
261902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu    }
262902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu
2632f5ebf3f6f7bb6a24856f389e369b247118ba119susnata    public void onTransitionStart() {
2644a4e0872bdf0548188e81740eb62085215e7f976Dake Gu        if (mVerticalGridView != null) {
2654a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setPruneChild(false);
2664a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setLayoutFrozen(true);
2674a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setFocusSearchDisabled(true);
2684a4e0872bdf0548188e81740eb62085215e7f976Dake Gu        }
26961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
27061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
2712f5ebf3f6f7bb6a24856f389e369b247118ba119susnata    public void onTransitionEnd() {
2724a4e0872bdf0548188e81740eb62085215e7f976Dake Gu        // be careful that fragment might be destroyed before header transition ends.
2734a4e0872bdf0548188e81740eb62085215e7f976Dake Gu        if (mVerticalGridView != null) {
2744a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setLayoutFrozen(false);
2754a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setAnimateChildLayout(true);
2764a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setPruneChild(true);
2774a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setFocusSearchDisabled(false);
2784a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setScrollEnabled(true);
2794a4e0872bdf0548188e81740eb62085215e7f976Dake Gu        }
28061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
28161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
2822f5ebf3f6f7bb6a24856f389e369b247118ba119susnata    public void setAlignment(int windowAlignOffsetTop) {
28361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (mVerticalGridView != null) {
28461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // align the top edge of item
28561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            mVerticalGridView.setItemAlignmentOffset(0);
28661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            mVerticalGridView.setItemAlignmentOffsetPercent(
28761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    VerticalGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED);
28861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
28961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // align to a fixed position from top
2902f5ebf3f6f7bb6a24856f389e369b247118ba119susnata            mVerticalGridView.setWindowAlignmentOffset(windowAlignOffsetTop);
29161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            mVerticalGridView.setWindowAlignmentOffsetPercent(
29261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    VerticalGridView.WINDOW_ALIGN_OFFSET_PERCENT_DISABLED);
29361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            mVerticalGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE);
29461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
29561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
29661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu}
297