Skip to content

Commit deed787

Browse files
committed
fix not to call deprecated getDrawable in postLolipop
1 parent 0697a36 commit deed787

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ project.ext {
2222

2323
ANDROID_MIN_SDK_VERSION = 8
2424
ANDROID_TARGET_SDK_VERSION = 22
25+
26+
// Google Stuffs
27+
supportPackageVersion = "22.0.0"
2528
}

lib/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ android {
1919

2020
dependencies {
2121
compile fileTree(dir: 'libs', include: ['*.jar'])
22+
// to support annotations such as @NonNull
23+
compile "com.android.support:support-annotations:${supportPackageVersion}"
2224
}
2325

2426
// for maven central deployment

lib/src/main/java/com/ms/square/android/expandabletextview/ExpandableTextView.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919

2020
import android.annotation.TargetApi;
2121
import android.content.Context;
22+
import android.content.res.Resources;
2223
import android.content.res.TypedArray;
2324
import android.graphics.drawable.Drawable;
2425
import android.os.Build;
26+
import android.support.annotation.DrawableRes;
27+
import android.support.annotation.NonNull;
2528
import android.text.TextUtils;
2629
import android.util.AttributeSet;
2730
import android.util.SparseBooleanArray;
@@ -233,10 +236,10 @@ private void init(AttributeSet attrs) {
233236
mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable);
234237

235238
if (mExpandDrawable == null) {
236-
mExpandDrawable = getResources().getDrawable(R.drawable.ic_expand_small_holo_light, null);
239+
mExpandDrawable = getDrawable(getResources(), R.drawable.ic_expand_small_holo_light);
237240
}
238241
if (mCollapseDrawable == null) {
239-
mCollapseDrawable = getResources().getDrawable(R.drawable.ic_collapse_small_holo_light, null);
242+
mCollapseDrawable = getDrawable(getResources(), R.drawable.ic_collapse_small_holo_light);
240243
}
241244

242245
typedArray.recycle();
@@ -254,6 +257,10 @@ private static boolean isPostHoneycomb() {
254257
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
255258
}
256259

260+
private static boolean isPostLolipop() {
261+
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
262+
}
263+
257264
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
258265
private static void applyAlphaAnimation(View view, float alpha) {
259266
if (isPostHoneycomb()) {
@@ -267,7 +274,16 @@ private static void applyAlphaAnimation(View view, float alpha) {
267274
}
268275
}
269276

270-
private static int getRealTextViewHeight(TextView textView) {
277+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
278+
private static Drawable getDrawable(@NonNull Resources resources, @DrawableRes int resId) {
279+
if (isPostLolipop()) {
280+
return resources.getDrawable(resId, null);
281+
} else {
282+
return resources.getDrawable(resId);
283+
}
284+
}
285+
286+
private static int getRealTextViewHeight(@NonNull TextView textView) {
271287
int textHeight = textView.getLayout().getLineTop(textView.getLineCount());
272288
int padding = textView.getCompoundPaddingTop() + textView.getCompoundPaddingBottom();
273289
return textHeight + padding;

0 commit comments

Comments
 (0)