OSDN Git Service

Fix 5299746: New UI layout, part 2.
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / ui / ManageCacheDrawer.java
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 static final int ICON_SIZE = 36;
27     private final ResourceTexture mCheckedItem;
28     private final ResourceTexture mUnCheckedItem;
29     private final SelectionManager mSelectionManager;
30
31     private final ResourceTexture mLocalAlbumIcon;
32     private final StringTexture mCachingText;
33
34     public ManageCacheDrawer(Context context, SelectionManager selectionManager) {
35         super(context);
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;
42     }
43
44     @Override
45     public void prepareDrawing() {
46     }
47
48     private static boolean isLocal(int dataSourceType) {
49         return dataSourceType != DATASOURCE_TYPE_PICASA;
50     }
51
52     @Override
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) {
57
58
59         int x = -width / 2;
60         int y = -height / 2;
61
62         drawWithRotationAndGray(canvas, content, x, y, width, height, rotation,
63                 topIndex);
64
65         if (((rotation / 90) & 0x01) == 1) {
66             int temp = width;
67             width = height;
68             height = temp;
69             x = -width / 2;
70             y = -height / 2;
71         }
72
73         drawMediaTypeOverlay(canvas, mediaType, isPanorama, x, y, width, height,
74                 topIndex);
75
76         if (topIndex == 0) {
77             drawLabelBackground(canvas, width, height, labelBackgroundHeight);
78             drawIcon(canvas, width, height, dataSourceType);
79         }
80
81         if (topIndex == 0) {
82             drawCachingIcon(canvas, path, dataSourceType, isCaching, wantCache,
83                     width, height);
84         }
85
86         if (mSelectionManager.isPressedPath(path)) {
87             drawPressedFrame(canvas, x, y, width, height);
88         }
89     }
90
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;
95
96         ResourceTexture icon = null;
97         if (isLocal(dataSourceType)) {
98             icon = mLocalAlbumIcon;
99         } else if (chooseToCache) {
100             icon = mCheckedItem;
101         } else {
102             icon = mUnCheckedItem;
103         }
104
105         int w = ICON_SIZE;
106         int h = ICON_SIZE;
107         int right = (width + 1) / 2;
108         int bottom = (height + 1) / 2;
109         int x = right - w;
110         int y = bottom - h;
111
112         icon.draw(canvas, x, y, w, h);
113
114         if (isCaching) {
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);
120         }
121     }
122
123     @Override
124     public void drawFocus(GLCanvas canvas, int width, int height) {
125     }
126 }