aboutsummaryrefslogtreecommitdiff
path: root/tuner/src/com/android/tv/tuner/setup/WelcomeFragment.java
blob: 788ba918ddd8807bfd5216c3d92b3e9c19ff5346 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.tv.tuner.setup;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
import android.support.v17.leanback.widget.GuidedAction;
import com.android.tv.common.ui.setup.SetupGuidedStepFragment;
import com.android.tv.common.ui.setup.SetupMultiPaneFragment;
import com.android.tv.tuner.R;
import com.android.tv.tuner.TunerHal;
import com.android.tv.tuner.TunerPreferences;
import java.util.List;

/** A fragment for initial screen. */
public class WelcomeFragment extends SetupMultiPaneFragment {
    public static final String ACTION_CATEGORY = "com.android.tv.tuner.setup.WelcomeFragment";

    @Override
    protected SetupGuidedStepFragment onCreateContentFragment() {
        ContentFragment fragment = new ContentFragment();
        fragment.setArguments(getArguments());
        return fragment;
    }

    @Override
    protected String getActionCategory() {
        return ACTION_CATEGORY;
    }

    @Override
    protected boolean needsDoneButton() {
        return false;
    }

    /** The content fragment of {@link WelcomeFragment}. */
    public static class ContentFragment extends SetupGuidedStepFragment {
        private int mChannelCountOnPreference;

        @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            mChannelCountOnPreference =
                    TunerPreferences.getScannedChannelCount(getActivity().getApplicationContext());
            super.onCreate(savedInstanceState);
        }

        @NonNull
        @Override
        public Guidance onCreateGuidance(Bundle savedInstanceState) {
            String title;
            String description;
            int tunerType =
                    getArguments()
                            .getInt(
                                    BaseTunerSetupActivity.KEY_TUNER_TYPE,
                                    TunerHal.TUNER_TYPE_BUILT_IN);
            if (mChannelCountOnPreference == 0) {
                switch (tunerType) {
                    case TunerHal.TUNER_TYPE_USB:
                        title = getString(R.string.ut_setup_new_title);
                        description = getString(R.string.ut_setup_new_description);
                        break;
                    case TunerHal.TUNER_TYPE_NETWORK:
                        title = getString(R.string.nt_setup_new_title);
                        description = getString(R.string.nt_setup_new_description);
                        break;
                    default:
                        title = getString(R.string.bt_setup_new_title);
                        description = getString(R.string.bt_setup_new_description);
                }
            } else {
                title = getString(R.string.bt_setup_again_title);
                switch (tunerType) {
                    case TunerHal.TUNER_TYPE_USB:
                        description = getString(R.string.ut_setup_again_description);
                        break;
                    case TunerHal.TUNER_TYPE_NETWORK:
                        description = getString(R.string.nt_setup_again_description);
                        break;
                    default:
                        description = getString(R.string.bt_setup_again_description);
                }
            }
            return new Guidance(title, description, null, null);
        }

        @Override
        public void onCreateActions(
                @NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
            String[] choices =
                    getResources()
                            .getStringArray(
                                    mChannelCountOnPreference == 0
                                            ? R.array.ut_setup_new_choices
                                            : R.array.ut_setup_again_choices);
            for (int i = 0; i < choices.length - 1; ++i) {
                actions.add(
                        new GuidedAction.Builder(getActivity()).id(i).title(choices[i]).build());
            }
            actions.add(
                    new GuidedAction.Builder(getActivity())
                            .id(ACTION_DONE)
                            .title(choices[choices.length - 1])
                            .build());
        }

        @Override
        protected String getActionCategory() {
            return ACTION_CATEGORY;
        }
    }
}