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.v17.leanback.widget.GuidanceStylist.Guidance; 22 import android.support.v17.leanback.widget.GuidedAction; 23 24 import com.android.tv.common.BuildConfig; 25 import com.android.tv.common.ui.setup.SetupGuidedStepFragment; 26 import com.android.tv.common.ui.setup.SetupMultiPaneFragment; 27 import com.android.tv.tuner.R; 28 29 import java.util.List; 30 import java.util.TimeZone; 31 32 /** 33 * A fragment for connection type selection. 34 */ 35 public class ConnectionTypeFragment extends SetupMultiPaneFragment { 36 public static final String ACTION_CATEGORY = 37 "com.android.tv.tuner.setup.ConnectionTypeFragment"; 38 39 @Override 40 public void onCreate(Bundle savedInstanceState) { 41 ((TunerSetupActivity) getActivity()).generateTunerHal(); 42 super.onCreate(savedInstanceState); 43 } 44 45 @Override 46 public void onResume() { 47 ((TunerSetupActivity) getActivity()).generateTunerHal(); 48 super.onResume(); 49 } 50 51 @Override 52 public void onDestroy() { 53 ((TunerSetupActivity) getActivity()).clearTunerHal(); 54 super.onDestroy(); 55 } 56 57 @Override 58 protected SetupGuidedStepFragment onCreateContentFragment() { 59 return new ContentFragment(); 60 } 61 62 @Override 63 protected String getActionCategory() { 64 return ACTION_CATEGORY; 65 } 66 67 @Override 68 protected boolean needsDoneButton() { 69 return false; 70 } 71 72 public static class ContentFragment extends SetupGuidedStepFragment { 73 74 @NonNull 75 @Override 76 public Guidance onCreateGuidance(Bundle savedInstanceState) { 77 return new Guidance(getString(R.string.ut_connection_title), 78 getString(R.string.ut_connection_description), 79 getString(R.string.ut_setup_breadcrumb), null); 80 } 81 82 @Override 83 public void onCreateActions(@NonNull List<GuidedAction> actions, 84 Bundle savedInstanceState) { 85 String[] choices = getResources().getStringArray(R.array.ut_connection_choices); 86 int length = choices.length - 1; 87 int startOffset = 0; 88 for (int i = 0; i < length; ++i) { 89 actions.add(new GuidedAction.Builder(getActivity()) 90 .id(startOffset + i) 91 .title(choices[i]) 92 .build()); 93 } 94 } 95 96 @Override 97 protected String getActionCategory() { 98 return ACTION_CATEGORY; 99 } 100 } 101 } 102