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