• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.TunerPreferences;
30 import com.android.tv.tuner.util.TunerInputInfoUtils;
31 
32 import java.util.List;
33 
34 /**
35  * A fragment for initial screen.
36  */
37 public class ScanResultFragment extends SetupMultiPaneFragment {
38     public static final String ACTION_CATEGORY =
39             "com.android.tv.tuner.setup.ScanResultFragment";
40 
41     @Override
onCreateContentFragment()42     protected SetupGuidedStepFragment onCreateContentFragment() {
43         return new ContentFragment();
44     }
45 
46     @Override
getActionCategory()47     protected String getActionCategory() {
48         return ACTION_CATEGORY;
49     }
50 
51     @Override
needsDoneButton()52     protected boolean needsDoneButton() {
53         return false;
54     }
55 
56     public static class ContentFragment extends SetupGuidedStepFragment {
57         private int mChannelCountOnPreference;
58 
59         @Override
onAttach(Context context)60         public void onAttach(Context context) {
61             super.onAttach(context);
62             mChannelCountOnPreference = TunerPreferences.getScannedChannelCount(context);
63         }
64 
65         @NonNull
66         @Override
onCreateGuidance(Bundle savedInstanceState)67         public Guidance onCreateGuidance(Bundle savedInstanceState) {
68             String title;
69             String description;
70             String breadcrumb;
71             if (mChannelCountOnPreference > 0) {
72                 Resources res = getResources();
73                 title = res.getQuantityString(R.plurals.ut_result_found_title,
74                         mChannelCountOnPreference, mChannelCountOnPreference);
75                 description = res.getQuantityString(R.plurals.ut_result_found_description,
76                         mChannelCountOnPreference, mChannelCountOnPreference);
77                 breadcrumb = null;
78             } else {
79                 title = getString(R.string.ut_result_not_found_title);
80                 if (TunerInputInfoUtils.isBuiltInTuner(getActivity())) {
81                     description = getString(R.string.bt_result_not_found_description);
82                 } else {
83                     description = getString(R.string.ut_result_not_found_description);
84                 }
85                 breadcrumb = getString(R.string.ut_setup_breadcrumb);
86             }
87             return new Guidance(title, description, breadcrumb, null);
88         }
89 
90         @Override
onCreateActions(@onNull List<GuidedAction> actions, Bundle savedInstanceState)91         public void onCreateActions(@NonNull List<GuidedAction> actions,
92                 Bundle savedInstanceState) {
93             String[] choices;
94             int doneActionIndex;
95             if (mChannelCountOnPreference > 0) {
96                 choices = getResources().getStringArray(R.array.ut_result_found_choices);
97                 doneActionIndex = 0;
98             } else {
99                 choices = getResources().getStringArray(R.array.ut_result_not_found_choices);
100                 doneActionIndex = 1;
101             }
102             for (int i = 0; i < choices.length; ++i) {
103                 if (i == doneActionIndex) {
104                     actions.add(new GuidedAction.Builder(getActivity()).id(ACTION_DONE)
105                             .title(choices[i]).build());
106                 } else {
107                     actions.add(new GuidedAction.Builder(getActivity()).id(i).title(choices[i])
108                             .build());
109                 }
110             }
111         }
112 
113         @Override
getActionCategory()114         protected String getActionCategory() {
115             return ACTION_CATEGORY;
116         }
117     }
118 }
119