aboutsummaryrefslogtreecommitdiff
path: root/src/com/android/tv/tuner/setup/ScanResultFragment.java
blob: 3b8cd8233ed2238d195b2b6d7a396b5d7cecd2da (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
/*
 * 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.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.NonNull;
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 com.android.tv.tuner.util.TunerInputInfoUtils;

import java.util.List;

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

    @Override
    protected SetupGuidedStepFragment onCreateContentFragment() {
        return new ContentFragment();
    }

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

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

    public static class ContentFragment extends SetupGuidedStepFragment {
        private int mChannelCountOnPreference;

        @Override
        public void onAttach(Context context) {
            super.onAttach(context);
            mChannelCountOnPreference = TunerPreferences.getScannedChannelCount(context);
        }

        @NonNull
        @Override
        public Guidance onCreateGuidance(Bundle savedInstanceState) {
            String title;
            String description;
            String breadcrumb;
            if (mChannelCountOnPreference > 0) {
                Resources res = getResources();
                title = res.getQuantityString(R.plurals.ut_result_found_title,
                        mChannelCountOnPreference, mChannelCountOnPreference);
                description = res.getQuantityString(R.plurals.ut_result_found_description,
                        mChannelCountOnPreference, mChannelCountOnPreference);
                breadcrumb = null;
            } else {
                Bundle args = getArguments();
                int tunerType =
                        (args == null ? 0 : args.getInt(TunerSetupActivity.KEY_TUNER_TYPE, 0));
                title = getString(R.string.ut_result_not_found_title);
                switch (tunerType) {
                    case TunerHal.TUNER_TYPE_USB:
                        description = getString(R.string.ut_result_not_found_description);
                        break;
                    case TunerHal.TUNER_TYPE_NETWORK:
                        description = getString(R.string.nt_result_not_found_description);
                        break;
                    default:
                        description = getString(R.string.bt_result_not_found_description);
                }
                breadcrumb = getString(R.string.ut_setup_breadcrumb);
            }
            return new Guidance(title, description, breadcrumb, null);
        }

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

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