2 * Copyright (C) 2012 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.gallery3d.filtershow.imageshow;
19 import android.content.Context;
20 import android.graphics.Bitmap;
21 import android.graphics.Canvas;
22 import android.graphics.Color;
23 import android.graphics.Paint;
24 import android.graphics.Path;
25 import android.graphics.Rect;
26 import android.graphics.RectF;
27 import android.graphics.Region;
28 import android.util.AttributeSet;
30 public class ImageSmallBorder extends ImageSmallFilter {
32 // TODO: move this to xml.
33 protected final int mSelectedBackgroundColor = Color.WHITE;
34 protected final int mInnerBorderColor = Color.BLACK;
35 protected final int mInnerBorderWidth = 2;
36 protected final float mImageScaleFactor = 3.5f;
38 public ImageSmallBorder(Context context) {
42 public ImageSmallBorder(Context context, AttributeSet attrs) {
43 super(context, attrs);
47 public void onDraw(Canvas canvas) {
48 requestFilteredImages();
49 canvas.drawColor(mBackgroundColor);
50 // TODO: simplify & make faster...
51 RectF border = new RectF(mMargin, 2*mMargin, getWidth() - mMargin - 1, getWidth());
54 mPaint.setColor(mSelectedBackgroundColor);
55 canvas.drawRect(0, mMargin, getWidth(), getWidth() + mMargin, mPaint);
58 mPaint.setColor(mInnerBorderColor);
59 mPaint.setStrokeWidth(mInnerBorderWidth);
60 Path path = new Path();
61 path.addRect(border, Path.Direction.CCW);
62 mPaint.setStyle(Paint.Style.STROKE);
63 canvas.drawPath(path, mPaint);
64 mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
66 canvas.clipRect(mMargin + 1, 2*mMargin, getWidth() - mMargin - 2, getWidth() - 1,
68 canvas.translate(mMargin + 1, 2*mMargin + 1);
69 canvas.scale(mImageScaleFactor, mImageScaleFactor);
70 Rect d = new Rect(0, 0, getWidth(), getWidth());
71 drawImage(canvas, getFilteredImage(), d);
76 public void drawImage(Canvas canvas, Bitmap image, Rect d) {
78 int iw = image.getWidth();
79 int ih = image.getHeight();
80 Rect s = new Rect(0, 0, iw, iw);
81 canvas.drawBitmap(image, s, d, mPaint);