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.dirlist; 17 18 import android.view.MotionEvent; 19 import android.view.View; 20 21 import androidx.annotation.Nullable; 22 import androidx.recyclerview.widget.RecyclerView; 23 import androidx.recyclerview.widget.RecyclerView.ViewHolder; 24 25 import com.android.documentsui.DocsSelectionHelper.DocDetailsLookup; 26 27 /** 28 * Access to details of an item associated with a {@link MotionEvent} instance. 29 */ 30 final class DocsItemDetailsLookup extends DocDetailsLookup { 31 32 private final RecyclerView mRecView; 33 DocsItemDetailsLookup(RecyclerView view)34 public DocsItemDetailsLookup(RecyclerView view) { 35 mRecView = view; 36 } 37 38 @Override getItemDetails(MotionEvent e)39 public DocumentItemDetails getItemDetails(MotionEvent e) { 40 @Nullable DocumentHolder holder = getDocumentHolder(e); 41 return holder == null ? null : holder.getItemDetails(); 42 } 43 getDocumentHolder(MotionEvent e)44 private @Nullable DocumentHolder getDocumentHolder(MotionEvent e) { 45 View childView = mRecView.findChildViewUnder(e.getX(), e.getY()); 46 if (childView != null) { 47 ViewHolder holder = mRecView.getChildViewHolder(childView); 48 if (holder instanceof DocumentHolder) { 49 return (DocumentHolder) holder; 50 } 51 } 52 return null; 53 } 54 } 55