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 android.view.MotionEvent;
     19 
     20 import com.android.documentsui.selection.ItemDetailsLookup.ItemDetails;
     21 import com.android.internal.widget.RecyclerView;
     22 
     23 public final class TestItemDetails extends ItemDetails {
     24 
     25     // DocumentsAdapter.ITEM_TYPE_DOCUMENT
     26     private int mViewType = -1;
     27     private int mPosition;
     28     private String mStableId;
     29     private boolean mInDragRegion;
     30     private boolean mInSelectionHotspot;
     31 
     32     public TestItemDetails() {
     33        mPosition = RecyclerView.NO_POSITION;
     34     }
     35 
     36     public TestItemDetails(TestItemDetails source) {
     37         mPosition = source.mPosition;
     38         mStableId = source.mStableId;
     39         mViewType = source.mViewType;
     40         mInDragRegion = source.mInDragRegion;
     41         mInSelectionHotspot = source.mInSelectionHotspot;
     42     }
     43 
     44     public void setViewType(int viewType) {
     45         mViewType = viewType;
     46     }
     47 
     48     public void at(int position) {
     49         mPosition = position;  // this is both "adapter position" and "item position".
     50         mStableId = (position == RecyclerView.NO_POSITION)
     51                 ? null
     52                 : String.valueOf(position);
     53     }
     54 
     55     public void setInItemDragRegion(boolean inHotspot) {
     56         mInDragRegion = inHotspot;
     57     }
     58 
     59     public void setInItemSelectRegion(boolean over) {
     60         mInSelectionHotspot = over;
     61     }
     62 
     63     @Override
     64     public int getItemViewType() {
     65         return mViewType;
     66     }
     67 
     68     @Override
     69     public boolean inDragRegion(MotionEvent event) {
     70         return mInDragRegion;
     71     }
     72 
     73     @Override
     74     public int hashCode() {
     75         return mPosition;
     76     }
     77 
     78     @Override
     79     public boolean equals(Object o) {
     80       if (this == o) {
     81           return true;
     82       }
     83 
     84       if (!(o instanceof TestItemDetails)) {
     85           return false;
     86       }
     87 
     88       TestItemDetails other = (TestItemDetails) o;
     89       return mPosition == other.mPosition
     90               && mStableId == other.mStableId
     91               && mViewType == other.mViewType;
     92     }
     93 
     94     @Override
     95     public int getPosition() {
     96         return mPosition;
     97     }
     98 
     99     @Override
    100     public String getStableId() {
    101         return mStableId;
    102     }
    103 
    104     @Override
    105     public boolean inSelectionHotspot(MotionEvent e) {
    106         return mInSelectionHotspot;
    107     }
    108 }
    109