blob: fbd9e7851b8e3e7ca47446db097189dd73198369 [file] [log] [blame]
Owen Lina2fba682011-08-17 22:07:43 +08001/*
2 * Copyright (C) 2010 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.gallery3d.ui;
18
19import com.android.gallery3d.R;
20import com.android.gallery3d.data.Path;
21
22import android.content.Context;
23import android.graphics.Color;
Chih-Chung Chang07069de2011-09-14 20:50:28 +080024import android.text.Layout;
Owen Lina2fba682011-08-17 22:07:43 +080025
26public class GridDrawer extends IconDrawer {
Owen Lina2fba682011-08-17 22:07:43 +080027 private Texture mImportLabel;
28 private int mGridWidth;
29 private final SelectionManager mSelectionManager;
30 private final Context mContext;
Chih-Chung Chang07069de2011-09-14 20:50:28 +080031 private final int IMPORT_FONT_SIZE = 14;
32 private final int IMPORT_FONT_COLOR = Color.WHITE;
33 private final int IMPORT_LABEL_MARGIN = 10;
Owen Lina2fba682011-08-17 22:07:43 +080034 private boolean mSelectionMode;
35
36 public GridDrawer(Context context, SelectionManager selectionManager) {
37 super(context);
38 mContext = context;
Owen Lina2fba682011-08-17 22:07:43 +080039 mSelectionManager = selectionManager;
40 }
41
42 @Override
43 public void prepareDrawing() {
44 mSelectionMode = mSelectionManager.inSelectionMode();
45 }
46
47 @Override
Chih-Chung Chang70a73a72011-09-19 11:09:39 +080048 public void draw(GLCanvas canvas, Texture content, int width,
49 int height, int rotation, Path path, int topIndex,
50 int dataSourceType, int mediaType, boolean isPanorama,
51 int labelBackgroundHeight, boolean wantCache, boolean isCaching) {
Owen Lina2fba682011-08-17 22:07:43 +080052
53 int x = -width / 2;
54 int y = -height / 2;
55
56 drawWithRotationAndGray(canvas, content, x, y, width, height, rotation,
57 topIndex);
58
59 if (((rotation / 90) & 0x01) == 1) {
60 int temp = width;
61 width = height;
62 height = temp;
63 x = -width / 2;
64 y = -height / 2;
65 }
66
Chih-Chung Chang70a73a72011-09-19 11:09:39 +080067 drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height,
68 topIndex);
Owen Lina2fba682011-08-17 22:07:43 +080069
Owen Lina2fba682011-08-17 22:07:43 +080070 if (topIndex == 0) {
Chih-Chung Chang70a73a72011-09-19 11:09:39 +080071 drawLabelBackground(canvas, width, height, labelBackgroundHeight);
Chih-Chung Chang07069de2011-09-14 20:50:28 +080072 drawIcon(canvas, width, height, dataSourceType);
73 if (dataSourceType == DATASOURCE_TYPE_MTP) {
74 drawImportLabel(canvas, width, height);
Owen Lina2fba682011-08-17 22:07:43 +080075 }
76 }
Chih-Chung Chang70a73a72011-09-19 11:09:39 +080077
78 if (mSelectionManager.isPressedPath(path)) {
79 drawPressedFrame(canvas, x, y, width, height);
80 } else if (mSelectionMode && mSelectionManager.isItemSelected(path)) {
Chih-Chung Change3312ff2011-09-22 14:55:32 +080081 drawSelectedFrame(canvas, x, y, width, height);
Chih-Chung Chang70a73a72011-09-19 11:09:39 +080082 }
Owen Lina2fba682011-08-17 22:07:43 +080083 }
84
Chih-Chung Chang07069de2011-09-14 20:50:28 +080085 // Draws the "click to import" label at the center of the frame
86 private void drawImportLabel(GLCanvas canvas, int width, int height) {
87 if (mImportLabel == null || mGridWidth != width) {
88 mGridWidth = width;
89 mImportLabel = MultiLineTexture.newInstance(
90 mContext.getString(R.string.click_import),
91 width - 2 * IMPORT_LABEL_MARGIN,
92 IMPORT_FONT_SIZE, IMPORT_FONT_COLOR,
93 Layout.Alignment.ALIGN_CENTER);
94 }
95 int w = mImportLabel.getWidth();
96 int h = mImportLabel.getHeight();
97 mImportLabel.draw(canvas, -w / 2, -h / 2);
98 }
99
Owen Lina2fba682011-08-17 22:07:43 +0800100 @Override
101 public void drawFocus(GLCanvas canvas, int width, int height) {
102 }
103}