Merge "Fix animations, padding in RTL mode." into klp-dev

This commit is contained in:
Jeff Sharkey
2013-10-02 01:43:12 +00:00
committed by Android (Google) Code Review
15 changed files with 116 additions and 8 deletions

View File

@@ -202,7 +202,13 @@ public class InsetDrawable extends Drawable implements Drawable.Callback
public void setColorFilter(ColorFilter cf) {
mInsetState.mDrawable.setColorFilter(cf);
}
/** {@hide} */
@Override
public void setLayoutDirection(int layoutDirection) {
mInsetState.mDrawable.setLayoutDirection(layoutDirection);
}
@Override
public int getOpacity() {
return mInsetState.mDrawable.getOpacity();

View File

@@ -219,16 +219,15 @@ public class NinePatchDrawable extends Drawable {
@Override
public void draw(Canvas canvas) {
final Rect bounds = getBounds();
final boolean needMirroring = isAutoMirrored() &&
getLayoutDirection() == LayoutDirection.RTL;
if (needMirroring) {
final boolean needsMirroring = needsMirroring();
if (needsMirroring) {
canvas.save();
// Mirror the 9patch
canvas.translate(bounds.right - bounds.left, 0);
canvas.scale(-1.0f, 1.0f);
}
mNinePatch.draw(canvas, bounds, mPaint);
if (needMirroring) {
if (needsMirroring) {
canvas.restore();
}
}
@@ -240,7 +239,11 @@ public class NinePatchDrawable extends Drawable {
@Override
public boolean getPadding(Rect padding) {
padding.set(mPadding);
if (needsMirroring()) {
padding.set(mPadding.right, mPadding.top, mPadding.left, mPadding.bottom);
} else {
padding.set(mPadding);
}
return true;
}
@@ -249,7 +252,12 @@ public class NinePatchDrawable extends Drawable {
*/
@Override
public Insets getOpticalInsets() {
return mOpticalInsets;
if (needsMirroring()) {
return Insets.of(mOpticalInsets.right, mOpticalInsets.top, mOpticalInsets.right,
mOpticalInsets.bottom);
} else {
return mOpticalInsets;
}
}
@Override
@@ -297,6 +305,10 @@ public class NinePatchDrawable extends Drawable {
mNinePatchState.mAutoMirrored = mirrored;
}
private boolean needsMirroring() {
return isAutoMirrored() && getLayoutDirection() == LayoutDirection.RTL;
}
@Override
public boolean isAutoMirrored() {
return mNinePatchState.mAutoMirrored;

View File

@@ -0,0 +1,22 @@
<!-- Copyright (C) 2013 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:valueFrom="-1"
android:valueTo="0"
android:propertyName="position"
android:valueType="floatType"
android:duration="@android:integer/config_mediumAnimTime"
android:interpolator="@android:interpolator/decelerate_quad" />

View File

@@ -0,0 +1,22 @@
<!-- Copyright (C) 2013 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:valueFrom="0"
android:valueTo="-1"
android:propertyName="position"
android:valueType="floatType"
android:duration="@android:integer/config_mediumAnimTime"
android:interpolator="@android:interpolator/accelerate_quad" />

View File

Before

Width:  |  Height:  |  Size: 184 B

After

Width:  |  Height:  |  Size: 184 B

View File

Before

Width:  |  Height:  |  Size: 163 B

After

Width:  |  Height:  |  Size: 163 B

View File

Before

Width:  |  Height:  |  Size: 193 B

After

Width:  |  Height:  |  Size: 193 B

View File

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 233 B

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
* Copyright 2013, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_dir_shadow_am"
android:autoMirrored="true">
</nine-patch>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
* Copyright 2013, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<nine-patch xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/ic_drawer_shadow_tablet_am"
android:autoMirrored="true">
</nine-patch>

View File

@@ -40,7 +40,7 @@ public class DirectoryView extends FrameLayout {
public void setBackground(Drawable background) {
final Rect rect = new Rect();
background.getPadding(rect);
final InsetDrawable inset = new InsetDrawable(background, -rect.left, 0, 0, 0);
final InsetDrawable inset = new InsetDrawable(background, -rect.left, 0, -rect.right, 0);
super.setBackground(inset);
}