155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout/*
255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * Copyright (C) 2014 The Android Open Source Project
355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout *
455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * in compliance with the License. You may obtain a copy of the License at
655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout *
755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * http://www.apache.org/licenses/LICENSE-2.0
855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout *
955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * Unless required by applicable law or agreed to in writing, software distributed under the License
1055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
1155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * or implied. See the License for the specific language governing permissions and limitations under
1255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout * the License.
1355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */
1455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutpackage android.support.v17.leanback.app;
1555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
1655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.app.Fragment;
1755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.os.Bundle;
1855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.ObjectAdapter;
1955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.PresenterSelector;
2055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.ItemBridgeAdapter;
21a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbournimport android.support.v17.leanback.widget.VerticalGridView;
2255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.Row;
2355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.support.v17.leanback.widget.ListRow;
240246318f27a905a31df5a8af445cfe67d31dfb68Dake Guimport android.support.v17.leanback.widget.OnChildViewHolderSelectedListener;
250246318f27a905a31df5a8af445cfe67d31dfb68Dake Guimport android.support.v7.widget.RecyclerView;
2655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.view.LayoutInflater;
2755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.view.View;
2855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutimport android.view.ViewGroup;
2955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
3055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout/**
31a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn * An internal base class for a fragment containing a list of rows.
3255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout */
3355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stoutabstract class BaseRowFragment extends Fragment {
3455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    private ObjectAdapter mAdapter;
35a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn    private VerticalGridView mVerticalGridView;
3655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    private PresenterSelector mPresenterSelector;
3755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    private ItemBridgeAdapter mBridgeAdapter;
3855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    private int mSelectedPosition = -1;
39902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu    private boolean mPendingTransitionPrepare;
4055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
4142752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    abstract int getLayoutResourceId();
4255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
430246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu    private final OnChildViewHolderSelectedListener mRowSelectedListener =
440246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu            new OnChildViewHolderSelectedListener() {
450246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                @Override
460246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                public void onChildViewHolderSelected(RecyclerView parent,
470246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                        RecyclerView.ViewHolder view, int position, int subposition) {
480246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                    onRowSelected(parent, view, position, subposition);
490246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                }
500246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu            };
5155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
520246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu    void onRowSelected(RecyclerView parent, RecyclerView.ViewHolder view,
530246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu            int position, int subposition) {
5455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
5555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
5655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    @Override
577a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu    public View onCreateView(LayoutInflater inflater, ViewGroup container,
587a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu            Bundle savedInstanceState) {
597a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu        View view = inflater.inflate(getLayoutResourceId(), container, false);
607a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu        mVerticalGridView = findGridViewFromRoot(view);
61902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu        if (mPendingTransitionPrepare) {
62902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu            mPendingTransitionPrepare = false;
63902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu            onTransitionPrepare();
64902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu        }
657a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu        return view;
667a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu    }
677a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu
6842752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    VerticalGridView findGridViewFromRoot(View view) {
697a208cd35be79a69b1f4f36724b85ab96eb23e75Dake Gu        return (VerticalGridView) view;
7055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
7155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
7255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    @Override
7355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    public void onViewCreated(View view, Bundle savedInstanceState) {
7455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        if (mBridgeAdapter != null) {
75a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn            mVerticalGridView.setAdapter(mBridgeAdapter);
7655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout            if (mSelectedPosition != -1) {
77a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn                mVerticalGridView.setSelectedPosition(mSelectedPosition);
7855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout            }
7955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        }
800246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu        mVerticalGridView.setOnChildViewHolderSelectedListener(mRowSelectedListener);
8155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
8255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
8355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    @Override
8455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    public void onDestroyView() {
8555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        super.onDestroyView();
86a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn        mVerticalGridView = null;
8755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
8855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
8955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    /**
90cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu     * Set the presenter selector used to create and bind views.
9155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout     */
92cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu    public final void setPresenterSelector(PresenterSelector presenterSelector) {
9355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        mPresenterSelector = presenterSelector;
9455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        updateAdapter();
9555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
9655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
9755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    /**
98cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu     * Get the presenter selector used to create and bind views.
99cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu     */
100cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu    public final PresenterSelector getPresenterSelector() {
101cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu        return mPresenterSelector;
102cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu    }
103cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu
104cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu    /**
10555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout     * Sets the adapter for the fragment.
10655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout     */
107cf94c5fa8ae8edb7e26a623133207415ceeed187Dake Gu    public final void setAdapter(ObjectAdapter rowsAdapter) {
10855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        mAdapter = rowsAdapter;
10955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        updateAdapter();
11055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
11155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
11255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    /**
11355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout     * Returns the list of rows.
11455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout     */
11555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    public final ObjectAdapter getAdapter() {
11655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        return mAdapter;
11755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
11855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
11955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    /**
12055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout     * Returns the bridge adapter.
12155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout     */
12242752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    final ItemBridgeAdapter getBridgeAdapter() {
12355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        return mBridgeAdapter;
12455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
12555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
12655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    /**
1273f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu     * Sets the selected row position with smooth animation.
12855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout     */
129025aa57d4fdd4e79289303c7dc54169311728f7bCraig Stout    public void setSelectedPosition(int position) {
1303f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu        setSelectedPosition(position, true);
1313f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu    }
1323f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu
1333f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu    /**
1343f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu     * Sets the selected row position.
1353f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu     */
1363f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu    public void setSelectedPosition(int position, boolean smooth) {
13755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        mSelectedPosition = position;
138a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn        if(mVerticalGridView != null && mVerticalGridView.getAdapter() != null) {
1393f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu            if (smooth) {
1403f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu                mVerticalGridView.setSelectedPositionSmooth(position);
1413f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu            } else {
1423f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu                mVerticalGridView.setSelectedPosition(position);
1433f0f3eb255bde49549a77c0b5d252decaa2a0202Dake Gu            }
14455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        }
14555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
14655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
147a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn    final VerticalGridView getVerticalGridView() {
148a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn        return mVerticalGridView;
14955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
15055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
15142752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    void updateAdapter() {
152e71207666a1a915e5a5bdf7503bd936f4d87b48bDake Gu        if (mBridgeAdapter != null) {
153e71207666a1a915e5a5bdf7503bd936f4d87b48bDake Gu            // detach observer from ObjectAdapter
154e71207666a1a915e5a5bdf7503bd936f4d87b48bDake Gu            mBridgeAdapter.clear();
155e71207666a1a915e5a5bdf7503bd936f4d87b48bDake Gu            mBridgeAdapter = null;
156e71207666a1a915e5a5bdf7503bd936f4d87b48bDake Gu        }
15755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
15855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        if (mAdapter != null) {
15955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout            // If presenter selector is null, adapter ps will be used
16055c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout            mBridgeAdapter = new ItemBridgeAdapter(mAdapter, mPresenterSelector);
16155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        }
162a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn        if (mVerticalGridView != null) {
163a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn            mVerticalGridView.setAdapter(mBridgeAdapter);
16455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout            if (mBridgeAdapter != null && mSelectedPosition != -1) {
165a8a3b898da49324e83ea32c3f08776a481312166Tim Kilbourn                mVerticalGridView.setSelectedPosition(mSelectedPosition);
16655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout            }
16755c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        }
16855c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
16955c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout
17042752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    Object getItem(Row row, int position) {
17155c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        if (row instanceof ListRow) {
17255c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout            return ((ListRow) row).getAdapter().get(position);
17355c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        } else {
17455c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout            return null;
17555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout        }
17655c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout    }
1772f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu
178902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu    boolean onTransitionPrepare() {
1792f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu        if (mVerticalGridView != null) {
1802f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu            mVerticalGridView.setAnimateChildLayout(false);
181902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu            mVerticalGridView.setScrollEnabled(false);
182902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu            return true;
1832f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu        }
184902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu        mPendingTransitionPrepare = true;
185902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu        return false;
186902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu    }
187902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu
188902e68c114f86e8002516ff3f0248b722b6c5711Dake Gu    void onTransitionStart() {
1894a4e0872bdf0548188e81740eb62085215e7f976Dake Gu        if (mVerticalGridView != null) {
1904a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setPruneChild(false);
1914a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setLayoutFrozen(true);
1924a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setFocusSearchDisabled(true);
1934a4e0872bdf0548188e81740eb62085215e7f976Dake Gu        }
1942f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu    }
1952f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu
1962f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu    void onTransitionEnd() {
1974a4e0872bdf0548188e81740eb62085215e7f976Dake Gu        // be careful that fragment might be destroyed before header transition ends.
1984a4e0872bdf0548188e81740eb62085215e7f976Dake Gu        if (mVerticalGridView != null) {
1994a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setLayoutFrozen(false);
2004a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setAnimateChildLayout(true);
2014a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setPruneChild(true);
2024a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setFocusSearchDisabled(false);
2034a4e0872bdf0548188e81740eb62085215e7f976Dake Gu            mVerticalGridView.setScrollEnabled(true);
2044a4e0872bdf0548188e81740eb62085215e7f976Dake Gu        }
2052f97594742886d045ca1ce409ebc6e6e780452f6Dake Gu    }
206e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu
207e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu    void setItemAlignment() {
208e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu        if (mVerticalGridView != null) {
209e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu            // align the top edge of item
210e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu            mVerticalGridView.setItemAlignmentOffset(0);
211e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu            mVerticalGridView.setItemAlignmentOffsetPercent(
212e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu                    VerticalGridView.ITEM_ALIGN_OFFSET_PERCENT_DISABLED);
213e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu        }
214e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu    }
215e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu
216e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu    void setWindowAlignmentFromTop(int alignedTop) {
217e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu        if (mVerticalGridView != null) {
218e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu            // align to a fixed position from top
219e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu            mVerticalGridView.setWindowAlignmentOffset(alignedTop);
220e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu            mVerticalGridView.setWindowAlignmentOffsetPercent(
221e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu                    VerticalGridView.WINDOW_ALIGN_OFFSET_PERCENT_DISABLED);
222e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu            mVerticalGridView.setWindowAlignment(VerticalGridView.WINDOW_ALIGN_NO_EDGE);
223e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu        }
224e43e9266c4b7e4902fefb5d2a0cacca90a3d2681Dake Gu    }
22555c9ee4b612ffc7b4632b1e4b7b7ab4900cd47c7Craig Stout}
226