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

Commit 3f5a90b2 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

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
parent 85176157
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -291,6 +291,7 @@ package android {
    field public static final int autoAdvanceViewId = 16843535; // 0x101030f
    field public static final int autoCompleteTextViewStyle = 16842859; // 0x101006b
    field public static final int autoLink = 16842928; // 0x10100b0
    field public static final int autoMirrored = 16843752; // 0x10103e8
    field public static final int autoStart = 16843445; // 0x10102b5
    field public static final deprecated int autoText = 16843114; // 0x101016a
    field public static final int autoUrlDetect = 16843404; // 0x101028c
@@ -9891,6 +9892,7 @@ package android.graphics.drawable {
    method public android.graphics.Shader.TileMode getTileModeY();
    method public boolean hasAntiAlias();
    method public boolean hasMipMap();
    method public final boolean isAutoMirrored();
    method public void setAlpha(int);
    method public void setAntiAlias(boolean);
    method public void setColorFilter(android.graphics.ColorFilter);
@@ -9957,6 +9959,7 @@ package android.graphics.drawable {
    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;
    method public void invalidateSelf();
    method public boolean isAutoMirrored();
    method public boolean isStateful();
    method public final boolean isVisible();
    method public void jumpToCurrentState();
@@ -9967,6 +9970,7 @@ package android.graphics.drawable {
    method public static int resolveOpacity(int, int);
    method public void scheduleSelf(java.lang.Runnable, long);
    method public abstract void setAlpha(int);
    method public void setAutoMirrored(boolean);
    method public void setBounds(int, int, int, int);
    method public void setBounds(android.graphics.Rect);
    method public final void setCallback(android.graphics.drawable.Drawable.Callback);
@@ -25138,6 +25142,13 @@ package android.util {
    method public android.util.JsonWriter value(java.lang.Number) throws java.io.IOException;
  }
  public abstract interface LayoutDirection {
    field public static final int INHERIT = 2; // 0x2
    field public static final int LOCALE = 3; // 0x3
    field public static final int LTR = 0; // 0x0
    field public static final int RTL = 1; // 0x1
  }
  public final class Log {
    method public static int d(java.lang.String, java.lang.String);
    method public static int d(java.lang.String, java.lang.String, java.lang.Throwable);
+44 −0
Original line number Diff line number Diff line
/*
 * 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.
 */

package android.util;

/**
 * An interface for defining layout directions. A layout direction can be left-to-right (LTR)
 * or right-to-left (RTL). It can also be inherited (from a parent) or deduced from the default
 * language script of a locale.
 */
public interface LayoutDirection {
    /**
     * Horizontal layout direction is from Left to Right.
     */
    public static final int LTR = 0;

    /**
     * Horizontal layout direction is from Right to Left.
     */
    public static final int RTL = 1;

    /**
     * Horizontal layout direction is inherited.
     */
    public static final int INHERIT = 2;

    /**
     * Horizontal layout direction is deduced from the default language script for the locale.
     */
    public static final int LOCALE = 3;
}
+5 −4
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.FloatProperty;
import android.util.LayoutDirection;
import android.util.Log;
import android.util.LongSparseLongArray;
import android.util.Pools.SynchronizedPool;
@@ -1801,25 +1802,25 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * Horizontal layout direction of this view is from Left to Right.
     * Use with {@link #setLayoutDirection}.
     */
    public static final int LAYOUT_DIRECTION_LTR = 0;
    public static final int LAYOUT_DIRECTION_LTR = LayoutDirection.LTR;
    /**
     * Horizontal layout direction of this view is from Right to Left.
     * Use with {@link #setLayoutDirection}.
     */
    public static final int LAYOUT_DIRECTION_RTL = 1;
    public static final int LAYOUT_DIRECTION_RTL = LayoutDirection.RTL;
    /**
     * Horizontal layout direction of this view is inherited from its parent.
     * Use with {@link #setLayoutDirection}.
     */
    public static final int LAYOUT_DIRECTION_INHERIT = 2;
    public static final int LAYOUT_DIRECTION_INHERIT = LayoutDirection.INHERIT;
    /**
     * Horizontal layout direction of this view is from deduced from the default language
     * script for the locale. Use with {@link #setLayoutDirection}.
     */
    public static final int LAYOUT_DIRECTION_LOCALE = 3;
    public static final int LAYOUT_DIRECTION_LOCALE = LayoutDirection.LOCALE;
    /**
     * Bit shift to get the horizontal layout direction. (bits after DRAG_HOVERED)
+9 −0
Original line number Diff line number Diff line
@@ -732,6 +732,15 @@ public class ImageView extends View {
        }
    }

    @Override
    public void onRtlPropertiesChanged(int layoutDirection) {
        super.onRtlPropertiesChanged(layoutDirection);

        if (mDrawable != null) {
            mDrawable.setLayoutDirection(layoutDirection);
        }
    }

    private static final Matrix.ScaleToFit[] sS2FArray = {
        Matrix.ScaleToFit.FILL,
        Matrix.ScaleToFit.START,
+2 −0
Original line number Diff line number Diff line
@@ -2042,6 +2042,8 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            dr.mDrawableRightInitial = right;
        }

        resetResolvedDrawables();
        resolveDrawables();
        invalidate();
        requestLayout();
    }
Loading