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