1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.wallpaper.compat;
17 
18 import android.graphics.drawable.Drawable;
19 import android.os.Build.VERSION;
20 import android.os.Build.VERSION_CODES;
21 import android.widget.Button;
22 
23 /**
24  * Compatibility class for adding Drawables to Buttons.
25  */
26 public class ButtonDrawableSetterCompat {
27 
28     /**
29      * Sets a Drawable to the start of a Button on API 17+ and to the left of a Button on older
30      * versions where RTL is not supported.
31      */
setDrawableToButtonStart(Button button, Drawable icon)32     public static void setDrawableToButtonStart(Button button, Drawable icon) {
33         // RTL method support was added in API 17.
34         if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN_MR1) {
35             button.setCompoundDrawablesRelativeWithIntrinsicBounds(icon, null, null, null);
36         } else {
37             // Fall back to "left" icon placement if RTL is not supported.
38             button.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
39         }
40     }
41 }
42