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 17package com.android.documentsui.dirlist; 18 19import static com.android.documentsui.model.DocumentInfo.getCursorString; 20 21import android.content.Context; 22import android.database.Cursor; 23import android.provider.DocumentsContract.Document; 24import android.view.ViewGroup; 25import android.widget.ImageView; 26import android.widget.TextView; 27 28import com.android.documentsui.R; 29import com.android.documentsui.State; 30 31final class GridDirectoryHolder extends DocumentHolder { 32 final TextView mTitle; 33 private ImageView mIconCheck; 34 private ImageView mIconMime; 35 36 public GridDirectoryHolder(Context context, ViewGroup parent) { 37 super(context, parent, R.layout.item_dir_grid); 38 39 mTitle = (TextView) itemView.findViewById(android.R.id.title); 40 mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime_sm); 41 mIconCheck = (ImageView) itemView.findViewById(R.id.icon_check); 42 } 43 44 @Override 45 public void setSelected(boolean selected, boolean animate) { 46 super.setSelected(selected, animate); 47 float checkAlpha = selected ? 1f : 0f; 48 49 if (animate) { 50 mIconCheck.animate().alpha(checkAlpha).start(); 51 mIconMime.animate().alpha(1f - checkAlpha).start(); 52 } else { 53 mIconCheck.setAlpha(checkAlpha); 54 mIconMime.setAlpha(1f - checkAlpha); 55 } 56 } 57 58 /** 59 * Bind this view to the given document for display. 60 * @param cursor Pointing to the item to be bound. 61 * @param modelId The model ID of the item. 62 * @param state Current display state. 63 */ 64 public void bind(Cursor cursor, String modelId, State state) { 65 assert(cursor != null); 66 67 this.modelId = modelId; 68 69 final String docDisplayName = getCursorString(cursor, Document.COLUMN_DISPLAY_NAME); 70 mTitle.setText(docDisplayName, TextView.BufferType.SPANNABLE); 71 72 } 73} 74