1666ea1b28a76aeba74744148b15099254d918671Owen Lin/* 2666ea1b28a76aeba74744148b15099254d918671Owen Lin * Copyright (C) 2008 The Android Open Source Project 3666ea1b28a76aeba74744148b15099254d918671Owen Lin * 4666ea1b28a76aeba74744148b15099254d918671Owen Lin * Licensed under the Apache License, Version 2.0 (the "License"); 5666ea1b28a76aeba74744148b15099254d918671Owen Lin * you may not use this file except in compliance with the License. 6666ea1b28a76aeba74744148b15099254d918671Owen Lin * You may obtain a copy of the License at 7666ea1b28a76aeba74744148b15099254d918671Owen Lin * 8666ea1b28a76aeba74744148b15099254d918671Owen Lin * http://www.apache.org/licenses/LICENSE-2.0 9666ea1b28a76aeba74744148b15099254d918671Owen Lin * 10666ea1b28a76aeba74744148b15099254d918671Owen Lin * Unless required by applicable law or agreed to in writing, software 11666ea1b28a76aeba74744148b15099254d918671Owen Lin * distributed under the License is distributed on an "AS IS" BASIS, 12666ea1b28a76aeba74744148b15099254d918671Owen Lin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13666ea1b28a76aeba74744148b15099254d918671Owen Lin * See the License for the specific language governing permissions and 14666ea1b28a76aeba74744148b15099254d918671Owen Lin * limitations under the License. 15666ea1b28a76aeba74744148b15099254d918671Owen Lin */ 16666ea1b28a76aeba74744148b15099254d918671Owen Lin 17666ea1b28a76aeba74744148b15099254d918671Owen Linpackage com.android.camera; 18666ea1b28a76aeba74744148b15099254d918671Owen Lin 19d6c2fb7a38fcdb58742fcfffd67a4594487ec71cOwen Linimport com.android.gallery.R; 20d6c2fb7a38fcdb58742fcfffd67a4594487ec71cOwen Lin 21666ea1b28a76aeba74744148b15099254d918671Owen Linimport android.content.Context; 22666ea1b28a76aeba74744148b15099254d918671Owen Linimport android.graphics.Canvas; 23666ea1b28a76aeba74744148b15099254d918671Owen Linimport android.graphics.Rect; 24666ea1b28a76aeba74744148b15099254d918671Owen Linimport android.graphics.drawable.Drawable; 25666ea1b28a76aeba74744148b15099254d918671Owen Linimport android.util.AttributeSet; 26666ea1b28a76aeba74744148b15099254d918671Owen Linimport android.widget.ImageView; 27666ea1b28a76aeba74744148b15099254d918671Owen Lin 28666ea1b28a76aeba74744148b15099254d918671Owen Linclass GalleryPickerItem extends ImageView { 29666ea1b28a76aeba74744148b15099254d918671Owen Lin private Drawable mFrame; 30666ea1b28a76aeba74744148b15099254d918671Owen Lin private Rect mFrameBounds = new Rect(); 31666ea1b28a76aeba74744148b15099254d918671Owen Lin private Drawable mOverlay; 32666ea1b28a76aeba74744148b15099254d918671Owen Lin 33666ea1b28a76aeba74744148b15099254d918671Owen Lin public GalleryPickerItem(Context context) { 34666ea1b28a76aeba74744148b15099254d918671Owen Lin this(context, null); 35666ea1b28a76aeba74744148b15099254d918671Owen Lin } 36666ea1b28a76aeba74744148b15099254d918671Owen Lin 37666ea1b28a76aeba74744148b15099254d918671Owen Lin public GalleryPickerItem(Context context, AttributeSet attrs) { 38666ea1b28a76aeba74744148b15099254d918671Owen Lin this(context, attrs, 0); 39666ea1b28a76aeba74744148b15099254d918671Owen Lin } 40666ea1b28a76aeba74744148b15099254d918671Owen Lin 41666ea1b28a76aeba74744148b15099254d918671Owen Lin public GalleryPickerItem(Context context, 42666ea1b28a76aeba74744148b15099254d918671Owen Lin AttributeSet attrs, 43666ea1b28a76aeba74744148b15099254d918671Owen Lin int defStyle) { 44666ea1b28a76aeba74744148b15099254d918671Owen Lin super(context, attrs, defStyle); 45666ea1b28a76aeba74744148b15099254d918671Owen Lin 46666ea1b28a76aeba74744148b15099254d918671Owen Lin mFrame = getResources().getDrawable(R.drawable.frame_gallery_preview); 47666ea1b28a76aeba74744148b15099254d918671Owen Lin mFrame.setCallback(this); 48666ea1b28a76aeba74744148b15099254d918671Owen Lin } 49666ea1b28a76aeba74744148b15099254d918671Owen Lin 50666ea1b28a76aeba74744148b15099254d918671Owen Lin @Override 51666ea1b28a76aeba74744148b15099254d918671Owen Lin protected boolean verifyDrawable(Drawable who) { 52666ea1b28a76aeba74744148b15099254d918671Owen Lin return super.verifyDrawable(who) || (who == mFrame) 53666ea1b28a76aeba74744148b15099254d918671Owen Lin || (who == mOverlay); 54666ea1b28a76aeba74744148b15099254d918671Owen Lin } 55666ea1b28a76aeba74744148b15099254d918671Owen Lin 56666ea1b28a76aeba74744148b15099254d918671Owen Lin @Override 57666ea1b28a76aeba74744148b15099254d918671Owen Lin protected void drawableStateChanged() { 58666ea1b28a76aeba74744148b15099254d918671Owen Lin super.drawableStateChanged(); 59666ea1b28a76aeba74744148b15099254d918671Owen Lin if (mFrame != null) { 60666ea1b28a76aeba74744148b15099254d918671Owen Lin int[] drawableState = getDrawableState(); 61666ea1b28a76aeba74744148b15099254d918671Owen Lin mFrame.setState(drawableState); 62666ea1b28a76aeba74744148b15099254d918671Owen Lin } 63666ea1b28a76aeba74744148b15099254d918671Owen Lin } 64666ea1b28a76aeba74744148b15099254d918671Owen Lin 65666ea1b28a76aeba74744148b15099254d918671Owen Lin @Override 66666ea1b28a76aeba74744148b15099254d918671Owen Lin protected void onDraw(Canvas canvas) { 67666ea1b28a76aeba74744148b15099254d918671Owen Lin super.onDraw(canvas); 68666ea1b28a76aeba74744148b15099254d918671Owen Lin final Rect frameBounds = mFrameBounds; 69666ea1b28a76aeba74744148b15099254d918671Owen Lin if (frameBounds.isEmpty()) { 70666ea1b28a76aeba74744148b15099254d918671Owen Lin final int w = getWidth(); 71666ea1b28a76aeba74744148b15099254d918671Owen Lin final int h = getHeight(); 72666ea1b28a76aeba74744148b15099254d918671Owen Lin 73666ea1b28a76aeba74744148b15099254d918671Owen Lin frameBounds.set(0, 0, w, h); 74666ea1b28a76aeba74744148b15099254d918671Owen Lin mFrame.setBounds(frameBounds); 75666ea1b28a76aeba74744148b15099254d918671Owen Lin if (mOverlay != null) { 76666ea1b28a76aeba74744148b15099254d918671Owen Lin mOverlay.setBounds(w - mOverlay.getIntrinsicWidth(), 77666ea1b28a76aeba74744148b15099254d918671Owen Lin h - mOverlay.getIntrinsicHeight(), w, h); 78666ea1b28a76aeba74744148b15099254d918671Owen Lin } 79666ea1b28a76aeba74744148b15099254d918671Owen Lin } 80666ea1b28a76aeba74744148b15099254d918671Owen Lin 81666ea1b28a76aeba74744148b15099254d918671Owen Lin mFrame.draw(canvas); 82666ea1b28a76aeba74744148b15099254d918671Owen Lin if (mOverlay != null) { 83666ea1b28a76aeba74744148b15099254d918671Owen Lin mOverlay.draw(canvas); 84666ea1b28a76aeba74744148b15099254d918671Owen Lin } 85666ea1b28a76aeba74744148b15099254d918671Owen Lin } 86666ea1b28a76aeba74744148b15099254d918671Owen Lin 87666ea1b28a76aeba74744148b15099254d918671Owen Lin 88666ea1b28a76aeba74744148b15099254d918671Owen Lin @Override 89666ea1b28a76aeba74744148b15099254d918671Owen Lin protected void onSizeChanged(int w, int h, int oldw, int oldh) { 90666ea1b28a76aeba74744148b15099254d918671Owen Lin super.onSizeChanged(w, h, oldw, oldh); 91666ea1b28a76aeba74744148b15099254d918671Owen Lin 92666ea1b28a76aeba74744148b15099254d918671Owen Lin mFrameBounds.setEmpty(); 93666ea1b28a76aeba74744148b15099254d918671Owen Lin } 94666ea1b28a76aeba74744148b15099254d918671Owen Lin 95666ea1b28a76aeba74744148b15099254d918671Owen Lin public void setOverlay(int overlayId) { 96666ea1b28a76aeba74744148b15099254d918671Owen Lin if (overlayId >= 0) { 97666ea1b28a76aeba74744148b15099254d918671Owen Lin mOverlay = getResources().getDrawable(overlayId); 98666ea1b28a76aeba74744148b15099254d918671Owen Lin mFrameBounds.setEmpty(); 99666ea1b28a76aeba74744148b15099254d918671Owen Lin } else { 100666ea1b28a76aeba74744148b15099254d918671Owen Lin mOverlay = null; 101666ea1b28a76aeba74744148b15099254d918671Owen Lin } 102666ea1b28a76aeba74744148b15099254d918671Owen Lin } 103666ea1b28a76aeba74744148b15099254d918671Owen Lin} 104