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