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 androidx.leanback.preference; 18 19 import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX; 20 21 import android.content.Context; 22 import android.util.AttributeSet; 23 import android.view.KeyEvent; 24 import android.widget.FrameLayout; 25 26 import androidx.annotation.RestrictTo; 27 28 import org.jspecify.annotations.NonNull; 29 30 /** 31 */ 32 @RestrictTo(LIBRARY_GROUP_PREFIX) 33 public class LeanbackSettingsRootView extends FrameLayout { 34 35 private OnKeyListener mOnBackKeyListener; 36 LeanbackSettingsRootView(Context context)37 public LeanbackSettingsRootView(Context context) { 38 super(context); 39 } 40 LeanbackSettingsRootView(Context context, AttributeSet attrs)41 public LeanbackSettingsRootView(Context context, AttributeSet attrs) { 42 super(context, attrs); 43 } 44 LeanbackSettingsRootView(Context context, AttributeSet attrs, int defStyleAttr)45 public LeanbackSettingsRootView(Context context, AttributeSet attrs, int defStyleAttr) { 46 super(context, attrs, defStyleAttr); 47 } 48 setOnBackKeyListener(OnKeyListener backKeyListener)49 public void setOnBackKeyListener(OnKeyListener backKeyListener) { 50 mOnBackKeyListener = backKeyListener; 51 } 52 53 @Override dispatchKeyEvent(@onNull KeyEvent event)54 public boolean dispatchKeyEvent(@NonNull KeyEvent event) { 55 boolean handled = false; 56 if (event.getAction() == KeyEvent.ACTION_UP && event.getKeyCode() == KeyEvent.KEYCODE_BACK 57 && mOnBackKeyListener != null) { 58 handled = mOnBackKeyListener.onKey(this, event.getKeyCode(), event); 59 } 60 return handled || super.dispatchKeyEvent(event); 61 } 62 } 63