Home | History | Annotate | Download | only in dirlist
      1 /*
      2  * Copyright (C) 2015 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 static com.android.documentsui.base.DocumentInfo.getCursorString;
     20 
     21 import android.content.Context;
     22 import android.database.Cursor;
     23 import android.graphics.Rect;
     24 import android.provider.DocumentsContract.Document;
     25 import android.view.MotionEvent;
     26 import android.view.ViewGroup;
     27 import android.widget.ImageView;
     28 import android.widget.TextView;
     29 
     30 import com.android.documentsui.R;
     31 
     32 final class GridDirectoryHolder extends DocumentHolder {
     33 
     34     final TextView mTitle;
     35 
     36     private final ImageView mIconCheck;
     37     private final ImageView mIconMime;
     38 
     39     public GridDirectoryHolder(Context context, ViewGroup parent) {
     40         super(context, parent, R.layout.item_dir_grid);
     41 
     42         mTitle = (TextView) itemView.findViewById(android.R.id.title);
     43         mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime_sm);
     44         mIconCheck = (ImageView) itemView.findViewById(R.id.icon_check);
     45     }
     46 
     47     @Override
     48     public void setSelected(boolean selected, boolean animate) {
     49         super.setSelected(selected, animate);
     50         float checkAlpha = selected ? 1f : 0f;
     51 
     52         if (animate) {
     53             fade(mIconCheck, checkAlpha).start();
     54             fade(mIconMime, 1f - checkAlpha).start();
     55         } else {
     56             mIconCheck.setAlpha(checkAlpha);
     57             mIconMime.setAlpha(1f - checkAlpha);
     58         }
     59     }
     60 
     61     @Override
     62     public boolean inDragRegion(MotionEvent event) {
     63         // Entire grid box should be draggable
     64         return true;
     65     }
     66 
     67     @Override
     68     public boolean inSelectRegion(MotionEvent event) {
     69         Rect iconRect = new Rect();
     70         mIconMime.getGlobalVisibleRect(iconRect);
     71 
     72         return iconRect.contains((int) event.getRawX(), (int) event.getRawY());
     73     }
     74 
     75     /**
     76      * Bind this view to the given document for display.
     77      * @param cursor Pointing to the item to be bound.
     78      * @param modelId The model ID of the item.
     79      */
     80     @Override
     81     public void bind(Cursor cursor, String modelId) {
     82         assert(cursor != null);
     83 
     84         this.mModelId = modelId;
     85 
     86         mTitle.setText(
     87                 getCursorString(cursor, Document.COLUMN_DISPLAY_NAME),
     88                 TextView.BufferType.SPANNABLE);
     89     }
     90 }
     91