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