131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki/* 231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Copyright (C) 2015 The Android Open Source Project 331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * 431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Licensed under the Apache License, Version 2.0 (the "License"); 531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * you may not use this file except in compliance with the License. 631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * You may obtain a copy of the License at 731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * 831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * http://www.apache.org/licenses/LICENSE-2.0 931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * 1031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Unless required by applicable law or agreed to in writing, software 1131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * distributed under the License is distributed on an "AS IS" BASIS, 1231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * See the License for the specific language governing permissions and 1431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * limitations under the License. 1531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki */ 1631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 1731a49efe2adb59e31611f6871895a3243d835127Yuichi Arakipackage android.support.v4.widget; 1831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 1931a49efe2adb59e31611f6871895a3243d835127Yuichi Arakiimport android.graphics.drawable.Drawable; 2031a49efe2adb59e31611f6871895a3243d835127Yuichi Arakiimport android.os.Build; 2139e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikovimport android.support.annotation.DrawableRes; 220bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikovimport android.support.annotation.IdRes; 2331a49efe2adb59e31611f6871895a3243d835127Yuichi Arakiimport android.support.annotation.NonNull; 2431a49efe2adb59e31611f6871895a3243d835127Yuichi Arakiimport android.support.annotation.Nullable; 2539e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikovimport android.support.annotation.StyleRes; 2631a49efe2adb59e31611f6871895a3243d835127Yuichi Arakiimport android.widget.TextView; 2731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 2831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki/** 2931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Helper for accessing features in {@link TextView} introduced after API level 3031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * 4 in a backwards compatible fashion. 3131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki */ 32c5847d13e40f5d52459f5c0dab32dc08f1a9a683Chris Banespublic final class TextViewCompat { 3331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 3431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki // Hide constructor 35092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes private TextViewCompat() {} 3631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 3731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki interface TextViewCompatImpl { 38092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes void setCompoundDrawablesRelative(@NonNull TextView textView, 3931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, 4031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable bottom); 41092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, 4231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, 4331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable bottom); 44092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, 4539e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov @DrawableRes int start, @DrawableRes int top, @DrawableRes int end, 4639e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov @DrawableRes int bottom); 47092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes int getMaxLines(TextView textView); 48092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes int getMinLines(TextView textView); 4939e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov void setTextAppearance(@NonNull TextView textView, @StyleRes int resId); 5031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 5131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 5231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki static class BaseTextViewCompatImpl implements TextViewCompatImpl { 5331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Override 5431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public void setCompoundDrawablesRelative(@NonNull TextView textView, 5531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, 5631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable bottom) { 5731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki textView.setCompoundDrawables(start, top, end, bottom); 5831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 5931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 6031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Override 6131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, 6231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, 6331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable bottom) { 6431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom); 6531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 6631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 6731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Override 6831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, 6939e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov @DrawableRes int start, @DrawableRes int top, @DrawableRes int end, 7039e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov @DrawableRes int bottom) { 7131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki textView.setCompoundDrawablesWithIntrinsicBounds(start, top, end, bottom); 7231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 7331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 74092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes @Override 75092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes public int getMaxLines(TextView textView) { 76092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes return TextViewCompatDonut.getMaxLines(textView); 77092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes } 78092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes 79092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes @Override 80092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes public int getMinLines(TextView textView) { 81092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes return TextViewCompatDonut.getMinLines(textView); 82092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes } 830bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov 840bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov @Override 8539e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov public void setTextAppearance(TextView textView, @StyleRes int resId) { 860bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov TextViewCompatDonut.setTextAppearance(textView, resId); 870bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov } 8831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 8931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 90092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes static class JbTextViewCompatImpl extends BaseTextViewCompatImpl { 91092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes @Override 92092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes public int getMaxLines(TextView textView) { 93092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes return TextViewCompatJb.getMaxLines(textView); 94092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes } 9531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 9631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Override 97092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes public int getMinLines(TextView textView) { 98092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes return TextViewCompatJb.getMinLines(textView); 99092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes } 100092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes } 101092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes 102092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes static class JbMr1TextViewCompatImpl extends JbTextViewCompatImpl { 103092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes @Override 10431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public void setCompoundDrawablesRelative(@NonNull TextView textView, 10531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, 10631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable bottom) { 10731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki TextViewCompatJbMr1.setCompoundDrawablesRelative(textView, start, top, end, bottom); 10831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 10931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 11031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Override 11131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, 11231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, 11331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable bottom) { 11431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki TextViewCompatJbMr1.setCompoundDrawablesRelativeWithIntrinsicBounds(textView, 11531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki start, top, end, bottom); 11631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 11731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 11831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Override 11931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, 12039e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov @DrawableRes int start, @DrawableRes int top, @DrawableRes int end, 12139e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov @DrawableRes int bottom) { 12231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki TextViewCompatJbMr1.setCompoundDrawablesRelativeWithIntrinsicBounds(textView, 12331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki start, top, end, bottom); 12431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 12531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 12631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 12731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki static class JbMr2TextViewCompatImpl extends JbMr1TextViewCompatImpl { 12831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Override 12931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public void setCompoundDrawablesRelative(@NonNull TextView textView, 13031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, 13131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable bottom) { 13231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki TextViewCompatJbMr2.setCompoundDrawablesRelative(textView, start, top, end, bottom); 13331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 13431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 13531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Override 13631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, 13731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, 13831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable bottom) { 13931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki TextViewCompatJbMr2 14031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki .setCompoundDrawablesRelativeWithIntrinsicBounds(textView, start, top, end, 14131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki bottom); 14231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 14331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 14431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Override 14531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, 14639e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov @DrawableRes int start, @DrawableRes int top, @DrawableRes int end, 14739e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov @DrawableRes int bottom) { 14831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki TextViewCompatJbMr2.setCompoundDrawablesRelativeWithIntrinsicBounds(textView, 14931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki start, top, end, bottom); 15031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 15131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 15231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 1530bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov static class Api23TextViewCompatImpl extends JbMr2TextViewCompatImpl { 1540bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov @Override 15539e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov public void setTextAppearance(@NonNull TextView textView, @StyleRes int resId) { 1560bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov TextViewCompatApi23.setTextAppearance(textView, resId); 1570bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov } 1580bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov } 1590bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov 16031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki static final TextViewCompatImpl IMPL; 16131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 16231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki static { 16331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki final int version = Build.VERSION.SDK_INT; 1640bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov if (version >= 23) { 1650bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov IMPL = new Api23TextViewCompatImpl(); 1660bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov } else if (version >= 18) { 16731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki IMPL = new JbMr2TextViewCompatImpl(); 16831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } else if (version >= 17) { 16931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki IMPL = new JbMr1TextViewCompatImpl(); 170092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes } else if (version >= 16) { 171092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes IMPL = new JbTextViewCompatImpl(); 17231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } else { 17331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki IMPL = new BaseTextViewCompatImpl(); 17431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 17531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 17631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 17731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki /** 17831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Sets the Drawables (if any) to appear to the start of, above, to the end 17931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * of, and below the text. Use {@code null} if you do not want a Drawable 18031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * there. The Drawables must already have had {@link Drawable#setBounds} 18131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * called. 18231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * <p/> 18331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Calling this method will overwrite any Drawables previously set using 18431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * {@link TextView#setCompoundDrawables} or related methods. 18531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * 18631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * @param textView The TextView against which to invoke the method. 187929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableStart 188929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableTop 189929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableEnd 190929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableBottom 19131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki */ 19231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public static void setCompoundDrawablesRelative(@NonNull TextView textView, 19331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, 19431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable bottom) { 19531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki IMPL.setCompoundDrawablesRelative(textView, start, top, end, bottom); 19631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 19731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 19831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki /** 19931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Sets the Drawables (if any) to appear to the start of, above, to the end 20031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * of, and below the text. Use {@code null} if you do not want a Drawable 20131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * there. The Drawables' bounds will be set to their intrinsic bounds. 20231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * <p/> 20331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Calling this method will overwrite any Drawables previously set using 20431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * {@link TextView#setCompoundDrawables} or related methods. 20531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * 20631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * @param textView The TextView against which to invoke the method. 207929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableStart 208929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableTop 209929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableEnd 210929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableBottom 21131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki */ 21231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, 21331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable start, @Nullable Drawable top, @Nullable Drawable end, 21431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki @Nullable Drawable bottom) { 21531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki IMPL.setCompoundDrawablesRelativeWithIntrinsicBounds(textView, start, top, end, bottom); 21631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 21731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 21831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki /** 21931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Sets the Drawables (if any) to appear to the start of, above, to the end 22031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * of, and below the text. Use 0 if you do not want a Drawable there. The 22131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Drawables' bounds will be set to their intrinsic bounds. 22231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * <p/> 22331a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * Calling this method will overwrite any Drawables previously set using 22431a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * {@link TextView#setCompoundDrawables} or related methods. 22531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * 22631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * @param textView The TextView against which to invoke the method. 22731a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * @param start Resource identifier of the start Drawable. 22831a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * @param top Resource identifier of the top Drawable. 22931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * @param end Resource identifier of the end Drawable. 23031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki * @param bottom Resource identifier of the bottom Drawable. 231929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableStart 232929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableTop 233929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableEnd 234929f27aab7ac7231f3734c988d5ee7201627d535Alan Viverette * @attr name android:drawableBottom 23531a49efe2adb59e31611f6871895a3243d835127Yuichi Araki */ 23631a49efe2adb59e31611f6871895a3243d835127Yuichi Araki public static void setCompoundDrawablesRelativeWithIntrinsicBounds(@NonNull TextView textView, 23739e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov @DrawableRes int start, @DrawableRes int top, @DrawableRes int end, 23839e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov @DrawableRes int bottom) { 23931a49efe2adb59e31611f6871895a3243d835127Yuichi Araki IMPL.setCompoundDrawablesRelativeWithIntrinsicBounds(textView, start, top, end, bottom); 24031a49efe2adb59e31611f6871895a3243d835127Yuichi Araki } 24131a49efe2adb59e31611f6871895a3243d835127Yuichi Araki 242092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes /** 243092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes * Returns the maximum number of lines displayed in the given TextView, or -1 if the maximum 244092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes * height was set in pixels instead. 245092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes */ 246092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes public static int getMaxLines(@NonNull TextView textView) { 247092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes return IMPL.getMaxLines(textView); 248092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes } 249092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes 250092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes /** 251092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes * Returns the minimum number of lines displayed in the given TextView, or -1 if the minimum 252092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes * height was set in pixels instead. 253092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes */ 254092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes public static int getMinLines(@NonNull TextView textView) { 255092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes return IMPL.getMinLines(textView); 256092bd179f5a24c29a63717ce69c6d4065e33abe6Chris Banes } 2570bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov 2580bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov /** 2590bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov * Sets the text appearance from the specified style resource. 2600bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov * <p> 2610bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov * Use a framework-defined {@code TextAppearance} style like 2620bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov * {@link android.R.style#TextAppearance_Material_Body1 @android:style/TextAppearance.Material.Body1} 2630bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov * or see {@link android.R.styleable#TextAppearance TextAppearance} for the 2640bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov * set of attributes that can be used in a custom style. 2650bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov * 2660bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov * @param textView The TextView against which to invoke the method. 2670bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov * @param resId The resource identifier of the style to apply. 2680bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov */ 26939e84476b45f10ed4929e307372d6f7a2103e9d5Kirill Grouchnikov public static void setTextAppearance(@NonNull TextView textView, @StyleRes int resId) { 2700bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov IMPL.setTextAppearance(textView, resId); 2710bd3435d26a1c5daa0d205324c327dee4992bfbeKirill Grouchnikov } 27231a49efe2adb59e31611f6871895a3243d835127Yuichi Araki} 273