1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14package android.support.v17.leanback.app; 15 16import android.content.Context; 17import android.support.v17.leanback.widget.Util; 18import android.util.AttributeSet; 19import android.view.View; 20import android.view.ViewGroup; 21import android.view.ViewParent; 22import android.widget.LinearLayout; 23 24/** 25 * Utility class used by GuidedStepFragment to disable focus out left/right. 26 * @hide 27 */ 28class GuidedStepRootLayout extends LinearLayout { 29 30 private boolean mFocusOutStart = false; 31 private boolean mFocusOutEnd = false; 32 33 public GuidedStepRootLayout(Context context, AttributeSet attrs) { 34 super(context, attrs); 35 } 36 37 public GuidedStepRootLayout(Context context, AttributeSet attrs, int defStyleAttr) { 38 super(context, attrs, defStyleAttr); 39 } 40 41 public void setFocusOutStart(boolean focusOutStart) { 42 mFocusOutStart = focusOutStart; 43 } 44 45 public void setFocusOutEnd(boolean focusOutEnd) { 46 mFocusOutEnd = focusOutEnd; 47 } 48 49 @Override 50 public View focusSearch(View focused, int direction) { 51 View newFocus = super.focusSearch(focused, direction); 52 if (direction == FOCUS_LEFT || direction == FOCUS_RIGHT) { 53 if (Util.isDescendant(this, newFocus)) { 54 return newFocus; 55 } 56 if (getLayoutDirection() == ViewGroup.LAYOUT_DIRECTION_LTR ? 57 direction == FOCUS_LEFT : direction == FOCUS_RIGHT) { 58 if (!mFocusOutStart) { 59 return focused; 60 } 61 } else { 62 if (!mFocusOutEnd) { 63 return focused; 64 } 65 } 66 } 67 return newFocus; 68 } 69} 70