Merge "Modified ShapeState#newDrawable to pass a deep copy of ShapeState"

This commit is contained in:
TreeHugger Robot
2018-04-05 00:26:20 +00:00
committed by Android (Google) Code Review
6 changed files with 124 additions and 2 deletions

View File

@@ -594,12 +594,12 @@ public class ShapeDrawable extends Drawable {
@Override
public Drawable newDrawable() {
return new ShapeDrawable(this, null);
return new ShapeDrawable(new ShapeState(this), null);
}
@Override
public Drawable newDrawable(Resources res) {
return new ShapeDrawable(this, res);
return new ShapeDrawable(new ShapeState(this), res);
}
@Override

View File

@@ -20,6 +20,8 @@ import android.graphics.Canvas;
import android.graphics.Outline;
import android.graphics.Paint;
import java.util.Objects;
/**
* Creates an arc shape. The arc shape starts at a specified angle and sweeps
* clockwise, drawing slices of pie.
@@ -74,5 +76,26 @@ public class ArcShape extends RectShape {
public ArcShape clone() throws CloneNotSupportedException {
return (ArcShape) super.clone();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
ArcShape arcShape = (ArcShape) o;
return Float.compare(arcShape.mStartAngle, mStartAngle) == 0
&& Float.compare(arcShape.mSweepAngle, mSweepAngle) == 0;
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mStartAngle, mSweepAngle);
}
}

View File

@@ -21,6 +21,8 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import java.util.Objects;
/**
* Creates geometric paths, utilizing the {@link android.graphics.Path} class.
* <p>
@@ -74,5 +76,30 @@ public class PathShape extends Shape {
shape.mPath = new Path(mPath);
return shape;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
PathShape pathShape = (PathShape) o;
return Float.compare(pathShape.mStdWidth, mStdWidth) == 0
&& Float.compare(pathShape.mStdHeight, mStdHeight) == 0
&& Float.compare(pathShape.mScaleX, mScaleX) == 0
&& Float.compare(pathShape.mScaleY, mScaleY) == 0
// Path does not have equals implementation but incase it gains one, use it here
&& Objects.equals(mPath, pathShape.mPath);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mStdWidth, mStdHeight, mPath, mScaleX, mScaleY);
}
}

View File

@@ -21,6 +21,8 @@ import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.RectF;
import java.util.Objects;
/**
* Defines a rectangle shape.
* <p>
@@ -63,4 +65,24 @@ public class RectShape extends Shape {
shape.mRect = new RectF(mRect);
return shape;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
RectShape rectShape = (RectShape) o;
return Objects.equals(mRect, rectShape.mRect);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), mRect);
}
}

View File

@@ -23,6 +23,9 @@ import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import java.util.Arrays;
import java.util.Objects;
/**
* Creates a rounded-corner rectangle. Optionally, an inset (rounded) rectangle
* can be included (to make a sort of "O" shape).
@@ -137,4 +140,31 @@ public class RoundRectShape extends RectShape {
shape.mPath = new Path(mPath);
return shape;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}
RoundRectShape that = (RoundRectShape) o;
return Arrays.equals(mOuterRadii, that.mOuterRadii)
&& Objects.equals(mInset, that.mInset)
&& Arrays.equals(mInnerRadii, that.mInnerRadii)
&& Objects.equals(mInnerRect, that.mInnerRect)
&& Objects.equals(mPath, that.mPath);
}
@Override
public int hashCode() {
int result = Objects.hash(super.hashCode(), mInset, mInnerRect, mPath);
result = 31 * result + Arrays.hashCode(mOuterRadii);
result = 31 * result + Arrays.hashCode(mInnerRadii);
return result;
}
}

View File

@@ -21,6 +21,8 @@ import android.graphics.Canvas;
import android.graphics.Outline;
import android.graphics.Paint;
import java.util.Objects;
/**
* Defines a generic graphical "shape."
* <p>
@@ -115,4 +117,22 @@ public abstract class Shape implements Cloneable {
public Shape clone() throws CloneNotSupportedException {
return (Shape) super.clone();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Shape shape = (Shape) o;
return Float.compare(shape.mWidth, mWidth) == 0
&& Float.compare(shape.mHeight, mHeight) == 0;
}
@Override
public int hashCode() {
return Objects.hash(mWidth, mHeight);
}
}