1a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell/*
2a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * Copyright (C) 2013 The Android Open Source Project
3a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell *
4a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * Licensed under the Apache License, Version 2.0 (the "License");
5a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * you may not use this file except in compliance with the License.
6a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * You may obtain a copy of the License at
7a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell *
8a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell *      http://www.apache.org/licenses/LICENSE-2.0
9a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell *
10a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * Unless required by applicable law or agreed to in writing, software
11a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * distributed under the License is distributed on an "AS IS" BASIS,
12a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * See the License for the specific language governing permissions and
14a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * limitations under the License.
15a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell */
16a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
17a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
18a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powellpackage android.support.v4.view;
19a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
20a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powellimport android.os.Build;
21a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powellimport android.view.ViewGroup;
22a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
23a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell/**
24a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * Helper for accessing API features in
25a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell * {@link android.view.ViewGroup.MarginLayoutParams MarginLayoutParams} added after API 4.
26a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell */
27a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powellpublic class MarginLayoutParamsCompat {
28a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    interface MarginLayoutParamsCompatImpl {
29a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        int getMarginStart(ViewGroup.MarginLayoutParams lp);
30a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        int getMarginEnd(ViewGroup.MarginLayoutParams lp);
31a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        void setMarginStart(ViewGroup.MarginLayoutParams lp, int marginStart);
32a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        void setMarginEnd(ViewGroup.MarginLayoutParams lp, int marginEnd);
33a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        boolean isMarginRelative(ViewGroup.MarginLayoutParams lp);
34a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        int getLayoutDirection(ViewGroup.MarginLayoutParams lp);
35a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        void setLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection);
36a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        void resolveLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection);
37a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
38a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
39a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    static class MarginLayoutParamsCompatImplBase implements MarginLayoutParamsCompatImpl {
40a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
41a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
42a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public int getMarginStart(ViewGroup.MarginLayoutParams lp) {
43a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            return lp.leftMargin;
44a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
45a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
46a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
47a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public int getMarginEnd(ViewGroup.MarginLayoutParams lp) {
48a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            return lp.rightMargin;
49a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
50a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
51a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
52a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public void setMarginStart(ViewGroup.MarginLayoutParams lp, int marginStart) {
53a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            lp.leftMargin = marginStart;
54a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
55a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
56a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
57a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public void setMarginEnd(ViewGroup.MarginLayoutParams lp, int marginEnd) {
58a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            lp.rightMargin = marginEnd;
59a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
60a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
61a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
62a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public boolean isMarginRelative(ViewGroup.MarginLayoutParams lp) {
63a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            return false;
64a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
65a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
66a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
67a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public int getLayoutDirection(ViewGroup.MarginLayoutParams lp) {
68a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            return ViewCompat.LAYOUT_DIRECTION_LTR;
69a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
70a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
71a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
72a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public void setLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection) {
73a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            // No-op
74a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
75a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
76a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
77a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public void resolveLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection) {
78a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            // No-op
79a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
80a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
81a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
82a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    static class MarginLayoutParamsCompatImplJbMr1 implements MarginLayoutParamsCompatImpl {
83a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
84a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
85a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public int getMarginStart(ViewGroup.MarginLayoutParams lp) {
86a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            return MarginLayoutParamsCompatJellybeanMr1.getMarginStart(lp);
87a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
88a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
89a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
90a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public int getMarginEnd(ViewGroup.MarginLayoutParams lp) {
91a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            return MarginLayoutParamsCompatJellybeanMr1.getMarginEnd(lp);
92a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
93a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
94a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
95a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public void setMarginStart(ViewGroup.MarginLayoutParams lp, int marginStart) {
96a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            MarginLayoutParamsCompatJellybeanMr1.setMarginStart(lp, marginStart);
97a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
98a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
99a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
100a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public void setMarginEnd(ViewGroup.MarginLayoutParams lp, int marginEnd) {
101a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            MarginLayoutParamsCompatJellybeanMr1.setMarginEnd(lp, marginEnd);
102a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
103a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
104a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
105a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public boolean isMarginRelative(ViewGroup.MarginLayoutParams lp) {
106a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            return MarginLayoutParamsCompatJellybeanMr1.isMarginRelative(lp);
107a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
108a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
109a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
110a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public int getLayoutDirection(ViewGroup.MarginLayoutParams lp) {
111a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            return MarginLayoutParamsCompatJellybeanMr1.getLayoutDirection(lp);
112a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
113a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
114a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
115a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public void setLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection) {
116a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            MarginLayoutParamsCompatJellybeanMr1.setLayoutDirection(lp, layoutDirection);
117a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
118a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
119a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        @Override
120a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        public void resolveLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection) {
121a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            MarginLayoutParamsCompatJellybeanMr1.resolveLayoutDirection(lp, layoutDirection);
122a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
123a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
124a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
125a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    static final MarginLayoutParamsCompatImpl IMPL;
126a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    static {
127a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        final int version = Build.VERSION.SDK_INT;
128a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        if (version >= 17) { // jb-mr1
129a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            IMPL = new MarginLayoutParamsCompatImplJbMr1();
130a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        } else {
131a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            IMPL = new MarginLayoutParamsCompatImplBase();
132a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        }
133a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
134a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
135a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    /**
136a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * Get the relative starting margin that was set.
137a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
138a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * <p>On platform versions supporting bidirectional text and layouts
139a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * this value will be resolved into the LayoutParams object's left or right
140a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * margin as appropriate when the associated View is attached to a window
141a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * or when the layout direction of that view changes.</p>
142a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
143a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @param lp LayoutParams to query
144a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @return the margin along the starting edge in pixels
145a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     */
146a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    public static int getMarginStart(ViewGroup.MarginLayoutParams lp) {
147a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        return IMPL.getMarginStart(lp);
148a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
149a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
150a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    /**
151a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * Get the relative ending margin that was set.
152a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
153a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * <p>On platform versions supporting bidirectional text and layouts
154a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * this value will be resolved into the LayoutParams object's left or right
155a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * margin as appropriate when the associated View is attached to a window
156a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * or when the layout direction of that view changes.</p>
157a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
158a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @param lp LayoutParams to query
159a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @return the margin along the ending edge in pixels
160a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     */
161a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    public static int getMarginEnd(ViewGroup.MarginLayoutParams lp) {
162a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        return IMPL.getMarginEnd(lp);
163a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
164a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
165a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    /**
166a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * Set the relative start margin.
167a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
168a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * <p>On platform versions supporting bidirectional text and layouts
169a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * this value will be resolved into the LayoutParams object's left or right
170a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * margin as appropriate when the associated View is attached to a window
171a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * or when the layout direction of that view changes.</p>
172a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
173a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @param lp LayoutParams to query
174a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @param marginStart the desired start margin in pixels
175a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     */
176a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    public static void setMarginStart(ViewGroup.MarginLayoutParams lp, int marginStart) {
177a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        IMPL.setMarginStart(lp, marginStart);
178a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
179a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
180a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    /**
181a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * Set the relative end margin.
182a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
183a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * <p>On platform versions supporting bidirectional text and layouts
184a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * this value will be resolved into the LayoutParams object's left or right
185a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * margin as appropriate when the associated View is attached to a window
186a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * or when the layout direction of that view changes.</p>
187a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
188a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @param lp LayoutParams to query
189a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @param marginEnd the desired end margin in pixels
190a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     */
191a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    public static void setMarginEnd(ViewGroup.MarginLayoutParams lp, int marginEnd) {
192a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        IMPL.setMarginEnd(lp, marginEnd);
193a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
194a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
195a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    /**
196a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * Check if margins are relative.
197a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
198a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @return true if either marginStart or marginEnd has been set.
199a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     */
200a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    public static boolean isMarginRelative(ViewGroup.MarginLayoutParams lp) {
201a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        return IMPL.isMarginRelative(lp);
202a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
203a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
204a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    /**
205a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * Retuns the layout direction. Can be either {@link ViewCompat#LAYOUT_DIRECTION_LTR} or
206a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * {@link ViewCompat#LAYOUT_DIRECTION_RTL}.
207a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
208a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @return the layout direction.
209a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     */
210a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    public static int getLayoutDirection(ViewGroup.MarginLayoutParams lp) {
211a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        return IMPL.getLayoutDirection(lp);
212a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
213a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
214a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    /**
215a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * Set the layout direction.
216a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *
217a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * @param layoutDirection the layout direction.
218a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *        Should be either {@link ViewCompat#LAYOUT_DIRECTION_LTR}
219a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     *                     or {@link ViewCompat#LAYOUT_DIRECTION_RTL}.
220a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     */
221a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    public static void setLayoutDirection(ViewGroup.MarginLayoutParams lp, int layoutDirection) {
222a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        IMPL.setLayoutDirection(lp, layoutDirection);
223a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
224a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell
225a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    /**
226a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * This will be called by {@link android.view.View#requestLayout()}. Left and Right margins
227a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     * may be overridden depending on layout direction.
228a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell     */
229a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    public static void resolveLayoutDirection(ViewGroup.MarginLayoutParams lp,
230a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell            int layoutDirection) {
231a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell        IMPL.resolveLayoutDirection(lp, layoutDirection);
232a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell    }
233a4ce8ce5dacb7902373edfe35d5b2075968d1125Adam Powell}
234