Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 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.model.DocumentInfo.getCursorString; |
| 20 | import static com.android.internal.util.Preconditions.checkNotNull; |
| 21 | |
| 22 | import android.content.Context; |
| 23 | import android.database.Cursor; |
| 24 | import android.provider.DocumentsContract.Document; |
| 25 | import android.view.ViewGroup; |
Ben Kwa | ddc3d21 | 2016-01-07 18:50:34 -0800 | [diff] [blame] | 26 | import android.widget.ImageView; |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 27 | import android.widget.TextView; |
| 28 | |
| 29 | import com.android.documentsui.R; |
| 30 | import com.android.documentsui.State; |
| 31 | |
| 32 | final class GridDirectoryHolder extends DocumentHolder { |
| 33 | final TextView mTitle; |
Ben Kwa | ddc3d21 | 2016-01-07 18:50:34 -0800 | [diff] [blame] | 34 | private ImageView mIconCheck; |
| 35 | private ImageView mIconMime; |
| 36 | |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 37 | public GridDirectoryHolder(Context context, ViewGroup parent) { |
| 38 | super(context, parent, R.layout.item_dir_grid); |
| 39 | |
| 40 | mTitle = (TextView) itemView.findViewById(android.R.id.title); |
Ben Kwa | ddc3d21 | 2016-01-07 18:50:34 -0800 | [diff] [blame] | 41 | mIconMime = (ImageView) itemView.findViewById(R.id.icon_mime_sm); |
| 42 | mIconCheck = (ImageView) itemView.findViewById(R.id.icon_check); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public void setSelected(boolean selected) { |
| 47 | super.setSelected(selected); |
| 48 | float checkAlpha = selected ? 1f : 0f; |
| 49 | |
| 50 | mIconCheck.animate().alpha(checkAlpha).start(); |
| 51 | mIconMime.animate().alpha(1f - checkAlpha).start(); |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Bind this view to the given document for display. |
| 56 | * @param cursor Pointing to the item to be bound. |
| 57 | * @param modelId The model ID of the item. |
| 58 | * @param state Current display state. |
| 59 | */ |
| 60 | public void bind(Cursor cursor, String modelId, State state) { |
| 61 | checkNotNull(cursor, "Cursor cannot be null."); |
| 62 | |
| 63 | this.modelId = modelId; |
| 64 | |
| 65 | final String docDisplayName = getCursorString(cursor, Document.COLUMN_DISPLAY_NAME); |
Ben Kwa | 22937c9 | 2016-02-23 23:00:01 -0800 | [diff] [blame] | 66 | mTitle.setText(docDisplayName, TextView.BufferType.SPANNABLE); |
| 67 | |
Ben Kwa | f8a51f6 | 2015-12-22 14:03:30 -0800 | [diff] [blame] | 68 | } |
| 69 | } |