2 * Copyright (C) 2015 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.camera.ui;
19 import android.graphics.Canvas;
20 import android.graphics.ColorFilter;
21 import android.graphics.Paint;
22 import android.graphics.PixelFormat;
23 import android.graphics.Rect;
24 import android.graphics.RectF;
25 import android.graphics.drawable.Drawable;
28 * Drawable that takes a {@link RectF} as a screen, and draws around that
29 * screen to fill margins between the screen and the edge of the {@link Canvas}
32 public class MarginDrawable extends Drawable {
34 private RectF mScreen = new RectF(0, 0, 0, 0);
35 private final Paint mPaint;
37 public MarginDrawable(int color) {
41 mPaint.setAntiAlias(true);
42 mPaint.setColor(color);
46 * Set the screen around which will be drawn margins. If the screen rect
47 * has no area (zero width or height), no margins will be drawn.
49 * @param screen A {@link RectF} describing the screen dimensions
51 public void setScreen(RectF screen) {
57 public void draw(Canvas canvas) {
59 if (s.top < s.bottom && s.left < s.right) {
60 Rect cb = canvas.getClipBounds();
62 canvas.drawRect(0, 0, cb.right, s.top + 1, mPaint);
65 canvas.drawRect(0, s.top, s.left + 1, s.bottom, mPaint);
67 if (s.right < cb.right) {
68 canvas.drawRect(s.right - 1, s.top, cb.right, s.bottom, mPaint);
70 if (s.bottom < cb.bottom) {
71 canvas.drawRect(0, s.bottom - 1, cb.right, cb.bottom, mPaint);
77 public void setAlpha(int alpha) {
81 public void setColorFilter(ColorFilter cf) {
85 public int getOpacity() {
86 return PixelFormat.OPAQUE;