xref: /aosp_15_r20/external/robolectric/shadows/framework/src/main/java/org/robolectric/shadows/ShadowPath.java (revision e6ba16074e6af37d123cb567d575f496bf0a58ee)
1 package org.robolectric.shadows;
2 
3 import android.graphics.Path;
4 import android.graphics.RectF;
5 import java.util.List;
6 import org.robolectric.annotation.Implements;
7 import org.robolectric.shadows.ShadowPath.Picker;
8 
9 /** Base class for {@link ShadowPath} classes. */
10 @SuppressWarnings({"UnusedDeclaration"})
11 @Implements(value = Path.class, shadowPicker = Picker.class)
12 public abstract class ShadowPath {
13 
14   /**
15    * @return all the points that have been added to the {@code Path}
16    */
getPoints()17   public abstract List<Point> getPoints();
18 
19   /**
20    * Fills the given {@link RectF} with the path bounds.
21    *
22    * @param bounds the RectF to be filled.
23    */
fillBounds(RectF bounds)24   public abstract void fillBounds(RectF bounds);
25 
26   public static class Point {
27     private final float x;
28     private final float y;
29     private final Type type;
30 
31     public enum Type {
32       MOVE_TO,
33       LINE_TO
34     }
35 
Point(float x, float y, Type type)36     public Point(float x, float y, Type type) {
37       this.x = x;
38       this.y = y;
39       this.type = type;
40     }
41 
42     @Override
equals(Object o)43     public boolean equals(Object o) {
44       if (this == o) return true;
45       if (!(o instanceof Point)) return false;
46 
47       Point point = (Point) o;
48 
49       if (Float.compare(point.x, x) != 0) return false;
50       if (Float.compare(point.y, y) != 0) return false;
51       if (type != point.type) return false;
52 
53       return true;
54     }
55 
56     @Override
hashCode()57     public int hashCode() {
58       int result = (x != +0.0f ? Float.floatToIntBits(x) : 0);
59       result = 31 * result + (y != +0.0f ? Float.floatToIntBits(y) : 0);
60       result = 31 * result + (type != null ? type.hashCode() : 0);
61       return result;
62     }
63 
64     @Override
toString()65     public String toString() {
66       return "Point(" + x + "," + y + "," + type + ")";
67     }
68 
getX()69     public float getX() {
70       return x;
71     }
72 
getY()73     public float getY() {
74       return y;
75     }
76 
getType()77     public Type getType() {
78       return type;
79     }
80   }
81 
82   /** Shadow picker for {@link Path}. */
83   public static final class Picker extends GraphicsShadowPicker<Object> {
Picker()84     public Picker() {
85       super(ShadowLegacyPath.class, ShadowNativePath.class);
86     }
87   }
88 }
89