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; 17 18 import android.support.v7.widget.RecyclerView; 19 import android.view.MotionEvent; 20 21 import javax.annotation.Nullable; 22 23 /** 24 * Test impl of ItemDetailsLookup. 25 */ 26 public class TestItemDetailsLookup extends ItemDetailsLookup { 27 28 private @Nullable TestItemDetails mDoc; 29 30 @Override overItem(MotionEvent e)31 public boolean overItem(MotionEvent e) { 32 return getItemPosition(e) != RecyclerView.NO_POSITION; 33 } 34 35 @Override overStableItem(MotionEvent e)36 public boolean overStableItem(MotionEvent e) { 37 return mDoc.getStableId() != null; 38 } 39 40 @Override inItemDragRegion(MotionEvent e)41 public boolean inItemDragRegion(MotionEvent e) { 42 return mDoc.inDragRegion(e); 43 } 44 45 @Override getItemPosition(MotionEvent e)46 public int getItemPosition(MotionEvent e) { 47 return mDoc.getPosition(); 48 } 49 50 @Override inItemSelectRegion(MotionEvent e)51 public boolean inItemSelectRegion(MotionEvent e) { 52 return mDoc.inSelectionHotspot(e); 53 } 54 55 @Override getItemDetails(MotionEvent e)56 public @Nullable ItemDetails getItemDetails(MotionEvent e) { 57 return mDoc; 58 } 59 60 /** 61 * Creates/installs/returns a new test document. Subsequent calls to 62 * any EventDocLookup methods will consult the newly created doc. 63 */ initAt(int position)64 public TestItemDetails initAt(int position) { 65 TestItemDetails doc = new TestItemDetails(); 66 doc.at(position); 67 mDoc = doc; 68 return doc; 69 } 70 reset()71 public void reset() { 72 mDoc = null; 73 } 74 } 75