• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import java.util.Objects;
24 
25 /**
26  * Creates an arc shape. The arc shape starts at a specified angle and sweeps
27  * clockwise, drawing slices of pie.
28  * <p>
29  * The arc can be drawn to a {@link Canvas} with its own
30  * {@link #draw(Canvas, Paint)} method, but more graphical control is available
31  * if you instead pass the ArcShape to a
32  * {@link android.graphics.drawable.ShapeDrawable}.
33  */
34 public class ArcShape extends RectShape {
35     private final float mStartAngle;
36     private final float mSweepAngle;
37 
38     /**
39      * ArcShape constructor.
40      *
41      * @param startAngle the angle (in degrees) where the arc begins
42      * @param sweepAngle the sweep angle (in degrees). Anything equal to or
43      *                   greater than 360 results in a complete circle/oval.
44      */
ArcShape(float startAngle, float sweepAngle)45     public ArcShape(float startAngle, float sweepAngle) {
46         mStartAngle = startAngle;
47         mSweepAngle = sweepAngle;
48     }
49 
50     /**
51      * @return the angle (in degrees) where the arc begins
52      */
getStartAngle()53     public final float getStartAngle() {
54         return mStartAngle;
55     }
56 
57     /**
58      * @return the sweep angle (in degrees)
59      */
getSweepAngle()60     public final float getSweepAngle() {
61         return mSweepAngle;
62     }
63 
64     @Override
draw(Canvas canvas, Paint paint)65     public void draw(Canvas canvas, Paint paint) {
66         canvas.drawArc(rect(), mStartAngle, mSweepAngle, true, paint);
67     }
68 
69     @Override
getOutline(Outline outline)70     public void getOutline(Outline outline) {
71         // Since we don't support concave outlines, arc shape does not attempt
72         // to provide an outline.
73     }
74 
75     @Override
clone()76     public ArcShape clone() throws CloneNotSupportedException {
77         return (ArcShape) super.clone();
78     }
79 
80     @Override
equals(Object o)81     public boolean equals(Object o) {
82         if (this == o) {
83             return true;
84         }
85         if (o == null || getClass() != o.getClass()) {
86             return false;
87         }
88         if (!super.equals(o)) {
89             return false;
90         }
91         ArcShape arcShape = (ArcShape) o;
92         return Float.compare(arcShape.mStartAngle, mStartAngle) == 0
93             && Float.compare(arcShape.mSweepAngle, mSweepAngle) == 0;
94     }
95 
96     @Override
hashCode()97     public int hashCode() {
98         return Objects.hash(super.hashCode(), mStartAngle, mSweepAngle);
99     }
100 }
101 
102