• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static org.junit.Assert.assertEquals;
20 
21 import android.view.KeyEvent;
22 import android.view.View;
23 
24 /**
25  * A purely dummy instance of FocusHandler.
26  */
27 public final class TestFocusHandler implements FocusHandler {
28 
29     public boolean handleKey;
30     public int focusPos = 0;
31     public String focusModelId;
32     public boolean advanceFocusAreaCalled;
33     public boolean focusDirectoryCalled;
34 
35     @Override
handleKey(DocumentHolder doc, int keyCode, KeyEvent event)36     public boolean handleKey(DocumentHolder doc, int keyCode, KeyEvent event) {
37         return handleKey;
38     }
39 
40     @Override
onFocusChange(View v, boolean hasFocus)41     public void onFocusChange(View v, boolean hasFocus) {
42     }
43 
44     @Override
advanceFocusArea()45     public boolean advanceFocusArea() {
46         advanceFocusAreaCalled = true;
47         return true;
48     }
49 
50     @Override
focusDirectoryList()51     public boolean focusDirectoryList() {
52         focusDirectoryCalled = true;
53         return true;
54     }
55 
56     @Override
hasFocusedItem()57     public boolean hasFocusedItem() {
58         return focusModelId != null;
59     }
60 
61     @Override
getFocusedPosition()62     public int getFocusedPosition() {
63         return focusPos;
64     }
65 
66     @Override
getFocusModelId()67     public String getFocusModelId() {
68         return focusModelId;
69     }
70 
71     @Override
focusDocument(String modelId)72     public void focusDocument(String modelId) {
73         focusModelId = modelId;
74     }
75 
76     @Override
onLayoutCompleted()77     public void onLayoutCompleted() {
78     }
79 
80     @Override
clearFocus()81     public void clearFocus() {
82         focusModelId = null;
83         focusPos = 0;
84     }
85 
assertHasFocus(boolean focused)86     public void assertHasFocus(boolean focused) {
87         assertEquals(focused, hasFocusedItem());
88     }
89 
assertFocused(String modelId)90     public void assertFocused(String modelId) {
91         assertEquals(modelId, getFocusModelId());
92     }
93 }
94