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 android.content.Context;
20 import android.database.Cursor;
21 import android.graphics.Rect;
22 import android.os.SystemClock;
23 import android.test.AndroidTestCase;
24 import android.view.KeyEvent;
25 import android.view.LayoutInflater;
26 import android.view.MotionEvent;
27 import android.view.MotionEvent.PointerCoords;
28 import android.view.MotionEvent.PointerProperties;
29 
30 import androidx.test.filters.SmallTest;
31 import androidx.test.filters.Suppress;
32 
33 import com.android.documentsui.R;
34 
35 @SmallTest
36 public class DocumentHolderTest extends AndroidTestCase {
37 
38     DocumentHolder mHolder;
39     TestListener mListener;
40 
41     @Override
setUp()42     public void setUp() throws Exception {
43         Context context = getContext();
44         LayoutInflater inflater = LayoutInflater.from(context);
45         mHolder = new DocumentHolder(getContext(), inflater.inflate(R.layout.item_doc_list, null)) {
46             @Override
47             public void bind(Cursor cursor, String modelId) {}
48         };
49 
50         mListener = new TestListener();
51         mHolder.addKeyEventListener(mListener);
52 
53         mHolder.itemView.requestLayout();
54         mHolder.itemView.invalidate();
55     }
56 
57     @Suppress
testIsInSelectionHotspot()58     public void testIsInSelectionHotspot() {
59         fail();
60     }
61 
62     @Suppress
testDelegatesKeyEvents()63     public void testDelegatesKeyEvents() {
64         fail();
65     }
66 
createEvent(int tooltype)67     public MotionEvent createEvent(int tooltype) {
68         long time = SystemClock.uptimeMillis();
69 
70         PointerProperties properties[] = new PointerProperties[] {
71                 new PointerProperties()
72         };
73         properties[0].toolType = tooltype;
74 
75         PointerCoords coords[] = new PointerCoords[] {
76                 new PointerCoords()
77         };
78 
79         Rect rect = new Rect();
80         mHolder.itemView.getHitRect(rect);
81         coords[0].x = rect.left;
82         coords[0].y = rect.top;
83 
84         return MotionEvent.obtain(
85                 time, // down time
86                 time, // event time
87                 MotionEvent.ACTION_UP, // action
88                 1, // pointer count
89                 properties, // pointer properties
90                 coords, // pointer coords
91                 0, // metastate
92                 0, // button state
93                 0, // xprecision
94                 0, // yprecision
95                 0, // deviceid
96                 0, // edgeflags
97                 0, // source
98                 0 // flags
99                 );
100     }
101 
102     private class TestListener extends KeyboardEventListener<DocumentItemDetails> {
103         @Override
onKey(DocumentItemDetails item, int keyCode, KeyEvent event)104         public boolean onKey(DocumentItemDetails item, int keyCode, KeyEvent event) {
105             return false;
106         }
107 
108     }
109 }
110