BaseRowSupportFragment.java revision e40904288950bc692751a30fcec42cfc4d03ff58
161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu/* 261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Copyright (C) 2014 The Android Open Source Project 361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * in compliance with the License. You may obtain a copy of the License at 661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * http://www.apache.org/licenses/LICENSE-2.0 861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * 961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Unless required by applicable law or agreed to in writing, software distributed under the License 1061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 1161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * or implied. See the License for the specific language governing permissions and limitations under 1261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * the License. 1361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 1461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gupackage android.support.v17.leanback.app; 1561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 1661905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.os.Bundle; 17cb3829a5ee01e3c0783019c04d083bde4d0082e8Jake Whartonimport android.support.annotation.NonNull; 18cb3829a5ee01e3c0783019c04d083bde4d0082e8Jake Whartonimport android.support.annotation.Nullable; 1961905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.ItemBridgeAdapter; 2061905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.ListRow; 212f5ebf3f6f7bb6a24856f389e369b247118ba119susnataimport android.support.v17.leanback.widget.ObjectAdapter; 220246318f27a905a31df5a8af445cfe67d31dfb68Dake Guimport android.support.v17.leanback.widget.OnChildViewHolderSelectedListener; 232f5ebf3f6f7bb6a24856f389e369b247118ba119susnataimport android.support.v17.leanback.widget.PresenterSelector; 242f5ebf3f6f7bb6a24856f389e369b247118ba119susnataimport android.support.v17.leanback.widget.Row; 252f5ebf3f6f7bb6a24856f389e369b247118ba119susnataimport android.support.v17.leanback.widget.VerticalGridView; 26b86a6c2c71514e0cb693597a955e224811b90f96Dake Guimport android.support.v4.app.Fragment; 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; 4050cf9ada93e50e906f20f5edf595234ada196d45Dake Gu final ItemBridgeAdapter mBridgeAdapter = new ItemBridgeAdapter(); 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) { 52514b6d101c6b7d4b7151cf8789424bde66fab511Dake Gu if (!mLateSelectionObserver.mIsLateSelection) { 53514b6d101c6b7d4b7151cf8789424bde66fab511Dake Gu mSelectedPosition = position; 54514b6d101c6b7d4b7151cf8789424bde66fab511Dake Gu onRowSelected(parent, view, position, subposition); 55514b6d101c6b7d4b7151cf8789424bde66fab511Dake Gu } 560246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu } 570246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu }; 5861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 590246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu void onRowSelected(RecyclerView parent, RecyclerView.ViewHolder view, 600246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu int position, int subposition) { 6161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 6261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 6361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 6461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public View onCreateView(LayoutInflater inflater, ViewGroup container, 6561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu Bundle savedInstanceState) { 6661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu View view = inflater.inflate(getLayoutResourceId(), container, false); 6761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mVerticalGridView = findGridViewFromRoot(view); 68902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu if (mPendingTransitionPrepare) { 69902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu mPendingTransitionPrepare = false; 70902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu onTransitionPrepare(); 71902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu } 7261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return view; 7361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 7461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 7542752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu VerticalGridView findGridViewFromRoot(View view) { 7661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return (VerticalGridView) view; 7761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 7861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 7961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 80cb3829a5ee01e3c0783019c04d083bde4d0082e8Jake Wharton public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 81fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak if (savedInstanceState != null) { 82fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak mSelectedPosition = savedInstanceState.getInt(CURRENT_SELECTED_POSITION, -1); 83fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak } 8450cf9ada93e50e906f20f5edf595234ada196d45Dake Gu setAdapterAndSelection(); 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() { 129c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu if (mAdapter == null) { 130c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu // delay until ItemBridgeAdapter has wrappedAdapter. Once we assign ItemBridgeAdapter 131c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu // to RecyclerView, it will not be allowed to change "hasStableId" to true. 132c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu return; 133c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu } 134c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu if (mVerticalGridView.getAdapter() != mBridgeAdapter) { 135c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu // avoid extra layout if ItemBridgeAdapter was already set. 136c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu mVerticalGridView.setAdapter(mBridgeAdapter); 137c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu } 138bb0a680c10b84b83833a59634373140f8bd0750csusnata // We don't set the selected position unless we've data in the adapter. 139bb0a680c10b84b83833a59634373140f8bd0750csusnata boolean lateSelection = mBridgeAdapter.getItemCount() == 0 && mSelectedPosition >= 0; 140bb0a680c10b84b83833a59634373140f8bd0750csusnata if (lateSelection) { 141bb0a680c10b84b83833a59634373140f8bd0750csusnata mLateSelectionObserver.startLateSelection(); 142bb0a680c10b84b83833a59634373140f8bd0750csusnata } else if (mSelectedPosition >= 0) { 143bb0a680c10b84b83833a59634373140f8bd0750csusnata mVerticalGridView.setSelectedPosition(mSelectedPosition); 144bb0a680c10b84b83833a59634373140f8bd0750csusnata } 14561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 14661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 14761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu @Override 14861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void onDestroyView() { 14961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu super.onDestroyView(); 150bb0a680c10b84b83833a59634373140f8bd0750csusnata mLateSelectionObserver.clear(); 15161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mVerticalGridView = null; 15261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 15361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 154fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak @Override 155fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak public void onSaveInstanceState(Bundle outState) { 156fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak super.onSaveInstanceState(outState); 157fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak outState.putInt(CURRENT_SELECTED_POSITION, mSelectedPosition); 158fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak } 159fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak 16061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 16161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Set the presenter selector used to create and bind views. 16261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 16361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public final void setPresenterSelector(PresenterSelector presenterSelector) { 164e40904288950bc692751a30fcec42cfc4d03ff58Dake Gu if (mPresenterSelector != presenterSelector) { 165e40904288950bc692751a30fcec42cfc4d03ff58Dake Gu mPresenterSelector = presenterSelector; 166e40904288950bc692751a30fcec42cfc4d03ff58Dake Gu updateAdapter(); 167e40904288950bc692751a30fcec42cfc4d03ff58Dake Gu } 16861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 16961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 17061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 17161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * Get the presenter selector used to create and bind views. 17261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 17361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public final PresenterSelector getPresenterSelector() { 17461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mPresenterSelector; 17561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 17661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 17761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 178c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * Sets the adapter that represents a list of rows. 179c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * @param rowsAdapter Adapter that represents list of rows. 18061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 18161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public final void setAdapter(ObjectAdapter rowsAdapter) { 182e40904288950bc692751a30fcec42cfc4d03ff58Dake Gu if (mAdapter != rowsAdapter) { 183e40904288950bc692751a30fcec42cfc4d03ff58Dake Gu mAdapter = rowsAdapter; 184e40904288950bc692751a30fcec42cfc4d03ff58Dake Gu updateAdapter(); 185e40904288950bc692751a30fcec42cfc4d03ff58Dake Gu } 18661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 18761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 18861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 189c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * Returns the Adapter that represents list of rows. 190c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * @return Adapter that represents list of rows. 19161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 19261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public final ObjectAdapter getAdapter() { 19361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mAdapter; 19461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 19561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 19661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 197c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * Returns the RecyclerView.Adapter that wraps {@link #getAdapter()}. 198c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * @return The RecyclerView.Adapter that wraps {@link #getAdapter()}. 19961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 200c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu public final ItemBridgeAdapter getBridgeAdapter() { 20161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mBridgeAdapter; 20261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 20361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 20461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu /** 2053f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu * Sets the selected row position with smooth animation. 20661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */ 20761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu public void setSelectedPosition(int position) { 2083f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu setSelectedPosition(position, true); 2093f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu } 2103f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu 2113f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu /** 2120d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu * Gets position of currently selected row. 2130d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu * @return Position of currently selected row. 2140d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu */ 2152f1bd591e01fe93f605844d4a10cde7116315b7cDake Gu public int getSelectedPosition() { 2160d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu return mSelectedPosition; 2170d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu } 2180d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu 2190d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu /** 2203f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu * Sets the selected row position. 2213f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu */ 2223f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu public void setSelectedPosition(int position, boolean smooth) { 2230d841b3454f896da58deb506ca22730bfd04f34fDake Gu if (mSelectedPosition == position) { 2240d841b3454f896da58deb506ca22730bfd04f34fDake Gu return; 2250d841b3454f896da58deb506ca22730bfd04f34fDake Gu } 22661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mSelectedPosition = position; 22750cf9ada93e50e906f20f5edf595234ada196d45Dake Gu if (mVerticalGridView != null) { 228bb0a680c10b84b83833a59634373140f8bd0750csusnata if (mLateSelectionObserver.mIsLateSelection) { 229bb0a680c10b84b83833a59634373140f8bd0750csusnata return; 230bb0a680c10b84b83833a59634373140f8bd0750csusnata } 2313f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu if (smooth) { 2323f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu mVerticalGridView.setSelectedPositionSmooth(position); 2333f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu } else { 2343f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu mVerticalGridView.setSelectedPosition(position); 2353f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu } 23661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 23761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 23861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 239935b033edfd9d03129fce6a5b7a1d3a327b74f91susnata public final VerticalGridView getVerticalGridView() { 24061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return mVerticalGridView; 24161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 24261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 24342752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu void updateAdapter() { 24450cf9ada93e50e906f20f5edf595234ada196d45Dake Gu mBridgeAdapter.setAdapter(mAdapter); 24550cf9ada93e50e906f20f5edf595234ada196d45Dake Gu mBridgeAdapter.setPresenter(mPresenterSelector); 24661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 24761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mVerticalGridView != null) { 248bb0a680c10b84b83833a59634373140f8bd0750csusnata setAdapterAndSelection(); 24961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 25061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 25161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 25242752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu Object getItem(Row row, int position) { 25361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (row instanceof ListRow) { 25461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return ((ListRow) row).getAdapter().get(position); 25561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } else { 25661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu return null; 25761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 25861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 25961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 2602f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public boolean onTransitionPrepare() { 26161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mVerticalGridView != null) { 26261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mVerticalGridView.setAnimateChildLayout(false); 263902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu mVerticalGridView.setScrollEnabled(false); 264902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu return true; 26561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 266902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu mPendingTransitionPrepare = true; 267902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu return false; 268902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu } 269902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu 2702f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public void onTransitionStart() { 2714a4e0872bdf0548188e81740eb62085215e7f976Dake Gu if (mVerticalGridView != null) { 2724a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setPruneChild(false); 2734a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setLayoutFrozen(true); 2744a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setFocusSearchDisabled(true); 2754a4e0872bdf0548188e81740eb62085215e7f976Dake Gu } 27661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 27761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 2782f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public void onTransitionEnd() { 2794a4e0872bdf0548188e81740eb62085215e7f976Dake Gu // be careful that fragment might be destroyed before header transition ends. 2804a4e0872bdf0548188e81740eb62085215e7f976Dake Gu if (mVerticalGridView != null) { 2814a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setLayoutFrozen(false); 2824a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setAnimateChildLayout(true); 2834a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setPruneChild(true); 2844a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setFocusSearchDisabled(false); 2854a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setScrollEnabled(true); 2864a4e0872bdf0548188e81740eb62085215e7f976Dake Gu } 28761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 28861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 2892f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public void setAlignment(int windowAlignOffsetTop) { 29061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu if (mVerticalGridView != null) { 29161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu // align the top edge of item 29261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mVerticalGridView.setItemAlignmentOffset(0); 29361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mVerticalGridView.setItemAlignmentOffsetPercent( 29461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu VerticalGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED); 29561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu 29661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu // align to a fixed position from top 2972f5ebf3f6f7bb6a24856f389e369b247118ba119susnata mVerticalGridView.setWindowAlignmentOffset(windowAlignOffsetTop); 29861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mVerticalGridView.setWindowAlignmentOffsetPercent( 29961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu VerticalGridView.WINDOW_ALIGN_OFFSET_PERCENT_DISABLED); 30061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu mVerticalGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE); 30161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 30261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu } 30361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu} 304