WelcomeFragment.java revision 721bd0da688cd552737fbb753a00597f95103b95
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.tv.tuner.setup; 18 19import android.os.Bundle; 20import android.support.annotation.NonNull; 21import android.support.v17.leanback.widget.GuidanceStylist.Guidance; 22import android.support.v17.leanback.widget.GuidedAction; 23import android.view.LayoutInflater; 24import android.view.View; 25import android.view.ViewGroup; 26 27import com.android.tv.common.ui.setup.SetupGuidedStepFragment; 28import com.android.tv.common.ui.setup.SetupMultiPaneFragment; 29import com.android.tv.tuner.R; 30import com.android.tv.tuner.TunerPreferences; 31import com.android.tv.tuner.util.TunerInputInfoUtils; 32 33import java.util.List; 34 35/** 36 * A fragment for initial screen. 37 */ 38public class WelcomeFragment extends SetupMultiPaneFragment { 39 public static final String ACTION_CATEGORY = 40 "com.android.tv.tuner.setup.WelcomeFragment"; 41 42 @Override 43 protected SetupGuidedStepFragment onCreateContentFragment() { 44 return new ContentFragment(); 45 } 46 47 @Override 48 protected String getActionCategory() { 49 return ACTION_CATEGORY; 50 } 51 52 @Override 53 protected boolean needsDoneButton() { 54 return false; 55 } 56 57 public static class ContentFragment extends SetupGuidedStepFragment { 58 private int mChannelCountOnPreference; 59 60 @Override 61 public View onCreateView(LayoutInflater inflater, ViewGroup container, 62 Bundle savedInstanceState) { 63 mChannelCountOnPreference = TunerPreferences 64 .getScannedChannelCount(getActivity().getApplicationContext()); 65 return super.onCreateView(inflater, container, savedInstanceState); 66 } 67 68 @NonNull 69 @Override 70 public Guidance onCreateGuidance(Bundle savedInstanceState) { 71 String title; 72 String description; 73 if (mChannelCountOnPreference == 0) { 74 if (TunerInputInfoUtils.isBuiltInTuner(getActivity())) { 75 title = getString(R.string.bt_setup_new_title); 76 description = getString(R.string.bt_setup_new_description); 77 } else { 78 title = getString(R.string.ut_setup_new_title); 79 description = getString(R.string.ut_setup_new_description); 80 } 81 } else { 82 title = getString(R.string.bt_setup_again_title); 83 if (TunerInputInfoUtils.isBuiltInTuner(getActivity())) { 84 description = getString(R.string.bt_setup_again_description); 85 } else { 86 description = getString(R.string.ut_setup_again_description); 87 } 88 } 89 return new Guidance(title, description, null, null); 90 } 91 92 @Override 93 public void onCreateActions(@NonNull List<GuidedAction> actions, 94 Bundle savedInstanceState) { 95 String[] choices = getResources().getStringArray(mChannelCountOnPreference == 0 96 ? R.array.ut_setup_new_choices : R.array.ut_setup_again_choices); 97 for (int i = 0; i < choices.length - 1; ++i) { 98 actions.add(new GuidedAction.Builder(getActivity()).id(i).title(choices[i]) 99 .build()); 100 } 101 actions.add(new GuidedAction.Builder(getActivity()).id(ACTION_DONE) 102 .title(choices[choices.length - 1]).build()); 103 } 104 105 @Override 106 protected String getActionCategory() { 107 return ACTION_CATEGORY; 108 } 109 } 110} 111