10e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam/*
20e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam * Copyright (C) 2015 The Android Open Source Project
30e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam *
40e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam * Licensed under the Apache License, Version 2.0 (the "License");
50e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam * you may not use this file except in compliance with the License.
60e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam * You may obtain a copy of the License at
70e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam *
80e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam *      http://www.apache.org/licenses/LICENSE-2.0
90e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam *
100e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam * Unless required by applicable law or agreed to in writing, software
110e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam * distributed under the License is distributed on an "AS IS" BASIS,
120e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam * See the License for the specific language governing permissions and
140e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam * limitations under the License.
150e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam */
160e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
170e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lampackage com.android.setupwizardlib.view;
180e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
199f9367672191190f903955d09a4314d40869acc6Maurice Lamimport android.annotation.TargetApi;
200e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport android.content.Context;
21a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lamimport android.content.pm.ApplicationInfo;
220e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport android.content.res.TypedArray;
230e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport android.graphics.Canvas;
240e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport android.graphics.Rect;
250e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport android.graphics.drawable.Drawable;
26b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lamimport android.os.Build.VERSION;
27b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lamimport android.os.Build.VERSION_CODES;
280e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport android.util.AttributeSet;
290e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport android.util.LayoutDirection;
300e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport android.view.Gravity;
310e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport android.view.ViewOutlineProvider;
320e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport android.widget.FrameLayout;
330e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
340e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lamimport com.android.setupwizardlib.R;
350e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
360e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam/**
37b38561602db3fc1b31c7ee907da41ec2c53e4764Maurice Lam * Class to draw the illustration of setup wizard. The {@code aspectRatio} attribute determines the
38b38561602db3fc1b31c7ee907da41ec2c53e4764Maurice Lam * aspect ratio of the top padding, which leaves space for the illustration. Draws the illustration
39b38561602db3fc1b31c7ee907da41ec2c53e4764Maurice Lam * drawable to fit the width of the view and fills the rest with the background.
400e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam *
41b38561602db3fc1b31c7ee907da41ec2c53e4764Maurice Lam * <p>If an aspect ratio is set, then the aspect ratio of the source drawable is maintained.
42b38561602db3fc1b31c7ee907da41ec2c53e4764Maurice Lam * Otherwise the the aspect ratio will be ignored, only increasing the width of the illustration.
430e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam */
440e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lampublic class Illustration extends FrameLayout {
450e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
460e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    // Size of the baseline grid in pixels
470e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    private float mBaselineGridSize;
480e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    private Drawable mBackground;
490e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    private Drawable mIllustration;
500e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    private final Rect mViewBounds = new Rect();
510e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    private final Rect mIllustrationBounds = new Rect();
520e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    private float mScale = 1.0f;
530e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    private float mAspectRatio = 0.0f;
540e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
550e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    public Illustration(Context context) {
569f9367672191190f903955d09a4314d40869acc6Maurice Lam        super(context);
579f9367672191190f903955d09a4314d40869acc6Maurice Lam        init(null, 0);
580e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    }
590e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
600e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    public Illustration(Context context, AttributeSet attrs) {
619f9367672191190f903955d09a4314d40869acc6Maurice Lam        super(context, attrs);
629f9367672191190f903955d09a4314d40869acc6Maurice Lam        init(attrs, 0);
630e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    }
640e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
659f9367672191190f903955d09a4314d40869acc6Maurice Lam    @TargetApi(VERSION_CODES.HONEYCOMB)
660e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    public Illustration(Context context, AttributeSet attrs, int defStyleAttr) {
67b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam        super(context, attrs, defStyleAttr);
689f9367672191190f903955d09a4314d40869acc6Maurice Lam        init(attrs, defStyleAttr);
699f9367672191190f903955d09a4314d40869acc6Maurice Lam    }
709f9367672191190f903955d09a4314d40869acc6Maurice Lam
719f9367672191190f903955d09a4314d40869acc6Maurice Lam    // All the constructors delegate to this init method. The 3-argument constructor is not
729f9367672191190f903955d09a4314d40869acc6Maurice Lam    // available in FrameLayout before v11, so call super with the exact same arguments.
739f9367672191190f903955d09a4314d40869acc6Maurice Lam    private void init(AttributeSet attrs, int defStyleAttr) {
740e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        if (attrs != null) {
759f9367672191190f903955d09a4314d40869acc6Maurice Lam            TypedArray a = getContext().obtainStyledAttributes(attrs,
76b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam                    R.styleable.SuwIllustration, defStyleAttr, 0);
770e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            mAspectRatio = a.getFloat(R.styleable.SuwIllustration_suwAspectRatio, 0.0f);
780e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            a.recycle();
790e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        }
800e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        // Number of pixels of the 8dp baseline grid as defined in material design specs
810e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        mBaselineGridSize = getResources().getDisplayMetrics().density * 8;
820e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        setWillNotDraw(false);
830e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    }
840e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
850e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    /**
860e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam     * The background will be drawn to fill up the rest of the view. It will also be scaled by the
870e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam     * same amount as the foreground so their textures look the same.
880e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam     */
89b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam    // Override the deprecated setBackgroundDrawable method to support API < 16. View.setBackground
90b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam    // forwards to setBackgroundDrawable in the framework implementation.
91b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam    @SuppressWarnings("deprecation")
920e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    @Override
93b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam    public void setBackgroundDrawable(Drawable background) {
940e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        if (background == mBackground) {
950e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            return;
960e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        }
970e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        mBackground = background;
980e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        invalidate();
990e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        requestLayout();
1000e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    }
1010e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
1020e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    /**
1030e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam     * Sets the drawable used as the illustration. The drawable is expected to have intrinsic
1040e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam     * width and height defined and will be scaled to fit the width of the view.
1050e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam     */
1060e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    public void setIllustration(Drawable illustration) {
1070e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        if (illustration == mIllustration) {
1080e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            return;
1090e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        }
1100e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        mIllustration = illustration;
1110e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        invalidate();
1120e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        requestLayout();
1130e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    }
1140e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
1157114577a094593dbf55b625146b3809800697030Jorim Jaggi    /**
1167114577a094593dbf55b625146b3809800697030Jorim Jaggi     * Set the aspect ratio reserved for the illustration. This overrides the top padding of the
1177114577a094593dbf55b625146b3809800697030Jorim Jaggi     * view according to the width of this view and the aspect ratio. Children views will start
1187114577a094593dbf55b625146b3809800697030Jorim Jaggi     * being laid out below this aspect ratio.
1197114577a094593dbf55b625146b3809800697030Jorim Jaggi     *
1207114577a094593dbf55b625146b3809800697030Jorim Jaggi     * @param aspectRatio A float value specifying the aspect ratio (= width / height). 0 to not
1217114577a094593dbf55b625146b3809800697030Jorim Jaggi     *                    override the top padding.
1227114577a094593dbf55b625146b3809800697030Jorim Jaggi     */
1237114577a094593dbf55b625146b3809800697030Jorim Jaggi    public void setAspectRatio(float aspectRatio) {
1247114577a094593dbf55b625146b3809800697030Jorim Jaggi        mAspectRatio = aspectRatio;
1257114577a094593dbf55b625146b3809800697030Jorim Jaggi        invalidate();
1267114577a094593dbf55b625146b3809800697030Jorim Jaggi        requestLayout();
1277114577a094593dbf55b625146b3809800697030Jorim Jaggi    }
1287114577a094593dbf55b625146b3809800697030Jorim Jaggi
1290e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    @Override
1300e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    @Deprecated
1310e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    public void setForeground(Drawable d) {
1320e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        setIllustration(d);
1330e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    }
1340e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
1350e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    @Override
1360e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
1370e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        if (mAspectRatio != 0.0f) {
1380e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
1390e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            int illustrationHeight = (int) (parentWidth / mAspectRatio);
1400e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            illustrationHeight -= illustrationHeight % mBaselineGridSize;
1410e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            setPadding(0, illustrationHeight, 0, 0);
1420e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        }
143b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam        if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
1443fa6e08ea0e8b2a9deff3096893cfa49761e2ac7Maurice Lam            //noinspection AndroidLintInlinedApi
145b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam            setOutlineProvider(ViewOutlineProvider.BOUNDS);
146b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam        }
1470e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
1480e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    }
1490e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
1500e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    @Override
1510e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
1520e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        final int layoutWidth = right - left;
1530e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        final int layoutHeight = bottom - top;
1540e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        if (mIllustration != null) {
1550e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            int intrinsicWidth = mIllustration.getIntrinsicWidth();
1560e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            int intrinsicHeight = mIllustration.getIntrinsicHeight();
1570e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
1580e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            mViewBounds.set(0, 0, layoutWidth, layoutHeight);
1590e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            if (mAspectRatio != 0f) {
1600e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam                mScale = layoutWidth / (float) intrinsicWidth;
1610e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam                intrinsicWidth = layoutWidth;
1620e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam                intrinsicHeight = (int) (intrinsicHeight * mScale);
1630e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            }
1640e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            Gravity.apply(Gravity.FILL_HORIZONTAL | Gravity.TOP, intrinsicWidth,
165b8f3330e8be7da2f141b65967ecf3a2bad4e02a4Maurice Lam                    intrinsicHeight, mViewBounds, mIllustrationBounds);
1660e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            mIllustration.setBounds(mIllustrationBounds);
1670e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        }
1680e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        if (mBackground != null) {
1690e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            // Scale the background bounds by the same scale to compensate for the scale done to the
1700e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            // canvas in onDraw.
1710e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            mBackground.setBounds(0, 0, (int) Math.ceil(layoutWidth / mScale),
1720e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam                    (int) Math.ceil((layoutHeight - mIllustrationBounds.height()) / mScale));
1730e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        }
1740e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        super.onLayout(changed, left, top, right, bottom);
1750e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    }
1760e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam
1770e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    @Override
1780e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    public void onDraw(Canvas canvas) {
1790e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        if (mBackground != null) {
1800e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            // Draw the background filling parts not covered by the illustration
1810e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            canvas.save();
1820e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            canvas.translate(0, mIllustrationBounds.height());
1830e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            // Scale the background so its size matches the foreground
1840e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            canvas.scale(mScale, mScale, 0, 0);
1859f9367672191190f903955d09a4314d40869acc6Maurice Lam            if (VERSION.SDK_INT > VERSION_CODES.JELLY_BEAN_MR1 &&
1865e79c37fe4dbe2b9c082b68ea08f4fc76a76d6a8Maurice Lam                    shouldMirrorDrawable(mBackground, getLayoutDirection())) {
187a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam                // Flip the illustration for RTL layouts
188a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam                canvas.scale(-1, 1);
189a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam                canvas.translate(-mBackground.getBounds().width(), 0);
1900e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            }
1910e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            mBackground.draw(canvas);
1920e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            canvas.restore();
1930e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        }
1940e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        if (mIllustration != null) {
1950e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            canvas.save();
1969f9367672191190f903955d09a4314d40869acc6Maurice Lam            if (VERSION.SDK_INT > VERSION_CODES.JELLY_BEAN_MR1 &&
1975e79c37fe4dbe2b9c082b68ea08f4fc76a76d6a8Maurice Lam                    shouldMirrorDrawable(mIllustration, getLayoutDirection())) {
198a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam                // Flip the illustration for RTL layouts
199a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam                canvas.scale(-1, 1);
200a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam                canvas.translate(-mIllustrationBounds.width(), 0);
2010e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            }
2020e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            // Draw the illustration
2030e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            mIllustration.draw(canvas);
2040e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam            canvas.restore();
2050e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        }
2060e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam        super.onDraw(canvas);
2070e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam    }
208a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam
2095e79c37fe4dbe2b9c082b68ea08f4fc76a76d6a8Maurice Lam    private boolean shouldMirrorDrawable(Drawable drawable, int layoutDirection) {
210a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam        if (layoutDirection == LayoutDirection.RTL) {
211a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam            if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
2125e79c37fe4dbe2b9c082b68ea08f4fc76a76d6a8Maurice Lam                return drawable.isAutoMirrored();
213a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam            } else if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
214a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam                final int flags = getContext().getApplicationInfo().flags;
2153fa6e08ea0e8b2a9deff3096893cfa49761e2ac7Maurice Lam                //noinspection AndroidLintInlinedApi
216a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam                return (flags & ApplicationInfo.FLAG_SUPPORTS_RTL) != 0;
217a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam            }
218a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam        }
219a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam        return false;
220a722cfbd655876203db00e86ab6749a1e4d2eeb5Maurice Lam    }
2210e6095c127b612821147a1c55d6ec4f679e5c47eMaurice Lam}
222