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