Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.gallery3d.ui; |
| 18 | |
| 19 | import com.android.gallery3d.R; |
| 20 | import com.android.gallery3d.data.Path; |
| 21 | |
| 22 | import android.content.Context; |
| 23 | import android.graphics.Color; |
Chih-Chung Chang | 07069de | 2011-09-14 20:50:28 +0800 | [diff] [blame] | 24 | import android.text.Layout; |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 25 | |
| 26 | public class GridDrawer extends IconDrawer { |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 27 | private Texture mImportLabel; |
| 28 | private int mGridWidth; |
| 29 | private final SelectionManager mSelectionManager; |
| 30 | private final Context mContext; |
Chih-Chung Chang | 07069de | 2011-09-14 20:50:28 +0800 | [diff] [blame] | 31 | 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 Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 34 | private boolean mSelectionMode; |
| 35 | |
| 36 | public GridDrawer(Context context, SelectionManager selectionManager) { |
| 37 | super(context); |
| 38 | mContext = context; |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 39 | mSelectionManager = selectionManager; |
| 40 | } |
| 41 | |
| 42 | @Override |
| 43 | public void prepareDrawing() { |
| 44 | mSelectionMode = mSelectionManager.inSelectionMode(); |
| 45 | } |
| 46 | |
| 47 | @Override |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 48 | 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 Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 52 | |
| 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 Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 67 | drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height, |
| 68 | topIndex); |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 69 | |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 70 | if (topIndex == 0) { |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 71 | drawLabelBackground(canvas, width, height, labelBackgroundHeight); |
Chih-Chung Chang | 07069de | 2011-09-14 20:50:28 +0800 | [diff] [blame] | 72 | drawIcon(canvas, width, height, dataSourceType); |
| 73 | if (dataSourceType == DATASOURCE_TYPE_MTP) { |
| 74 | drawImportLabel(canvas, width, height); |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 75 | } |
| 76 | } |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 77 | |
| 78 | if (mSelectionManager.isPressedPath(path)) { |
| 79 | drawPressedFrame(canvas, x, y, width, height); |
| 80 | } else if (mSelectionMode && mSelectionManager.isItemSelected(path)) { |
Chih-Chung Chang | e3312ff | 2011-09-22 14:55:32 +0800 | [diff] [blame^] | 81 | drawSelectedFrame(canvas, x, y, width, height); |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 82 | } |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 83 | } |
| 84 | |
Chih-Chung Chang | 07069de | 2011-09-14 20:50:28 +0800 | [diff] [blame] | 85 | // 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 Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 100 | @Override |
| 101 | public void drawFocus(GLCanvas canvas, int width, int height) { |
| 102 | } |
| 103 | } |