Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0cd655ad authored by Fabrice Di Meglio's avatar Fabrice Di Meglio Committed by Android (Google) Code Review
Browse files

Merge "Revert "Revert "Clean up layout direction APIs for Drawable"""

parents cff77782 b03b4340
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -9227,12 +9227,12 @@ package android.graphics.drawable {
    method public android.graphics.drawable.Drawable getCurrent();
    method public int getIntrinsicHeight();
    method public int getIntrinsicWidth();
    method public int getLayoutDirection();
    method public final int getLevel();
    method public int getMinimumHeight();
    method public int getMinimumWidth();
    method public abstract int getOpacity();
    method public boolean getPadding(android.graphics.Rect);
    method public int getResolvedLayoutDirectionSelf();
    method public int[] getState();
    method public android.graphics.Region getTransparentRegion();
    method public void inflate(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet) throws java.io.IOException, org.xmlpull.v1.XmlPullParserException;
@@ -9255,6 +9255,7 @@ package android.graphics.drawable {
    method public void setColorFilter(int, android.graphics.PorterDuff.Mode);
    method public void setDither(boolean);
    method public void setFilterBitmap(boolean);
    method public void setLayoutDirection(int);
    method public final boolean setLevel(int);
    method public boolean setState(int[]);
    method public boolean setVisible(boolean, boolean);
@@ -9267,10 +9268,6 @@ package android.graphics.drawable {
    method public abstract void unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable);
  }
  public static abstract interface Drawable.Callback2 implements android.graphics.drawable.Drawable.Callback {
    method public abstract int getResolvedLayoutDirection(android.graphics.drawable.Drawable);
  }
  public static abstract class Drawable.ConstantState {
    ctor public Drawable.ConstantState();
    method public abstract int getChangingConfigurations();
@@ -23946,7 +23943,7 @@ package android.view {
    method public void recycle();
  }
  public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.graphics.drawable.Drawable.Callback2 android.view.KeyEvent.Callback {
  public class View implements android.view.accessibility.AccessibilityEventSource android.graphics.drawable.Drawable.Callback android.view.KeyEvent.Callback {
    ctor public View(android.content.Context);
    ctor public View(android.content.Context, android.util.AttributeSet);
    ctor public View(android.content.Context, android.util.AttributeSet, int);
@@ -24091,7 +24088,6 @@ package android.view {
    method public float getPivotX();
    method public float getPivotY();
    method public int getResolvedLayoutDirection();
    method public int getResolvedLayoutDirection(android.graphics.drawable.Drawable);
    method public int getResolvedTextAlignment();
    method public int getResolvedTextDirection();
    method public android.content.res.Resources getResources();
@@ -24223,6 +24219,7 @@ package android.view {
    method protected void onOverScrolled(int, int, boolean, boolean);
    method public void onPaddingChanged(int);
    method public void onPopulateAccessibilityEvent(android.view.accessibility.AccessibilityEvent);
    method public void onResolveDrawables(int);
    method public void onResolvedLayoutDirectionChanged();
    method public void onResolvedLayoutDirectionReset();
    method public void onResolvedTextAlignmentChanged();
@@ -24274,6 +24271,7 @@ package android.view {
    method public void resetResolvedLayoutDirection();
    method public void resetResolvedTextAlignment();
    method public void resetResolvedTextDirection();
    method public void resolveDrawables();
    method public void resolveLayoutDirection();
    method public void resolvePadding();
    method public static int resolveSize(int, int);
@@ -28766,7 +28764,6 @@ package android.widget {
    method public boolean onTextContextMenuItem(int);
    method public void removeTextChangedListener(android.text.TextWatcher);
    method protected void resetResolvedDrawables();
    method protected void resolveDrawables();
    method public void setAllCaps(boolean);
    method public final void setAutoLinkMask(int);
    method public void setCompoundDrawablePadding(int);
+35 −8
Original line number Diff line number Diff line
@@ -660,7 +660,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
 *
 * @see android.view.ViewGroup
 */
public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Callback,
public class View implements Drawable.Callback, KeyEvent.Callback,
        AccessibilityEventSource {
    private static final boolean DBG = false;
@@ -3838,6 +3838,15 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
            scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true);
        }
        // Apply layout direction to the new Drawables if needed
        final int layoutDirection = getResolvedLayoutDirection();
        if (track != null) {
            track.setLayoutDirection(layoutDirection);
        }
        if (thumb != null) {
            thumb.setLayoutDirection(layoutDirection);
        }
        // Re-apply user/background padding so that scrollbar(s) get added
        resolvePadding();
    }
@@ -13863,12 +13872,29 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
    }
    /**
    * Return the layout direction of a given Drawable.
     * Resolve the Drawables depending on the layout direction. This is implicitly supposing
     * that the View directionality can and will be resolved before its Drawables.
     *
    * @param who the Drawable to query
     * Will call {@link View#onResolveDrawables} when resolution is done.
     */
    public void resolveDrawables() {
        if (mBackground != null) {
            mBackground.setLayoutDirection(getResolvedLayoutDirection());
        }
        onResolveDrawables(getResolvedLayoutDirection());
    }
    /**
     * Called when layout direction has been resolved.
     *
     * The default implementation does nothing.
     *
     * @param layoutDirection The resolved layout direction.
     *
     * @see {@link #LAYOUT_DIRECTION_LTR}
     * @see {@link #LAYOUT_DIRECTION_RTL}
     */
    public int getResolvedLayoutDirection(Drawable who) {
        return (who == mBackground) ? getResolvedLayoutDirection() : LAYOUT_DIRECTION_DEFAULT;
    public void onResolveDrawables(int layoutDirection) {
    }
    /**
@@ -14137,8 +14163,9 @@ public class View implements Drawable.Callback, Drawable.Callback2, KeyEvent.Cal
                padding = new Rect();
                sThreadLocal.set(padding);
            }
            background.setLayoutDirection(getResolvedLayoutDirection());
            if (background.getPadding(padding)) {
                switch (background.getResolvedLayoutDirectionSelf()) {
                switch (background.getLayoutDirection()) {
                    case LAYOUT_DIRECTION_RTL:
                        setPadding(padding.right, padding.top, padding.left, padding.bottom);
                        break;
+1 −6
Original line number Diff line number Diff line
@@ -193,12 +193,6 @@ public class ImageView extends View {
        }
    }

    @Override
    public int getResolvedLayoutDirection(Drawable dr) {
        return (dr == mDrawable) ?
                getResolvedLayoutDirection() : super.getResolvedLayoutDirection(dr);
    }

    @Override
    public boolean hasOverlappingRendering() {
        return (getBackground() != null);
@@ -672,6 +666,7 @@ public class ImageView extends View {
                d.setState(getDrawableState());
            }
            d.setLevel(mLevel);
            d.setLayoutDirection(getLayoutDirection());
            mDrawableWidth = d.getIntrinsicWidth();
            mDrawableHeight = d.getIntrinsicHeight();
            applyColorMod();
+4 −6
Original line number Diff line number Diff line
@@ -478,6 +478,9 @@ public class ProgressBar extends View {
            d.setCallback(this);
        }
        mIndeterminateDrawable = d;
        if (mIndeterminateDrawable != null) {
            mIndeterminateDrawable.setLayoutDirection(getLayoutDirection());
        }
        if (mIndeterminate) {
            mCurrentDrawable = d;
            postInvalidate();
@@ -517,6 +520,7 @@ public class ProgressBar extends View {

        if (d != null) {
            d.setCallback(this);
            d.setLayoutDirection(getLayoutDirection());

            // Make sure the ProgressBar is always tall enough
            int drawableHeight = d.getMinimumHeight();
@@ -975,12 +979,6 @@ public class ProgressBar extends View {
        }
    }

    @Override
    public int getResolvedLayoutDirection(Drawable who) {
        return (who == mProgressDrawable || who == mIndeterminateDrawable) ?
            getResolvedLayoutDirection() : super.getResolvedLayoutDirection(who);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        updateDrawableBounds(w, h);
+19 −22
Original line number Diff line number Diff line
@@ -4578,20 +4578,6 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
    }

    @Override
    public int getResolvedLayoutDirection(Drawable who) {
        if (who == null) return View.LAYOUT_DIRECTION_LTR;
        if (mDrawables != null) {
            final Drawables drawables = mDrawables;
            if (who == drawables.mDrawableLeft || who == drawables.mDrawableRight ||
                who == drawables.mDrawableTop || who == drawables.mDrawableBottom ||
                who == drawables.mDrawableStart || who == drawables.mDrawableEnd) {
                return getResolvedLayoutDirection();
            }
        }
        return super.getResolvedLayoutDirection(who);
    }

    @Override
    public boolean hasOverlappingRendering() {
        return (getBackground() != null || mText instanceof Spannable || hasSelection());
@@ -8203,13 +8189,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }
    }

    /**
     * Subclasses will need to override this method to implement their own way of resolving
     * drawables depending on the layout direction.
     *
     * A call to the super method will be required from the subclasses implementation.
     */
    protected void resolveDrawables() {
    @Override
    public void onResolveDrawables(int layoutDirection) {
        // No need to resolve twice
        if (mResolvedDrawables) {
            return;
@@ -8225,7 +8206,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        }

        Drawables dr = mDrawables;
        switch(getResolvedLayoutDirection()) {
        switch(layoutDirection) {
            case LAYOUT_DIRECTION_RTL:
                if (dr.mDrawableStart != null) {
                    dr.mDrawableRight = dr.mDrawableStart;
@@ -8257,9 +8238,25 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
                }
                break;
        }
        updateDrawablesLayoutDirection(dr, layoutDirection);
        mResolvedDrawables = true;
    }

    private void updateDrawablesLayoutDirection(Drawables dr, int layoutDirection) {
        if (dr.mDrawableLeft != null) {
            dr.mDrawableLeft.setLayoutDirection(layoutDirection);
        }
        if (dr.mDrawableRight != null) {
            dr.mDrawableRight.setLayoutDirection(layoutDirection);
        }
        if (dr.mDrawableTop != null) {
            dr.mDrawableTop.setLayoutDirection(layoutDirection);
        }
        if (dr.mDrawableBottom != null) {
            dr.mDrawableBottom.setLayoutDirection(layoutDirection);
        }
    }

    protected void resetResolvedDrawables() {
        mResolvedDrawables = false;
    }
Loading