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 androidx.leanback.widget.GuidanceStylist.Guidance;
22 import androidx.leanback.widget.GuidedAction;
23 import com.android.tv.common.ui.setup.SetupGuidedStepFragment;
24 import com.android.tv.common.ui.setup.SetupMultiPaneFragment;
25 import com.android.tv.tuner.R;
26 import java.util.List;
27 
28 /** A fragment for connection type selection. */
29 public class ConnectionTypeFragment extends SetupMultiPaneFragment {
30     public static final String ACTION_CATEGORY =
31             "com.android.tv.tuner.setup.ConnectionTypeFragment";
32 
33     @Override
onCreate(Bundle savedInstanceState)34     public void onCreate(Bundle savedInstanceState) {
35         ((BaseTunerSetupActivity) getActivity()).generateTunerHal();
36         super.onCreate(savedInstanceState);
37     }
38 
39     @Override
onResume()40     public void onResume() {
41         ((BaseTunerSetupActivity) getActivity()).generateTunerHal();
42         super.onResume();
43     }
44 
45     @Override
onDestroy()46     public void onDestroy() {
47         ((BaseTunerSetupActivity) getActivity()).clearTunerHal();
48         super.onDestroy();
49     }
50 
51     @Override
onCreateContentFragment()52     protected SetupGuidedStepFragment onCreateContentFragment() {
53         return new ContentFragment();
54     }
55 
56     @Override
getActionCategory()57     protected String getActionCategory() {
58         return ACTION_CATEGORY;
59     }
60 
61     @Override
needsDoneButton()62     protected boolean needsDoneButton() {
63         return false;
64     }
65 
66     /** The content fragment of {@link ConnectionTypeFragment}. */
67     public static class ContentFragment extends SetupGuidedStepFragment {
68         @NonNull
69         @Override
onCreateGuidance(Bundle savedInstanceState)70         public Guidance onCreateGuidance(Bundle savedInstanceState) {
71             return new Guidance(
72                     getString(R.string.ut_connection_title),
73                     getString(R.string.ut_connection_description),
74                     getString(R.string.ut_setup_breadcrumb),
75                     null);
76         }
77 
78         @Override
onCreateActions( @onNull List<GuidedAction> actions, Bundle savedInstanceState)79         public void onCreateActions(
80                 @NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
81             String[] choices = getResources().getStringArray(R.array.ut_connection_choices);
82             int length = choices.length - 1;
83             int startOffset = 0;
84             for (int i = 0; i < length; ++i) {
85                 actions.add(
86                         new GuidedAction.Builder(getActivity())
87                                 .id(startOffset + i)
88                                 .title(choices[i])
89                                 .build());
90             }
91         }
92 
93         @Override
getActionCategory()94         protected String getActionCategory() {
95             return ACTION_CATEGORY;
96         }
97     }
98 }
99