SetupWizardListLayout.java revision 0ceb8d53e39ebb5bc103863787afb39ec5c41ad8
1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.setupwizardlib;
18
19import android.annotation.TargetApi;
20import android.content.Context;
21import android.graphics.drawable.Drawable;
22import android.os.Build.VERSION_CODES;
23import android.util.AttributeSet;
24import android.view.LayoutInflater;
25import android.view.View;
26import android.view.ViewGroup;
27import android.widget.ListAdapter;
28import android.widget.ListView;
29
30import com.android.setupwizardlib.template.ListMixin;
31import com.android.setupwizardlib.template.ListViewScrollHandlingDelegate;
32import com.android.setupwizardlib.template.RequireScrollMixin;
33
34public class SetupWizardListLayout extends SetupWizardLayout {
35
36    private static final String TAG = "SetupWizardListLayout";
37
38    private ListMixin mListMixin;
39
40    public SetupWizardListLayout(Context context) {
41        this(context, 0, 0);
42    }
43
44    public SetupWizardListLayout(Context context, int template) {
45        this(context, template, 0);
46    }
47
48    public SetupWizardListLayout(Context context, int template, int containerId) {
49        super(context, template, containerId);
50        init(context, null, 0);
51    }
52
53    public SetupWizardListLayout(Context context, AttributeSet attrs) {
54        super(context, attrs);
55        init(context, attrs, 0);
56    }
57
58    @TargetApi(VERSION_CODES.HONEYCOMB)
59    public SetupWizardListLayout(Context context, AttributeSet attrs, int defStyleAttr) {
60        super(context, attrs, defStyleAttr);
61        init(context, attrs, defStyleAttr);
62    }
63
64    private void init(Context context, AttributeSet attrs, int defStyleAttr) {
65        mListMixin = new ListMixin(this, attrs, defStyleAttr);
66        registerMixin(ListMixin.class, mListMixin);
67
68        final RequireScrollMixin requireScrollMixin = getMixin(RequireScrollMixin.class);
69        requireScrollMixin.setScrollHandlingDelegate(
70                new ListViewScrollHandlingDelegate(requireScrollMixin, getListView()));
71    }
72
73    @Override
74    protected View onInflateTemplate(LayoutInflater inflater, int template) {
75        if (template == 0) {
76            template = R.layout.suw_list_template;
77        }
78        return super.onInflateTemplate(inflater, template);
79    }
80
81    @Override
82    protected ViewGroup findContainer(int containerId) {
83        if (containerId == 0) {
84            containerId = android.R.id.list;
85        }
86        return super.findContainer(containerId);
87    }
88
89    @Override
90    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
91        super.onLayout(changed, left, top, right, bottom);
92        mListMixin.onLayout();
93    }
94
95    public ListView getListView() {
96        return mListMixin.getListView();
97    }
98
99    public void setAdapter(ListAdapter adapter) {
100        mListMixin.setAdapter(adapter);
101    }
102
103    public ListAdapter getAdapter() {
104        return mListMixin.getAdapter();
105    }
106
107    /**
108     * Sets the start inset of the divider. This will use the default divider drawable set in the
109     * theme and inset it {@code inset} pixels to the right (or left in RTL layouts).
110     *
111     * @param inset The number of pixels to inset on the "start" side of the list divider. Typically
112     *              this will be either {@code @dimen/suw_items_icon_divider_inset} or
113     *              {@code @dimen/suw_items_text_divider_inset}.
114     *
115     * @see ListMixin#setDividerInset(int)
116     */
117    public void setDividerInset(int inset) {
118        mListMixin.setDividerInset(inset);
119    }
120
121    /**
122     * @see ListMixin#getDividerInset()
123     */
124    public int getDividerInset() {
125        return mListMixin.getDividerInset();
126    }
127
128    /**
129     * @see ListMixin#getDivider()
130     */
131    public Drawable getDivider() {
132        return mListMixin.getDivider();
133    }
134}
135