Java Code Examples for com.android.setupwizardlib.util.DrawableLayoutDirectionHelper

Following code examples demonstrate how to use com.android.setupwizardlib.util.DrawableLayoutDirectionHelperfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use com.android.setupwizardlib.util.DrawableLayoutDirectionHelperand various code implementation of this class.

    public void testCreateRelativeInsetDrawableContextRtl() {
        final Drawable drawable = new ColorDrawable(Color.RED);
        Context context = getContext();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            final Configuration config = new Configuration();
            config.setLayoutDirection(new Locale("fa", "IR"));
            context = getContext().createConfigurationContext(config);
        }
        final InsetDrawable insetDrawable =
                DrawableLayoutDirectionHelper.createRelativeInsetDrawable(drawable,
                        1 , 2 , 3 , 4 , context);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            assertSame("Drawable from getDrawable() should be same as passed in", drawable,
                    insetDrawable.getDrawable());
        }
        Rect outRect = new Rect();
        insetDrawable.getPadding(outRect);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            assertEquals("InsetDrawable padding should be same as inset", new Rect(3, 2, 1, 4),
                    outRect);
        } else {
            assertEquals("InsetDrawable padding should be same as inset", new Rect(1, 2, 3, 4),
                    outRect);
        }
    } 


    public void testCreateRelativeInsetDrawableRtl() {
        final Drawable drawable = new ColorDrawable(Color.RED);
        final InsetDrawable insetDrawable =
                DrawableLayoutDirectionHelper.createRelativeInsetDrawable(drawable,
                        1 , 2 , 3 , 4 ,
                        View.LAYOUT_DIRECTION_RTL);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            assertSame("Drawable from getDrawable() should be same as passed in", drawable,
                    insetDrawable.getDrawable());
        }
        Rect outRect = new Rect();
        insetDrawable.getPadding(outRect);
        assertEquals("InsetDrawable padding should be same as inset", new Rect(3, 2, 1, 4),
                outRect);
    } 

    public void testCreateRelativeInsetDrawableViewRtl() {
        final Drawable drawable = new ColorDrawable(Color.RED);
        final View view = new ForceRtlView(getContext());
        final InsetDrawable insetDrawable =
                DrawableLayoutDirectionHelper.createRelativeInsetDrawable(drawable,
                        1 , 2 , 3 , 4 , view);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            assertSame("Drawable from getDrawable() should be same as passed in", drawable,
                    insetDrawable.getDrawable());
        }
        Rect outRect = new Rect();
        insetDrawable.getPadding(outRect);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
            assertEquals("InsetDrawable padding should be same as inset", new Rect(3, 2, 1, 4),
                    outRect);
        } else {
            assertEquals("InsetDrawable padding should be same as inset", new Rect(1, 2, 3, 4),
                    outRect);
        }
    } 

    public void testCreateRelativeInsetDrawableLtr() {
        final Drawable drawable = new ColorDrawable(Color.RED);
        final InsetDrawable insetDrawable =
                DrawableLayoutDirectionHelper.createRelativeInsetDrawable(drawable,
                        1 , 2 , 3 , 4 ,
                        View.LAYOUT_DIRECTION_LTR);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            assertSame("Drawable from getDrawable() should be same as passed in", drawable,
                    insetDrawable.getDrawable());
        }
        Rect outRect = new Rect();
        insetDrawable.getPadding(outRect);
        assertEquals("InsetDrawable padding should be same as inset", new Rect(1, 2, 3, 4),
                outRect);
    } 

        if (shouldUpdate) {
            ListView listView = getListView();
            if (this.mDefaultDivider == null) {
                this.mDefaultDivider = listView.getDivider();
            }
            this.mDivider = DrawableLayoutDirectionHelper.createRelativeInsetDrawable(this.mDefaultDivider, this.mDividerInset, 0, 0, 0, (View) this);
            listView.setDivider(this.mDivider);
        } 

Advertisement
Javadoc
Provides convenience methods to handle drawable layout directions in different SDK versions.
Advertisement