1 /* 2 * Copyright (C) 2016 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 com.android.documentsui.dirlist; 18 19 import androidx.annotation.Nullable; 20 import android.view.KeyEvent; 21 import android.view.View; 22 23 /** 24 * A class that manages focus and keyboard driven navigation in the activity. 25 */ 26 public interface FocusHandler extends View.OnFocusChangeListener { 27 28 /** 29 * Handles navigation (setting focus, adjusting selection if needed) arising from incoming key 30 * events. 31 * 32 * @param doc The DocumentHolder receiving the key event. 33 * @param keyCode 34 * @param event 35 * @return Whether the event was handled. 36 */ handleKey(DocumentHolder doc, int keyCode, KeyEvent event)37 boolean handleKey(DocumentHolder doc, int keyCode, KeyEvent event); 38 39 @Override onFocusChange(View v, boolean hasFocus)40 void onFocusChange(View v, boolean hasFocus); 41 onLayoutCompleted()42 void onLayoutCompleted(); 43 focusDocument(String modelId)44 void focusDocument(String modelId); 45 46 /** 47 * Requests focus on the the directory list. Will specifically 48 * attempt to focus the item in the directory list that last had focus. 49 * Scrolls to that item if necessary. 50 * 51 * <p>If focus is unsuccessful, return false. 52 */ focusDirectoryList()53 boolean focusDirectoryList(); 54 55 /** 56 * Attempts to advance the focus to the next available focus area 57 * in the app. As of this writing, known focus areas are the sidebar 58 * and the directory list (specifically an item in the directory list). 59 */ advanceFocusArea()60 boolean advanceFocusArea(); 61 62 /** 63 * @return The adapter position of the last focused item. 64 */ getFocusedPosition()65 int getFocusedPosition(); 66 67 /** 68 * @return True if there is currently an item in focus, false otherwise. 69 */ hasFocusedItem()70 boolean hasFocusedItem(); 71 72 /** 73 * If there is an item which has focus, the focus is removed. 74 */ clearFocus()75 void clearFocus(); 76 77 /** 78 * @return The modelId of the last focused item. If no item is focused, this should return null. 79 */ getFocusModelId()80 @Nullable String getFocusModelId(); 81 } 82