Add automatic Drawable mirroring capability when in RTL layout direction
- default value is "no mirroring" - introduce android:autoMirrored as a new attribute for Drawable, BitmapDrawable, LayerDrawable, StateListDrawable and NinePatchDrawable - setting android:autoMirrored="true" means that the drawable will be mirrored when the layout direction is RTL (right-to-left) - also fix an issue with ImageView drawable layout direction not updated correctly when RTL properties were changed See bug #7034321 Need Drawable RTL support Change-Id: If595ee5106c786f38e786d3a032e182f784a9d97
This commit is contained in:
@@ -172,6 +172,19 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
||||
return mDrawableContainerState.isStateful();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAutoMirrored(boolean mirrored) {
|
||||
mDrawableContainerState.mAutoMirrored = mirrored;
|
||||
if (mCurrDrawable != null) {
|
||||
mCurrDrawable.mutate().setAutoMirrored(mDrawableContainerState.mAutoMirrored);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAutoMirrored() {
|
||||
return mDrawableContainerState.mAutoMirrored;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jumpToCurrentState() {
|
||||
boolean changed = false;
|
||||
@@ -334,6 +347,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
||||
d.setLevel(getLevel());
|
||||
d.setBounds(getBounds());
|
||||
d.setLayoutDirection(getLayoutDirection());
|
||||
d.setAutoMirrored(mDrawableContainerState.mAutoMirrored);
|
||||
}
|
||||
} else {
|
||||
mCurrDrawable = null;
|
||||
@@ -471,6 +485,8 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
||||
int mEnterFadeDuration;
|
||||
int mExitFadeDuration;
|
||||
|
||||
boolean mAutoMirrored;
|
||||
|
||||
DrawableContainerState(DrawableContainerState orig, DrawableContainer owner,
|
||||
Resources res) {
|
||||
mOwner = owner;
|
||||
@@ -490,6 +506,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
|
||||
mLayoutDirection = orig.mLayoutDirection;
|
||||
mEnterFadeDuration = orig.mEnterFadeDuration;
|
||||
mExitFadeDuration = orig.mExitFadeDuration;
|
||||
mAutoMirrored = orig.mAutoMirrored;
|
||||
|
||||
// Cloning the following values may require creating futures.
|
||||
mConstantPadding = orig.getConstantPadding();
|
||||
|
||||
Reference in New Issue
Block a user