16193c12a1897723c87b41f4e304a8cd04deef2dcDake Gu/* This file is auto-generated from HeadersFragment.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 Gu
1761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gupackage android.support.v17.leanback.app;
1861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
1961905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.content.Context;
2061905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.graphics.Color;
219a49e322d10c1a67860d812352a5ea710843b75eDake Guimport android.graphics.drawable.ColorDrawable;
2261905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.graphics.drawable.Drawable;
2361905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.graphics.drawable.GradientDrawable;
2461905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.os.Bundle;
2561905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.R;
268ff4c54cdaf5e8164fba7eac999c1ceafc462fc8Dake Guimport android.support.v17.leanback.widget.ClassPresenterSelector;
278ff4c54cdaf5e8164fba7eac999c1ceafc462fc8Dake Guimport android.support.v17.leanback.widget.DividerPresenter;
288ff4c54cdaf5e8164fba7eac999c1ceafc462fc8Dake Guimport android.support.v17.leanback.widget.DividerRow;
2961905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.FocusHighlightHelper;
302f5ebf3f6f7bb6a24856f389e369b247118ba119susnataimport android.support.v17.leanback.widget.HorizontalGridView;
3161905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.ItemBridgeAdapter;
3261905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.PresenterSelector;
3361905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.Row;
3461905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.RowHeaderPresenter;
358ff4c54cdaf5e8164fba7eac999c1ceafc462fc8Dake Guimport android.support.v17.leanback.widget.SectionRow;
3661905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.VerticalGridView;
370246318f27a905a31df5a8af445cfe67d31dfb68Dake Guimport android.support.v7.widget.RecyclerView;
3861905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.View;
3961905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.ViewGroup;
4061905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.View.OnLayoutChangeListener;
4161905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.widget.FrameLayout;
4261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
4361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu/**
4461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * An internal fragment containing a list of row headers.
4561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */
4661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gupublic class HeadersSupportFragment extends BaseRowSupportFragment {
4761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
48729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu    /**
49729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu     * Interface definition for a callback to be invoked when a header item is clicked.
50729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu     */
51729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu    public interface OnHeaderClickedListener {
52729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu        /**
53729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu         * Called when a header item has been clicked.
54729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu         *
55729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu         * @param viewHolder Row ViewHolder object corresponding to the selected Header.
56729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu         * @param row Row object corresponding to the selected Header.
57729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu         */
58729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu        void onHeaderClicked(RowHeaderPresenter.ViewHolder viewHolder, Row row);
5961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
6061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
61729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu    /**
62729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu     * Interface definition for a callback to be invoked when a header item is selected.
63729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu     */
64729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu    public interface OnHeaderViewSelectedListener {
65729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu        /**
66729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu         * Called when a header item has been selected.
67729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu         *
68729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu         * @param viewHolder Row ViewHolder object corresponding to the selected Header.
69729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu         * @param row Row object corresponding to the selected Header.
70729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu         */
718df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu        void onHeaderSelected(RowHeaderPresenter.ViewHolder viewHolder, Row row);
728df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu    }
738df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu
748df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu    private OnHeaderViewSelectedListener mOnHeaderViewSelectedListener;
7599ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    OnHeaderClickedListener mOnHeaderClickedListener;
7661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private boolean mHeadersEnabled = true;
7761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private boolean mHeadersGone = false;
7861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private int mBackgroundColor;
7961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private boolean mBackgroundColorSet;
8061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
818ff4c54cdaf5e8164fba7eac999c1ceafc462fc8Dake Gu    private static final PresenterSelector sHeaderPresenter = new ClassPresenterSelector()
828ff4c54cdaf5e8164fba7eac999c1ceafc462fc8Dake Gu            .addClassPresenter(DividerRow.class, new DividerPresenter())
838ff4c54cdaf5e8164fba7eac999c1ceafc462fc8Dake Gu            .addClassPresenter(SectionRow.class,
848ff4c54cdaf5e8164fba7eac999c1ceafc462fc8Dake Gu                    new RowHeaderPresenter(R.layout.lb_section_header, false))
858ff4c54cdaf5e8164fba7eac999c1ceafc462fc8Dake Gu            .addClassPresenter(Row.class, new RowHeaderPresenter(R.layout.lb_header));
8661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
8761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public HeadersSupportFragment() {
8861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        setPresenterSelector(sHeaderPresenter);
8961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
9061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
9161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public void setOnHeaderClickedListener(OnHeaderClickedListener listener) {
9261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mOnHeaderClickedListener = listener;
9361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
9461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
958df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu    public void setOnHeaderViewSelectedListener(OnHeaderViewSelectedListener listener) {
968df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu        mOnHeaderViewSelectedListener = listener;
9761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
9861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
9961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
10042752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    VerticalGridView findGridViewFromRoot(View view) {
10161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        return (VerticalGridView) view.findViewById(R.id.browse_headers);
10261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
10361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
10461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
1050246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu    void onRowSelected(RecyclerView parent, RecyclerView.ViewHolder viewHolder,
1060246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu            int position, int subposition) {
1078df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu        if (mOnHeaderViewSelectedListener != null) {
1080246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu            if (viewHolder != null && position >= 0) {
1090246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder) viewHolder;
1108df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu                mOnHeaderViewSelectedListener.onHeaderSelected(
111729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu                        (RowHeaderPresenter.ViewHolder) vh.getViewHolder(), (Row) vh.getItem());
11261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            } else {
1138df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu                mOnHeaderViewSelectedListener.onHeaderSelected(null, null);
11461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
11561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
11661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
11761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
11861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private final ItemBridgeAdapter.AdapterListener mAdapterListener =
11961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            new ItemBridgeAdapter.AdapterListener() {
12061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        @Override
121729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu        public void onCreate(final ItemBridgeAdapter.ViewHolder viewHolder) {
12261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            View headerView = viewHolder.getViewHolder().view;
12361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            headerView.setOnClickListener(new View.OnClickListener() {
12461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                @Override
12561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                public void onClick(View v) {
12661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    if (mOnHeaderClickedListener != null) {
127729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu                        mOnHeaderClickedListener.onHeaderClicked(
128729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu                                (RowHeaderPresenter.ViewHolder) viewHolder.getViewHolder(),
129729cbf4cd57c87bcd569db5974c8cbd51a942581Dake Gu                                (Row) viewHolder.getItem());
13061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    }
13161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                }
13261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            });
13361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            if (mWrapper != null) {
13461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                viewHolder.itemView.addOnLayoutChangeListener(sLayoutChangeListener);
13561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            } else {
13661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                headerView.addOnLayoutChangeListener(sLayoutChangeListener);
13761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
13861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
13961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
14061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    };
14161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
14299ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    static OnLayoutChangeListener sLayoutChangeListener = new OnLayoutChangeListener() {
14361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        @Override
14461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public void onLayoutChange(View v, int left, int top, int right, int bottom,
14561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            int oldLeft, int oldTop, int oldRight, int oldBottom) {
1468e3566285de4ac771d6188f62fe947e23d371a3dKris Giesing            v.setPivotX(v.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL ? v.getWidth() : 0);
14761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            v.setPivotY(v.getMeasuredHeight() / 2);
14861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
14961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    };
15061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
15161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
15242752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    int getLayoutResourceId() {
15361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        return R.layout.lb_headers_fragment;
15461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
15561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
15661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
15761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public void onViewCreated(View view, Bundle savedInstanceState) {
15861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        super.onViewCreated(view, savedInstanceState);
15961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        final VerticalGridView listView = getVerticalGridView();
16061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (listView == null) {
16161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            return;
16261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
16361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (getBridgeAdapter() != null) {
16461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            FocusHighlightHelper.setupHeaderItemFocusHighlight(listView);
16561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
1667f43e18536eae40705d5c63830e9edb283f196adDake Gu        if (mBackgroundColorSet) {
1679a49e322d10c1a67860d812352a5ea710843b75eDake Gu            listView.setBackgroundColor(mBackgroundColor);
1687f43e18536eae40705d5c63830e9edb283f196adDake Gu            updateFadingEdgeToBrandColor(mBackgroundColor);
1699a49e322d10c1a67860d812352a5ea710843b75eDake Gu        } else {
1709a49e322d10c1a67860d812352a5ea710843b75eDake Gu            Drawable d = listView.getBackground();
1719a49e322d10c1a67860d812352a5ea710843b75eDake Gu            if (d instanceof ColorDrawable) {
1729a49e322d10c1a67860d812352a5ea710843b75eDake Gu                updateFadingEdgeToBrandColor(((ColorDrawable) d).getColor());
1739a49e322d10c1a67860d812352a5ea710843b75eDake Gu            }
1747f43e18536eae40705d5c63830e9edb283f196adDake Gu        }
17561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        updateListViewVisibility();
17661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
17761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
17861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private void updateListViewVisibility() {
17961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        final VerticalGridView listView = getVerticalGridView();
18061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (listView != null) {
18161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            getView().setVisibility(mHeadersGone ? View.GONE : View.VISIBLE);
18261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            if (!mHeadersGone) {
18361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                if (mHeadersEnabled) {
18461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    listView.setChildrenVisibility(View.VISIBLE);
18561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                } else {
18661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    listView.setChildrenVisibility(View.INVISIBLE);
18761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                }
18861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
18961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
19061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
19161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
19261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    void setHeadersEnabled(boolean enabled) {
19361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mHeadersEnabled = enabled;
19461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        updateListViewVisibility();
19561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
19661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
19761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    void setHeadersGone(boolean gone) {
19861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mHeadersGone = gone;
19961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        updateListViewVisibility();
20061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
20161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
20261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    static class NoOverlappingFrameLayout extends FrameLayout {
20361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
20461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public NoOverlappingFrameLayout(Context context) {
20561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            super(context);
20661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
20761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
20861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        /**
20961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu         * Avoid creating hardware layer for header dock.
21061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu         */
21161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        @Override
21261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public boolean hasOverlappingRendering() {
21361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            return false;
21461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
21561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
21661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
21761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    // Wrapper needed because of conflict between RecyclerView's use of alpha
218c9a859537b0871f84afeeb706a5b425fe3f2b4ddAurimas Liutikas    // for ADD animations, and RowHeaderPresenter's use of alpha for selected level.
21999ec8b0cb375f7e5577ea3ec9f09e6ff7a95de0dAurimas Liutikas    final ItemBridgeAdapter.Wrapper mWrapper = new ItemBridgeAdapter.Wrapper() {
22061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        @Override
22161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public void wrap(View wrapper, View wrapped) {
22261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            ((FrameLayout) wrapper).addView(wrapped);
22361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
22461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
22561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        @Override
22661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public View createWrapper(View root) {
22761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            return new NoOverlappingFrameLayout(root.getContext());
22861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
22961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    };
23061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
23142752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    void updateAdapter() {
23261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        super.updateAdapter();
23361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        ItemBridgeAdapter adapter = getBridgeAdapter();
23461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (adapter != null) {
23561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            adapter.setAdapterListener(mAdapterListener);
23661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            adapter.setWrapper(mWrapper);
23761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
23861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (adapter != null && getVerticalGridView() != null) {
23961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            FocusHighlightHelper.setupHeaderItemFocusHighlight(getVerticalGridView());
24061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
24161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
24261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
24361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    void setBackgroundColor(int color) {
24461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mBackgroundColor = color;
24561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mBackgroundColorSet = true;
24661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
2479a49e322d10c1a67860d812352a5ea710843b75eDake Gu        if (getVerticalGridView() != null) {
2489a49e322d10c1a67860d812352a5ea710843b75eDake Gu            getVerticalGridView().setBackgroundColor(mBackgroundColor);
24961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            updateFadingEdgeToBrandColor(mBackgroundColor);
25061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
25161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
25261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
25361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private void updateFadingEdgeToBrandColor(int backgroundColor) {
25461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        View fadingView = getView().findViewById(R.id.fade_out_edge);
25561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        Drawable background = fadingView.getBackground();
25661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (background instanceof GradientDrawable) {
25761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            background.mutate();
25861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            ((GradientDrawable) background).setColors(
25961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    new int[] {Color.TRANSPARENT, backgroundColor});
26061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
26161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
26261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
26361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
2642f5ebf3f6f7bb6a24856f389e369b247118ba119susnata    public void onTransitionStart() {
26561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        super.onTransitionStart();
26661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (!mHeadersEnabled) {
26761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // When enabling headers fragment,  the RowHeaderView gets a focus but
268c9a859537b0871f84afeeb706a5b425fe3f2b4ddAurimas Liutikas            // isShown() is still false because its parent is INVISIBLE, accessibility
26961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // event is not sent.
27061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // Workaround is: prevent focus to a child view during transition and put
27161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // focus on it after transition is done.
27261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            final VerticalGridView listView = getVerticalGridView();
27361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            if (listView != null) {
27461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
27561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                if (listView.hasFocus()) {
27661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    listView.requestFocus();
27761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                }
27861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
27961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
28061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
28161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
28261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
2832f5ebf3f6f7bb6a24856f389e369b247118ba119susnata    public void onTransitionEnd() {
28461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (mHeadersEnabled) {
28561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            final VerticalGridView listView = getVerticalGridView();
28661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            if (listView != null) {
28761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
28861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                if (listView.hasFocus()) {
28961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    listView.requestFocus();
29061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                }
29161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
29261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
29361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        super.onTransitionEnd();
29461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
2952f5ebf3f6f7bb6a24856f389e369b247118ba119susnata
2962f5ebf3f6f7bb6a24856f389e369b247118ba119susnata    public boolean isScrolling() {
2972f5ebf3f6f7bb6a24856f389e369b247118ba119susnata        return getVerticalGridView().getScrollState()
2982f5ebf3f6f7bb6a24856f389e369b247118ba119susnata                != HorizontalGridView.SCROLL_STATE_IDLE;
2992f5ebf3f6f7bb6a24856f389e369b247118ba119susnata    }
30061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu}
301