Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bc1d9755 authored by Stuart Scott's avatar Stuart Scott Committed by Android Git Automerger
Browse files

am 0e58219f: am 90cf41c3: Merge "SubInfoRecord provides a tinted icon with the...

am 0e58219f: am 90cf41c3: Merge "SubInfoRecord provides a tinted icon with the initial embossed." into lmp-mr1-dev

* commit '0e58219f':
  SubInfoRecord provides a tinted icon with the initial embossed.
parents 83892ecb 0e58219f
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -28870,12 +28870,12 @@ package android.telephony {
  }
  }
  public class SubInfoRecord implements android.os.Parcelable {
  public class SubInfoRecord implements android.os.Parcelable {
    method public android.graphics.Bitmap createIconBitmap(android.content.Context);
    method public int describeContents();
    method public int describeContents();
    method public int getColor();
    method public int getDataRoaming();
    method public int getDataRoaming();
    method public java.lang.CharSequence getDisplayName();
    method public java.lang.CharSequence getDisplayName();
    method public java.lang.String getIccId();
    method public java.lang.String getIccId();
    method public android.graphics.drawable.BitmapDrawable getIcon();
    method public int getIconTint();
    method public int getMcc();
    method public int getMcc();
    method public int getMnc();
    method public int getMnc();
    method public int getNameSource();
    method public int getNameSource();
+72 −52
Original line number Original line Diff line number Diff line
@@ -16,7 +16,15 @@


package android.telephony;
package android.telephony;


import android.graphics.drawable.BitmapDrawable;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;


@@ -59,9 +67,9 @@ public class SubInfoRecord implements Parcelable {
    private int mNameSource;
    private int mNameSource;


    /**
    /**
     * The color to be used for when displaying to the user
     * The color to be used for tinting the icon when displaying to the user
     */
     */
    private int mColor;
    private int mIconTint;


    /**
    /**
     * A number presented to the user identify this subscription
     * A number presented to the user identify this subscription
@@ -74,9 +82,9 @@ public class SubInfoRecord implements Parcelable {
    private int mDataRoaming;
    private int mDataRoaming;


    /**
    /**
     * SIM Icon resource identifiers. FIXME: Check with MTK what it really is
     * SIM Icon bitmap
     */
     */
    private int[] mSimIconRes;
    private Bitmap mIconBitmap;


    /**
    /**
     * Mobile Country Code
     * Mobile Country Code
@@ -88,40 +96,22 @@ public class SubInfoRecord implements Parcelable {
     */
     */
    private int mMnc;
    private int mMnc;


    /**
     * @hide
    public SubInfoRecord() {
        this.mId = SubscriptionManager.INVALID_SUB_ID;
        this.mIccId = "";
        this.mSimSlotIndex = SubscriptionManager.INVALID_SLOT_ID;
        this.mDisplayName = "";
        this.mCarrierName = "";
        this.mNameSource = 0;
        this.mColor = 0;
        this.mNumber = "";
        this.mDataRoaming = 0;
        this.mSimIconRes = new int[2];
        this.mMcc = 0;
        this.mMnc = 0;
    }
     */

    /**
    /**
     * @hide
     * @hide
     */
     */
    public SubInfoRecord(int id, String iccId, int simSlotIndex, CharSequence displayName,
    public SubInfoRecord(int id, String iccId, int simSlotIndex, CharSequence displayName,
            CharSequence carrierName, int nameSource, int color, String number, int roaming,
            CharSequence carrierName, int nameSource, int iconTint, String number, int roaming,
            int[] iconRes, int mcc, int mnc) {
            Bitmap icon, int mcc, int mnc) {
        this.mId = id;
        this.mId = id;
        this.mIccId = iccId;
        this.mIccId = iccId;
        this.mSimSlotIndex = simSlotIndex;
        this.mSimSlotIndex = simSlotIndex;
        this.mDisplayName = displayName;
        this.mDisplayName = displayName;
        this.mCarrierName = carrierName;
        this.mCarrierName = carrierName;
        this.mNameSource = nameSource;
        this.mNameSource = nameSource;
        this.mColor = color;
        this.mIconTint = iconTint;
        this.mNumber = number;
        this.mNumber = number;
        this.mDataRoaming = roaming;
        this.mDataRoaming = roaming;
        this.mSimIconRes = iconRes;
        this.mIconBitmap = icon;
        this.mMcc = mcc;
        this.mMcc = mcc;
        this.mMnc = mnc;
        this.mMnc = mnc;
    }
    }
@@ -187,21 +177,58 @@ public class SubInfoRecord implements Parcelable {
    }
    }


    /**
    /**
     * Return the color to be used for when displaying to the user. This is the value of the color.
     * Creates and returns an icon {@code Bitmap} to represent this {@code SubInfoRecord} in a user
     * ex: 0x00ff00
     * interface.
     *
     * @param context A {@code Context} to get the {@code DisplayMetrics}s from.
     *
     * @return A bitmap icon for this {@code SubInfoRecord}.
     */
    public Bitmap createIconBitmap(Context context) {
        int width = mIconBitmap.getWidth();
        int height = mIconBitmap.getHeight();

        // Create a new bitmap of the same size because it will be modified.
        Bitmap workingBitmap = Bitmap.createBitmap(context.getResources().getDisplayMetrics(),
                width, height, mIconBitmap.getConfig());

        Canvas canvas = new Canvas(workingBitmap);
        Paint paint = new Paint();

        // Tint the icon with the color.
        paint.setColorFilter(new PorterDuffColorFilter(mIconTint, PorterDuff.Mode.SRC_ATOP));
        canvas.drawBitmap(mIconBitmap, 0, 0, paint);
        paint.setColorFilter(null);

        // Write the sim slot index.
        paint.setTypeface(Typeface.create("sans-serif", Typeface.NORMAL));
        paint.setColor(Color.WHITE);
        paint.setTextSize(12);
        final String index = Integer.toString(mSimSlotIndex);
        final Rect textBound = new Rect();
        paint.getTextBounds(index, 0, 1, textBound);
        final float xOffset = (width / 2.f) - textBound.centerX();
        final float yOffset = (height / 2.f) - textBound.centerY();
        canvas.drawText(index, xOffset, yOffset, paint);

        return workingBitmap;
    }

    /**
     * A highlight color to use in displaying information about this {@code PhoneAccount}.
     *
     * @return A hexadecimal color value.
     */
     */
    public int getColor() {
    public int getIconTint() {
        // Note: This color is currently an index into a list of drawables, but this is soon to
        return mIconTint;
        // change.
        return this.mColor;
    }
    }


    /**
    /**
     * Sets the color displayed to the user that identifies this subscription
     * Sets the color displayed to the user that identifies this subscription
     * @hide
     * @hide
     */
     */
    public void setColor(int color) {
    public void setIconTint(int iconTint) {
        this.mColor = color;
        this.mIconTint = iconTint;
    }
    }


    /**
    /**
@@ -218,13 +245,6 @@ public class SubInfoRecord implements Parcelable {
        return this.mDataRoaming;
        return this.mDataRoaming;
    }
    }


    /**
     * Return the icon used to identify this subscription.
     */
    public BitmapDrawable getIcon() {
        return new BitmapDrawable();
    }

    /**
    /**
     * Returns the MCC.
     * Returns the MCC.
     */
     */
@@ -248,16 +268,15 @@ public class SubInfoRecord implements Parcelable {
            CharSequence displayName = source.readCharSequence();
            CharSequence displayName = source.readCharSequence();
            CharSequence carrierName = source.readCharSequence();
            CharSequence carrierName = source.readCharSequence();
            int nameSource = source.readInt();
            int nameSource = source.readInt();
            int color = source.readInt();
            int iconTint = source.readInt();
            String number = source.readString();
            String number = source.readString();
            int dataRoaming = source.readInt();
            int dataRoaming = source.readInt();
            int[] iconRes = new int[2];
            source.readIntArray(iconRes);
            int mcc = source.readInt();
            int mcc = source.readInt();
            int mnc = source.readInt();
            int mnc = source.readInt();
            Bitmap iconBitmap = Bitmap.CREATOR.createFromParcel(source);


            return new SubInfoRecord(id, iccId, simSlotIndex, displayName, carrierName,
            return new SubInfoRecord(id, iccId, simSlotIndex, displayName, carrierName, nameSource,
                    nameSource, color, number, dataRoaming, iconRes, mcc, mnc);
                    iconTint, number, dataRoaming, iconBitmap, mcc, mnc);
        }
        }


        @Override
        @Override
@@ -274,12 +293,12 @@ public class SubInfoRecord implements Parcelable {
        dest.writeCharSequence(mDisplayName);
        dest.writeCharSequence(mDisplayName);
        dest.writeCharSequence(mCarrierName);
        dest.writeCharSequence(mCarrierName);
        dest.writeInt(mNameSource);
        dest.writeInt(mNameSource);
        dest.writeInt(mColor);
        dest.writeInt(mIconTint);
        dest.writeString(mNumber);
        dest.writeString(mNumber);
        dest.writeInt(mDataRoaming);
        dest.writeInt(mDataRoaming);
        dest.writeIntArray(mSimIconRes);
        dest.writeInt(mMcc);
        dest.writeInt(mMcc);
        dest.writeInt(mMnc);
        dest.writeInt(mMnc);
        mIconBitmap.writeToParcel(dest, flags);
    }
    }


    @Override
    @Override
@@ -290,8 +309,9 @@ public class SubInfoRecord implements Parcelable {
    @Override
    @Override
    public String toString() {
    public String toString() {
        return "{id=" + mId + ", iccId=" + mIccId + " simSlotIndex=" + mSimSlotIndex
        return "{id=" + mId + ", iccId=" + mIccId + " simSlotIndex=" + mSimSlotIndex
                + " displayName=" + mDisplayName + " carrierName=" + mCarrierName + " nameSource=" + mNameSource + " color=" + mColor
                + " displayName=" + mDisplayName + " carrierName=" + mCarrierName
                + " number=" + mNumber + " dataRoaming=" + mDataRoaming + " simIconRes=" + mSimIconRes
                + " nameSource=" + mNameSource + " iconTint=" + mIconTint + " number=" + mNumber
                + " mcc " + mMcc + " mnc " + mMnc + "}";
                + " dataRoaming=" + mDataRoaming + " iconBitmap=" + mIconBitmap + " mcc " + mMcc
                + " mnc " + mMnc + "}";
    }
    }
}
}
+6 −68
Original line number Original line Diff line number Diff line
@@ -246,13 +246,6 @@ public class SubscriptionManager implements BaseColumns {
     */
     */
    public static final String MNC = "mnc";
    public static final String MNC = "mnc";



    private static final int RES_TYPE_BACKGROUND_DARK = 0;

    private static final int RES_TYPE_BACKGROUND_LIGHT = 1;

    private static final int[] sSimBackgroundDarkRes = setSimResource(RES_TYPE_BACKGROUND_DARK);

    /**
    /**
     * Broadcast Action: The user has changed one of the default subs related to
     * Broadcast Action: The user has changed one of the default subs related to
     * data, phone calls, or sms</p>
     * data, phone calls, or sms</p>
@@ -476,17 +469,16 @@ public class SubscriptionManager implements BaseColumns {
    }
    }


    /**
    /**
     * Set SIM color by simInfo index
     * Set SIM icon tint color by simInfo index
     * @param color the rgb value of color of the SIM
     * @param tint the rgb value of icon tint color of the SIM
     * @param subId the unique SubInfoRecord index in database
     * @param subId the unique SubInfoRecord index in database
     * @return the number of records updated
     * @return the number of records updated
     * @hide
     * @hide
     */
     */
    public static int setColor(int color, int subId) {
    public static int setIconTint(int tint, int subId) {
        if (VDBG) logd("[setColor]+ color:" + color + " subId:" + subId);
        if (VDBG) logd("[setIconTint]+ tint:" + tint + " subId:" + subId);
        int size = sSimBackgroundDarkRes.length;
        if (!isValidSubId(subId)) {
        if (!isValidSubId(subId)) {
            logd("[setColor]- fail");
            logd("[setIconTint]- fail");
            return -1;
            return -1;
        }
        }


@@ -495,7 +487,7 @@ public class SubscriptionManager implements BaseColumns {
        try {
        try {
            ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
            ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
            if (iSub != null) {
            if (iSub != null) {
                result = iSub.setColor(color, subId);
                result = iSub.setIconTint(tint, subId);
            }
            }
        } catch (RemoteException ex) {
        } catch (RemoteException ex) {
            // ignore it
            // ignore it
@@ -578,35 +570,6 @@ public class SubscriptionManager implements BaseColumns {


    }
    }


    /**
     * Set number display format. 0: none, 1: the first four digits, 2: the last four digits
     * @param format the display format of phone number
     * @param subId the unique SubInfoRecord index in database
     * @return the number of records updated
     * @hide
     */
    public static int setDisplayNumberFormat(int format, int subId) {
        if (VDBG) logd("[setDisplayNumberFormat]+ format:" + format + " subId:" + subId);
        if (format < 0 || !isValidSubId(subId)) {
            logd("[setDisplayNumberFormat]- fail, return -1");
            return -1;
        }

        int result = 0;

        try {
            ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
            if (iSub != null) {
                result = iSub.setDisplayNumberFormat(format, subId);
            }
        } catch (RemoteException ex) {
            // ignore it
        }

        return result;

    }

    /**
    /**
     * Set data roaming by simInfo index
     * Set data roaming by simInfo index
     * @param roaming 0:Don't allow data when roaming, 1:Allow data when roaming
     * @param roaming 0:Don't allow data when roaming, 1:Allow data when roaming
@@ -704,31 +667,6 @@ public class SubscriptionManager implements BaseColumns {


    }
    }


    private static int[] setSimResource(int type) {
        int[] simResource = null;

        switch (type) {
            case RES_TYPE_BACKGROUND_DARK:
                simResource = new int[] {
                    com.android.internal.R.drawable.sim_dark_blue,
                    com.android.internal.R.drawable.sim_dark_orange,
                    com.android.internal.R.drawable.sim_dark_green,
                    com.android.internal.R.drawable.sim_dark_purple
                };
                break;
            case RES_TYPE_BACKGROUND_LIGHT:
                simResource = new int[] {
                    com.android.internal.R.drawable.sim_light_blue,
                    com.android.internal.R.drawable.sim_light_orange,
                    com.android.internal.R.drawable.sim_light_green,
                    com.android.internal.R.drawable.sim_light_purple
                };
                break;
        }

        return simResource;
    }

    private static void logd(String msg) {
    private static void logd(String msg) {
        Rlog.d(LOG_TAG, "[SubManager] " + msg);
        Rlog.d(LOG_TAG, "[SubManager] " + msg);
    }
    }
+3 −11
Original line number Original line Diff line number Diff line
@@ -74,12 +74,12 @@ interface ISub {
    int addSubInfoRecord(String iccId, int slotId);
    int addSubInfoRecord(String iccId, int slotId);


    /**
    /**
     * Set SIM color by simInfo index
     * Set SIM icon tint color by simInfo index
     * @param color the color of the SIM
     * @param tint the icon tint color of the SIM
     * @param subId the unique SubInfoRecord index in database
     * @param subId the unique SubInfoRecord index in database
     * @return the number of records updated
     * @return the number of records updated
     */
     */
    int setColor(int color, int subId);
    int setIconTint(int tint, int subId);


    /**
    /**
     * Set display name by simInfo index
     * Set display name by simInfo index
@@ -106,14 +106,6 @@ interface ISub {
     */
     */
    int setDisplayNumber(String number, int subId);
    int setDisplayNumber(String number, int subId);


    /**
     * Set number display format. 0: none, 1: the first four digits, 2: the last four digits
     * @param format the display format of phone number
     * @param subId the unique SubInfoRecord index in database
     * @return the number of records updated
     */
    int setDisplayNumberFormat(int format, int subId);

    /**
    /**
     * Set data roaming by simInfo index
     * Set data roaming by simInfo index
     * @param roaming 0:Don't allow data when roaming, 1:Allow data when roaming
     * @param roaming 0:Don't allow data when roaming, 1:Allow data when roaming