Merge "Fixed issue where GradientDrawable orientation was not consumed properly" into qt-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9625faaf73
@@ -637,8 +637,7 @@ public class GradientDrawable extends Drawable {
|
|||||||
* @see #setOrientation(Orientation)
|
* @see #setOrientation(Orientation)
|
||||||
*/
|
*/
|
||||||
public Orientation getOrientation() {
|
public Orientation getOrientation() {
|
||||||
updateGradientStateOrientation();
|
return mGradientState.getOrientation();
|
||||||
return mGradientState.mOrientation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -654,10 +653,7 @@ public class GradientDrawable extends Drawable {
|
|||||||
* @see #getOrientation()
|
* @see #getOrientation()
|
||||||
*/
|
*/
|
||||||
public void setOrientation(Orientation orientation) {
|
public void setOrientation(Orientation orientation) {
|
||||||
// Update the angle here so that subsequent attempts to obtain the orientation
|
mGradientState.setOrientation(orientation);
|
||||||
// from the angle overwrite previously configured values during inflation
|
|
||||||
mGradientState.mAngle = getAngleFromOrientation(orientation);
|
|
||||||
mGradientState.mOrientation = orientation;
|
|
||||||
mGradientIsDirty = true;
|
mGradientIsDirty = true;
|
||||||
invalidateSelf();
|
invalidateSelf();
|
||||||
}
|
}
|
||||||
@@ -1245,76 +1241,6 @@ public class GradientDrawable extends Drawable {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the orientation of the gradient based on the given angle only if the type is
|
|
||||||
* {@link #LINEAR_GRADIENT}
|
|
||||||
*/
|
|
||||||
private void updateGradientStateOrientation() {
|
|
||||||
if (mGradientState.mGradient == LINEAR_GRADIENT) {
|
|
||||||
int angle = mGradientState.mAngle;
|
|
||||||
if (angle % 45 != 0) {
|
|
||||||
throw new IllegalArgumentException("Linear gradient requires 'angle' attribute to "
|
|
||||||
+ "be a multiple of 45");
|
|
||||||
}
|
|
||||||
|
|
||||||
Orientation orientation;
|
|
||||||
switch (angle) {
|
|
||||||
case 0:
|
|
||||||
orientation = Orientation.LEFT_RIGHT;
|
|
||||||
break;
|
|
||||||
case 45:
|
|
||||||
orientation = Orientation.BL_TR;
|
|
||||||
break;
|
|
||||||
case 90:
|
|
||||||
orientation = Orientation.BOTTOM_TOP;
|
|
||||||
break;
|
|
||||||
case 135:
|
|
||||||
orientation = Orientation.BR_TL;
|
|
||||||
break;
|
|
||||||
case 180:
|
|
||||||
orientation = Orientation.RIGHT_LEFT;
|
|
||||||
break;
|
|
||||||
case 225:
|
|
||||||
orientation = Orientation.TR_BL;
|
|
||||||
break;
|
|
||||||
case 270:
|
|
||||||
orientation = Orientation.TOP_BOTTOM;
|
|
||||||
break;
|
|
||||||
case 315:
|
|
||||||
orientation = Orientation.TL_BR;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
// Should not get here as exception is thrown above if angle is not multiple
|
|
||||||
// of 45 degrees
|
|
||||||
orientation = Orientation.LEFT_RIGHT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
mGradientState.mOrientation = orientation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getAngleFromOrientation(Orientation orientation) {
|
|
||||||
switch (orientation) {
|
|
||||||
default:
|
|
||||||
case LEFT_RIGHT:
|
|
||||||
return 0;
|
|
||||||
case BL_TR:
|
|
||||||
return 45;
|
|
||||||
case BOTTOM_TOP:
|
|
||||||
return 90;
|
|
||||||
case BR_TL:
|
|
||||||
return 135;
|
|
||||||
case RIGHT_LEFT:
|
|
||||||
return 180;
|
|
||||||
case TR_BL:
|
|
||||||
return 225;
|
|
||||||
case TOP_BOTTOM:
|
|
||||||
return 270;
|
|
||||||
case TL_BR:
|
|
||||||
return 315;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This checks mGradientIsDirty, and if it is true, recomputes both our drawing
|
* This checks mGradientIsDirty, and if it is true, recomputes both our drawing
|
||||||
* rectangle (mRect) and the gradient itself, since it depends on our
|
* rectangle (mRect) and the gradient itself, since it depends on our
|
||||||
@@ -1344,8 +1270,7 @@ public class GradientDrawable extends Drawable {
|
|||||||
|
|
||||||
if (st.mGradient == LINEAR_GRADIENT) {
|
if (st.mGradient == LINEAR_GRADIENT) {
|
||||||
final float level = st.mUseLevel ? getLevel() / 10000.0f : 1.0f;
|
final float level = st.mUseLevel ? getLevel() / 10000.0f : 1.0f;
|
||||||
updateGradientStateOrientation();
|
switch (st.getOrientation()) {
|
||||||
switch (st.mOrientation) {
|
|
||||||
case TOP_BOTTOM:
|
case TOP_BOTTOM:
|
||||||
x0 = r.left; y0 = r.top;
|
x0 = r.left; y0 = r.top;
|
||||||
x1 = x0; y1 = level * r.bottom;
|
x1 = x0; y1 = level * r.bottom;
|
||||||
@@ -2056,7 +1981,7 @@ public class GradientDrawable extends Drawable {
|
|||||||
int[] mAttrPadding;
|
int[] mAttrPadding;
|
||||||
|
|
||||||
public GradientState(Orientation orientation, int[] gradientColors) {
|
public GradientState(Orientation orientation, int[] gradientColors) {
|
||||||
mOrientation = orientation;
|
setOrientation(orientation);
|
||||||
setGradientColors(gradientColors);
|
setGradientColors(gradientColors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2259,6 +2184,93 @@ public class GradientDrawable extends Drawable {
|
|||||||
mCenterY = y;
|
mCenterY = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOrientation(Orientation orientation) {
|
||||||
|
// Update the angle here so that subsequent attempts to obtain the orientation
|
||||||
|
// from the angle overwrite previously configured values during inflation
|
||||||
|
mAngle = getAngleFromOrientation(orientation);
|
||||||
|
mOrientation = orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public Orientation getOrientation() {
|
||||||
|
updateGradientStateOrientation();
|
||||||
|
return mOrientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the orientation of the gradient based on the given angle only if the type is
|
||||||
|
* {@link #LINEAR_GRADIENT}
|
||||||
|
*/
|
||||||
|
private void updateGradientStateOrientation() {
|
||||||
|
if (mGradient == LINEAR_GRADIENT) {
|
||||||
|
int angle = mAngle;
|
||||||
|
if (angle % 45 != 0) {
|
||||||
|
throw new IllegalArgumentException("Linear gradient requires 'angle' attribute "
|
||||||
|
+ "to be a multiple of 45");
|
||||||
|
}
|
||||||
|
|
||||||
|
Orientation orientation;
|
||||||
|
switch (angle) {
|
||||||
|
case 0:
|
||||||
|
orientation = Orientation.LEFT_RIGHT;
|
||||||
|
break;
|
||||||
|
case 45:
|
||||||
|
orientation = Orientation.BL_TR;
|
||||||
|
break;
|
||||||
|
case 90:
|
||||||
|
orientation = Orientation.BOTTOM_TOP;
|
||||||
|
break;
|
||||||
|
case 135:
|
||||||
|
orientation = Orientation.BR_TL;
|
||||||
|
break;
|
||||||
|
case 180:
|
||||||
|
orientation = Orientation.RIGHT_LEFT;
|
||||||
|
break;
|
||||||
|
case 225:
|
||||||
|
orientation = Orientation.TR_BL;
|
||||||
|
break;
|
||||||
|
case 270:
|
||||||
|
orientation = Orientation.TOP_BOTTOM;
|
||||||
|
break;
|
||||||
|
case 315:
|
||||||
|
orientation = Orientation.TL_BR;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Should not get here as exception is thrown above if angle is not multiple
|
||||||
|
// of 45 degrees
|
||||||
|
orientation = Orientation.LEFT_RIGHT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mOrientation = orientation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getAngleFromOrientation(@Nullable Orientation orientation) {
|
||||||
|
if (orientation != null) {
|
||||||
|
switch (orientation) {
|
||||||
|
default:
|
||||||
|
case LEFT_RIGHT:
|
||||||
|
return 0;
|
||||||
|
case BL_TR:
|
||||||
|
return 45;
|
||||||
|
case BOTTOM_TOP:
|
||||||
|
return 90;
|
||||||
|
case BR_TL:
|
||||||
|
return 135;
|
||||||
|
case RIGHT_LEFT:
|
||||||
|
return 180;
|
||||||
|
case TR_BL:
|
||||||
|
return 225;
|
||||||
|
case TOP_BOTTOM:
|
||||||
|
return 270;
|
||||||
|
case TL_BR:
|
||||||
|
return 315;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setGradientColors(@Nullable int[] colors) {
|
public void setGradientColors(@Nullable int[] colors) {
|
||||||
mGradientColors = colors;
|
mGradientColors = colors;
|
||||||
mSolidColors = null;
|
mSolidColors = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user