1b86a6c2c71514e0cb693597a955e224811b90f96Dake Gu// CHECKSTYLE:OFF Generated code 2b86a6c2c71514e0cb693597a955e224811b90f96Dake Gu/* This file is auto-generated from BaseRowSupportFragment.java. DO NOT MODIFY. */ 3b86a6c2c71514e0cb693597a955e224811b90f96Dake Gu 455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout/* 555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * Copyright (C) 2014 The Android Open Source Project 655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * 755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * in compliance with the License. You may obtain a copy of the License at 955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * 1055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * http://www.apache.org/licenses/LICENSE-2.0 1155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * 1255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * Unless required by applicable law or agreed to in writing, software distributed under the License 1355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 1455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * or implied. See the License for the specific language governing permissions and limitations under 1555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * the License. 1655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */ 1755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutpackage android.support.v17.leanback.app; 1855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 1955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.os.Bundle; 2055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.ItemBridgeAdapter; 2155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport 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; 27b86a6c2c71514e0cb693597a955e224811b90f96Dake Guimport android.app.Fragment; 280246318f27a905a31df5a8af445cfe67d31dfb68Dake Guimport android.support.v7.widget.RecyclerView; 2955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.view.LayoutInflater; 3055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.view.View; 3155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.view.ViewGroup; 3255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 3355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout/** 34a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn * An internal base class for a fragment containing a list of rows. 3555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */ 3655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutabstract class BaseRowFragment extends Fragment { 37fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak private static final String CURRENT_SELECTED_POSITION = "currentSelectedPosition"; 3855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout private ObjectAdapter mAdapter; 3999ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas VerticalGridView mVerticalGridView; 4055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout private PresenterSelector mPresenterSelector; 4150cf9ada93e50e906f20f5edf595234ada196d45Dake Gu final ItemBridgeAdapter mBridgeAdapter = new ItemBridgeAdapter(); 4299ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas int mSelectedPosition = -1; 43902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu private boolean mPendingTransitionPrepare; 44bb0a680c10b84b83833a59634373140f8bd0750csusnata private LateSelectionObserver mLateSelectionObserver = new LateSelectionObserver(); 4555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 4642752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu abstract int getLayoutResourceId(); 4755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 480246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu private final OnChildViewHolderSelectedListener mRowSelectedListener = 490246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu new OnChildViewHolderSelectedListener() { 500246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu @Override 510246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu public void onChildViewHolderSelected(RecyclerView parent, 520246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu RecyclerView.ViewHolder view, int position, int subposition) { 53514b6d101c6b7d4b7151cf8789424bde66fab511Dake Gu if (!mLateSelectionObserver.mIsLateSelection) { 54514b6d101c6b7d4b7151cf8789424bde66fab511Dake Gu mSelectedPosition = position; 55514b6d101c6b7d4b7151cf8789424bde66fab511Dake Gu onRowSelected(parent, view, position, subposition); 56514b6d101c6b7d4b7151cf8789424bde66fab511Dake Gu } 570246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu } 580246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu }; 5955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 600246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu void onRowSelected(RecyclerView parent, RecyclerView.ViewHolder view, 610246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu int position, int subposition) { 6255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 6355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 6455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout @Override 657a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu public View onCreateView(LayoutInflater inflater, ViewGroup container, 667a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu Bundle savedInstanceState) { 677a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu View view = inflater.inflate(getLayoutResourceId(), container, false); 687a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu mVerticalGridView = findGridViewFromRoot(view); 69902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu if (mPendingTransitionPrepare) { 70902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu mPendingTransitionPrepare = false; 71902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu onTransitionPrepare(); 72902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu } 737a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu return view; 747a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu } 757a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu 7642752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu VerticalGridView findGridViewFromRoot(View view) { 777a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu return (VerticalGridView) view; 7855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 7955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 8055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout @Override 8155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout public void onViewCreated(View view, Bundle savedInstanceState) { 82fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak if (savedInstanceState != null) { 83fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak mSelectedPosition = savedInstanceState.getInt(CURRENT_SELECTED_POSITION, -1); 84fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak } 8550cf9ada93e50e906f20f5edf595234ada196d45Dake Gu setAdapterAndSelection(); 86bb0a680c10b84b83833a59634373140f8bd0750csusnata mVerticalGridView.setOnChildViewHolderSelectedListener(mRowSelectedListener); 87bb0a680c10b84b83833a59634373140f8bd0750csusnata } 88bb0a680c10b84b83833a59634373140f8bd0750csusnata 89bb0a680c10b84b83833a59634373140f8bd0750csusnata /** 90bb0a680c10b84b83833a59634373140f8bd0750csusnata * This class waits for the adapter to be updated before setting the selected 91bb0a680c10b84b83833a59634373140f8bd0750csusnata * row. 92bb0a680c10b84b83833a59634373140f8bd0750csusnata */ 93bb0a680c10b84b83833a59634373140f8bd0750csusnata private class LateSelectionObserver extends RecyclerView.AdapterDataObserver { 94bb0a680c10b84b83833a59634373140f8bd0750csusnata boolean mIsLateSelection = false; 95bb0a680c10b84b83833a59634373140f8bd0750csusnata 9699ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas LateSelectionObserver() { 9799ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas } 9899ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas 9915375aa6fd54b036f97f99229aefab2822c8a1c9Aurimas Liutikas @Override 100bb0a680c10b84b83833a59634373140f8bd0750csusnata public void onChanged() { 101bb0a680c10b84b83833a59634373140f8bd0750csusnata performLateSelection(); 102bb0a680c10b84b83833a59634373140f8bd0750csusnata } 103bb0a680c10b84b83833a59634373140f8bd0750csusnata 10415375aa6fd54b036f97f99229aefab2822c8a1c9Aurimas Liutikas @Override 105bb0a680c10b84b83833a59634373140f8bd0750csusnata public void onItemRangeInserted(int positionStart, int itemCount) { 106bb0a680c10b84b83833a59634373140f8bd0750csusnata performLateSelection(); 107bb0a680c10b84b83833a59634373140f8bd0750csusnata } 108bb0a680c10b84b83833a59634373140f8bd0750csusnata 109bb0a680c10b84b83833a59634373140f8bd0750csusnata void startLateSelection() { 110bb0a680c10b84b83833a59634373140f8bd0750csusnata mIsLateSelection = true; 111bb0a680c10b84b83833a59634373140f8bd0750csusnata mBridgeAdapter.registerAdapterDataObserver(this); 112bb0a680c10b84b83833a59634373140f8bd0750csusnata } 113bb0a680c10b84b83833a59634373140f8bd0750csusnata 114bb0a680c10b84b83833a59634373140f8bd0750csusnata void performLateSelection() { 115bb0a680c10b84b83833a59634373140f8bd0750csusnata clear(); 116bb0a680c10b84b83833a59634373140f8bd0750csusnata if (mVerticalGridView != null) { 117a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn mVerticalGridView.setSelectedPosition(mSelectedPosition); 11855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 11955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 120bb0a680c10b84b83833a59634373140f8bd0750csusnata 121bb0a680c10b84b83833a59634373140f8bd0750csusnata void clear() { 122bb0a680c10b84b83833a59634373140f8bd0750csusnata if (mIsLateSelection) { 123bb0a680c10b84b83833a59634373140f8bd0750csusnata mIsLateSelection = false; 124bb0a680c10b84b83833a59634373140f8bd0750csusnata mBridgeAdapter.unregisterAdapterDataObserver(this); 125bb0a680c10b84b83833a59634373140f8bd0750csusnata } 126bb0a680c10b84b83833a59634373140f8bd0750csusnata } 127bb0a680c10b84b83833a59634373140f8bd0750csusnata } 128bb0a680c10b84b83833a59634373140f8bd0750csusnata 129bb0a680c10b84b83833a59634373140f8bd0750csusnata void setAdapterAndSelection() { 130c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu if (mAdapter == null) { 131c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu // delay until ItemBridgeAdapter has wrappedAdapter. Once we assign ItemBridgeAdapter 132c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu // to RecyclerView, it will not be allowed to change "hasStableId" to true. 133c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu return; 134c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu } 135c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu if (mVerticalGridView.getAdapter() != mBridgeAdapter) { 136c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu // avoid extra layout if ItemBridgeAdapter was already set. 137c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu mVerticalGridView.setAdapter(mBridgeAdapter); 138c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu } 139bb0a680c10b84b83833a59634373140f8bd0750csusnata // We don't set the selected position unless we've data in the adapter. 140bb0a680c10b84b83833a59634373140f8bd0750csusnata boolean lateSelection = mBridgeAdapter.getItemCount() == 0 && mSelectedPosition >= 0; 141bb0a680c10b84b83833a59634373140f8bd0750csusnata if (lateSelection) { 142bb0a680c10b84b83833a59634373140f8bd0750csusnata mLateSelectionObserver.startLateSelection(); 143bb0a680c10b84b83833a59634373140f8bd0750csusnata } else if (mSelectedPosition >= 0) { 144bb0a680c10b84b83833a59634373140f8bd0750csusnata mVerticalGridView.setSelectedPosition(mSelectedPosition); 145bb0a680c10b84b83833a59634373140f8bd0750csusnata } 14655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 14755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 14855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout @Override 14955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout public void onDestroyView() { 15055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout super.onDestroyView(); 151bb0a680c10b84b83833a59634373140f8bd0750csusnata mLateSelectionObserver.clear(); 152a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn mVerticalGridView = null; 15355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 15455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 155fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak @Override 156fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak public void onSaveInstanceState(Bundle outState) { 157fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak super.onSaveInstanceState(outState); 158fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak outState.putInt(CURRENT_SELECTED_POSITION, mSelectedPosition); 159fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak } 160fb11ded6cfa3965883e68625e0c7e14b4b4fe0b3Susnata Basak 16155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout /** 162cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu * Set the presenter selector used to create and bind views. 16355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */ 164cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu public final void setPresenterSelector(PresenterSelector presenterSelector) { 16555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout mPresenterSelector = presenterSelector; 16655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout updateAdapter(); 16755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 16855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 16955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout /** 170cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu * Get the presenter selector used to create and bind views. 171cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu */ 172cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu public final PresenterSelector getPresenterSelector() { 173cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu return mPresenterSelector; 174cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu } 175cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu 176cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu /** 177c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * Sets the adapter that represents a list of rows. 178c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * @param rowsAdapter Adapter that represents list of rows. 17955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */ 180cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu public final void setAdapter(ObjectAdapter rowsAdapter) { 18155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout mAdapter = rowsAdapter; 18255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout updateAdapter(); 18355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 18455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 18555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout /** 186c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * Returns the Adapter that represents list of rows. 187c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * @return Adapter that represents list of rows. 18855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */ 18955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout public final ObjectAdapter getAdapter() { 19055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout return mAdapter; 19155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 19255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 19355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout /** 194c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * Returns the RecyclerView.Adapter that wraps {@link #getAdapter()}. 195c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu * @return The RecyclerView.Adapter that wraps {@link #getAdapter()}. 19655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */ 197c807587e03e775abb23f62894ad59bfb91cfbd97Dake Gu public final ItemBridgeAdapter getBridgeAdapter() { 19855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout return mBridgeAdapter; 19955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 20055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 20155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout /** 2023f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu * Sets the selected row position with smooth animation. 20355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */ 204025aa57d4fdd4e79289303c7dc54169311728f7bCraig Stout public void setSelectedPosition(int position) { 2053f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu setSelectedPosition(position, true); 2063f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu } 2073f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu 2083f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu /** 2090d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu * Gets position of currently selected row. 2100d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu * @return Position of currently selected row. 2110d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu */ 2122f1bd591e01fe93f605844d4a10cde7116315b7cDake Gu public int getSelectedPosition() { 2130d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu return mSelectedPosition; 2140d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu } 2150d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu 2160d73d42df7cf4b325b8f49660e3326204915ce8fDake Gu /** 2173f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu * Sets the selected row position. 2183f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu */ 2193f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu public void setSelectedPosition(int position, boolean smooth) { 2200d841b3454f896da58deb506ca22730bfd04f34fDake Gu if (mSelectedPosition == position) { 2210d841b3454f896da58deb506ca22730bfd04f34fDake Gu return; 2220d841b3454f896da58deb506ca22730bfd04f34fDake Gu } 22355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout mSelectedPosition = position; 22450cf9ada93e50e906f20f5edf595234ada196d45Dake Gu if (mVerticalGridView != null) { 225bb0a680c10b84b83833a59634373140f8bd0750csusnata if (mLateSelectionObserver.mIsLateSelection) { 226bb0a680c10b84b83833a59634373140f8bd0750csusnata return; 227bb0a680c10b84b83833a59634373140f8bd0750csusnata } 2283f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu if (smooth) { 2293f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu mVerticalGridView.setSelectedPositionSmooth(position); 2303f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu } else { 2313f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu mVerticalGridView.setSelectedPosition(position); 2323f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu } 23355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 23455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 23555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 236935b033edfd9d03129fce6a5b7a1d3a327b74f91susnata public final VerticalGridView getVerticalGridView() { 237a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn return mVerticalGridView; 23855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 23955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 24042752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu void updateAdapter() { 24150cf9ada93e50e906f20f5edf595234ada196d45Dake Gu mBridgeAdapter.setAdapter(mAdapter); 24250cf9ada93e50e906f20f5edf595234ada196d45Dake Gu mBridgeAdapter.setPresenter(mPresenterSelector); 24355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 244a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn if (mVerticalGridView != null) { 245bb0a680c10b84b83833a59634373140f8bd0750csusnata setAdapterAndSelection(); 24655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 24755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 24855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout 24942752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu Object getItem(Row row, int position) { 25055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout if (row instanceof ListRow) { 25155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout return ((ListRow) row).getAdapter().get(position); 25255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } else { 25355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout return null; 25455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 25555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout } 2562f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu 2572f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public boolean onTransitionPrepare() { 2582f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu if (mVerticalGridView != null) { 2592f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu mVerticalGridView.setAnimateChildLayout(false); 260902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu mVerticalGridView.setScrollEnabled(false); 261902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu return true; 2622f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu } 263902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu mPendingTransitionPrepare = true; 264902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu return false; 265902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu } 266902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu 2672f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public void onTransitionStart() { 2684a4e0872bdf0548188e81740eb62085215e7f976Dake Gu if (mVerticalGridView != null) { 2694a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setPruneChild(false); 2704a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setLayoutFrozen(true); 2714a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setFocusSearchDisabled(true); 2724a4e0872bdf0548188e81740eb62085215e7f976Dake Gu } 2732f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu } 2742f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu 2752f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public void onTransitionEnd() { 2764a4e0872bdf0548188e81740eb62085215e7f976Dake Gu // be careful that fragment might be destroyed before header transition ends. 2774a4e0872bdf0548188e81740eb62085215e7f976Dake Gu if (mVerticalGridView != null) { 2784a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setLayoutFrozen(false); 2794a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setAnimateChildLayout(true); 2804a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setPruneChild(true); 2814a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setFocusSearchDisabled(false); 2824a4e0872bdf0548188e81740eb62085215e7f976Dake Gu mVerticalGridView.setScrollEnabled(true); 2834a4e0872bdf0548188e81740eb62085215e7f976Dake Gu } 2842f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu } 285e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu 2862f5ebf3f6f7bb6a24856f389e369b247118ba119susnata public void setAlignment(int windowAlignOffsetTop) { 287e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu if (mVerticalGridView != null) { 288e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu // align the top edge of item 289e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu mVerticalGridView.setItemAlignmentOffset(0); 290e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu mVerticalGridView.setItemAlignmentOffsetPercent( 291e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu VerticalGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED); 292e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu 293e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu // align to a fixed position from top 2942f5ebf3f6f7bb6a24856f389e369b247118ba119susnata mVerticalGridView.setWindowAlignmentOffset(windowAlignOffsetTop); 295e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu mVerticalGridView.setWindowAlignmentOffsetPercent( 296e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu VerticalGridView.WINDOW_ALIGN_OFFSET_PERCENT_DISABLED); 297e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu mVerticalGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE); 298e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu } 299e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu } 30055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout} 301