Methods Summary |
---|
private static int | bitToBnW(int bit)Decode one bit to a black and white color:
0 is black
1 is white
if(bit == 1){
return Color.WHITE;
} else {
return Color.BLACK;
}
|
public void | dispose()
mSimFH = null;
if (sThread != null) {
sThread.quit();
sThread = null;
}
mIconsCache = null;
sLoader = null;
|
static com.android.internal.telephony.cat.IconLoader | getInstance(android.os.Handler caller, com.android.internal.telephony.uicc.IccFileHandler fh)
if (sLoader != null) {
return sLoader;
}
if (fh != null) {
sThread = new HandlerThread("Cat Icon Loader");
sThread.start();
return new IconLoader(sThread.getLooper(), fh);
}
return null;
|
private static int | getMask(int numOfBits)Calculate bit mask for a given number of bits. The mask should enable to
make a bitwise and to the given number of bits.
int mask = 0x00;
switch (numOfBits) {
case 1:
mask = 0x01;
break;
case 2:
mask = 0x03;
break;
case 3:
mask = 0x07;
break;
case 4:
mask = 0x0F;
break;
case 5:
mask = 0x1F;
break;
case 6:
mask = 0x3F;
break;
case 7:
mask = 0x7F;
break;
case 8:
mask = 0xFF;
break;
}
return mask;
|
private boolean | handleImageDescriptor(byte[] rawData)Handles Image descriptor parsing and required processing. This is the
first step required to handle retrieving icons from the SIM.
mId = ImageDescriptor.parse(rawData, 1);
if (mId == null) {
return false;
}
return true;
|
public void | handleMessage(android.os.Message msg)
AsyncResult ar;
try {
switch (msg.what) {
case EVENT_READ_EF_IMG_RECOED_DONE:
ar = (AsyncResult) msg.obj;
if (handleImageDescriptor((byte[]) ar.result)) {
readIconData();
} else {
throw new Exception("Unable to parse image descriptor");
}
break;
case EVENT_READ_ICON_DONE:
CatLog.d(this, "load icon done");
ar = (AsyncResult) msg.obj;
byte[] rawData = ((byte[]) ar.result);
if (mId.mCodingScheme == ImageDescriptor.CODING_SCHEME_BASIC) {
mCurrentIcon = parseToBnW(rawData, rawData.length);
mIconsCache.put(mRecordNumber, mCurrentIcon);
postIcon();
} else if (mId.mCodingScheme == ImageDescriptor.CODING_SCHEME_COLOUR) {
mIconData = rawData;
readClut();
} else {
CatLog.d(this, "else /postIcon ");
postIcon();
}
break;
case EVENT_READ_CLUT_DONE:
ar = (AsyncResult) msg.obj;
byte [] clut = ((byte[]) ar.result);
mCurrentIcon = parseToRGB(mIconData, mIconData.length,
false, clut);
mIconsCache.put(mRecordNumber, mCurrentIcon);
postIcon();
break;
}
} catch (Exception e) {
CatLog.d(this, "Icon load failed");
// post null icon back to the caller.
postIcon();
}
|
void | loadIcon(int recordNumber, android.os.Message msg)
if (msg == null) {
return;
}
mEndMsg = msg;
mState = STATE_SINGLE_ICON;
startLoadingIcon(recordNumber);
|
void | loadIcons(int[] recordNumbers, android.os.Message msg)
if (recordNumbers == null || recordNumbers.length == 0 || msg == null) {
return;
}
mEndMsg = msg;
// initialize multi icons load variables.
mIcons = new Bitmap[recordNumbers.length];
mRecordNumbers = recordNumbers;
mCurrentRecordIndex = 0;
mState = STATE_MULTI_ICONS;
startLoadingIcon(recordNumbers[0]);
|
public static android.graphics.Bitmap | parseToBnW(byte[] data, int length)Convert a TS 131.102 image instance of code scheme '11' into Bitmap
int valueIndex = 0;
int width = data[valueIndex++] & 0xFF;
int height = data[valueIndex++] & 0xFF;
int numOfPixels = width*height;
int[] pixels = new int[numOfPixels];
int pixelIndex = 0;
int bitIndex = 7;
byte currentByte = 0x00;
while (pixelIndex < numOfPixels) {
// reassign data and index for every byte (8 bits).
if (pixelIndex % 8 == 0) {
currentByte = data[valueIndex++];
bitIndex = 7;
}
pixels[pixelIndex++] = bitToBnW((currentByte >> bitIndex-- ) & 0x01);
}
if (pixelIndex != numOfPixels) {
CatLog.d("IconLoader", "parseToBnW; size error");
}
return Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_8888);
|
public static android.graphics.Bitmap | parseToRGB(byte[] data, int length, boolean transparency, byte[] clut)a TS 131.102 image instance of code scheme '11' into color Bitmap
int valueIndex = 0;
int width = data[valueIndex++] & 0xFF;
int height = data[valueIndex++] & 0xFF;
int bitsPerImg = data[valueIndex++] & 0xFF;
int numOfClutEntries = data[valueIndex++] & 0xFF;
if (true == transparency) {
clut[numOfClutEntries - 1] = Color.TRANSPARENT;
}
int numOfPixels = width * height;
int[] pixels = new int[numOfPixels];
valueIndex = 6;
int pixelIndex = 0;
int bitsStartOffset = 8 - bitsPerImg;
int bitIndex = bitsStartOffset;
byte currentByte = data[valueIndex++];
int mask = getMask(bitsPerImg);
boolean bitsOverlaps = (8 % bitsPerImg == 0);
while (pixelIndex < numOfPixels) {
// reassign data and index for every byte (8 bits).
if (bitIndex < 0) {
currentByte = data[valueIndex++];
bitIndex = bitsOverlaps ? (bitsStartOffset) : (bitIndex * -1);
}
int clutEntry = ((currentByte >> bitIndex) & mask);
int clutIndex = clutEntry * CLUT_ENTRY_SIZE;
pixels[pixelIndex++] = Color.rgb(clut[clutIndex],
clut[clutIndex + 1], clut[clutIndex + 2]);
bitIndex -= bitsPerImg;
}
return Bitmap.createBitmap(pixels, width, height,
Bitmap.Config.ARGB_8888);
|
private void | postIcon()
if (mState == STATE_SINGLE_ICON) {
mEndMsg.obj = mCurrentIcon;
mEndMsg.sendToTarget();
} else if (mState == STATE_MULTI_ICONS) {
mIcons[mCurrentRecordIndex++] = mCurrentIcon;
// If not all icons were loaded, start loading the next one.
if (mCurrentRecordIndex < mRecordNumbers.length) {
startLoadingIcon(mRecordNumbers[mCurrentRecordIndex]);
} else {
mEndMsg.obj = mIcons;
mEndMsg.sendToTarget();
}
}
|
private void | readClut()
int length = mIconData[3] * CLUT_ENTRY_SIZE;
Message msg = obtainMessage(EVENT_READ_CLUT_DONE);
mSimFH.loadEFImgTransparent(mId.mImageId,
mIconData[CLUT_LOCATION_OFFSET],
mIconData[CLUT_LOCATION_OFFSET + 1], length, msg);
|
private void | readIconData()
Message msg = obtainMessage(EVENT_READ_ICON_DONE);
mSimFH.loadEFImgTransparent(mId.mImageId, 0, 0, mId.mLength ,msg);
|
private void | readId()
if (mRecordNumber < 0) {
mCurrentIcon = null;
postIcon();
return;
}
Message msg = obtainMessage(EVENT_READ_EF_IMG_RECOED_DONE);
mSimFH.loadEFImgLinearFixed(mRecordNumber, msg);
|
private void | startLoadingIcon(int recordNumber)
// Reset the load variables.
mId = null;
mIconData = null;
mCurrentIcon = null;
mRecordNumber = recordNumber;
// make sure the icon was not already loaded and saved in the local cache.
if (mIconsCache.containsKey(recordNumber)) {
mCurrentIcon = mIconsCache.get(recordNumber);
postIcon();
return;
}
// start the first phase ==> loading Image Descriptor.
readId();
|