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 | |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | |
Owen Lin | 73a04ff | 2012-03-14 17:27:24 +0800 | [diff] [blame] | 21 | import com.android.gallery3d.R; |
| 22 | import com.android.gallery3d.data.Path; |
| 23 | |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 24 | public class ManageCacheDrawer extends IconDrawer { |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 25 | private final ResourceTexture mCheckedItem; |
| 26 | private final ResourceTexture mUnCheckedItem; |
| 27 | private final SelectionManager mSelectionManager; |
| 28 | |
| 29 | private final ResourceTexture mLocalAlbumIcon; |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 30 | private final StringTexture mCachingText; |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 31 | |
Chih-Chung Chang | 32a8c90 | 2011-09-21 14:04:34 +0800 | [diff] [blame] | 32 | private final int mCachePinSize; |
| 33 | private final int mCachePinMargin; |
| 34 | |
| 35 | public ManageCacheDrawer(Context context, SelectionManager selectionManager, |
| 36 | int cachePinSize, int cachePinMargin) { |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 37 | super(context); |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 38 | mCheckedItem = new ResourceTexture(context, R.drawable.btn_make_offline_normal_on_holo_dark); |
| 39 | mUnCheckedItem = new ResourceTexture(context, R.drawable.btn_make_offline_normal_off_holo_dark); |
| 40 | mLocalAlbumIcon = new ResourceTexture(context, R.drawable.btn_make_offline_disabled_on_holo_dark); |
| 41 | String cachingLabel = context.getString(R.string.caching_label); |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 42 | mCachingText = StringTexture.newInstance(cachingLabel, 12, 0xffffffff); |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 43 | mSelectionManager = selectionManager; |
Chih-Chung Chang | 32a8c90 | 2011-09-21 14:04:34 +0800 | [diff] [blame] | 44 | mCachePinSize = cachePinSize; |
| 45 | mCachePinMargin = cachePinMargin; |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public void prepareDrawing() { |
| 50 | } |
| 51 | |
| 52 | private static boolean isLocal(int dataSourceType) { |
| 53 | return dataSourceType != DATASOURCE_TYPE_PICASA; |
| 54 | } |
| 55 | |
| 56 | @Override |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 57 | public void draw(GLCanvas canvas, Texture content, int width, |
Chih-Chung Chang | 1b2af5e | 2011-09-27 19:44:36 +0800 | [diff] [blame] | 58 | int height, int rotation, Path path, |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 59 | int dataSourceType, int mediaType, boolean isPanorama, |
| 60 | int labelBackgroundHeight, boolean wantCache, boolean isCaching) { |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 61 | |
Chih-Chung Chang | 344617d | 2011-11-03 19:25:58 +0800 | [diff] [blame] | 62 | boolean selected = mSelectionManager.isItemSelected(path); |
| 63 | boolean chooseToCache = wantCache ^ selected; |
| 64 | boolean available = isLocal(dataSourceType) || chooseToCache; |
| 65 | |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 66 | int x = -width / 2; |
| 67 | int y = -height / 2; |
| 68 | |
Chih-Chung Chang | 344617d | 2011-11-03 19:25:58 +0800 | [diff] [blame] | 69 | if (!available) { |
| 70 | canvas.save(GLCanvas.SAVE_FLAG_ALPHA); |
| 71 | canvas.multiplyAlpha(0.6f); |
| 72 | } |
| 73 | |
Chih-Chung Chang | 1b2af5e | 2011-09-27 19:44:36 +0800 | [diff] [blame] | 74 | drawWithRotation(canvas, content, x, y, width, height, rotation); |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 75 | |
Chih-Chung Chang | 344617d | 2011-11-03 19:25:58 +0800 | [diff] [blame] | 76 | if (!available) { |
| 77 | canvas.restore(); |
| 78 | } |
| 79 | |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 80 | if (((rotation / 90) & 0x01) == 1) { |
| 81 | int temp = width; |
| 82 | width = height; |
| 83 | height = temp; |
| 84 | x = -width / 2; |
| 85 | y = -height / 2; |
| 86 | } |
| 87 | |
Chih-Chung Chang | 1b2af5e | 2011-09-27 19:44:36 +0800 | [diff] [blame] | 88 | drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height); |
| 89 | drawLabelBackground(canvas, width, height, labelBackgroundHeight); |
| 90 | drawIcon(canvas, width, height, dataSourceType); |
Chih-Chung Chang | 344617d | 2011-11-03 19:25:58 +0800 | [diff] [blame] | 91 | drawCachingPin(canvas, path, dataSourceType, isCaching, chooseToCache, |
Chih-Chung Chang | 1b2af5e | 2011-09-27 19:44:36 +0800 | [diff] [blame] | 92 | width, height); |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 93 | |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 94 | if (mSelectionManager.isPressedPath(path)) { |
| 95 | drawPressedFrame(canvas, x, y, width, height); |
| 96 | } |
| 97 | } |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 98 | |
Chih-Chung Chang | 32a8c90 | 2011-09-21 14:04:34 +0800 | [diff] [blame] | 99 | private void drawCachingPin(GLCanvas canvas, Path path, int dataSourceType, |
Chih-Chung Chang | 344617d | 2011-11-03 19:25:58 +0800 | [diff] [blame] | 100 | boolean isCaching, boolean chooseToCache, int width, int height) { |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 101 | |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 102 | ResourceTexture icon = null; |
| 103 | if (isLocal(dataSourceType)) { |
| 104 | icon = mLocalAlbumIcon; |
| 105 | } else if (chooseToCache) { |
| 106 | icon = mCheckedItem; |
| 107 | } else { |
| 108 | icon = mUnCheckedItem; |
| 109 | } |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 110 | |
Chih-Chung Chang | 32a8c90 | 2011-09-21 14:04:34 +0800 | [diff] [blame] | 111 | int w = mCachePinSize; |
| 112 | int h = mCachePinSize; |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 113 | int right = (width + 1) / 2; |
| 114 | int bottom = (height + 1) / 2; |
Chih-Chung Chang | 32a8c90 | 2011-09-21 14:04:34 +0800 | [diff] [blame] | 115 | int x = right - w - mCachePinMargin; |
| 116 | int y = bottom - h - mCachePinMargin; |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 117 | |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 118 | icon.draw(canvas, x, y, w, h); |
| 119 | |
| 120 | if (isCaching) { |
| 121 | int textWidth = mCachingText.getWidth(); |
| 122 | int textHeight = mCachingText.getHeight(); |
Chih-Chung Chang | 32a8c90 | 2011-09-21 14:04:34 +0800 | [diff] [blame] | 123 | // Align the center of the text to the center of the pin icon |
| 124 | x = right - mCachePinMargin - (textWidth + mCachePinSize) / 2; |
Chih-Chung Chang | 70a73a7 | 2011-09-19 11:09:39 +0800 | [diff] [blame] | 125 | y = bottom - textHeight; |
| 126 | mCachingText.draw(canvas, x, y); |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public void drawFocus(GLCanvas canvas, int width, int height) { |
| 132 | } |
| 133 | } |