Backport Context.getDrawable()

Context.getDrawable() was added in API level 21. In order to backport it,
we could use ContextCompat.getDrawable(). However, the code in PhoneCommon
is built as part of master in packages/services/Telephony as well and it
doesn't include the support library. Simply importing ContextCompat would
break master, so we handle compatibility in the class itself.

Bug: 25629359
Change-Id: I98a413a1b7e0a9a94a722059e18318e22939040d
diff --git a/src/com/android/phone/common/dialpad/DialpadView.java b/src/com/android/phone/common/dialpad/DialpadView.java
index 1d71687..d8ee4db 100644
--- a/src/com/android/phone/common/dialpad/DialpadView.java
+++ b/src/com/android/phone/common/dialpad/DialpadView.java
@@ -22,7 +22,9 @@
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
+import android.graphics.drawable.Drawable;
 import android.graphics.drawable.RippleDrawable;
+import android.os.Build;
 import android.text.Spannable;
 import android.text.TextUtils;
 import android.text.style.TtsSpan;
@@ -187,8 +189,8 @@
                 numberContentDescription = spannable;
             }
 
-            final RippleDrawable rippleBackground =
-                    (RippleDrawable) getContext().getDrawable(R.drawable.btn_dialpad_key);
+            final RippleDrawable rippleBackground = (RippleDrawable)
+                    getDrawableCompat(getContext(), R.drawable.btn_dialpad_key);
             if (mRippleColor != null) {
                 rippleBackground.setColor(mRippleColor);
             }
@@ -213,6 +215,14 @@
 
     }
 
+    private Drawable getDrawableCompat(Context context, int id) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            return context.getDrawable(id);
+        } else {
+            return context.getResources().getDrawable(id);
+        }
+    }
+
     public void setShowVoicemailButton(boolean show) {
         View view = findViewById(R.id.dialpad_key_voicemail);
         if (view != null) {