Loading core/java/android/widget/Editor.java +1 −1 Original line number Diff line number Diff line Loading @@ -316,7 +316,7 @@ public class Editor { private void setErrorIcon(Drawable icon) { Drawables dr = mTextView.mDrawables; if (dr == null) { mTextView.mDrawables = dr = new Drawables(); mTextView.mDrawables = dr = new Drawables(mTextView.getContext()); } dr.setErrorDrawable(icon, mTextView); Loading core/java/android/widget/TextView.java +77 −34 Original line number Diff line number Diff line Loading @@ -136,6 +136,8 @@ import java.util.ArrayList; import java.util.Locale; import java.util.concurrent.locks.ReentrantLock; import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; /** * Displays text to the user and optionally allows them to edit it. A TextView * is a complete text editor, however the basic class is configured to not Loading Loading @@ -294,6 +296,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener Drawable mDrawableTop, mDrawableBottom, mDrawableLeft, mDrawableRight, mDrawableStart, mDrawableEnd, mDrawableError, mDrawableTemp; Drawable mDrawableLeftInitial, mDrawableRightInitial; boolean mIsRtlCompatibilityMode; boolean mOverride; int mDrawableSizeTop, mDrawableSizeBottom, mDrawableSizeLeft, mDrawableSizeRight, mDrawableSizeStart, mDrawableSizeEnd, mDrawableSizeError, mDrawableSizeTemp; Loading @@ -304,18 +310,44 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener int mDrawableSaved = DRAWABLE_NONE; public Drawables(Context context) { final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion; mIsRtlCompatibilityMode = (targetSdkVersion < JELLY_BEAN_MR1 || !context.getApplicationInfo().hasRtlSupport()); mOverride = false; } public void resolveWithLayoutDirection(int layoutDirection) { // First reset "left" and "right" drawables to their initial values mDrawableLeft = mDrawableLeftInitial; mDrawableRight = mDrawableRightInitial; if (mIsRtlCompatibilityMode) { // Use "start" drawable as "left" drawable if the "left" drawable was not defined if (mDrawableStart != null && mDrawableLeft == null) { mDrawableLeft = mDrawableStart; mDrawableSizeLeft = mDrawableSizeStart; mDrawableHeightLeft = mDrawableHeightStart; } // Use "end" drawable as "right" drawable if the "right" drawable was not defined if (mDrawableEnd != null && mDrawableRight == null) { mDrawableRight = mDrawableEnd; mDrawableSizeRight = mDrawableSizeEnd; mDrawableHeightRight = mDrawableHeightEnd; } } else { // JB-MR1+ normal case: "start" / "end" drawables are overriding "left" / "right" // drawable if and only if they have been defined switch(layoutDirection) { case LAYOUT_DIRECTION_RTL: if (mDrawableStart != null) { if (mOverride) { mDrawableRight = mDrawableStart; mDrawableSizeRight = mDrawableSizeStart; mDrawableHeightRight = mDrawableHeightStart; } if (mDrawableEnd != null) { mDrawableLeft = mDrawableEnd; if (mOverride) { mDrawableLeft = mDrawableEnd; mDrawableSizeLeft = mDrawableSizeEnd; mDrawableHeightLeft = mDrawableHeightEnd; } Loading @@ -323,20 +355,20 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener case LAYOUT_DIRECTION_LTR: default: if (mDrawableStart != null) { if (mOverride) { mDrawableLeft = mDrawableStart; mDrawableSizeLeft = mDrawableSizeStart; mDrawableHeightLeft = mDrawableHeightStart; } if (mDrawableEnd != null) { mDrawableRight = mDrawableEnd; if (mOverride) { mDrawableRight = mDrawableEnd; mDrawableSizeRight = mDrawableSizeEnd; mDrawableHeightRight = mDrawableHeightEnd; } break; } } applyErrorDrawableIfNeeded(layoutDirection); updateDrawablesLayoutDirection(layoutDirection); } Loading Loading @@ -1154,6 +1186,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener bufferType = BufferType.SPANNABLE; } // This call will save the initial left/right drawables setCompoundDrawablesWithIntrinsicBounds( drawableLeft, drawableTop, drawableRight, drawableBottom); setRelativeDrawablesIfNeeded(drawableStart, drawableEnd); Loading Loading @@ -1302,8 +1335,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (hasRelativeDrawables) { Drawables dr = mDrawables; if (dr == null) { mDrawables = dr = new Drawables(); mDrawables = dr = new Drawables(getContext()); } mDrawables.mOverride = true; final Rect compoundRect = dr.mCompoundRect; int[] state = getDrawableState(); if (start != null) { Loading Loading @@ -1876,9 +1910,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } else { if (dr == null) { mDrawables = dr = new Drawables(); mDrawables = dr = new Drawables(getContext()); } mDrawables.mOverride = false; if (dr.mDrawableLeft != left && dr.mDrawableLeft != null) { dr.mDrawableLeft.setCallback(null); } Loading Loading @@ -1945,6 +1981,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } // Save initial left/right drawables if (dr != null) { dr.mDrawableLeftInitial = left; dr.mDrawableRightInitial = right; } invalidate(); requestLayout(); } Loading Loading @@ -2045,9 +2087,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } else { if (dr == null) { mDrawables = dr = new Drawables(); mDrawables = dr = new Drawables(getContext()); } mDrawables.mOverride = true; if (dr.mDrawableStart != start && dr.mDrawableStart != null) { dr.mDrawableStart.setCallback(null); } Loading Loading @@ -2114,6 +2158,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } resetResolvedDrawables(); resolveDrawables(); invalidate(); requestLayout(); Loading @@ -2138,7 +2183,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @android.view.RemotableViewMethod public void setCompoundDrawablesRelativeWithIntrinsicBounds(int start, int top, int end, int bottom) { resetResolvedDrawables(); final Resources resources = getContext().getResources(); setCompoundDrawablesRelativeWithIntrinsicBounds( start != 0 ? resources.getDrawable(start) : null, Loading @@ -2161,7 +2205,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener public void setCompoundDrawablesRelativeWithIntrinsicBounds(Drawable start, Drawable top, Drawable end, Drawable bottom) { resetResolvedDrawables(); if (start != null) { start.setBounds(0, 0, start.getIntrinsicWidth(), start.getIntrinsicHeight()); } Loading Loading @@ -2230,7 +2273,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } else { if (dr == null) { mDrawables = dr = new Drawables(); mDrawables = dr = new Drawables(getContext()); } dr.mDrawablePadding = pad; } Loading Loading
core/java/android/widget/Editor.java +1 −1 Original line number Diff line number Diff line Loading @@ -316,7 +316,7 @@ public class Editor { private void setErrorIcon(Drawable icon) { Drawables dr = mTextView.mDrawables; if (dr == null) { mTextView.mDrawables = dr = new Drawables(); mTextView.mDrawables = dr = new Drawables(mTextView.getContext()); } dr.setErrorDrawable(icon, mTextView); Loading
core/java/android/widget/TextView.java +77 −34 Original line number Diff line number Diff line Loading @@ -136,6 +136,8 @@ import java.util.ArrayList; import java.util.Locale; import java.util.concurrent.locks.ReentrantLock; import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1; /** * Displays text to the user and optionally allows them to edit it. A TextView * is a complete text editor, however the basic class is configured to not Loading Loading @@ -294,6 +296,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener Drawable mDrawableTop, mDrawableBottom, mDrawableLeft, mDrawableRight, mDrawableStart, mDrawableEnd, mDrawableError, mDrawableTemp; Drawable mDrawableLeftInitial, mDrawableRightInitial; boolean mIsRtlCompatibilityMode; boolean mOverride; int mDrawableSizeTop, mDrawableSizeBottom, mDrawableSizeLeft, mDrawableSizeRight, mDrawableSizeStart, mDrawableSizeEnd, mDrawableSizeError, mDrawableSizeTemp; Loading @@ -304,18 +310,44 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener int mDrawableSaved = DRAWABLE_NONE; public Drawables(Context context) { final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion; mIsRtlCompatibilityMode = (targetSdkVersion < JELLY_BEAN_MR1 || !context.getApplicationInfo().hasRtlSupport()); mOverride = false; } public void resolveWithLayoutDirection(int layoutDirection) { // First reset "left" and "right" drawables to their initial values mDrawableLeft = mDrawableLeftInitial; mDrawableRight = mDrawableRightInitial; if (mIsRtlCompatibilityMode) { // Use "start" drawable as "left" drawable if the "left" drawable was not defined if (mDrawableStart != null && mDrawableLeft == null) { mDrawableLeft = mDrawableStart; mDrawableSizeLeft = mDrawableSizeStart; mDrawableHeightLeft = mDrawableHeightStart; } // Use "end" drawable as "right" drawable if the "right" drawable was not defined if (mDrawableEnd != null && mDrawableRight == null) { mDrawableRight = mDrawableEnd; mDrawableSizeRight = mDrawableSizeEnd; mDrawableHeightRight = mDrawableHeightEnd; } } else { // JB-MR1+ normal case: "start" / "end" drawables are overriding "left" / "right" // drawable if and only if they have been defined switch(layoutDirection) { case LAYOUT_DIRECTION_RTL: if (mDrawableStart != null) { if (mOverride) { mDrawableRight = mDrawableStart; mDrawableSizeRight = mDrawableSizeStart; mDrawableHeightRight = mDrawableHeightStart; } if (mDrawableEnd != null) { mDrawableLeft = mDrawableEnd; if (mOverride) { mDrawableLeft = mDrawableEnd; mDrawableSizeLeft = mDrawableSizeEnd; mDrawableHeightLeft = mDrawableHeightEnd; } Loading @@ -323,20 +355,20 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener case LAYOUT_DIRECTION_LTR: default: if (mDrawableStart != null) { if (mOverride) { mDrawableLeft = mDrawableStart; mDrawableSizeLeft = mDrawableSizeStart; mDrawableHeightLeft = mDrawableHeightStart; } if (mDrawableEnd != null) { mDrawableRight = mDrawableEnd; if (mOverride) { mDrawableRight = mDrawableEnd; mDrawableSizeRight = mDrawableSizeEnd; mDrawableHeightRight = mDrawableHeightEnd; } break; } } applyErrorDrawableIfNeeded(layoutDirection); updateDrawablesLayoutDirection(layoutDirection); } Loading Loading @@ -1154,6 +1186,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener bufferType = BufferType.SPANNABLE; } // This call will save the initial left/right drawables setCompoundDrawablesWithIntrinsicBounds( drawableLeft, drawableTop, drawableRight, drawableBottom); setRelativeDrawablesIfNeeded(drawableStart, drawableEnd); Loading Loading @@ -1302,8 +1335,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (hasRelativeDrawables) { Drawables dr = mDrawables; if (dr == null) { mDrawables = dr = new Drawables(); mDrawables = dr = new Drawables(getContext()); } mDrawables.mOverride = true; final Rect compoundRect = dr.mCompoundRect; int[] state = getDrawableState(); if (start != null) { Loading Loading @@ -1876,9 +1910,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } else { if (dr == null) { mDrawables = dr = new Drawables(); mDrawables = dr = new Drawables(getContext()); } mDrawables.mOverride = false; if (dr.mDrawableLeft != left && dr.mDrawableLeft != null) { dr.mDrawableLeft.setCallback(null); } Loading Loading @@ -1945,6 +1981,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } // Save initial left/right drawables if (dr != null) { dr.mDrawableLeftInitial = left; dr.mDrawableRightInitial = right; } invalidate(); requestLayout(); } Loading Loading @@ -2045,9 +2087,11 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } else { if (dr == null) { mDrawables = dr = new Drawables(); mDrawables = dr = new Drawables(getContext()); } mDrawables.mOverride = true; if (dr.mDrawableStart != start && dr.mDrawableStart != null) { dr.mDrawableStart.setCallback(null); } Loading Loading @@ -2114,6 +2158,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } resetResolvedDrawables(); resolveDrawables(); invalidate(); requestLayout(); Loading @@ -2138,7 +2183,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener @android.view.RemotableViewMethod public void setCompoundDrawablesRelativeWithIntrinsicBounds(int start, int top, int end, int bottom) { resetResolvedDrawables(); final Resources resources = getContext().getResources(); setCompoundDrawablesRelativeWithIntrinsicBounds( start != 0 ? resources.getDrawable(start) : null, Loading @@ -2161,7 +2205,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener public void setCompoundDrawablesRelativeWithIntrinsicBounds(Drawable start, Drawable top, Drawable end, Drawable bottom) { resetResolvedDrawables(); if (start != null) { start.setBounds(0, 0, start.getIntrinsicWidth(), start.getIntrinsicHeight()); } Loading Loading @@ -2230,7 +2273,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } else { if (dr == null) { mDrawables = dr = new Drawables(); mDrawables = dr = new Drawables(getContext()); } dr.mDrawablePadding = pad; } Loading