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.usbtuner.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.usbtuner.R;
30import com.android.usbtuner.UsbTunerPreferences;
31
32import java.util.List;
33
34/**
35 * A fragment for initial screen.
36 */
37public class WelcomeFragment extends SetupMultiPaneFragment {
38    public static final String ACTION_CATEGORY =
39            "com.android.usbtuner.setup.WelcomeFragment";
40
41    @Override
42    protected SetupGuidedStepFragment onCreateContentFragment() {
43        return new ContentFragment();
44    }
45
46    @Override
47    protected String getActionCategory() {
48        return ACTION_CATEGORY;
49    }
50
51    @Override
52    protected boolean needsDoneButton() {
53        return false;
54    }
55
56    public static class ContentFragment extends SetupGuidedStepFragment {
57        private int mChannelCountOnPreference;
58
59        @Override
60        public View onCreateView(LayoutInflater inflater, ViewGroup container,
61                Bundle savedInstanceState) {
62            mChannelCountOnPreference = UsbTunerPreferences
63                    .getScannedChannelCount(getActivity().getApplicationContext());
64            return super.onCreateView(inflater, container, savedInstanceState);
65        }
66
67        @NonNull
68        @Override
69        public Guidance onCreateGuidance(Bundle savedInstanceState) {
70            String title;
71            String description;
72            if (mChannelCountOnPreference == 0) {
73                title = getString(R.string.ut_setup_new_title);
74                description = getString(R.string.ut_setup_new_description);
75            } else {
76                title = getString(R.string.ut_setup_again_title);
77                description = getString(R.string.ut_setup_again_description);
78            }
79            return new Guidance(title, description, null, null);
80        }
81
82        @Override
83        public void onCreateActions(@NonNull List<GuidedAction> actions,
84                Bundle savedInstanceState) {
85            String[] choices = getResources().getStringArray(mChannelCountOnPreference == 0
86                    ? R.array.ut_setup_new_choices : R.array.ut_setup_again_choices);
87            for (int i = 0; i < choices.length - 1; ++i) {
88                actions.add(new GuidedAction.Builder(getActivity()).id(i).title(choices[i])
89                        .build());
90            }
91            actions.add(new GuidedAction.Builder(getActivity()).id(ACTION_DONE)
92                    .title(choices[choices.length - 1]).build());
93        }
94
95        @Override
96        protected String getActionCategory() {
97            return ACTION_CATEGORY;
98        }
99    }
100}
101