2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.gallery3d.ui;
19 import com.android.gallery3d.R;
20 import com.android.gallery3d.common.Utils;
21 import com.android.gallery3d.data.Path;
23 import android.content.Context;
25 public class ManageCacheDrawer extends IconDrawer {
26 private static final int ICON_SIZE = 36;
27 private final ResourceTexture mCheckedItem;
28 private final ResourceTexture mUnCheckedItem;
29 private final SelectionManager mSelectionManager;
31 private final ResourceTexture mLocalAlbumIcon;
32 private final StringTexture mCachingText;
34 public ManageCacheDrawer(Context context, SelectionManager selectionManager) {
36 mCheckedItem = new ResourceTexture(context, R.drawable.btn_make_offline_normal_on_holo_dark);
37 mUnCheckedItem = new ResourceTexture(context, R.drawable.btn_make_offline_normal_off_holo_dark);
38 mLocalAlbumIcon = new ResourceTexture(context, R.drawable.btn_make_offline_disabled_on_holo_dark);
39 String cachingLabel = context.getString(R.string.caching_label);
40 mCachingText = StringTexture.newInstance(cachingLabel, 12, 0xffffffff);
41 mSelectionManager = selectionManager;
45 public void prepareDrawing() {
48 private static boolean isLocal(int dataSourceType) {
49 return dataSourceType != DATASOURCE_TYPE_PICASA;
53 public void draw(GLCanvas canvas, Texture content, int width,
54 int height, int rotation, Path path, int topIndex,
55 int dataSourceType, int mediaType, boolean isPanorama,
56 int labelBackgroundHeight, boolean wantCache, boolean isCaching) {
62 drawWithRotationAndGray(canvas, content, x, y, width, height, rotation,
65 if (((rotation / 90) & 0x01) == 1) {
73 drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height,
77 drawLabelBackground(canvas, width, height, labelBackgroundHeight);
78 drawIcon(canvas, width, height, dataSourceType);
82 drawCachingIcon(canvas, path, dataSourceType, isCaching, wantCache,
86 if (mSelectionManager.isPressedPath(path)) {
87 drawPressedFrame(canvas, x, y, width, height);
91 private void drawCachingIcon(GLCanvas canvas, Path path, int dataSourceType,
92 boolean isCaching, boolean wantCache, int width, int height) {
93 boolean selected = mSelectionManager.isItemSelected(path);
94 boolean chooseToCache = wantCache ^ selected;
96 ResourceTexture icon = null;
97 if (isLocal(dataSourceType)) {
98 icon = mLocalAlbumIcon;
99 } else if (chooseToCache) {
102 icon = mUnCheckedItem;
107 int right = (width + 1) / 2;
108 int bottom = (height + 1) / 2;
112 icon.draw(canvas, x, y, w, h);
115 int textWidth = mCachingText.getWidth();
116 int textHeight = mCachingText.getHeight();
117 x = right - ICON_SIZE - textWidth;
118 y = bottom - textHeight;
119 mCachingText.draw(canvas, x, y);
124 public void drawFocus(GLCanvas canvas, int width, int height) {