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