• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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.contacts.common.compat;
17 
18 import android.content.Context;
19 import android.graphics.drawable.Drawable;
20 import android.graphics.drawable.Icon;
21 import android.support.annotation.Nullable;
22 import android.telecom.PhoneAccount;
23 
24 /** Compatiblity class for {@link android.telecom.PhoneAccount} */
25 public class PhoneAccountCompat {
26 
27   /**
28    * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user
29    * interface.
30    *
31    * @param phoneAccount the PhoneAccount from which to build the icon.
32    * @param context A {@code Context} to use for loading Drawables.
33    * @return An icon for this PhoneAccount, or null
34    */
35   @Nullable
createIconDrawable( @ullable PhoneAccount phoneAccount, @Nullable Context context)36   public static Drawable createIconDrawable(
37       @Nullable PhoneAccount phoneAccount, @Nullable Context context) {
38     if (phoneAccount == null || context == null) {
39       return null;
40     }
41     return createIconDrawableMarshmallow(phoneAccount, context);
42   }
43 
44   @Nullable
createIconDrawableMarshmallow( PhoneAccount phoneAccount, Context context)45   private static Drawable createIconDrawableMarshmallow(
46       PhoneAccount phoneAccount, Context context) {
47     Icon accountIcon = phoneAccount.getIcon();
48     if (accountIcon == null) {
49       return null;
50     }
51     return accountIcon.loadDrawable(context);
52   }
53 }
54