summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wei <markwei@google.com>2015-04-14 10:53:05 -0700
committerMark Wei <markwei@google.com>2015-04-14 10:53:05 -0700
commit856e2a9d72fe3a79cd7bfa5cf443d13a60495c4b (patch)
tree61236f21478868f7cfc67bf03573a7b3d38d68e1
parent5b1cf894eed356a0c0a729e7b2175473dfea5fed (diff)
downloadbitmap-856e2a9d72fe3a79cd7bfa5cf443d13a60495c4b.tar.gz
Update bitmap drawables with RTL support.android-wear-n-preview-3android-wear-n-preview-2android-wear-n-preview-1android-wear-7.1.1_r1android-n-preview-5android-n-preview-4android-n-preview-3android-n-preview-2android-n-preview-1android-n-iot-preview-2android-cts-6.0_r9android-cts-6.0_r8android-cts-6.0_r7android-cts-6.0_r6android-cts-6.0_r5android-cts-6.0_r4android-cts-6.0_r32android-cts-6.0_r31android-cts-6.0_r30android-cts-6.0_r3android-cts-6.0_r29android-cts-6.0_r28android-cts-6.0_r27android-cts-6.0_r26android-cts-6.0_r25android-cts-6.0_r24android-cts-6.0_r23android-cts-6.0_r22android-cts-6.0_r21android-cts-6.0_r20android-cts-6.0_r2android-cts-6.0_r19android-cts-6.0_r18android-cts-6.0_r17android-cts-6.0_r16android-cts-6.0_r15android-cts-6.0_r14android-cts-6.0_r13android-cts-6.0_r12android-cts-6.0_r1android-6.0.1_r9android-6.0.1_r81android-6.0.1_r80android-6.0.1_r8android-6.0.1_r79android-6.0.1_r78android-6.0.1_r77android-6.0.1_r74android-6.0.1_r73android-6.0.1_r72android-6.0.1_r70android-6.0.1_r7android-6.0.1_r69android-6.0.1_r68android-6.0.1_r67android-6.0.1_r66android-6.0.1_r65android-6.0.1_r63android-6.0.1_r62android-6.0.1_r61android-6.0.1_r60android-6.0.1_r59android-6.0.1_r58android-6.0.1_r57android-6.0.1_r56android-6.0.1_r55android-6.0.1_r54android-6.0.1_r53android-6.0.1_r52android-6.0.1_r51android-6.0.1_r50android-6.0.1_r5android-6.0.1_r49android-6.0.1_r48android-6.0.1_r47android-6.0.1_r46android-6.0.1_r45android-6.0.1_r43android-6.0.1_r42android-6.0.1_r41android-6.0.1_r40android-6.0.1_r4android-6.0.1_r33android-6.0.1_r32android-6.0.1_r31android-6.0.1_r30android-6.0.1_r3android-6.0.1_r28android-6.0.1_r27android-6.0.1_r26android-6.0.1_r25android-6.0.1_r24android-6.0.1_r22android-6.0.1_r21android-6.0.1_r20android-6.0.1_r18android-6.0.1_r17android-6.0.1_r16android-6.0.1_r13android-6.0.1_r12android-6.0.1_r11android-6.0.1_r10android-6.0.1_r1android-6.0.0_r7android-6.0.0_r6android-6.0.0_r5android-6.0.0_r41android-6.0.0_r4android-6.0.0_r3android-6.0.0_r26android-6.0.0_r25android-6.0.0_r24android-6.0.0_r23android-6.0.0_r2android-6.0.0_r13android-6.0.0_r12android-6.0.0_r11android-6.0.0_r1nougat-mr1-wear-releasen-iot-preview-2marshmallow-releasemarshmallow-mr3-releasemarshmallow-mr2-releasemarshmallow-mr1-releasemarshmallow-mr1-devmarshmallow-dr1.6-releasemarshmallow-dr1.5-releasemarshmallow-dr1.5-devmarshmallow-dr-releasemarshmallow-dr-dragon-releasemarshmallow-dr-devmarshmallow-devmarshmallow-cts-release
Change-Id: Iafcbb41208b2e7e3396f2b86bee994cbaf57009f
-rw-r--r--src/com/android/bitmap/drawable/BasicBitmapDrawable.java36
-rw-r--r--src/com/android/bitmap/drawable/StyledCornersBitmapDrawable.java58
-rw-r--r--src/com/android/bitmap/view/BitmapDrawableImageView.java8
3 files changed, 88 insertions, 14 deletions
diff --git a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java
index 67884df..ca429ee 100644
--- a/src/com/android/bitmap/drawable/BasicBitmapDrawable.java
+++ b/src/com/android/bitmap/drawable/BasicBitmapDrawable.java
@@ -73,6 +73,8 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback,
private DecodeTask mTask;
private Cancelable mCreateFileDescriptorFactoryTask;
+ private int mLayoutDirection;
+
// based on framework CL:I015d77
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
private static final int CORE_POOL_SIZE = CPU_COUNT + 1;
@@ -128,6 +130,40 @@ public class BasicBitmapDrawable extends Drawable implements DecodeCallback,
}
/**
+ * Set layout direction.
+ * It ends with Local so as not conflict with hidden Drawable.setLayoutDirection.
+ * @param layoutDirection the resolved layout direction for the drawable,
+ * either {@link android.view.View#LAYOUT_DIRECTION_LTR}
+ * or {@link android.view.View#LAYOUT_DIRECTION_RTL}
+ */
+ public void setLayoutDirectionLocal(int layoutDirection) {
+ if (mLayoutDirection != layoutDirection) {
+ mLayoutDirection = layoutDirection;
+ onLayoutDirectionChangeLocal(layoutDirection);
+ }
+ }
+
+ /**
+ * Called when the drawable's resolved layout direction changes.
+ * It ends with Local so as not conflict with hidden Drawable.onLayoutDirectionChange.
+ *
+ * @param layoutDirection the new resolved layout direction
+ */
+ public void onLayoutDirectionChangeLocal(int layoutDirection) {}
+
+ /**
+ * Returns the resolved layout direction for this Drawable.
+ * It ends with Local so as not conflict with hidden Drawable.getLayoutDirection.
+ *
+ * @return One of {@link android.view.View#LAYOUT_DIRECTION_LTR},
+ * {@link android.view.View#LAYOUT_DIRECTION_RTL}
+ * @see #setLayoutDirectionLocal(int)
+ */
+ public int getLayoutDirectionLocal() {
+ return mLayoutDirection;
+ }
+
+ /**
* Binds to the given key and start the decode process. This will first look in the cache, then
* decode from the request key if not found.
*
diff --git a/src/com/android/bitmap/drawable/StyledCornersBitmapDrawable.java b/src/com/android/bitmap/drawable/StyledCornersBitmapDrawable.java
index 953bfd0..5582344 100644
--- a/src/com/android/bitmap/drawable/StyledCornersBitmapDrawable.java
+++ b/src/com/android/bitmap/drawable/StyledCornersBitmapDrawable.java
@@ -25,6 +25,7 @@ import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.Log;
+import android.view.View;
import com.android.bitmap.BitmapCache;
@@ -65,6 +66,12 @@ public class StyledCornersBitmapDrawable extends ExtendedBitmapDrawable {
private int mTopRightCornerStyle = CORNER_STYLE_SHARP;
private int mBottomRightCornerStyle = CORNER_STYLE_SHARP;
private int mBottomLeftCornerStyle = CORNER_STYLE_SHARP;
+
+ private int mTopStartCornerStyle = CORNER_STYLE_SHARP;
+ private int mTopEndCornerStyle = CORNER_STYLE_SHARP;
+ private int mBottomEndCornerStyle = CORNER_STYLE_SHARP;
+ private int mBottomStartCornerStyle = CORNER_STYLE_SHARP;
+
private int mScrimColor;
private float mBorderWidth;
private boolean mIsCompatibilityMode;
@@ -122,21 +129,18 @@ public class StyledCornersBitmapDrawable extends ExtendedBitmapDrawable {
}
}
- /** Set the corner styles for all four corners */
- public void setCornerStyles(int topLeft, int topRight, int bottomRight, int bottomLeft) {
- boolean changed = mTopLeftCornerStyle != topLeft
- || mTopRightCornerStyle != topRight
- || mBottomRightCornerStyle != bottomRight
- || mBottomLeftCornerStyle != bottomLeft;
-
- mTopLeftCornerStyle = topLeft;
- mTopRightCornerStyle = topRight;
- mBottomRightCornerStyle = bottomRight;
- mBottomLeftCornerStyle = bottomLeft;
+ /** Set the corner styles for all four corners specified in RTL friendly ways */
+ public void setCornerStylesRelative(int topStart, int topEnd, int bottomEnd, int bottomStart) {
+ mTopStartCornerStyle = topStart;
+ mTopEndCornerStyle = topEnd;
+ mBottomEndCornerStyle = bottomEnd;
+ mBottomStartCornerStyle = bottomStart;
+ resolveCornerStyles();
+ }
- if (changed) {
- recalculatePath();
- }
+ @Override
+ public void onLayoutDirectionChangeLocal(int layoutDirection) {
+ resolveCornerStyles();
}
/**
@@ -462,4 +466,30 @@ public class StyledCornersBitmapDrawable extends ExtendedBitmapDrawable {
// Finish.
mClipPath.close();
}
+
+ private void resolveCornerStyles() {
+ boolean isLtr = getLayoutDirectionLocal() == View.LAYOUT_DIRECTION_LTR;
+ setCornerStyles(
+ isLtr ? mTopStartCornerStyle : mTopEndCornerStyle,
+ isLtr ? mTopEndCornerStyle : mTopStartCornerStyle,
+ isLtr ? mBottomEndCornerStyle : mBottomStartCornerStyle,
+ isLtr ? mBottomStartCornerStyle : mBottomEndCornerStyle);
+ }
+
+ /** Set the corner styles for all four corners */
+ private void setCornerStyles(int topLeft, int topRight, int bottomRight, int bottomLeft) {
+ boolean changed = mTopLeftCornerStyle != topLeft
+ || mTopRightCornerStyle != topRight
+ || mBottomRightCornerStyle != bottomRight
+ || mBottomLeftCornerStyle != bottomLeft;
+
+ mTopLeftCornerStyle = topLeft;
+ mTopRightCornerStyle = topRight;
+ mBottomRightCornerStyle = bottomRight;
+ mBottomLeftCornerStyle = bottomLeft;
+
+ if (changed) {
+ recalculatePath();
+ }
+ }
}
diff --git a/src/com/android/bitmap/view/BitmapDrawableImageView.java b/src/com/android/bitmap/view/BitmapDrawableImageView.java
index 5cbc58d..12e5b0e 100644
--- a/src/com/android/bitmap/view/BitmapDrawableImageView.java
+++ b/src/com/android/bitmap/view/BitmapDrawableImageView.java
@@ -157,4 +157,12 @@ public class BitmapDrawableImageView extends ImageView {
unbindDrawable(TEMPORARY);
}
}
+
+ @Override
+ public void onRtlPropertiesChanged(int layoutDirection) {
+ super.onRtlPropertiesChanged(layoutDirection);
+ if (mDrawable != null) {
+ mDrawable.setLayoutDirectionLocal(layoutDirection);
+ }
+ }
}