summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/filtershow/imageshow/ImageSmallBorder.java
blob: a60c33d52251f58087a9edad38488e759953154b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

package com.android.gallery3d.filtershow.imageshow;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.util.AttributeSet;

public class ImageSmallBorder extends ImageSmallFilter {

    // TODO: move this to xml.
    protected final int mSelectedBackgroundColor = Color.WHITE;
    protected final int mInnerBorderColor = Color.BLACK;
    protected final int mInnerBorderWidth = 2;
    protected final float mImageScaleFactor = 3.5f;

    public ImageSmallBorder(Context context) {
        super(context);
    }

    public ImageSmallBorder(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onDraw(Canvas canvas) {
        requestFilteredImages();
        canvas.drawColor(mBackgroundColor);
        // TODO: simplify & make faster...
        RectF border = new RectF(mMargin, 2*mMargin, getWidth() - mMargin - 1, getWidth());

        if (mIsSelected) {
            mPaint.setColor(mSelectedBackgroundColor);
            canvas.drawRect(0, mMargin, getWidth(), getWidth() + mMargin, mPaint);
        }

        mPaint.setColor(mInnerBorderColor);
        mPaint.setStrokeWidth(mInnerBorderWidth);
        Path path = new Path();
        path.addRect(border, Path.Direction.CCW);
        mPaint.setStyle(Paint.Style.STROKE);
        canvas.drawPath(path, mPaint);
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        canvas.save();
        canvas.clipRect(mMargin + 1, 2*mMargin, getWidth() - mMargin - 2, getWidth() - 1,
                Region.Op.INTERSECT);
        canvas.translate(mMargin + 1, 2*mMargin + 1);
        canvas.scale(mImageScaleFactor, mImageScaleFactor);
        Rect d = new Rect(0, 0, getWidth(), getWidth());
        drawImage(canvas, getFilteredImage(), d);
        canvas.restore();
    }

    @Override
    public void drawImage(Canvas canvas, Bitmap image, Rect d) {
        if (image != null) {
            int iw = image.getWidth();
            int ih = image.getHeight();
            Rect s = new Rect(0, 0, iw, iw);
            canvas.drawBitmap(image, s, d, mPaint);
        }
    }
}