• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 package com.android.documentsui.selection.testing;
17 
18 import static org.junit.Assert.assertEquals;
19 import static org.junit.Assert.assertTrue;
20 
21 import android.support.v7.widget.RecyclerView;
22 import android.view.MotionEvent;
23 
24 import com.android.documentsui.selection.MouseInputHandler;
25 import com.android.documentsui.selection.ItemDetailsLookup.ItemDetails;
26 
27 public final class TestMouseCallbacks extends MouseInputHandler.Callbacks {
28 
29     private String mFocusItemId;
30     private int mFocusPosition;
31     private MotionEvent mLastContextEvent;
32     private ItemDetails mActivated;
33 
34     @Override
onItemActivated(ItemDetails item, MotionEvent e)35     public boolean onItemActivated(ItemDetails item, MotionEvent e) {
36         mActivated = item;
37         return true;
38     }
39 
40     @Override
onContextClick(MotionEvent e)41     public boolean onContextClick(MotionEvent e) {
42         mLastContextEvent = e;
43         return false;
44     }
45 
46     @Override
onPerformHapticFeedback()47     public void onPerformHapticFeedback() {
48     }
49 
50     @Override
clearFocus()51     public void clearFocus() {
52         mFocusPosition = RecyclerView.NO_POSITION;
53         mFocusItemId = null;
54     }
55 
56     @Override
focusItem(ItemDetails item)57     public void focusItem(ItemDetails item) {
58         mFocusItemId = item.getStableId();
59         mFocusPosition = item.getPosition();
60     }
61 
62     @Override
getFocusedPosition()63     public int getFocusedPosition() {
64         return mFocusPosition;
65     }
66 
67     @Override
hasFocusedItem()68     public boolean hasFocusedItem() {
69         return mFocusItemId != null;
70     }
71 
assertLastEvent(MotionEvent expected)72     public void assertLastEvent(MotionEvent expected) {
73         // sadly, MotionEvent doesn't implement equals, so we compare references.
74         assertTrue(expected == mLastContextEvent);
75     }
76 
assertActivated(ItemDetails expected)77     public void assertActivated(ItemDetails expected) {
78         assertEquals(expected, mActivated);
79     }
80 
assertHasFocus(boolean focused)81     public void assertHasFocus(boolean focused) {
82         assertEquals(focused, hasFocusedItem());
83     }
84 
assertFocused(String expectedId)85     public void assertFocused(String expectedId) {
86         assertEquals(expectedId, mFocusItemId);
87     }
88 }