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