blob: 7734fb331dedb85b0020dfff97cdb2a45d218c92 [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
Owen Lina2fba682011-08-17 22:07:43 +080019import android.content.Context;
20
Owen Lin73a04ff2012-03-14 17:27:24 +080021import com.android.gallery3d.R;
22import com.android.gallery3d.data.Path;
23
Owen Lina2fba682011-08-17 22:07:43 +080024public class ManageCacheDrawer extends IconDrawer {
Owen Lina2fba682011-08-17 22:07:43 +080025 private final ResourceTexture mCheckedItem;
26 private final ResourceTexture mUnCheckedItem;
27 private final SelectionManager mSelectionManager;
28
29 private final ResourceTexture mLocalAlbumIcon;
Chih-Chung Chang70a73a72011-09-19 11:09:39 +080030 private final StringTexture mCachingText;
Owen Lina2fba682011-08-17 22:07:43 +080031
Chih-Chung Chang32a8c902011-09-21 14:04:34 +080032 private final int mCachePinSize;
33 private final int mCachePinMargin;
34
35 public ManageCacheDrawer(Context context, SelectionManager selectionManager,
36 int cachePinSize, int cachePinMargin) {
Owen Lina2fba682011-08-17 22:07:43 +080037 super(context);
Owen Lina2fba682011-08-17 22:07:43 +080038 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 Chang70a73a72011-09-19 11:09:39 +080042 mCachingText = StringTexture.newInstance(cachingLabel, 12, 0xffffffff);
Owen Lina2fba682011-08-17 22:07:43 +080043 mSelectionManager = selectionManager;
Chih-Chung Chang32a8c902011-09-21 14:04:34 +080044 mCachePinSize = cachePinSize;
45 mCachePinMargin = cachePinMargin;
Owen Lina2fba682011-08-17 22:07:43 +080046 }
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 Chang70a73a72011-09-19 11:09:39 +080057 public void draw(GLCanvas canvas, Texture content, int width,
Chih-Chung Chang1b2af5e2011-09-27 19:44:36 +080058 int height, int rotation, Path path,
Chih-Chung Chang70a73a72011-09-19 11:09:39 +080059 int dataSourceType, int mediaType, boolean isPanorama,
60 int labelBackgroundHeight, boolean wantCache, boolean isCaching) {
Owen Lina2fba682011-08-17 22:07:43 +080061
Chih-Chung Chang344617d2011-11-03 19:25:58 +080062 boolean selected = mSelectionManager.isItemSelected(path);
63 boolean chooseToCache = wantCache ^ selected;
64 boolean available = isLocal(dataSourceType) || chooseToCache;
65
Owen Lina2fba682011-08-17 22:07:43 +080066 int x = -width / 2;
67 int y = -height / 2;
68
Chih-Chung Chang344617d2011-11-03 19:25:58 +080069 if (!available) {
70 canvas.save(GLCanvas.SAVE_FLAG_ALPHA);
71 canvas.multiplyAlpha(0.6f);
72 }
73
Chih-Chung Chang1b2af5e2011-09-27 19:44:36 +080074 drawWithRotation(canvas, content, x, y, width, height, rotation);
Owen Lina2fba682011-08-17 22:07:43 +080075
Chih-Chung Chang344617d2011-11-03 19:25:58 +080076 if (!available) {
77 canvas.restore();
78 }
79
Owen Lina2fba682011-08-17 22:07:43 +080080 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 Chang1b2af5e2011-09-27 19:44:36 +080088 drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height);
89 drawLabelBackground(canvas, width, height, labelBackgroundHeight);
90 drawIcon(canvas, width, height, dataSourceType);
Chih-Chung Chang344617d2011-11-03 19:25:58 +080091 drawCachingPin(canvas, path, dataSourceType, isCaching, chooseToCache,
Chih-Chung Chang1b2af5e2011-09-27 19:44:36 +080092 width, height);
Owen Lina2fba682011-08-17 22:07:43 +080093
Chih-Chung Chang70a73a72011-09-19 11:09:39 +080094 if (mSelectionManager.isPressedPath(path)) {
95 drawPressedFrame(canvas, x, y, width, height);
96 }
97 }
Owen Lina2fba682011-08-17 22:07:43 +080098
Chih-Chung Chang32a8c902011-09-21 14:04:34 +080099 private void drawCachingPin(GLCanvas canvas, Path path, int dataSourceType,
Chih-Chung Chang344617d2011-11-03 19:25:58 +0800100 boolean isCaching, boolean chooseToCache, int width, int height) {
Owen Lina2fba682011-08-17 22:07:43 +0800101
Chih-Chung Chang70a73a72011-09-19 11:09:39 +0800102 ResourceTexture icon = null;
103 if (isLocal(dataSourceType)) {
104 icon = mLocalAlbumIcon;
105 } else if (chooseToCache) {
106 icon = mCheckedItem;
107 } else {
108 icon = mUnCheckedItem;
109 }
Owen Lina2fba682011-08-17 22:07:43 +0800110
Chih-Chung Chang32a8c902011-09-21 14:04:34 +0800111 int w = mCachePinSize;
112 int h = mCachePinSize;
Chih-Chung Chang70a73a72011-09-19 11:09:39 +0800113 int right = (width + 1) / 2;
114 int bottom = (height + 1) / 2;
Chih-Chung Chang32a8c902011-09-21 14:04:34 +0800115 int x = right - w - mCachePinMargin;
116 int y = bottom - h - mCachePinMargin;
Owen Lina2fba682011-08-17 22:07:43 +0800117
Chih-Chung Chang70a73a72011-09-19 11:09:39 +0800118 icon.draw(canvas, x, y, w, h);
119
120 if (isCaching) {
121 int textWidth = mCachingText.getWidth();
122 int textHeight = mCachingText.getHeight();
Chih-Chung Chang32a8c902011-09-21 14:04:34 +0800123 // Align the center of the text to the center of the pin icon
124 x = right - mCachePinMargin - (textWidth + mCachePinSize) / 2;
Chih-Chung Chang70a73a72011-09-19 11:09:39 +0800125 y = bottom - textHeight;
126 mCachingText.draw(canvas, x, y);
Owen Lina2fba682011-08-17 22:07:43 +0800127 }
128 }
129
130 @Override
131 public void drawFocus(GLCanvas canvas, int width, int height) {
132 }
133}