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.data.Path; 21 22 import android.content.Context; 23 import android.graphics.Rect; 24 25 public class StripDrawer extends SelectionDrawer { 26 private NinePatchTexture mFramePressed; 27 private NinePatchTexture mFocusBox; 28 private Rect mFocusBoxPadding; 29 private Path mPressedPath; 30 31 public StripDrawer(Context context) { 32 mFramePressed = new NinePatchTexture(context, R.drawable.grid_pressed); 33 mFocusBox = new NinePatchTexture(context, R.drawable.thumb_selected); 34 mFocusBoxPadding = mFocusBox.getPaddings(); 35 } 36 37 public void setPressedPath(Path path) { 38 mPressedPath = path; 39 } 40 41 private boolean isPressedPath(Path path) { 42 return path != null && path == mPressedPath; 43 } 44 45 @Override 46 public void prepareDrawing() { 47 } 48 49 @Override 50 public void draw(GLCanvas canvas, Texture content, 51 int width, int height, int rotation, Path path, 52 int dataSourceType, int mediaType, boolean isPanorama, 53 int labelBackgroundHeight, boolean wantCache, boolean isCaching) { 54 55 int x = -width / 2; 56 int y = -height / 2; 57 58 drawWithRotation(canvas, content, x, y, width, height, rotation); 59 60 if (isPressedPath(path)) { 61 drawFrame(canvas, mFramePressed, x, y, width, height); 62 } 63 } 64 65 @Override 66 public void drawFocus(GLCanvas canvas, int width, int height) { 67 int x = -width / 2; 68 int y = -height / 2; 69 Rect p = mFocusBoxPadding; 70 mFocusBox.draw(canvas, x - p.left, y - p.top, 71 width + p.left + p.right, height + p.top + p.bottom); 72 } 73 } 74