ControlBarPresenter.java revision aa93f6777233b789feb14d95d900b158d0ac4841
17ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout/*
27ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Copyright (C) 2014 The Android Open Source Project
37ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
47ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
57ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * in compliance with the License. You may obtain a copy of the License at
67ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
77ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * http://www.apache.org/licenses/LICENSE-2.0
87ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
97ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Unless required by applicable law or agreed to in writing, software distributed under the License
107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * or implied. See the License for the specific language governing permissions and limitations under
127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * the License.
137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */
147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutpackage android.support.v17.leanback.widget;
157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
16aa93f6777233b789feb14d95d900b158d0ac4841Craig Stoutimport android.content.Context;
177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.support.v17.leanback.R;
187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.util.SparseArray;
197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.LayoutInflater;
207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.View;
217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.view.ViewGroup;
227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutimport android.widget.LinearLayout;
237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout/**
257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * A presenter that assumes a LinearLayout container for a series
267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * of control buttons backed by objects of type {@link Action}.
277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout *
287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * Different layouts may be passed to the presenter constructor.
297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout * The layout must contain a view with id control_bar.
307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout */
317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stoutclass ControlBarPresenter extends Presenter {
327ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
337ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private static final int MAX_CONTROLS = 7;
347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * The data type expected by this presenter.
377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    static class BoundData {
397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Adapter containing objects of type {@link Action}.
417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ObjectAdapter adapter;
437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * The presenter to be used for the adapter objects.
467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        Presenter presenter;
487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * A ViewHolder for an actions bar.
527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    class ViewHolder extends Presenter.ViewHolder {
547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ObjectAdapter mAdapter;
557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        Presenter mPresenter;
56aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout        ControlBar mControlBar;
577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        SparseArray<Presenter.ViewHolder> mViewHolders =
587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                new SparseArray<Presenter.ViewHolder>();
597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ObjectAdapter.DataObserver mDataObserver;
607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        /**
627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         * Constructor for the ViewHolder.
637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout         */
647ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ViewHolder(View rootView) {
657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            super(rootView);
66aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout            mControlBar = (ControlBar) rootView.findViewById(R.id.control_bar);
677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            if (mControlBar == null) {
687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                throw new IllegalStateException("Couldn't find control_bar");
697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            }
707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mDataObserver = new ObjectAdapter.DataObserver() {
717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                @Override
727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                public void onChanged() {
737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    showControls(mAdapter, mPresenter);
747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                }
757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                @Override
767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                public void onItemRangeChanged(int positionStart, int itemCount) {
777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    for (int i = 0; i < itemCount; i++) {
787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                        bindControlToAction(positionStart + i, mAdapter, mPresenter);
797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    }
807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                }
817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            };
827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
84aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout        int getChildMarginFromCenter(Context context, int numControls) {
85aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout            // Includes margin between icons plus two times half the icon width.
86aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout            return getChildMarginDefault(context) + getControlIconWidth(context);
87aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout        }
88aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout
897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        void showControls(ObjectAdapter adapter, Presenter presenter) {
907ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            View focusedChild = mControlBar.getFocusedChild();
917ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            mControlBar.removeAllViews();
927ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            for (int position = 0; position < adapter.size() && position < MAX_CONTROLS;
937ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    position++) {
947ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                bindControlToAction(position, adapter, presenter);
957ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            }
967ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            if (focusedChild != null) {
977ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                focusedChild.requestFocus();
987ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            }
99aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout            mControlBar.setChildMarginFromCenter(
100aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout                    getChildMarginFromCenter(mControlBar.getContext(), adapter.size()));
1017ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
1027ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1037ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        void bindControlToAction(final int position, ObjectAdapter adapter, Presenter presenter) {
1047ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            Presenter.ViewHolder vh = mViewHolders.get(position);
1057ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            Object item = adapter.get(position);
1067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            if (vh == null) {
1077ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                vh = presenter.onCreateViewHolder(mControlBar);
1087ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                mViewHolders.put(position, vh);
1097ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                presenter.setOnClickListener(vh, new View.OnClickListener() {
1107ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    @Override
1117ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    public void onClick(View v) {
1127ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                        Object item = getAdapter().get(position);
1137ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                        if (mOnActionClickedListener != null && item instanceof Action) {
1147ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                            mOnActionClickedListener.onActionClicked((Action) item);
1157ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                        }
1167ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                    }
1177ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                });
1187ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            }
1197ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            if (vh.view.getParent() == null) {
1207ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout                mControlBar.addView(vh.view);
1217ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            }
1227ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            presenter.onBindViewHolder(vh, item);
1237ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
1247ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1257ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ObjectAdapter getAdapter() {
1267ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            return mAdapter;
1277ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
1287ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1297ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1307ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private OnActionClickedListener mOnActionClickedListener;
1317ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    private int mLayoutResourceId;
132aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout    private static int sChildMarginDefault;
133aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout    private static int sControlIconWidth;
1347ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1357ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1367ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Constructor for a ControlBarPresenter.
1377ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     *
1387ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * @param layoutResourceId The resource id of the layout for this presenter.
1397ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1407ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public ControlBarPresenter(int layoutResourceId) {
1417ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mLayoutResourceId = layoutResourceId;
1427ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1437ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1447ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1457ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Returns the layout resource id.
1467ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1477ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public int getLayoutResourceId() {
1487ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mLayoutResourceId;
1497ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1507ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1517ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1527ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Sets the listener for {@link Action} click events.
1537ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1547ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public void setOnActionClickedListener(OnActionClickedListener listener) {
1557ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        mOnActionClickedListener = listener;
1567ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1577ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1587ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    /**
1597ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     * Gets the listener for {@link Action} click events.
1607ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout     */
1617ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public OnActionClickedListener getOnActionClickedListener() {
1627ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return mOnActionClickedListener;
1637ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1647ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1657ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    @Override
1667ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
1677ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        View v = LayoutInflater.from(parent.getContext())
1687ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            .inflate(getLayoutResourceId(), parent, false);
1697ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        return new ViewHolder(v);
1707ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1717ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1727ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    @Override
1737ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public void onBindViewHolder(Presenter.ViewHolder holder, Object item) {
1747ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ViewHolder vh = (ViewHolder) holder;
1757ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        BoundData data = (BoundData) item;
1767ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        if (vh.mAdapter != data.adapter) {
1777ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mAdapter = data.adapter;
1787ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout            vh.mAdapter.registerObserver(vh.mDataObserver);
1797ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        }
1807ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mPresenter = data.presenter;
1817ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.showControls(vh.mAdapter, vh.mPresenter);
1827ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
1837ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout
1847ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    @Override
1857ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    public void onUnbindViewHolder(Presenter.ViewHolder holder) {
1867ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        ViewHolder vh = (ViewHolder) holder;
1877ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mAdapter.unregisterObserver(vh.mDataObserver);
1887ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout        vh.mAdapter = null;
1897ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout    }
190aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout
191aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout    int getChildMarginDefault(Context context) {
192aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout        if (sChildMarginDefault == 0) {
193aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout            sChildMarginDefault = context.getResources().getDimensionPixelSize(
194aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout                    R.dimen.lb_playback_controls_child_margin_default);
195aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout        }
196aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout        return sChildMarginDefault;
197aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout    }
198aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout
199aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout    int getControlIconWidth(Context context) {
200aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout        if (sControlIconWidth == 0) {
201aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout            sControlIconWidth = context.getResources().getDimensionPixelSize(
202aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout                    R.dimen.lb_control_icon_width);
203aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout        }
204aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout        return sControlIconWidth;
205aa93f6777233b789feb14d95d900b158d0ac4841Craig Stout    }
2067ab1edf2b49f3cdcb9db7a1c60d0dc1e17a9aef7Craig Stout}
207