diff options
author | Santos Cordon <santoscordon@google.com> | 2015-05-13 11:17:25 -0700 |
---|---|---|
committer | Santos Cordon <santoscordon@google.com> | 2015-05-13 16:57:48 -0700 |
commit | cad84a2070b68093ab31b05389685fdbcd0d9f85 (patch) | |
tree | 9dbb39304cf02950bb4d295c0c3b872be432642b /telecomm/java | |
parent | 90c66e3ded4a91613b0c1760ab2ef15e0d118a36 (diff) | |
download | frameworks_base-cad84a2070b68093ab31b05389685fdbcd0d9f85.zip frameworks_base-cad84a2070b68093ab31b05389685fdbcd0d9f85.tar.gz frameworks_base-cad84a2070b68093ab31b05389685fdbcd0d9f85.tar.bz2 |
[1/4] Use new Icon class in PhoneAccount.
Bug: 21088522
Change-Id: Ia03171d4861f758701e89733f4082863587e8c11
Diffstat (limited to 'telecomm/java')
-rw-r--r-- | telecomm/java/android/telecom/PhoneAccount.java | 218 |
1 files changed, 32 insertions, 186 deletions
diff --git a/telecomm/java/android/telecom/PhoneAccount.java b/telecomm/java/android/telecom/PhoneAccount.java index 86475b1..f05a1ef 100644 --- a/telecomm/java/android/telecom/PhoneAccount.java +++ b/telecomm/java/android/telecom/PhoneAccount.java @@ -26,6 +26,7 @@ import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.Icon; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; @@ -127,6 +128,7 @@ public final class PhoneAccount implements Parcelable { /** * Indicating no icon tint is set. + * @hide */ public static final int NO_ICON_TINT = 0; @@ -144,14 +146,11 @@ public final class PhoneAccount implements Parcelable { private final Uri mAddress; private final Uri mSubscriptionAddress; private final int mCapabilities; - private final int mIconResId; - private final String mIconPackageName; - private final Bitmap mIconBitmap; - private final int mIconTint; private final int mHighlightColor; private final CharSequence mLabel; private final CharSequence mShortDescription; private final List<String> mSupportedUriSchemes; + private final Icon mIcon; /** * Helper class for creating a {@link PhoneAccount}. @@ -161,14 +160,11 @@ public final class PhoneAccount implements Parcelable { private Uri mAddress; private Uri mSubscriptionAddress; private int mCapabilities; - private int mIconResId; - private String mIconPackageName; - private Bitmap mIconBitmap; - private int mIconTint = NO_ICON_TINT; private int mHighlightColor = NO_HIGHLIGHT_COLOR; private CharSequence mLabel; private CharSequence mShortDescription; private List<String> mSupportedUriSchemes = new ArrayList<String>(); + private Icon mIcon; /** * Creates a builder with the specified {@link PhoneAccountHandle} and label. @@ -189,14 +185,11 @@ public final class PhoneAccount implements Parcelable { mAddress = phoneAccount.getAddress(); mSubscriptionAddress = phoneAccount.getSubscriptionAddress(); mCapabilities = phoneAccount.getCapabilities(); - mIconResId = phoneAccount.getIconResId(); - mIconPackageName = phoneAccount.getIconPackageName(); - mIconBitmap = phoneAccount.getIconBitmap(); - mIconTint = phoneAccount.getIconTint(); mHighlightColor = phoneAccount.getHighlightColor(); mLabel = phoneAccount.getLabel(); mShortDescription = phoneAccount.getShortDescription(); mSupportedUriSchemes.addAll(phoneAccount.getSupportedUriSchemes()); + mIcon = phoneAccount.getIcon(); } /** @@ -233,65 +226,12 @@ public final class PhoneAccount implements Parcelable { } /** - * Sets the icon. See {@link PhoneAccount#createIconDrawable}. - * - * @param packageContext The package from which to load an icon. - * @param iconResId The resource in {@code iconPackageName} representing the icon. - * @return The builder. - */ - public Builder setIcon(Context packageContext, int iconResId) { - return setIcon(packageContext.getPackageName(), iconResId); - } - - /** - * Sets the icon. See {@link PhoneAccount#createIconDrawable}. - * - * @param iconPackageName The package from which to load an icon. - * @param iconResId The resource in {@code iconPackageName} representing the icon. - * @return The builder. - */ - public Builder setIcon(String iconPackageName, int iconResId) { - return setIcon(iconPackageName, iconResId, NO_ICON_TINT); - } - - /** - * Sets the icon. See {@link PhoneAccount#createIconDrawable}. + * Sets the icon. See {@link PhoneAccount#getIcon}. * - * @param packageContext The package from which to load an icon. - * @param iconResId The resource in {@code iconPackageName} representing the icon. - * @param iconTint A color with which to tint this icon. - * @return The builder. + * @param icon The icon to set. */ - public Builder setIcon(Context packageContext, int iconResId, int iconTint) { - return setIcon(packageContext.getPackageName(), iconResId, iconTint); - } - - /** - * Sets the icon. See {@link PhoneAccount#createIconDrawable}. - * - * @param iconPackageName The package from which to load an icon. - * @param iconResId The resource in {@code iconPackageName} representing the icon. - * @param iconTint A color with which to tint this icon. - * @return The builder. - */ - public Builder setIcon(String iconPackageName, int iconResId, int iconTint) { - this.mIconPackageName = iconPackageName; - this.mIconResId = iconResId; - this.mIconTint = iconTint; - return this; - } - - /** - * Sets the icon. See {@link PhoneAccount#createIconDrawable}. - * - * @param iconBitmap The icon bitmap. - * @return The builder. - */ - public Builder setIcon(Bitmap iconBitmap) { - this.mIconBitmap = iconBitmap; - this.mIconPackageName = null; - this.mIconResId = NO_RESOURCE_ID; - this.mIconTint = NO_ICON_TINT; + public Builder setIcon(Icon icon) { + mIcon = icon; return this; } @@ -363,10 +303,7 @@ public final class PhoneAccount implements Parcelable { mAddress, mSubscriptionAddress, mCapabilities, - mIconResId, - mIconPackageName, - mIconBitmap, - mIconTint, + mIcon, mHighlightColor, mLabel, mShortDescription, @@ -379,10 +316,7 @@ public final class PhoneAccount implements Parcelable { Uri address, Uri subscriptionAddress, int capabilities, - int iconResId, - String iconPackageName, - Bitmap iconBitmap, - int iconTint, + Icon icon, int highlightColor, CharSequence label, CharSequence shortDescription, @@ -391,10 +325,7 @@ public final class PhoneAccount implements Parcelable { mAddress = address; mSubscriptionAddress = subscriptionAddress; mCapabilities = capabilities; - mIconResId = iconResId; - mIconPackageName = iconPackageName; - mIconBitmap = iconBitmap; - mIconTint = iconTint; + mIcon = icon; mHighlightColor = highlightColor; mLabel = label; mShortDescription = shortDescription; @@ -497,6 +428,15 @@ public final class PhoneAccount implements Parcelable { } /** + * The icon to represent this {@code PhoneAccount}. + * + * @return The icon. + */ + public Icon getIcon() { + return mIcon; + } + + /** * Determines if the {@link PhoneAccount} supports calls to/from addresses with a specified URI * scheme. * @@ -518,59 +458,6 @@ public final class PhoneAccount implements Parcelable { } /** - * The icon resource ID for the icon of this {@code PhoneAccount}. - * <p> - * Creators of a {@code PhoneAccount} who possess the icon in static resources should prefer - * this method of indicating the icon rather than using {@link #getIconBitmap()}, since it - * leads to less resource usage. - * <p> - * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}. - * - * @return A resource ID. - */ - public int getIconResId() { - return mIconResId; - } - - /** - * The package name from which to load the icon of this {@code PhoneAccount}. - * <p> - * If this property is {@code null}, the resource {@link #getIconResId()} will be loaded from - * the package in the {@link ComponentName} of the {@link #getAccountHandle()}. - * <p> - * Clients wishing to display a {@code PhoneAccount} should use {@link #createIconDrawable(Context)}. - * - * @return A package name. - */ - public String getIconPackageName() { - return mIconPackageName; - } - - /** - * A tint to apply to the icon of this {@code PhoneAccount}. - * - * @return A hexadecimal color value. - */ - public int getIconTint() { - return mIconTint; - } - - /** - * A literal icon bitmap to represent this {@code PhoneAccount} in a user interface. - * <p> - * If this property is specified, it is to be considered the preferred icon. Otherwise, the - * resource specified by {@link #getIconResId()} should be used. - * <p> - * Clients wishing to display a {@code PhoneAccount} should use - * {@link #createIconDrawable(Context)}. - * - * @return A bitmap. - */ - public Bitmap getIconBitmap() { - return mIconBitmap; - } - - /** * A highlight color to use in displaying information about this {@code PhoneAccount}. * * @return A hexadecimal color value. @@ -579,41 +466,6 @@ public final class PhoneAccount implements Parcelable { return mHighlightColor; } - /** - * Builds and returns an icon {@code Drawable} to represent this {@code PhoneAccount} in a user - * interface. Uses the properties {@link #getIconResId()}, {@link #getIconPackageName()}, and - * {@link #getIconBitmap()} as necessary. - * - * @param context A {@code Context} to use for loading {@code Drawable}s. - * - * @return An icon for this {@code PhoneAccount}. - */ - public Drawable createIconDrawable(Context context) { - if (mIconBitmap != null) { - return new BitmapDrawable(context.getResources(), mIconBitmap); - } - - if (mIconResId != 0) { - try { - Context packageContext = context.createPackageContext(mIconPackageName, 0); - try { - Drawable iconDrawable = packageContext.getDrawable(mIconResId); - if (mIconTint != NO_ICON_TINT) { - iconDrawable.setTint(mIconTint); - } - return iconDrawable; - } catch (NotFoundException | MissingResourceException e) { - Log.e(this, e, "Cannot find icon %d in package %s", - mIconResId, mIconPackageName); - } - } catch (PackageManager.NameNotFoundException e) { - Log.w(this, "Cannot find package %s", mIconPackageName); - } - } - - return new ColorDrawable(Color.TRANSPARENT); - } - // // Parcelable implementation // @@ -644,19 +496,16 @@ public final class PhoneAccount implements Parcelable { mSubscriptionAddress.writeToParcel(out, flags); } out.writeInt(mCapabilities); - out.writeInt(mIconResId); - out.writeString(mIconPackageName); - if (mIconBitmap == null) { - out.writeInt(0); - } else { - out.writeInt(1); - mIconBitmap.writeToParcel(out, flags); - } - out.writeInt(mIconTint); out.writeInt(mHighlightColor); out.writeCharSequence(mLabel); out.writeCharSequence(mShortDescription); out.writeStringList(mSupportedUriSchemes); + if (mIcon == null) { + out.writeInt(0); + } else { + out.writeInt(1); + mIcon.writeToParcel(out, flags); + } } public static final Creator<PhoneAccount> CREATOR @@ -689,18 +538,15 @@ public final class PhoneAccount implements Parcelable { mSubscriptionAddress = null; } mCapabilities = in.readInt(); - mIconResId = in.readInt(); - mIconPackageName = in.readString(); - if (in.readInt() > 0) { - mIconBitmap = Bitmap.CREATOR.createFromParcel(in); - } else { - mIconBitmap = null; - } - mIconTint = in.readInt(); mHighlightColor = in.readInt(); mLabel = in.readCharSequence(); mShortDescription = in.readCharSequence(); mSupportedUriSchemes = Collections.unmodifiableList(in.createStringArrayList()); + if (in.readInt() > 0) { + mIcon = Icon.CREATOR.createFromParcel(in); + } else { + mIcon = null; + } } @Override |