SetupWizardListLayout.java revision bdfc0132ff90a333de202adfbf204cdc8139e632
195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam/*
295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam * Copyright (C) 2015 The Android Open Source Project
395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam *
495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam * Licensed under the Apache License, Version 2.0 (the "License");
595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam * you may not use this file except in compliance with the License.
695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam * You may obtain a copy of the License at
795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam *
895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam *      http://www.apache.org/licenses/LICENSE-2.0
995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam *
1095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam * Unless required by applicable law or agreed to in writing, software
1195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam * distributed under the License is distributed on an "AS IS" BASIS,
1295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam * See the License for the specific language governing permissions and
1495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam * limitations under the License.
1595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam */
1695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
1795af12dac219e6945bab6142ea3a4099077314aaMaurice Lampackage com.android.setupwizardlib;
1895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
199f9367672191190f903955d09a4314d40869acc6Maurice Lamimport android.annotation.TargetApi;
2095af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.content.Context;
219f9367672191190f903955d09a4314d40869acc6Maurice Lamimport android.os.Build.VERSION_CODES;
2295af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.util.AttributeSet;
2395af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.view.LayoutInflater;
2495af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.view.View;
25bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lamimport android.view.ViewGroup;
2695af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.widget.ListAdapter;
2795af12dac219e6945bab6142ea3a4099077314aaMaurice Lamimport android.widget.ListView;
2895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
2995af12dac219e6945bab6142ea3a4099077314aaMaurice Lampublic class SetupWizardListLayout extends SetupWizardLayout {
3095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
3195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    private static final String TAG = "SetupWizardListLayout";
3295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    private ListView mListView;
3395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
3495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public SetupWizardListLayout(Context context) {
35bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        this(context, 0, 0);
3695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
3795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
3895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public SetupWizardListLayout(Context context, int template) {
39bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        this(context, template, 0);
40bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam    }
41bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam
42bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam    public SetupWizardListLayout(Context context, int template, int containerId) {
43bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        super(context, template, containerId);
4495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
4595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
4695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public SetupWizardListLayout(Context context, AttributeSet attrs) {
479f9367672191190f903955d09a4314d40869acc6Maurice Lam        super(context, attrs);
4895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
4995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
509f9367672191190f903955d09a4314d40869acc6Maurice Lam    @TargetApi(VERSION_CODES.HONEYCOMB)
5195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public SetupWizardListLayout(Context context, AttributeSet attrs, int defStyleAttr) {
529f9367672191190f903955d09a4314d40869acc6Maurice Lam        super(context, attrs, defStyleAttr);
5395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
5495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
5595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    @Override
5695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    protected View onInflateTemplate(LayoutInflater inflater, int template) {
5795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        if (template == 0) {
5895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam            template = R.layout.suw_list_template;
5995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        }
60bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        return super.onInflateTemplate(inflater, template);
6195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
6295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
6395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    @Override
64bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam    protected ViewGroup findContainer(int containerId) {
65bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        if (containerId == 0) {
66bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam            containerId = android.R.id.list;
67bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        }
68bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        return super.findContainer(containerId);
6995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
7095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
7195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    @Override
72bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam    protected void onTemplateInflated() {
73bdfc0132ff90a333de202adfbf204cdc8139e632Maurice Lam        mListView = (ListView) findViewById(android.R.id.list);
7495af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
7595af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
7695af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public ListView getListView() {
7795af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        return mListView;
7895af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
7995af12dac219e6945bab6142ea3a4099077314aaMaurice Lam
8095af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    public void setAdapter(ListAdapter adapter) {
8195af12dac219e6945bab6142ea3a4099077314aaMaurice Lam        getListView().setAdapter(adapter);
8295af12dac219e6945bab6142ea3a4099077314aaMaurice Lam    }
8395af12dac219e6945bab6142ea3a4099077314aaMaurice Lam}
84