146878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka/* 246878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * Copyright (C) 2013 The Android Open Source Project 346878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * 446878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * Licensed under the Apache License, Version 2.0 (the "License"); 546878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * you may not use this file except in compliance with the License. 646878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * You may obtain a copy of the License at 746878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * 846878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * http://www.apache.org/licenses/LICENSE-2.0 946878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * 1046878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * Unless required by applicable law or agreed to in writing, software 1146878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * distributed under the License is distributed on an "AS IS" BASIS, 1246878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1346878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * See the License for the specific language governing permissions and 1446878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka * limitations under the License. 1546878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka */ 1646878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka 1746878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaokapackage com.android.inputmethod.compat; 1846878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka 1946878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaokaimport android.graphics.drawable.Drawable; 2046878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaokaimport android.widget.TextView; 2146878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka 2246878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaokaimport java.lang.reflect.Method; 2346878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka 2446878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaokapublic final class TextViewCompatUtils { 25d794f5ae2aee44b9ce75cd675cb7138cd9a4ea82Tadashi G. Takaoka // Note that TextView.setCompoundDrawablesRelativeWithIntrinsicBounds(Drawable,Drawable, 26d794f5ae2aee44b9ce75cd675cb7138cd9a4ea82Tadashi G. Takaoka // Drawable,Drawable) has been introduced in API level 17 (Build.VERSION_CODE.JELLY_BEAN_MR1). 27d794f5ae2aee44b9ce75cd675cb7138cd9a4ea82Tadashi G. Takaoka private static final Method METHOD_setCompoundDrawablesRelativeWithIntrinsicBounds = 28d794f5ae2aee44b9ce75cd675cb7138cd9a4ea82Tadashi G. Takaoka CompatUtils.getMethod(TextView.class, "setCompoundDrawablesRelativeWithIntrinsicBounds", 2946878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka Drawable.class, Drawable.class, Drawable.class, Drawable.class); 3046878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka 3146878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka private TextViewCompatUtils() { 3246878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka // This utility class is not publicly instantiable. 3346878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka } 3446878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka 35d794f5ae2aee44b9ce75cd675cb7138cd9a4ea82Tadashi G. Takaoka public static void setCompoundDrawablesRelativeWithIntrinsicBounds(final TextView textView, 36d794f5ae2aee44b9ce75cd675cb7138cd9a4ea82Tadashi G. Takaoka final Drawable start, final Drawable top, final Drawable end, final Drawable bottom) { 37d794f5ae2aee44b9ce75cd675cb7138cd9a4ea82Tadashi G. Takaoka if (METHOD_setCompoundDrawablesRelativeWithIntrinsicBounds == null) { 38d794f5ae2aee44b9ce75cd675cb7138cd9a4ea82Tadashi G. Takaoka textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom); 3946878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka return; 4046878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka } 41d794f5ae2aee44b9ce75cd675cb7138cd9a4ea82Tadashi G. Takaoka CompatUtils.invoke(textView, null, METHOD_setCompoundDrawablesRelativeWithIntrinsicBounds, 4246878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka start, top, end, bottom); 4346878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka } 4446878544ec894fd3db368e183404a01c3e3ecc92Tadashi G. Takaoka} 45