blob: 99e4a586f679180274084a544f8c2b6bab3ab180 [file] [log] [blame]
The Android Open Source Projectb64d3452009-03-03 19:32:20 -08001/*
2 * Copyright (C) 2008 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
17package com.android.camera;
18
19import android.content.Context;
20import android.graphics.Canvas;
21import android.graphics.Rect;
22import android.graphics.drawable.Drawable;
23import android.util.AttributeSet;
24import android.widget.ImageView;
25
Ray Chen254590b2009-04-02 03:21:24 -070026class GalleryPickerItem extends ImageView {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080027 private Drawable mFrame;
28 private Rect mFrameBounds = new Rect();
29 private Drawable mOverlay;
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080030
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080031 public GalleryPickerItem(Context context) {
32 this(context, null);
33 }
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080034
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080035 public GalleryPickerItem(Context context, AttributeSet attrs) {
36 this(context, attrs, 0);
37 }
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080038
39 public GalleryPickerItem(Context context,
40 AttributeSet attrs,
Ray Chen254590b2009-04-02 03:21:24 -070041 int defStyle) {
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080042 super(context, attrs, defStyle);
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080043
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080044 mFrame = getResources().getDrawable(R.drawable.frame_gallery_preview);
45 mFrame.setCallback(this);
46 }
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080047
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080048 @Override
49 protected boolean verifyDrawable(Drawable who) {
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080050 return super.verifyDrawable(who) || (who == mFrame)
Ray Chen254590b2009-04-02 03:21:24 -070051 || (who == mOverlay);
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080052 }
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080053
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080054 @Override
55 protected void drawableStateChanged() {
56 super.drawableStateChanged();
57 if (mFrame != null) {
58 int[] drawableState = getDrawableState();
59 mFrame.setState(drawableState);
60 }
61 }
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080062
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080063 @Override
64 protected void onDraw(Canvas canvas) {
65 super.onDraw(canvas);
66 final Rect frameBounds = mFrameBounds;
67 if (frameBounds.isEmpty()) {
68 final int w = getWidth();
69 final int h = getHeight();
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080070
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080071 frameBounds.set(0, 0, w, h);
72 mFrame.setBounds(frameBounds);
73 if (mOverlay != null) {
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080074 mOverlay.setBounds(w - mOverlay.getIntrinsicWidth(),
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080075 h - mOverlay.getIntrinsicHeight(), w, h);
76 }
77 }
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080078
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080079 mFrame.draw(canvas);
80 if (mOverlay != null) {
81 mOverlay.draw(canvas);
82 }
83 }
Chih-Chung Chang0a475e12009-04-16 11:42:12 +080084
85
The Android Open Source Projectb64d3452009-03-03 19:32:20 -080086 @Override
87 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
88 super.onSizeChanged(w, h, oldw, oldh);
89
90 mFrameBounds.setEmpty();
91 }
92
93 public void setOverlay(int overlayId) {
94 if (overlayId >= 0) {
95 mOverlay = getResources().getDrawable(overlayId);
96 mFrameBounds.setEmpty();
97 } else {
98 mOverlay = null;
99 }
100 }
101}