1/* 2 * Copyright 2017 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 androidx.recyclerview.selection; 18 19import androidx.annotation.NonNull; 20import androidx.recyclerview.selection.ItemDetailsLookup.ItemDetails; 21import androidx.recyclerview.widget.RecyclerView; 22 23/** 24 * Override methods in this class to provide application specific behaviors 25 * related to focusing item. 26 * 27 * @param <K> Selection key type. @see {@link StorageStrategy} for supported types. 28 */ 29public abstract class FocusDelegate<K> { 30 31 static <K> FocusDelegate<K> dummy() { 32 return new FocusDelegate<K>() { 33 @Override 34 public void focusItem(@NonNull ItemDetails<K> item) { 35 } 36 37 @Override 38 public boolean hasFocusedItem() { 39 return false; 40 } 41 42 @Override 43 public int getFocusedPosition() { 44 return RecyclerView.NO_POSITION; 45 } 46 47 @Override 48 public void clearFocus() { 49 } 50 }; 51 } 52 53 /** 54 * If environment supports focus, focus {@code item}. 55 */ 56 public abstract void focusItem(@NonNull ItemDetails<K> item); 57 58 /** 59 * @return true if there is a focused item. 60 */ 61 public abstract boolean hasFocusedItem(); 62 63 /** 64 * @return the position of the currently focused item, if any. 65 */ 66 public abstract int getFocusedPosition(); 67 68 /** 69 * If the environment supports focus and something is focused, unfocus it. 70 */ 71 public abstract void clearFocus(); 72} 73