| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
| Tyler Gunn | ef9f6f9 | 2014-09-12 22:16:17 -0700 | [diff] [blame] | 17 | package android.telecom; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 18 | |
| Evan Charlton | 0e094d9 | 2014-11-08 15:49:16 -0800 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 20 | import android.content.ComponentName; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.pm.PackageManager; |
| Santos Cordon | e8dc4be | 2014-07-21 01:28:28 -0700 | [diff] [blame] | 23 | import android.content.res.Resources.NotFoundException; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 24 | import android.graphics.Bitmap; |
| 25 | import android.graphics.Color; |
| 26 | import android.graphics.drawable.BitmapDrawable; |
| 27 | import android.graphics.drawable.ColorDrawable; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 28 | import android.graphics.drawable.Drawable; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 29 | import android.net.Uri; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 30 | import android.os.Parcel; |
| 31 | import android.os.Parcelable; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 32 | import android.text.TextUtils; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 33 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 34 | import java.lang.String; |
| 35 | import java.util.ArrayList; |
| 36 | import java.util.Collections; |
| 37 | import java.util.List; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 38 | import java.util.MissingResourceException; |
| 39 | |
| 40 | /** |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 41 | * Represents a distinct method to place or receive a phone call. Apps which can place calls and |
| 42 | * want those calls to be integrated into the dialer and in-call UI should build an instance of |
| Brian Attwell | 48d8442e | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 43 | * this class and register it with the system using {@link TelecomManager}. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 44 | * <p> |
| 45 | * {@link TelecomManager} uses registered {@link PhoneAccount}s to present the user with |
| 46 | * alternative options when placing a phone call. When building a {@link PhoneAccount}, the app |
| Brian Attwell | 48d8442e | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 47 | * should supply a valid {@link PhoneAccountHandle} that references the connection service |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 48 | * implementation Telecom will use to interact with the app. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 49 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 50 | public class PhoneAccount implements Parcelable { |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 51 | |
| 52 | /** |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 53 | * Flag indicating that this {@code PhoneAccount} can act as a connection manager for |
| 54 | * other connections. The {@link ConnectionService} associated with this {@code PhoneAccount} |
| 55 | * will be allowed to manage phone calls including using its own proprietary phone-call |
| 56 | * implementation (like VoIP calling) to make calls instead of the telephony stack. |
| 57 | * <p> |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 58 | * When a user opts to place a call using the SIM-based telephony stack, the |
| 59 | * {@link ConnectionService} associated with this {@code PhoneAccount} will be attempted first |
| 60 | * if the user has explicitly selected it to be used as the default connection manager. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 61 | * <p> |
| 62 | * See {@link #getCapabilities} |
| 63 | */ |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 64 | public static final int CAPABILITY_CONNECTION_MANAGER = 0x1; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 67 | * Flag indicating that this {@code PhoneAccount} can make phone calls in place of |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 68 | * traditional SIM-based telephony calls. This account will be treated as a distinct method |
| 69 | * for placing calls alongside the traditional SIM-based telephony stack. This flag is |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 70 | * distinct from {@link #CAPABILITY_CONNECTION_MANAGER} in that it is not allowed to manage |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 71 | * or place calls from the built-in telephony stack. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 72 | * <p> |
| 73 | * See {@link #getCapabilities} |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 74 | * <p> |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 75 | */ |
| 76 | public static final int CAPABILITY_CALL_PROVIDER = 0x2; |
| 77 | |
| Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 78 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 79 | * Flag indicating that this {@code PhoneAccount} represents a built-in PSTN SIM |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 80 | * subscription. |
| Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 81 | * <p> |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 82 | * Only the Android framework can register a {@code PhoneAccount} having this capability. |
| 83 | * <p> |
| 84 | * See {@link #getCapabilities} |
| Ihab Awad | 7522bbd6 | 2014-07-18 15:53:17 -0700 | [diff] [blame] | 85 | */ |
| 86 | public static final int CAPABILITY_SIM_SUBSCRIPTION = 0x4; |
| 87 | |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 88 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 89 | * Flag indicating that this {@code PhoneAccount} is capable of placing video calls. |
| 90 | * <p> |
| 91 | * See {@link #getCapabilities} |
| Tyler Gunn | be74de0 | 2014-08-29 14:51:48 -0700 | [diff] [blame] | 92 | * @hide |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 93 | */ |
| Brian Attwell | 48d8442e | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 94 | @SystemApi |
| Ihab Awad | f8b6988 | 2014-07-25 15:14:01 -0700 | [diff] [blame] | 95 | public static final int CAPABILITY_VIDEO_CALLING = 0x8; |
| 96 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 97 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 98 | * Flag indicating that this {@code PhoneAccount} is capable of placing emergency calls. |
| 99 | * By default all PSTN {@code PhoneAccount}s are capable of placing emergency calls. |
| 100 | * <p> |
| 101 | * See {@link #getCapabilities} |
| 102 | */ |
| 103 | public static final int CAPABILITY_PLACE_EMERGENCY_CALLS = 0x10; |
| 104 | |
| 105 | /** |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 106 | * Flag indicating that this {@code PhoneAccount} is capable of being used by all users. This |
| 107 | * should only be used by system apps (and will be ignored for all other apps trying to use it). |
| 108 | * <p> |
| 109 | * See {@link #getCapabilities} |
| 110 | * @hide |
| 111 | */ |
| Brian Attwell | 48d8442e | 2014-12-19 11:37:16 -0800 | [diff] [blame] | 112 | @SystemApi |
| Evan Charlton | 134dd68 | 2014-11-25 14:12:57 -0800 | [diff] [blame] | 113 | public static final int CAPABILITY_MULTI_USER = 0x20; |
| 114 | |
| 115 | /** |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 116 | * URI scheme for telephone number URIs. |
| 117 | */ |
| 118 | public static final String SCHEME_TEL = "tel"; |
| 119 | |
| 120 | /** |
| 121 | * URI scheme for voicemail URIs. |
| 122 | */ |
| 123 | public static final String SCHEME_VOICEMAIL = "voicemail"; |
| 124 | |
| 125 | /** |
| 126 | * URI scheme for SIP URIs. |
| 127 | */ |
| 128 | public static final String SCHEME_SIP = "sip"; |
| 129 | |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 130 | /** |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 131 | * Indicating no icon tint is set. |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 132 | */ |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 133 | public static final int NO_ICON_TINT = 0; |
| 134 | |
| 135 | /** |
| 136 | * Indicating no hightlight color is set. |
| 137 | */ |
| 138 | public static final int NO_HIGHLIGHT_COLOR = 0; |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 139 | |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 140 | /** |
| 141 | * Indicating no resource ID is set. |
| 142 | */ |
| 143 | public static final int NO_RESOURCE_ID = -1; |
| 144 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 145 | private final PhoneAccountHandle mAccountHandle; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 146 | private final Uri mAddress; |
| 147 | private final Uri mSubscriptionAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 148 | private final int mCapabilities; |
| 149 | private final int mIconResId; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 150 | private final String mIconPackageName; |
| 151 | private final Bitmap mIconBitmap; |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 152 | private final int mIconTint; |
| 153 | private final int mHighlightColor; |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 154 | private final CharSequence mLabel; |
| 155 | private final CharSequence mShortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 156 | private final List<String> mSupportedUriSchemes; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 157 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 158 | /** |
| 159 | * Helper class for creating a {@link PhoneAccount}. |
| 160 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 161 | public static class Builder { |
| 162 | private PhoneAccountHandle mAccountHandle; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 163 | private Uri mAddress; |
| 164 | private Uri mSubscriptionAddress; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 165 | private int mCapabilities; |
| 166 | private int mIconResId; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 167 | private String mIconPackageName; |
| 168 | private Bitmap mIconBitmap; |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 169 | private int mIconTint = NO_ICON_TINT; |
| 170 | private int mHighlightColor = NO_HIGHLIGHT_COLOR; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 171 | private CharSequence mLabel; |
| 172 | private CharSequence mShortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 173 | private List<String> mSupportedUriSchemes = new ArrayList<String>(); |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 174 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Creates a builder with the specified {@link PhoneAccountHandle} and label. |
| 177 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 178 | public Builder(PhoneAccountHandle accountHandle, CharSequence label) { |
| 179 | this.mAccountHandle = accountHandle; |
| 180 | this.mLabel = label; |
| 181 | } |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 182 | |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 183 | /** |
| 184 | * Creates an instance of the {@link PhoneAccount.Builder} from an existing |
| 185 | * {@link PhoneAccount}. |
| 186 | * |
| 187 | * @param phoneAccount The {@link PhoneAccount} used to initialize the builder. |
| 188 | */ |
| 189 | public Builder(PhoneAccount phoneAccount) { |
| 190 | mAccountHandle = phoneAccount.getAccountHandle(); |
| 191 | mAddress = phoneAccount.getAddress(); |
| 192 | mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); |
| 193 | mCapabilities = phoneAccount.getCapabilities(); |
| 194 | mIconResId = phoneAccount.getIconResId(); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 195 | mIconPackageName = phoneAccount.getIconPackageName(); |
| 196 | mIconBitmap = phoneAccount.getIconBitmap(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 197 | mIconTint = phoneAccount.getIconTint(); |
| 198 | mHighlightColor = phoneAccount.getHighlightColor(); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 199 | mLabel = phoneAccount.getLabel(); |
| 200 | mShortDescription = phoneAccount.getShortDescription(); |
| 201 | mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 204 | /** |
| 205 | * Sets the address. See {@link PhoneAccount#getAddress}. |
| 206 | * |
| 207 | * @param value The address of the phone account. |
| 208 | * @return The builder. |
| 209 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 210 | public Builder setAddress(Uri value) { |
| 211 | this.mAddress = value; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 212 | return this; |
| 213 | } |
| 214 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 215 | /** |
| 216 | * Sets the subscription address. See {@link PhoneAccount#getSubscriptionAddress}. |
| 217 | * |
| 218 | * @param value The subscription address. |
| 219 | * @return The builder. |
| 220 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 221 | public Builder setSubscriptionAddress(Uri value) { |
| 222 | this.mSubscriptionAddress = value; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 223 | return this; |
| 224 | } |
| 225 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 226 | /** |
| 227 | * Sets the capabilities. See {@link PhoneAccount#getCapabilities}. |
| 228 | * |
| 229 | * @param value The capabilities to set. |
| 230 | * @return The builder. |
| 231 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 232 | public Builder setCapabilities(int value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 233 | this.mCapabilities = value; |
| 234 | return this; |
| 235 | } |
| 236 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 237 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 238 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 239 | * |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 240 | * @param packageContext The package from which to load an icon. |
| 241 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 242 | * @return The builder. |
| 243 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 244 | public Builder setIcon(Context packageContext, int iconResId) { |
| 245 | return setIcon(packageContext.getPackageName(), iconResId); |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 250 | * |
| 251 | * @param iconPackageName The package from which to load an icon. |
| 252 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| 253 | * @return The builder. |
| 254 | */ |
| 255 | public Builder setIcon(String iconPackageName, int iconResId) { |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 256 | return setIcon(iconPackageName, iconResId, NO_ICON_TINT); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | /** |
| 260 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 261 | * |
| 262 | * @param packageContext The package from which to load an icon. |
| 263 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| 264 | * @param iconTint A color with which to tint this icon. |
| 265 | * @return The builder. |
| 266 | */ |
| 267 | public Builder setIcon(Context packageContext, int iconResId, int iconTint) { |
| 268 | return setIcon(packageContext.getPackageName(), iconResId, iconTint); |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| 273 | * |
| 274 | * @param iconPackageName The package from which to load an icon. |
| 275 | * @param iconResId The resource in {@code iconPackageName} representing the icon. |
| 276 | * @param iconTint A color with which to tint this icon. |
| 277 | * @return The builder. |
| 278 | */ |
| 279 | public Builder setIcon(String iconPackageName, int iconResId, int iconTint) { |
| 280 | this.mIconPackageName = iconPackageName; |
| 281 | this.mIconResId = iconResId; |
| 282 | this.mIconTint = iconTint; |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 283 | return this; |
| 284 | } |
| 285 | |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 286 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 287 | * Sets the icon. See {@link PhoneAccount#createIconDrawable}. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 288 | * |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 289 | * @param iconBitmap The icon bitmap. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 290 | * @return The builder. |
| 291 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 292 | public Builder setIcon(Bitmap iconBitmap) { |
| 293 | this.mIconBitmap = iconBitmap; |
| 294 | this.mIconPackageName = null; |
| 295 | this.mIconResId = NO_RESOURCE_ID; |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 296 | this.mIconTint = NO_ICON_TINT; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 297 | return this; |
| 298 | } |
| 299 | |
| 300 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 301 | * Sets the highlight color. See {@link PhoneAccount#getHighlightColor}. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 302 | * |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 303 | * @param value The highlight color. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 304 | * @return The builder. |
| 305 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 306 | public Builder setHighlightColor(int value) { |
| 307 | this.mHighlightColor = value; |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 308 | return this; |
| 309 | } |
| 310 | |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 311 | /** |
| 312 | * Sets the short description. See {@link PhoneAccount#getShortDescription}. |
| 313 | * |
| 314 | * @param value The short description. |
| 315 | * @return The builder. |
| 316 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 317 | public Builder setShortDescription(CharSequence value) { |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 318 | this.mShortDescription = value; |
| 319 | return this; |
| 320 | } |
| 321 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 322 | /** |
| 323 | * Specifies an additional URI scheme supported by the {@link PhoneAccount}. |
| 324 | * |
| 325 | * @param uriScheme The URI scheme. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 326 | * @return The builder. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 327 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 328 | public Builder addSupportedUriScheme(String uriScheme) { |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 329 | if (!TextUtils.isEmpty(uriScheme) && !mSupportedUriSchemes.contains(uriScheme)) { |
| 330 | this.mSupportedUriSchemes.add(uriScheme); |
| 331 | } |
| 332 | return this; |
| 333 | } |
| 334 | |
| 335 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 336 | * Specifies the URI schemes supported by the {@link PhoneAccount}. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 337 | * |
| 338 | * @param uriSchemes The URI schemes. |
| Santos Cordon | 32c65a5 | 2014-10-27 14:57:49 -0700 | [diff] [blame] | 339 | * @return The builder. |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 340 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 341 | public Builder setSupportedUriSchemes(List<String> uriSchemes) { |
| 342 | mSupportedUriSchemes.clear(); |
| 343 | |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 344 | if (uriSchemes != null && !uriSchemes.isEmpty()) { |
| 345 | for (String uriScheme : uriSchemes) { |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 346 | addSupportedUriScheme(uriScheme); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | return this; |
| 350 | } |
| 351 | |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 352 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 353 | * Creates an instance of a {@link PhoneAccount} based on the current builder settings. |
| 354 | * |
| 355 | * @return The {@link PhoneAccount}. |
| 356 | */ |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 357 | public PhoneAccount build() { |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 358 | // If no supported URI schemes were defined, assume "tel" is supported. |
| 359 | if (mSupportedUriSchemes.isEmpty()) { |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 360 | addSupportedUriScheme(SCHEME_TEL); |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 363 | return new PhoneAccount( |
| 364 | mAccountHandle, |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 365 | mAddress, |
| 366 | mSubscriptionAddress, |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 367 | mCapabilities, |
| 368 | mIconResId, |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 369 | mIconPackageName, |
| 370 | mIconBitmap, |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 371 | mIconTint, |
| 372 | mHighlightColor, |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 373 | mLabel, |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 374 | mShortDescription, |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 375 | mSupportedUriSchemes); |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
| 379 | private PhoneAccount( |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 380 | PhoneAccountHandle account, |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 381 | Uri address, |
| 382 | Uri subscriptionAddress, |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 383 | int capabilities, |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 384 | int iconResId, |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 385 | String iconPackageName, |
| 386 | Bitmap iconBitmap, |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 387 | int iconTint, |
| 388 | int highlightColor, |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 389 | CharSequence label, |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 390 | CharSequence shortDescription, |
| Nancy Chen | 210ef03 | 2014-09-15 17:58:42 -0700 | [diff] [blame] | 391 | List<String> supportedUriSchemes) { |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 392 | mAccountHandle = account; |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 393 | mAddress = address; |
| 394 | mSubscriptionAddress = subscriptionAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 395 | mCapabilities = capabilities; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 396 | mIconResId = iconResId; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 397 | mIconPackageName = iconPackageName; |
| 398 | mIconBitmap = iconBitmap; |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 399 | mIconTint = iconTint; |
| 400 | mHighlightColor = highlightColor; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 401 | mLabel = label; |
| 402 | mShortDescription = shortDescription; |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 403 | mSupportedUriSchemes = Collections.unmodifiableList(supportedUriSchemes); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 406 | public static Builder builder( |
| 407 | PhoneAccountHandle accountHandle, |
| 408 | CharSequence label) { |
| 409 | return new Builder(accountHandle, label); |
| 410 | } |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 411 | |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 412 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 413 | * Returns a builder initialized with the current {@link PhoneAccount} instance. |
| 414 | * |
| 415 | * @return The builder. |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 416 | */ |
| 417 | public Builder toBuilder() { return new Builder(this); } |
| 418 | |
| 419 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 420 | * The unique identifier of this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 421 | * |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 422 | * @return A {@code PhoneAccountHandle}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 423 | */ |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 424 | public PhoneAccountHandle getAccountHandle() { |
| 425 | return mAccountHandle; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 429 | * The address (e.g., a phone number) associated with this {@code PhoneAccount}. This |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 430 | * represents the destination from which outgoing calls using this {@code PhoneAccount} |
| Evan Charlton | 6eb262c | 2014-07-19 18:18:19 -0700 | [diff] [blame] | 431 | * will appear to come, if applicable, and the destination to which incoming calls using this |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 432 | * {@code PhoneAccount} may be addressed. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 433 | * |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 434 | * @return A address expressed as a {@code Uri}, for example, a phone number. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 435 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 436 | public Uri getAddress() { |
| 437 | return mAddress; |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 441 | * The raw callback number used for this {@code PhoneAccount}, as distinct from |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 442 | * {@link #getAddress()}. For the majority of {@code PhoneAccount}s this should be registered |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 443 | * as {@code null}. It is used by the system for SIM-based {@code PhoneAccount} registration |
| Junda Liu | f52ac90 | 2014-09-25 17:36:48 +0000 | [diff] [blame] | 444 | * where {@link android.telephony.TelephonyManager#setLine1NumberForDisplay(String, String)} |
| 445 | * has been used to alter the callback number. |
| 446 | * <p> |
| Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 447 | * |
| 448 | * @return The subscription number, suitable for display to the user. |
| 449 | */ |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 450 | public Uri getSubscriptionAddress() { |
| 451 | return mSubscriptionAddress; |
| Evan Charlton | 222db525 | 2014-07-17 16:59:18 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /** |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 455 | * The capabilities of this {@code PhoneAccount}. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 456 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 457 | * @return A bit field of flags describing this {@code PhoneAccount}'s capabilities. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 458 | */ |
| 459 | public int getCapabilities() { |
| 460 | return mCapabilities; |
| 461 | } |
| 462 | |
| 463 | /** |
| Tyler Gunn | a1ed7d1 | 2014-09-08 09:52:22 -0700 | [diff] [blame] | 464 | * Determines if this {@code PhoneAccount} has a capabilities specified by the passed in |
| 465 | * bit mask. |
| 466 | * |
| 467 | * @param capability The capabilities to check. |
| 468 | * @return {@code True} if the phone account has the capability. |
| 469 | */ |
| 470 | public boolean hasCapabilities(int capability) { |
| 471 | return (mCapabilities & capability) == capability; |
| 472 | } |
| 473 | |
| 474 | /** |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 475 | * A short label describing a {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 476 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 477 | * @return A label for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 478 | */ |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 479 | public CharSequence getLabel() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 480 | return mLabel; |
| 481 | } |
| 482 | |
| 483 | /** |
| Ihab Awad | b19a0bc | 2014-08-07 19:46:01 -0700 | [diff] [blame] | 484 | * A short paragraph describing this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 485 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 486 | * @return A description for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 487 | */ |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 488 | public CharSequence getShortDescription() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 489 | return mShortDescription; |
| 490 | } |
| 491 | |
| 492 | /** |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 493 | * The URI schemes supported by this {@code PhoneAccount}. |
| 494 | * |
| 495 | * @return The URI schemes. |
| 496 | */ |
| 497 | public List<String> getSupportedUriSchemes() { |
| 498 | return mSupportedUriSchemes; |
| 499 | } |
| 500 | |
| 501 | /** |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 502 | * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 503 | * scheme. |
| 504 | * |
| 505 | * @param uriScheme The URI scheme to check. |
| Andrew Lee | 3085a6c | 2014-09-04 10:59:13 -0700 | [diff] [blame] | 506 | * @return {@code True} if the {@code PhoneAccount} supports calls to/from addresses with the |
| Tyler Gunn | f5b29dc | 2014-09-03 09:09:12 -0700 | [diff] [blame] | 507 | * specified URI scheme. |
| 508 | */ |
| 509 | public boolean supportsUriScheme(String uriScheme) { |
| 510 | if (mSupportedUriSchemes == null || uriScheme == null) { |
| 511 | return false; |
| 512 | } |
| 513 | |
| 514 | for (String scheme : mSupportedUriSchemes) { |
| 515 | if (scheme != null && scheme.equals(uriScheme)) { |
| 516 | return true; |
| 517 | } |
| 518 | } |
| 519 | return false; |
| 520 | } |
| 521 | |
| 522 | /** |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 523 | * The icon resource ID for the icon of this {@code PhoneAccount}. |
| 524 | * <p> |
| 525 | * Creators of a {@code PhoneAccount} who possess the icon in static resources should prefer |
| 526 | * this method of indicating the icon rather than using {@link #getIconBitmap()}, since it |
| 527 | * leads to less resource usage. |
| 528 | * <p> |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 529 | * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}. |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 530 | * |
| 531 | * @return A resource ID. |
| 532 | */ |
| 533 | public int getIconResId() { |
| 534 | return mIconResId; |
| 535 | } |
| 536 | |
| 537 | /** |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 538 | * The package name from which to load the icon of this {@code PhoneAccount}. |
| 539 | * <p> |
| 540 | * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from |
| 541 | * the package in the {@link ComponentName} of the {@link #getAccountHandle()}. |
| 542 | * <p> |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 543 | * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 544 | * |
| 545 | * @return A package name. |
| 546 | */ |
| 547 | public String getIconPackageName() { |
| 548 | return mIconPackageName; |
| 549 | } |
| 550 | |
| 551 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 552 | * A tint to apply to the icon of this {@code PhoneAccount}. |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 553 | * |
| 554 | * @return A hexadecimal color value. |
| 555 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 556 | public int getIconTint() { |
| 557 | return mIconTint; |
| Nancy Chen | 3ace54b | 2014-10-22 17:45:26 -0700 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /** |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 561 | * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface. |
| 562 | * <p> |
| 563 | * If this property is specified, it is to be considered the preferred icon. Otherwise, the |
| 564 | * resource specified by {@link #getIconResId()} should be used. |
| 565 | * <p> |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 566 | * Clients wishing to display a {@code PhoneAccount} should use |
| 567 | * {@link #createIconDrawable(Context)}. |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 568 | * |
| 569 | * @return A bitmap. |
| 570 | */ |
| 571 | public Bitmap getIconBitmap() { |
| 572 | return mIconBitmap; |
| 573 | } |
| 574 | |
| 575 | /** |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 576 | * A highlight color to use in displaying information about this {@code PhoneAccount}. |
| 577 | * |
| 578 | * @return A hexadecimal color value. |
| 579 | */ |
| 580 | public int getHighlightColor() { |
| 581 | return mHighlightColor; |
| 582 | } |
| 583 | |
| 584 | /** |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 585 | * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user |
| 586 | * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and |
| 587 | * {@link #getIconBitmap()} as necessary. |
| 588 | * |
| 589 | * @param context A {@code Context} to use for loading {@code Drawable}s. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 590 | * |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 591 | * @return An icon for this {@code PhoneAccount}. |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 592 | */ |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 593 | public Drawable createIconDrawable(Context context) { |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 594 | if (mIconBitmap != null) { |
| 595 | return new BitmapDrawable(context.getResources(), mIconBitmap); |
| Sailesh Nepal | 77780a4 | 2014-09-26 18:12:00 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 598 | if (mIconResId != 0) { |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 599 | try { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 600 | Context packageContext = context.createPackageContext(mIconPackageName, 0); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 601 | try { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 602 | Drawable iconDrawable = packageContext.getDrawable(mIconResId); |
| Ihab Awad | 5c9c86e | 2014-11-12 13:41:16 -0800 | [diff] [blame] | 603 | if (mIconTint != NO_ICON_TINT) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 604 | iconDrawable.setTint(mIconTint); |
| 605 | } |
| 606 | return iconDrawable; |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 607 | } catch (NotFoundException | MissingResourceException e) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 608 | Log.e(this, e, "Cannot find icon %d in package %s", |
| 609 | mIconResId, mIconPackageName); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 610 | } |
| 611 | } catch (PackageManager.NameNotFoundException e) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 612 | Log.w(this, "Cannot find package %s", mIconPackageName); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 613 | } |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 614 | } |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 615 | |
| 616 | return new ColorDrawable(Color.TRANSPARENT); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | // |
| 620 | // Parcelable implementation |
| 621 | // |
| 622 | |
| 623 | @Override |
| 624 | public int describeContents() { |
| 625 | return 0; |
| 626 | } |
| 627 | |
| 628 | @Override |
| 629 | public void writeToParcel(Parcel out, int flags) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 630 | if (mAccountHandle == null) { |
| 631 | out.writeInt(0); |
| 632 | } else { |
| 633 | out.writeInt(1); |
| 634 | mAccountHandle.writeToParcel(out, flags); |
| 635 | } |
| 636 | if (mAddress == null) { |
| 637 | out.writeInt(0); |
| 638 | } else { |
| 639 | out.writeInt(1); |
| 640 | mAddress.writeToParcel(out, flags); |
| 641 | } |
| 642 | if (mSubscriptionAddress == null) { |
| 643 | out.writeInt(0); |
| 644 | } else { |
| 645 | out.writeInt(1); |
| 646 | mSubscriptionAddress.writeToParcel(out, flags); |
| 647 | } |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 648 | out.writeInt(mCapabilities); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 649 | out.writeInt(mIconResId); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 650 | out.writeString(mIconPackageName); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 651 | if (mIconBitmap == null) { |
| 652 | out.writeInt(0); |
| 653 | } else { |
| Ihab Awad | 96802ad | 2014-11-11 18:41:39 -0800 | [diff] [blame] | 654 | out.writeInt(1); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 655 | mIconBitmap.writeToParcel(out, flags); |
| 656 | } |
| 657 | out.writeInt(mIconTint); |
| 658 | out.writeInt(mHighlightColor); |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 659 | out.writeCharSequence(mLabel); |
| 660 | out.writeCharSequence(mShortDescription); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 661 | out.writeStringList(mSupportedUriSchemes); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 664 | public static final Creator<PhoneAccount> CREATOR |
| 665 | = new Creator<PhoneAccount>() { |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 666 | @Override |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 667 | public PhoneAccount createFromParcel(Parcel in) { |
| 668 | return new PhoneAccount(in); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | @Override |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 672 | public PhoneAccount[] newArray(int size) { |
| 673 | return new PhoneAccount[size]; |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 674 | } |
| 675 | }; |
| 676 | |
| Evan Charlton | 8c8a062 | 2014-07-20 12:31:00 -0700 | [diff] [blame] | 677 | private PhoneAccount(Parcel in) { |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 678 | if (in.readInt() > 0) { |
| 679 | mAccountHandle = PhoneAccountHandle.CREATOR.createFromParcel(in); |
| 680 | } else { |
| 681 | mAccountHandle = null; |
| 682 | } |
| 683 | if (in.readInt() > 0) { |
| 684 | mAddress = Uri.CREATOR.createFromParcel(in); |
| 685 | } else { |
| 686 | mAddress = null; |
| 687 | } |
| 688 | if (in.readInt() > 0) { |
| 689 | mSubscriptionAddress = Uri.CREATOR.createFromParcel(in); |
| 690 | } else { |
| 691 | mSubscriptionAddress = null; |
| 692 | } |
| Ihab Awad | 94cf4bf | 2014-07-17 11:21:19 -0700 | [diff] [blame] | 693 | mCapabilities = in.readInt(); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 694 | mIconResId = in.readInt(); |
| Ihab Awad | 074bf10 | 2014-10-24 11:42:32 -0700 | [diff] [blame] | 695 | mIconPackageName = in.readString(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 696 | if (in.readInt() > 0) { |
| 697 | mIconBitmap = Bitmap.CREATOR.createFromParcel(in); |
| 698 | } else { |
| 699 | mIconBitmap = null; |
| 700 | } |
| 701 | mIconTint = in.readInt(); |
| 702 | mHighlightColor = in.readInt(); |
| Santos Cordon | 146a3e3 | 2014-07-21 00:00:44 -0700 | [diff] [blame] | 703 | mLabel = in.readCharSequence(); |
| 704 | mShortDescription = in.readCharSequence(); |
| Ihab Awad | 476cc83 | 2014-11-03 09:47:51 -0800 | [diff] [blame] | 705 | mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList()); |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 706 | } |
| Tyler Gunn | 76c01a5 | 2014-09-30 14:47:51 -0700 | [diff] [blame] | 707 | |
| 708 | @Override |
| 709 | public String toString() { |
| 710 | StringBuilder sb = new StringBuilder().append("[PhoneAccount: ") |
| 711 | .append(mAccountHandle) |
| 712 | .append(" Capabilities: ") |
| 713 | .append(mCapabilities) |
| 714 | .append(" Schemes: "); |
| 715 | for (String scheme : mSupportedUriSchemes) { |
| 716 | sb.append(scheme) |
| 717 | .append(" "); |
| 718 | } |
| 719 | sb.append("]"); |
| 720 | return sb.toString(); |
| 721 | } |
| Ihab Awad | 807fe0a | 2014-07-09 12:30:52 -0700 | [diff] [blame] | 722 | } |