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;
2161905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.graphics.drawable.Drawable;
2261905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.graphics.drawable.GradientDrawable;
2361905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.os.Bundle;
2461905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.R;
2561905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.FocusHighlightHelper;
2661905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.ItemBridgeAdapter;
2761905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.PresenterSelector;
288df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Guimport android.support.v17.leanback.widget.OnItemViewSelectedListener;
2961905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.Row;
3061905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.RowHeaderPresenter;
3161905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.SinglePresenterSelector;
3261905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.support.v17.leanback.widget.VerticalGridView;
330246318f27a905a31df5a8af445cfe67d31dfb68Dake Guimport android.support.v7.widget.RecyclerView;
3461905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.util.TypedValue;
3561905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.View;
3661905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.ViewGroup;
3761905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.view.View.OnLayoutChangeListener;
3861905b0b52c50018dcaebcd79699c39b8f28d622Dake Guimport android.widget.FrameLayout;
3961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
4061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu/**
4161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu * An internal fragment containing a list of row headers.
4261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu */
4361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gupublic class HeadersSupportFragment extends BaseRowSupportFragment {
4461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
4561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    interface OnHeaderClickedListener {
4661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        void onHeaderClicked();
4761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
4861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
498df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu    interface OnHeaderViewSelectedListener {
508df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu        void onHeaderSelected(RowHeaderPresenter.ViewHolder viewHolder, Row row);
518df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu    }
528df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu
538df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu    private OnHeaderViewSelectedListener mOnHeaderViewSelectedListener;
5461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private OnHeaderClickedListener mOnHeaderClickedListener;
5561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private boolean mHeadersEnabled = true;
5661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private boolean mHeadersGone = false;
5761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private int mBackgroundColor;
5861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private boolean mBackgroundColorSet;
5961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
6061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private static final PresenterSelector sHeaderPresenter = new SinglePresenterSelector(
6161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            new RowHeaderPresenter(R.layout.lb_header));
6261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
6361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public HeadersSupportFragment() {
6461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        setPresenterSelector(sHeaderPresenter);
6561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
6661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
6761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public void setOnHeaderClickedListener(OnHeaderClickedListener listener) {
6861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mOnHeaderClickedListener = listener;
6961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
7061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
718df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu    public void setOnHeaderViewSelectedListener(OnHeaderViewSelectedListener listener) {
728df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu        mOnHeaderViewSelectedListener = listener;
7361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
7461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
7561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
7642752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    VerticalGridView findGridViewFromRoot(View view) {
7761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        return (VerticalGridView) view.findViewById(R.id.browse_headers);
7861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
7961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
8061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
810246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu    void onRowSelected(RecyclerView parent, RecyclerView.ViewHolder viewHolder,
820246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu            int position, int subposition) {
838df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu        if (mOnHeaderViewSelectedListener != null) {
840246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu            if (viewHolder != null && position >= 0) {
8561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                Row row = (Row) getAdapter().get(position);
860246318f27a905a31df5a8af445cfe67d31dfb68Dake Gu                ItemBridgeAdapter.ViewHolder vh = (ItemBridgeAdapter.ViewHolder) viewHolder;
878df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu                mOnHeaderViewSelectedListener.onHeaderSelected(
888df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu                        (RowHeaderPresenter.ViewHolder) vh.getViewHolder(), row);
8961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            } else {
908df88a1ead9ea62456fc3bbda41657ccf61d5721Dake Gu                mOnHeaderViewSelectedListener.onHeaderSelected(null, null);
9161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
9261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
9361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
9461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
9561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private final ItemBridgeAdapter.AdapterListener mAdapterListener =
9661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            new ItemBridgeAdapter.AdapterListener() {
9761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        @Override
9861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public void onCreate(ItemBridgeAdapter.ViewHolder viewHolder) {
9961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            View headerView = viewHolder.getViewHolder().view;
10061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            headerView.setOnClickListener(new View.OnClickListener() {
10161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                @Override
10261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                public void onClick(View v) {
10361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    if (mOnHeaderClickedListener != null) {
10461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                        mOnHeaderClickedListener.onHeaderClicked();
10561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    }
10661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                }
10761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            });
10861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            headerView.setFocusable(true);
10961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            headerView.setFocusableInTouchMode(true);
11061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            if (mWrapper != null) {
11161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                viewHolder.itemView.addOnLayoutChangeListener(sLayoutChangeListener);
11261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            } else {
11361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                headerView.addOnLayoutChangeListener(sLayoutChangeListener);
11461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
11561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
11661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
11761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    };
11861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
11961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private static OnLayoutChangeListener sLayoutChangeListener = new OnLayoutChangeListener() {
12061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        @Override
12161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public void onLayoutChange(View v, int left, int top, int right, int bottom,
12261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            int oldLeft, int oldTop, int oldRight, int oldBottom) {
1238e3566285de4ac771d6188f62fe947e23d371a3dKris Giesing            v.setPivotX(v.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL ? v.getWidth() : 0);
12461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            v.setPivotY(v.getMeasuredHeight() / 2);
12561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
12661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    };
12761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
12861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
12942752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    int getLayoutResourceId() {
13061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        return R.layout.lb_headers_fragment;
13161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
13261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
13361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
13461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    public void onViewCreated(View view, Bundle savedInstanceState) {
13561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        super.onViewCreated(view, savedInstanceState);
13661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        final VerticalGridView listView = getVerticalGridView();
13761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (listView == null) {
13861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            return;
13961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
14061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (getBridgeAdapter() != null) {
14161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            FocusHighlightHelper.setupHeaderItemFocusHighlight(listView);
14261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
14361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        view.setBackgroundColor(getBackgroundColor());
14461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        updateFadingEdgeToBrandColor(getBackgroundColor());
14561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        updateListViewVisibility();
14661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
14761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
14861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private void updateListViewVisibility() {
14961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        final VerticalGridView listView = getVerticalGridView();
15061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (listView != null) {
15161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            getView().setVisibility(mHeadersGone ? View.GONE : View.VISIBLE);
15261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            if (!mHeadersGone) {
15361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                if (mHeadersEnabled) {
15461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    listView.setChildrenVisibility(View.VISIBLE);
15561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                } else {
15661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    listView.setChildrenVisibility(View.INVISIBLE);
15761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                }
15861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
15961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
16061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
16161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
16261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    void setHeadersEnabled(boolean enabled) {
16361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mHeadersEnabled = enabled;
16461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        updateListViewVisibility();
16561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
16661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
16761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    void setHeadersGone(boolean gone) {
16861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mHeadersGone = gone;
16961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        updateListViewVisibility();
17061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
17161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
17261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    static class NoOverlappingFrameLayout extends FrameLayout {
17361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
17461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public NoOverlappingFrameLayout(Context context) {
17561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            super(context);
17661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
17761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
17861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        /**
17961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu         * Avoid creating hardware layer for header dock.
18061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu         */
18161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        @Override
18261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public boolean hasOverlappingRendering() {
18361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            return false;
18461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
18561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
18661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
18761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    // Wrapper needed because of conflict between RecyclerView's use of alpha
18861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    // for ADD animations, and RowHeaderPresnter's use of alpha for selected level.
18961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private final ItemBridgeAdapter.Wrapper mWrapper = new ItemBridgeAdapter.Wrapper() {
19061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        @Override
19161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public void wrap(View wrapper, View wrapped) {
19261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            ((FrameLayout) wrapper).addView(wrapped);
19361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
19461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
19561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        @Override
19661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        public View createWrapper(View root) {
19761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            return new NoOverlappingFrameLayout(root.getContext());
19861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
19961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    };
20061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
20142752c860a26deacca04ea9ebeb00ddb4d8ce2fcDake Gu    void updateAdapter() {
20261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        super.updateAdapter();
20361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        ItemBridgeAdapter adapter = getBridgeAdapter();
20461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (adapter != null) {
20561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            adapter.setAdapterListener(mAdapterListener);
20661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            adapter.setWrapper(mWrapper);
20761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
20861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (adapter != null && getVerticalGridView() != null) {
20961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            FocusHighlightHelper.setupHeaderItemFocusHighlight(getVerticalGridView());
21061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
21161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
21261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
21361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    void setBackgroundColor(int color) {
21461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mBackgroundColor = color;
21561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        mBackgroundColorSet = true;
21661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
21761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (getView() != null) {
21861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            getView().setBackgroundColor(mBackgroundColor);
21961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            updateFadingEdgeToBrandColor(mBackgroundColor);
22061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
22161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
22261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
22361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    private void updateFadingEdgeToBrandColor(int backgroundColor) {
22461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        View fadingView = getView().findViewById(R.id.fade_out_edge);
22561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        Drawable background = fadingView.getBackground();
22661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (background instanceof GradientDrawable) {
22761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            background.mutate();
22861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            ((GradientDrawable) background).setColors(
22961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    new int[] {Color.TRANSPARENT, backgroundColor});
23061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
23161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
23261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
23361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    int getBackgroundColor() {
23461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (getActivity() == null) {
23561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            throw new IllegalStateException("Activity must be attached");
23661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
23761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
23861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (mBackgroundColorSet) {
23961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            return mBackgroundColor;
24061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
24161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
24261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        TypedValue outValue = new TypedValue();
24346443cb5b092f1d9156342645088eead9da026f6Dake Gu        if (getActivity().getTheme().resolveAttribute(R.attr.defaultBrandColor, outValue, true)) {
24446443cb5b092f1d9156342645088eead9da026f6Dake Gu            return getResources().getColor(outValue.resourceId);
24546443cb5b092f1d9156342645088eead9da026f6Dake Gu        }
24646443cb5b092f1d9156342645088eead9da026f6Dake Gu        return getResources().getColor(R.color.lb_default_brand_color);
24761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
24861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
24961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
25061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    void onTransitionStart() {
25161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        super.onTransitionStart();
25261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (!mHeadersEnabled) {
25361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // When enabling headers fragment,  the RowHeaderView gets a focus but
25461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // isShown() is still false because its parent is INVSIBILE, accessibility
25561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // event is not sent.
25661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // Workaround is: prevent focus to a child view during transition and put
25761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            // focus on it after transition is done.
25861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            final VerticalGridView listView = getVerticalGridView();
25961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            if (listView != null) {
26061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
26161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                if (listView.hasFocus()) {
26261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    listView.requestFocus();
26361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                }
26461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
26561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
26661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
26761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu
26861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    @Override
26961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    void onTransitionEnd() {
27061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        if (mHeadersEnabled) {
27161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            final VerticalGridView listView = getVerticalGridView();
27261905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            if (listView != null) {
27361905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
27461905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                if (listView.hasFocus()) {
27561905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                    listView.requestFocus();
27661905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu                }
27761905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu            }
27861905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        }
27961905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu        super.onTransitionEnd();
28061905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu    }
28161905b0b52c50018dcaebcd79699c39b8f28d622Dake Gu}
282