blob: a0ff1b5812aef92fe79a956969ae0aeb56388eb7 [file] [log] [blame]
Ben Kwaf8a51f62015-12-22 14:03:30 -08001/*
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;
20import static com.android.internal.util.Preconditions.checkNotNull;
21
22import android.content.Context;
23import android.database.Cursor;
24import android.provider.DocumentsContract.Document;
25import android.view.ViewGroup;
Ben Kwaddc3d212016-01-07 18:50:34 -080026import android.widget.ImageView;
Ben Kwaf8a51f62015-12-22 14:03:30 -080027import android.widget.TextView;
28
29import com.android.documentsui.R;
30import com.android.documentsui.State;
31
32final class GridDirectoryHolder extends DocumentHolder {
33 final TextView mTitle;
Ben Kwaddc3d212016-01-07 18:50:34 -080034 private ImageView mIconCheck;
35 private ImageView mIconMime;
36
Ben Kwaf8a51f62015-12-22 14:03:30 -080037 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 Kwaddc3d212016-01-07 18:50:34 -080041 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 Kwaf8a51f62015-12-22 14:03:30 -080052 }
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 Kwa22937c92016-02-23 23:00:01 -080066 mTitle.setText(docDisplayName, TextView.BufferType.SPANNABLE);
67
Ben Kwaf8a51f62015-12-22 14:03:30 -080068 }
69}