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.onboarding; 18 19 import android.app.Fragment; 20 import android.os.Build; 21 import android.os.Bundle; 22 import android.transition.Slide; 23 import android.view.Gravity; 24 import android.view.LayoutInflater; 25 import android.view.View; 26 import android.view.ViewGroup; 27 28 import com.android.tv.R; 29 import com.android.tv.TvApplication; 30 import com.android.tv.common.ui.setup.OnActionClickListener; 31 import com.android.tv.common.ui.setup.SetupActionHelper; 32 import com.android.tv.util.SetupUtils; 33 34 /** 35 * A fragment for new channel source info/setup. 36 */ 37 public class NewSourcesFragment extends Fragment { 38 public static final String ACTION_CATEOGRY = NewSourcesFragment.class.getCanonicalName(); 39 public static final int ACTION_SETUP = 1; 40 public static final int ACTION_SKIP = 2; 41 42 private OnActionClickListener mOnActionClickListener; 43 NewSourcesFragment()44 public NewSourcesFragment() { 45 setAllowEnterTransitionOverlap(false); 46 setAllowReturnTransitionOverlap(false); 47 setEnterTransition(new Slide(Gravity.BOTTOM)); 48 setExitTransition(new Slide(Gravity.BOTTOM)); 49 setReenterTransition(new Slide(Gravity.BOTTOM)); 50 setReturnTransition(new Slide(Gravity.BOTTOM)); 51 } 52 53 @Override onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)54 public View onCreateView(LayoutInflater inflater, ViewGroup container, 55 Bundle savedInstanceState) { 56 View view = inflater.inflate(R.layout.fragment_new_sources, container, false); 57 initializeButton(view.findViewById(R.id.setup), ACTION_SETUP); 58 initializeButton(view.findViewById(R.id.skip), ACTION_SKIP); 59 SetupUtils.getInstance(getActivity()).markAllInputsRecognized(TvApplication 60 .getSingletons(getActivity()).getTvInputManagerHelper()); 61 view.requestFocus(); 62 return view; 63 } 64 65 /** 66 * Sets the {@link OnActionClickListener}. This method should be called before the views are 67 * created. 68 */ setOnActionClickListener(OnActionClickListener onActionClickListener)69 public void setOnActionClickListener(OnActionClickListener onActionClickListener) { 70 mOnActionClickListener = onActionClickListener; 71 } 72 initializeButton(View view, int actionId)73 private void initializeButton(View view, int actionId) { 74 view.setOnClickListener(SetupActionHelper.createOnClickListenerForAction( 75 mOnActionClickListener, ACTION_CATEOGRY, actionId)); 76 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { 77 // Prior to M, foreground ripple animation is not supported. 78 // Use background ripple drawable instead of drawing in the foreground manually. 79 view.setBackground(getActivity().getDrawable(R.drawable.setup_selector_background)); 80 } 81 } 82 } 83