Home | History | Annotate | Download | only in selection
      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 static android.support.v4.util.Preconditions.checkArgument;
     19 
     20 import android.support.annotation.Nullable;
     21 import android.view.MotionEvent;
     22 
     23 import com.android.documentsui.selection.ItemDetailsLookup.ItemDetails;
     24 
     25 /**
     26  * BandPredicate that consults ItemDetails, premitting band selection to start
     27  * when the event is not in the drag region of the item.
     28  */
     29 public final class DefaultBandPredicate extends BandPredicate {
     30 
     31     private final ItemDetailsLookup mDetailsLookup;
     32 
     33     public DefaultBandPredicate(ItemDetailsLookup detailsLookup) {
     34         checkArgument(detailsLookup != null);
     35 
     36         mDetailsLookup = detailsLookup;
     37     }
     38 
     39     @Override
     40     public boolean canInitiate(MotionEvent e) {
     41         @Nullable ItemDetails details = mDetailsLookup.getItemDetails(e);
     42         return (details != null)
     43             ? !details.inDragRegion(e)
     44             : true;
     45     }
     46 }
     47