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