1/*
2 * Copyright (C) 2017 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.template;
18
19import android.view.View;
20
21import com.android.setupwizardlib.R;
22import com.android.setupwizardlib.TemplateLayout;
23import com.android.setupwizardlib.view.NavigationBar;
24import com.android.setupwizardlib.view.NavigationBar.NavigationBarListener;
25
26/**
27 * A {@link Mixin} for interacting with a {@link NavigationBar}.
28 */
29public class NavigationBarMixin implements Mixin {
30
31    private TemplateLayout mTemplateLayout;
32
33    /**
34     * @param layout The layout this mixin belongs to.
35     */
36    public NavigationBarMixin(TemplateLayout layout) {
37        mTemplateLayout = layout;
38    }
39
40    /**
41     * @return The navigation bar instance in the layout, or null if the layout does not have a
42     *         navigation bar.
43     */
44    public NavigationBar getNavigationBar() {
45        final View view = mTemplateLayout.findManagedViewById(R.id.suw_layout_navigation_bar);
46        return view instanceof NavigationBar ? (NavigationBar) view : null;
47    }
48
49    /**
50     * Sets the label of the next button.
51     *
52     * @param text Label of the next button.
53     */
54    public void setNextButtonText(int text) {
55        getNavigationBar().getNextButton().setText(text);
56    }
57
58    /**
59     * Sets the label of the next button.
60     *
61     * @param text Label of the next button.
62     */
63    public void setNextButtonText(CharSequence text) {
64        getNavigationBar().getNextButton().setText(text);
65    }
66
67    /**
68     * @return The current label of the next button.
69     */
70    public CharSequence getNextButtonText() {
71        return getNavigationBar().getNextButton().getText();
72    }
73
74    /**
75     * Sets the listener to handle back and next button clicks in the navigation bar.
76     *
77     * @see NavigationBar#setNavigationBarListener(NavigationBarListener)
78     * @see NavigationBarListener
79     */
80    public void setNavigationBarListener(NavigationBarListener listener) {
81        getNavigationBar().setNavigationBarListener(listener);
82    }
83}
84