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