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