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