use of android.util.SparseIntArray in project XobotOS by xamarin.
the class GsmAlphabet method stringToGsm8BitUnpackedField.
/**
* Write a String into a GSM 8-bit unpacked field of
* Field is padded with 0xff's, string is truncated if necessary
*
* @param s the string to encode
* @param dest the destination byte array
* @param offset the starting offset for the encoded string
* @param length the maximum number of bytes to write
*/
public static void stringToGsm8BitUnpackedField(String s, byte[] dest, int offset, int length) {
int outByteIndex = offset;
SparseIntArray charToLanguageTable = sCharsToGsmTables[0];
SparseIntArray charToShiftTable = sCharsToShiftTables[0];
// Septets are stored in byte-aligned octets
for (int i = 0, sz = s.length(); i < sz && (outByteIndex - offset) < length; i++) {
char c = s.charAt(i);
int v = charToLanguageTable.get(c, -1);
if (v == -1) {
v = charToShiftTable.get(c, -1);
if (v == -1) {
// fall back to ASCII space
v = charToLanguageTable.get(' ', ' ');
} else {
// make sure we can fit an escaped char
if (!(outByteIndex + 1 - offset < length)) {
break;
}
dest[outByteIndex++] = GSM_EXTENDED_ESCAPE;
}
}
dest[outByteIndex++] = (byte) v;
}
// pad with 0xff's
while ((outByteIndex - offset) < length) {
dest[outByteIndex++] = (byte) 0xff;
}
}
use of android.util.SparseIntArray in project XobotOS by xamarin.
the class GsmAlphabet method findGsmSeptetLimitIndex.
/**
* Returns the index into <code>s</code> of the first character
* after <code>limit</code> septets have been reached, starting at
* index <code>start</code>. This is used when dividing messages
* into units within the SMS message size limit.
*
* @param s source string
* @param start index of where to start counting septets
* @param limit maximum septets to include,
* e.g. <code>MAX_USER_DATA_SEPTETS</code>
* @param langTable the 7 bit character table to use (0 for default GSM 7-bit alphabet)
* @param langShiftTable the 7 bit shift table to use (0 for default GSM extension table)
* @return index of first character that won't fit, or the length
* of the entire string if everything fits
*/
public static int findGsmSeptetLimitIndex(String s, int start, int limit, int langTable, int langShiftTable) {
int accumulator = 0;
int size = s.length();
SparseIntArray charToLangTable = sCharsToGsmTables[langTable];
SparseIntArray charToLangShiftTable = sCharsToShiftTables[langShiftTable];
for (int i = start; i < size; i++) {
int encodedSeptet = charToLangTable.get(s.charAt(i), -1);
if (encodedSeptet == -1) {
encodedSeptet = charToLangShiftTable.get(s.charAt(i), -1);
if (encodedSeptet == -1) {
// char not found, assume we're replacing with space
accumulator++;
} else {
// escape character + shift table index
accumulator += 2;
}
} else {
accumulator++;
}
if (accumulator > limit) {
return i;
}
}
return size;
}
use of android.util.SparseIntArray in project XobotOS by xamarin.
the class TableRow method mapIndexAndColumns.
private void mapIndexAndColumns() {
if (mColumnToChildIndex == null) {
int virtualCount = 0;
final int count = getChildCount();
mColumnToChildIndex = new SparseIntArray();
final SparseIntArray columnToChild = mColumnToChildIndex;
for (int i = 0; i < count; i++) {
final View child = getChildAt(i);
final LayoutParams layoutParams = (LayoutParams) child.getLayoutParams();
if (layoutParams.column >= virtualCount) {
virtualCount = layoutParams.column;
}
for (int j = 0; j < layoutParams.span; j++) {
columnToChild.put(virtualCount++, i);
}
}
mNumColumns = virtualCount;
}
}
use of android.util.SparseIntArray in project android_frameworks_base by ResurrectionRemix.
the class ExifInterface method setTagDefinition.
/**
* Creates a new tag definition in this ExifInterface object for a given TID
* and default IFD. Creating a definition with the same TID and default IFD
* as a previous definition will override it.
*
* @param tagId the TID for the tag.
* @param defaultIfd the default IFD for the tag.
* @param tagType the type of the tag (see {@link ExifTag#getDataType()}).
* @param defaultComponentCount the number of elements of this tag's type in
* the tags value.
* @param allowedIfds the IFD's this tag is allowed to be put in.
* @return the defined tag constant (e.g. {@link #TAG_IMAGE_WIDTH}) or
* {@link #TAG_NULL} if the definition could not be made.
*/
public int setTagDefinition(short tagId, int defaultIfd, short tagType, short defaultComponentCount, int[] allowedIfds) {
if (sBannedDefines.contains(tagId)) {
return TAG_NULL;
}
if (ExifTag.isValidType(tagType) && ExifTag.isValidIfd(defaultIfd)) {
int tagDef = defineTag(defaultIfd, tagId);
if (tagDef == TAG_NULL) {
return TAG_NULL;
}
int[] otherDefs = getTagDefinitionsForTagId(tagId);
SparseIntArray infos = getTagInfo();
// Make sure defaultIfd is in allowedIfds
boolean defaultCheck = false;
for (int i : allowedIfds) {
if (defaultIfd == i) {
defaultCheck = true;
}
if (!ExifTag.isValidIfd(i)) {
return TAG_NULL;
}
}
if (!defaultCheck) {
return TAG_NULL;
}
int ifdFlags = getFlagsFromAllowedIfds(allowedIfds);
// Make sure no identical tags can exist in allowedIfds
if (otherDefs != null) {
for (int def : otherDefs) {
int tagInfo = infos.get(def);
int allowedFlags = getAllowedIfdFlagsFromInfo(tagInfo);
if ((ifdFlags & allowedFlags) != 0) {
return TAG_NULL;
}
}
}
getTagInfo().put(tagDef, ifdFlags << 24 | (tagType << 16) | defaultComponentCount);
return tagDef;
}
return TAG_NULL;
}
use of android.util.SparseIntArray in project android_frameworks_base by ResurrectionRemix.
the class ExifInterface method getTagDefinitionsForTagId.
protected int[] getTagDefinitionsForTagId(short tagId) {
int[] ifds = IfdData.getIfds();
int[] defs = new int[ifds.length];
int counter = 0;
SparseIntArray infos = getTagInfo();
for (int i : ifds) {
int def = defineTag(i, tagId);
if (infos.get(def) != DEFINITION_NULL) {
defs[counter++] = def;
}
}
if (counter == 0) {
return null;
}
return Arrays.copyOfRange(defs, 0, counter);
}
Aggregations