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