1e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam/*
2e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * Copyright (C) 2015 The Android Open Source Project
3e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam *
4e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * Licensed under the Apache License, Version 2.0 (the "License");
5e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * you may not use this file except in compliance with the License.
6e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * You may obtain a copy of the License at
7e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam *
8e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam *      http://www.apache.org/licenses/LICENSE-2.0
9e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam *
10e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * Unless required by applicable law or agreed to in writing, software
11e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * distributed under the License is distributed on an "AS IS" BASIS,
12e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * See the License for the specific language governing permissions and
14e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * limitations under the License.
15e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam */
16e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
17e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lampackage com.android.setupwizardlib;
18e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
19e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lamimport android.annotation.TargetApi;
20e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lamimport android.content.Context;
21180360409c9e4e9163c670ff48663244b4057eafMaurice Lamimport android.graphics.drawable.Drawable;
22e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lamimport android.os.Build.VERSION_CODES;
23e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lamimport android.util.AttributeSet;
24e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lamimport android.view.LayoutInflater;
25e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lamimport android.view.View;
26e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lamimport android.view.ViewGroup;
27e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lamimport android.widget.ListAdapter;
28e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lamimport android.widget.ListView;
29e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
30d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lamimport com.android.setupwizardlib.template.ListMixin;
310ceb8d53e39ebb5bc103863787afb39ec5c41ad8Maurice Lamimport com.android.setupwizardlib.template.ListViewScrollHandlingDelegate;
320ceb8d53e39ebb5bc103863787afb39ec5c41ad8Maurice Lamimport com.android.setupwizardlib.template.RequireScrollMixin;
33e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
34e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam/**
35e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * A GLIF themed layout with a ListView. {@code android:entries} can also be used to specify an
36e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam * {@link com.android.setupwizardlib.items.ItemHierarchy} to be used with this layout in XML.
37e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam */
38e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lampublic class GlifListLayout extends GlifLayout {
39e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
40180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    /* static section */
41180360409c9e4e9163c670ff48663244b4057eafMaurice Lam
42e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    private static final String TAG = "GlifListLayout";
43180360409c9e4e9163c670ff48663244b4057eafMaurice Lam
44180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    /* non-static section */
45180360409c9e4e9163c670ff48663244b4057eafMaurice Lam
46d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam    private ListMixin mListMixin;
47e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
48e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    public GlifListLayout(Context context) {
49e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        this(context, 0, 0);
50e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
51e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
52e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    public GlifListLayout(Context context, int template) {
53e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        this(context, template, 0);
54e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
55e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
56e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    public GlifListLayout(Context context, int template, int containerId) {
57e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        super(context, template, containerId);
58e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        init(context, null, 0);
59e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
60e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
61e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    public GlifListLayout(Context context, AttributeSet attrs) {
62e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        super(context, attrs);
63e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        init(context, attrs, 0);
64e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
65e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
66e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    @TargetApi(VERSION_CODES.HONEYCOMB)
67e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    public GlifListLayout(Context context, AttributeSet attrs, int defStyleAttr) {
68e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        super(context, attrs, defStyleAttr);
69e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        init(context, attrs, defStyleAttr);
70e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
71e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
72e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    private void init(Context context, AttributeSet attrs, int defStyleAttr) {
73d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam        mListMixin = new ListMixin(this, attrs, defStyleAttr);
74d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam        registerMixin(ListMixin.class, mListMixin);
750ceb8d53e39ebb5bc103863787afb39ec5c41ad8Maurice Lam
760ceb8d53e39ebb5bc103863787afb39ec5c41ad8Maurice Lam        final RequireScrollMixin requireScrollMixin = getMixin(RequireScrollMixin.class);
770ceb8d53e39ebb5bc103863787afb39ec5c41ad8Maurice Lam        requireScrollMixin.setScrollHandlingDelegate(
780ceb8d53e39ebb5bc103863787afb39ec5c41ad8Maurice Lam                new ListViewScrollHandlingDelegate(requireScrollMixin, getListView()));
79e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
80e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
81e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    @Override
82180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
83180360409c9e4e9163c670ff48663244b4057eafMaurice Lam        super.onLayout(changed, left, top, right, bottom);
84d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam        mListMixin.onLayout();
85180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    }
86180360409c9e4e9163c670ff48663244b4057eafMaurice Lam
87180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    @Override
88e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    protected View onInflateTemplate(LayoutInflater inflater, int template) {
89e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        if (template == 0) {
90e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam            template = R.layout.suw_glif_list_template;
91e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        }
92e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        return super.onInflateTemplate(inflater, template);
93e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
94e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
95e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    @Override
96e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    protected ViewGroup findContainer(int containerId) {
97e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        if (containerId == 0) {
98e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam            containerId = android.R.id.list;
99e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        }
100e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam        return super.findContainer(containerId);
101e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
102e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
103e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    public ListView getListView() {
104d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam        return mListMixin.getListView();
105e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
106e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
107e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    public void setAdapter(ListAdapter adapter) {
108d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam        mListMixin.setAdapter(adapter);
109e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
110e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam
111e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    public ListAdapter getAdapter() {
112d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam        return mListMixin.getAdapter();
113e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam    }
114180360409c9e4e9163c670ff48663244b4057eafMaurice Lam
115180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    /**
1166011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     * @deprecated Use {@link #setDividerInsets(int, int)} instead.
1176011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     */
1186011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    @Deprecated
1196011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    public void setDividerInset(int inset) {
1206011b35deae30839cd454e0ec5866487e90860f5Maurice Lam        mListMixin.setDividerInset(inset);
1216011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    }
1226011b35deae30839cd454e0ec5866487e90860f5Maurice Lam
1236011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    /**
124180360409c9e4e9163c670ff48663244b4057eafMaurice Lam     * Sets the start inset of the divider. This will use the default divider drawable set in the
1256011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     * theme and apply insets to it.
126180360409c9e4e9163c670ff48663244b4057eafMaurice Lam     *
1276011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     * @param start The number of pixels to inset on the "start" side of the list divider. Typically
12815391fc05a0fc45e9af85b653abffa41df575e91Maurice Lam     *              this will be either {@code @dimen/suw_items_glif_icon_divider_inset} or
12915391fc05a0fc45e9af85b653abffa41df575e91Maurice Lam     *              {@code @dimen/suw_items_glif_text_divider_inset}.
1306011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     * @param end The number of pixels to inset on the "end" side of the list divider.
131d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam     *
1326011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     * @see ListMixin#setDividerInsets(int, int)
133180360409c9e4e9163c670ff48663244b4057eafMaurice Lam     */
1346011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    public void setDividerInsets(int start, int end) {
1356011b35deae30839cd454e0ec5866487e90860f5Maurice Lam        mListMixin.setDividerInsets(start, end);
136180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    }
137180360409c9e4e9163c670ff48663244b4057eafMaurice Lam
138d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam    /**
1396011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     * @deprecated Use {@link #getDividerInsetStart()} instead.
140d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam     */
1416011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    @Deprecated
142180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    public int getDividerInset() {
143d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam        return mListMixin.getDividerInset();
144180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    }
145180360409c9e4e9163c670ff48663244b4057eafMaurice Lam
146d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam    /**
1476011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     * @see ListMixin#getDividerInsetStart()
1486011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     */
1496011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    public int getDividerInsetStart() {
1506011b35deae30839cd454e0ec5866487e90860f5Maurice Lam        return mListMixin.getDividerInsetStart();
1516011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    }
1526011b35deae30839cd454e0ec5866487e90860f5Maurice Lam
1536011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    /**
1546011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     * @see ListMixin#getDividerInsetEnd()
1556011b35deae30839cd454e0ec5866487e90860f5Maurice Lam     */
1566011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    public int getDividerInsetEnd() {
1576011b35deae30839cd454e0ec5866487e90860f5Maurice Lam        return mListMixin.getDividerInsetEnd();
1586011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    }
1596011b35deae30839cd454e0ec5866487e90860f5Maurice Lam
1606011b35deae30839cd454e0ec5866487e90860f5Maurice Lam    /**
161d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam     * @see ListMixin#getDivider()
162d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam     */
163180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    public Drawable getDivider() {
164d349adb3941c88ae27ec451acd19641ba03205dfMaurice Lam        return mListMixin.getDivider();
165180360409c9e4e9163c670ff48663244b4057eafMaurice Lam    }
166e15b8a2489610e3a6fe0a5bc2e26625b067631e0Maurice Lam}
167