1 /* 2 * Copyright (C) 2007 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 17 package android.graphics.drawable.shapes; 18 19 import android.graphics.Canvas; 20 import android.graphics.Outline; 21 import android.graphics.Paint; 22 23 /** 24 * Creates an arc shape. The arc shape starts at a specified angle and sweeps 25 * clockwise, drawing slices of pie. 26 * <p> 27 * The arc can be drawn to a {@link Canvas} with its own 28 * {@link #draw(Canvas, Paint)} method, but more graphical control is available 29 * if you instead pass the ArcShape to a 30 * {@link android.graphics.drawable.ShapeDrawable}. 31 */ 32 public class ArcShape extends RectShape { 33 private final float mStartAngle; 34 private final float mSweepAngle; 35 36 /** 37 * ArcShape constructor. 38 * 39 * @param startAngle the angle (in degrees) where the arc begins 40 * @param sweepAngle the sweep angle (in degrees). Anything equal to or 41 * greater than 360 results in a complete circle/oval. 42 */ ArcShape(float startAngle, float sweepAngle)43 public ArcShape(float startAngle, float sweepAngle) { 44 mStartAngle = startAngle; 45 mSweepAngle = sweepAngle; 46 } 47 48 /** 49 * @return the angle (in degrees) where the arc begins 50 */ getStartAngle()51 public final float getStartAngle() { 52 return mStartAngle; 53 } 54 55 /** 56 * @return the sweep angle (in degrees) 57 */ getSweepAngle()58 public final float getSweepAngle() { 59 return mSweepAngle; 60 } 61 62 @Override draw(Canvas canvas, Paint paint)63 public void draw(Canvas canvas, Paint paint) { 64 canvas.drawArc(rect(), mStartAngle, mSweepAngle, true, paint); 65 } 66 67 @Override getOutline(Outline outline)68 public void getOutline(Outline outline) { 69 // Since we don't support concave outlines, arc shape does not attempt 70 // to provide an outline. 71 } 72 73 @Override clone()74 public ArcShape clone() throws CloneNotSupportedException { 75 return (ArcShape) super.clone(); 76 } 77 } 78 79