am 6c37f374: Merge "PhoneAccounts include literal icon bitmap (1/4)" into lmp-mr1-dev
* commit '6c37f374b5d86c798f799ac498b806d948c77f97': PhoneAccounts include literal icon bitmap (1/4)
This commit is contained in:
@@ -28233,6 +28233,8 @@ package android.telecom {
|
|||||||
method public int getCapabilities();
|
method public int getCapabilities();
|
||||||
method public int getColor();
|
method public int getColor();
|
||||||
method public android.graphics.drawable.Drawable getIcon(android.content.Context);
|
method public android.graphics.drawable.Drawable getIcon(android.content.Context);
|
||||||
|
method public android.graphics.Bitmap getIconBitmap();
|
||||||
|
method public java.lang.String getIconPackageName();
|
||||||
method public int getIconResId();
|
method public int getIconResId();
|
||||||
method public java.lang.CharSequence getLabel();
|
method public java.lang.CharSequence getLabel();
|
||||||
method public java.lang.CharSequence getShortDescription();
|
method public java.lang.CharSequence getShortDescription();
|
||||||
@@ -28258,6 +28260,8 @@ package android.telecom {
|
|||||||
method public android.telecom.PhoneAccount.Builder setAddress(android.net.Uri);
|
method public android.telecom.PhoneAccount.Builder setAddress(android.net.Uri);
|
||||||
method public android.telecom.PhoneAccount.Builder setCapabilities(int);
|
method public android.telecom.PhoneAccount.Builder setCapabilities(int);
|
||||||
method public android.telecom.PhoneAccount.Builder setColor(int);
|
method public android.telecom.PhoneAccount.Builder setColor(int);
|
||||||
|
method public android.telecom.PhoneAccount.Builder setIconBitmap(android.graphics.Bitmap);
|
||||||
|
method public android.telecom.PhoneAccount.Builder setIconPackageName(java.lang.String);
|
||||||
method public android.telecom.PhoneAccount.Builder setIconResId(int);
|
method public android.telecom.PhoneAccount.Builder setIconResId(int);
|
||||||
method public android.telecom.PhoneAccount.Builder setShortDescription(java.lang.CharSequence);
|
method public android.telecom.PhoneAccount.Builder setShortDescription(java.lang.CharSequence);
|
||||||
method public android.telecom.PhoneAccount.Builder setSubscriptionAddress(android.net.Uri);
|
method public android.telecom.PhoneAccount.Builder setSubscriptionAddress(android.net.Uri);
|
||||||
|
|||||||
@@ -16,9 +16,14 @@
|
|||||||
|
|
||||||
package android.telecom;
|
package android.telecom;
|
||||||
|
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources.NotFoundException;
|
import android.content.res.Resources.NotFoundException;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
@@ -121,6 +126,8 @@ public class PhoneAccount implements Parcelable {
|
|||||||
private final Uri mSubscriptionAddress;
|
private final Uri mSubscriptionAddress;
|
||||||
private final int mCapabilities;
|
private final int mCapabilities;
|
||||||
private final int mIconResId;
|
private final int mIconResId;
|
||||||
|
private final String mIconPackageName;
|
||||||
|
private final Bitmap mIconBitmap;
|
||||||
private final int mColor;
|
private final int mColor;
|
||||||
private final CharSequence mLabel;
|
private final CharSequence mLabel;
|
||||||
private final CharSequence mShortDescription;
|
private final CharSequence mShortDescription;
|
||||||
@@ -135,6 +142,8 @@ public class PhoneAccount implements Parcelable {
|
|||||||
private Uri mSubscriptionAddress;
|
private Uri mSubscriptionAddress;
|
||||||
private int mCapabilities;
|
private int mCapabilities;
|
||||||
private int mIconResId;
|
private int mIconResId;
|
||||||
|
private String mIconPackageName;
|
||||||
|
private Bitmap mIconBitmap;
|
||||||
private int mColor = NO_COLOR;
|
private int mColor = NO_COLOR;
|
||||||
private CharSequence mLabel;
|
private CharSequence mLabel;
|
||||||
private CharSequence mShortDescription;
|
private CharSequence mShortDescription;
|
||||||
@@ -160,6 +169,8 @@ public class PhoneAccount implements Parcelable {
|
|||||||
mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
|
mSubscriptionAddress = phoneAccount.getSubscriptionAddress();
|
||||||
mCapabilities = phoneAccount.getCapabilities();
|
mCapabilities = phoneAccount.getCapabilities();
|
||||||
mIconResId = phoneAccount.getIconResId();
|
mIconResId = phoneAccount.getIconResId();
|
||||||
|
mIconPackageName = phoneAccount.getIconPackageName();
|
||||||
|
mIconBitmap = phoneAccount.getIconBitmap();
|
||||||
mColor = phoneAccount.getColor();
|
mColor = phoneAccount.getColor();
|
||||||
mLabel = phoneAccount.getLabel();
|
mLabel = phoneAccount.getLabel();
|
||||||
mShortDescription = phoneAccount.getShortDescription();
|
mShortDescription = phoneAccount.getShortDescription();
|
||||||
@@ -210,6 +221,34 @@ public class PhoneAccount implements Parcelable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the icon package name. See {@link PhoneAccount#getIconPackageName}.
|
||||||
|
*
|
||||||
|
* @param value The name of the package from which to load the icon.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
public Builder setIconPackageName(String value) {
|
||||||
|
this.mIconPackageName = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the icon bitmap. See {@link PhoneAccount#getIconBitmap}.
|
||||||
|
*
|
||||||
|
* @param value The icon bitmap.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
|
public Builder setIconBitmap(Bitmap value) {
|
||||||
|
this.mIconBitmap = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the color. See {@link PhoneAccount#getColor}.
|
||||||
|
*
|
||||||
|
* @param value The resource ID of the icon.
|
||||||
|
* @return The builder.
|
||||||
|
*/
|
||||||
public Builder setColor(int value) {
|
public Builder setColor(int value) {
|
||||||
this.mColor = value;
|
this.mColor = value;
|
||||||
return this;
|
return this;
|
||||||
@@ -274,6 +313,8 @@ public class PhoneAccount implements Parcelable {
|
|||||||
mSubscriptionAddress,
|
mSubscriptionAddress,
|
||||||
mCapabilities,
|
mCapabilities,
|
||||||
mIconResId,
|
mIconResId,
|
||||||
|
mIconPackageName,
|
||||||
|
mIconBitmap,
|
||||||
mColor,
|
mColor,
|
||||||
mLabel,
|
mLabel,
|
||||||
mShortDescription,
|
mShortDescription,
|
||||||
@@ -287,6 +328,8 @@ public class PhoneAccount implements Parcelable {
|
|||||||
Uri subscriptionAddress,
|
Uri subscriptionAddress,
|
||||||
int capabilities,
|
int capabilities,
|
||||||
int iconResId,
|
int iconResId,
|
||||||
|
String iconPackageName,
|
||||||
|
Bitmap iconBitmap,
|
||||||
int color,
|
int color,
|
||||||
CharSequence label,
|
CharSequence label,
|
||||||
CharSequence shortDescription,
|
CharSequence shortDescription,
|
||||||
@@ -296,6 +339,8 @@ public class PhoneAccount implements Parcelable {
|
|||||||
mSubscriptionAddress = subscriptionAddress;
|
mSubscriptionAddress = subscriptionAddress;
|
||||||
mCapabilities = capabilities;
|
mCapabilities = capabilities;
|
||||||
mIconResId = iconResId;
|
mIconResId = iconResId;
|
||||||
|
mIconPackageName = iconPackageName;
|
||||||
|
mIconBitmap = iconBitmap;
|
||||||
mColor = color;
|
mColor = color;
|
||||||
mLabel = label;
|
mLabel = label;
|
||||||
mShortDescription = shortDescription;
|
mShortDescription = shortDescription;
|
||||||
@@ -420,8 +465,13 @@ public class PhoneAccount implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The icon resource ID for the icon of this {@code PhoneAccount}. Telecom will search for the
|
* The icon resource ID for the icon of this {@code PhoneAccount}.
|
||||||
* icon using the package name specified in the {@link PhoneAccountHandle}.
|
* <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 #getIcon(Context)}.
|
||||||
*
|
*
|
||||||
* @return A resource ID.
|
* @return A resource ID.
|
||||||
*/
|
*/
|
||||||
@@ -429,6 +479,20 @@ public class PhoneAccount implements Parcelable {
|
|||||||
return mIconResId;
|
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 #getIcon(Context)}.
|
||||||
|
*
|
||||||
|
* @return A package name.
|
||||||
|
*/
|
||||||
|
public String getIconPackageName() {
|
||||||
|
return mIconPackageName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A highlight color to use in displaying information about this {@code PhoneAccount}.
|
* A highlight color to use in displaying information about this {@code PhoneAccount}.
|
||||||
*
|
*
|
||||||
@@ -439,35 +503,51 @@ public class PhoneAccount implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An icon to represent this {@code PhoneAccount} in a user interface.
|
* 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 #getIcon(Context)}.
|
||||||
|
*
|
||||||
|
* @return A bitmap.
|
||||||
|
*/
|
||||||
|
public Bitmap getIconBitmap() {
|
||||||
|
return mIconBitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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}.
|
* @return An icon for this {@code PhoneAccount}.
|
||||||
*/
|
*/
|
||||||
public Drawable getIcon(Context context) {
|
public Drawable getIcon(Context context) {
|
||||||
return getIcon(context, mIconResId);
|
if (mIconBitmap != null) {
|
||||||
}
|
return new BitmapDrawable(context.getResources(), mIconBitmap);
|
||||||
|
|
||||||
private Drawable getIcon(Context context, int resId) {
|
|
||||||
if (resId == 0) {
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Context packageContext;
|
if (mIconResId != 0) {
|
||||||
try {
|
String packageName = mIconPackageName == null
|
||||||
packageContext = context.createPackageContext(
|
? mAccountHandle.getComponentName().getPackageName()
|
||||||
mAccountHandle.getComponentName().getPackageName(), 0);
|
: mIconPackageName;
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
Log.w(this, "Cannot find package %s",
|
try {
|
||||||
mAccountHandle.getComponentName().getPackageName());
|
Context packageContext = context.createPackageContext(packageName, 0);
|
||||||
return null;
|
try {
|
||||||
}
|
return packageContext.getDrawable(mIconResId);
|
||||||
try {
|
} catch (NotFoundException | MissingResourceException e) {
|
||||||
return packageContext.getDrawable(resId);
|
Log.e(this, e, "Cannot find icon %d in package %s", mIconResId, packageName);
|
||||||
} catch (NotFoundException|MissingResourceException e) {
|
}
|
||||||
Log.e(this, e, "Cannot find icon %d in package %s",
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
resId, mAccountHandle.getComponentName().getPackageName());
|
Log.w(this, "Cannot find package %s", packageName);
|
||||||
return null;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new ColorDrawable(Color.TRANSPARENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -486,6 +566,8 @@ public class PhoneAccount implements Parcelable {
|
|||||||
out.writeParcelable(mSubscriptionAddress, 0);
|
out.writeParcelable(mSubscriptionAddress, 0);
|
||||||
out.writeInt(mCapabilities);
|
out.writeInt(mCapabilities);
|
||||||
out.writeInt(mIconResId);
|
out.writeInt(mIconResId);
|
||||||
|
out.writeString(mIconPackageName);
|
||||||
|
out.writeParcelable(mIconBitmap, 0);
|
||||||
out.writeInt(mColor);
|
out.writeInt(mColor);
|
||||||
out.writeCharSequence(mLabel);
|
out.writeCharSequence(mLabel);
|
||||||
out.writeCharSequence(mShortDescription);
|
out.writeCharSequence(mShortDescription);
|
||||||
@@ -513,6 +595,8 @@ public class PhoneAccount implements Parcelable {
|
|||||||
mSubscriptionAddress = in.readParcelable(getClass().getClassLoader());
|
mSubscriptionAddress = in.readParcelable(getClass().getClassLoader());
|
||||||
mCapabilities = in.readInt();
|
mCapabilities = in.readInt();
|
||||||
mIconResId = in.readInt();
|
mIconResId = in.readInt();
|
||||||
|
mIconPackageName = in.readString();
|
||||||
|
mIconBitmap = in.readParcelable(getClass().getClassLoader());
|
||||||
mColor = in.readInt();
|
mColor = in.readInt();
|
||||||
mLabel = in.readCharSequence();
|
mLabel = in.readCharSequence();
|
||||||
mShortDescription = in.readCharSequence();
|
mShortDescription = in.readCharSequence();
|
||||||
|
|||||||
Reference in New Issue
Block a user