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