|
Android example source code file (ValueParser.java)
The ValueParser.java Android example source code/* * Copyright (C) 2006-2007 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.android.internal.telephony.cat; import com.android.internal.telephony.GsmAlphabet; import com.android.internal.telephony.IccUtils; import com.android.internal.telephony.cat.Duration.TimeUnit; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; abstract class ValueParser { /** * Search for a Command Details object from a list. * * @param ctlvs List of ComprehensionTlv objects used for search * @return An CtlvCommandDetails object found from the objects. If no * Command Details object is found, ResultException is thrown. * @throws ResultException */ static CommandDetails retrieveCommandDetails(ComprehensionTlv ctlv) throws ResultException { CommandDetails cmdDet = new CommandDetails(); byte[] rawValue = ctlv.getRawValue(); int valueIndex = ctlv.getValueIndex(); try { cmdDet.compRequired = ctlv.isComprehensionRequired(); cmdDet.commandNumber = rawValue[valueIndex] & 0xff; cmdDet.typeOfCommand = rawValue[valueIndex + 1] & 0xff; cmdDet.commandQualifier = rawValue[valueIndex + 2] & 0xff; return cmdDet; } catch (IndexOutOfBoundsException e) { throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); } } /** * Search for a Device Identities object from a list. * * @param ctlvs List of ComprehensionTlv objects used for search * @return An CtlvDeviceIdentities object found from the objects. If no * Command Details object is found, ResultException is thrown. * @throws ResultException */ static DeviceIdentities retrieveDeviceIdentities(ComprehensionTlv ctlv) throws ResultException { DeviceIdentities devIds = new DeviceIdentities(); byte[] rawValue = ctlv.getRawValue(); int valueIndex = ctlv.getValueIndex(); try { devIds.sourceId = rawValue[valueIndex] & 0xff; devIds.destinationId = rawValue[valueIndex + 1] & 0xff; return devIds; } catch (IndexOutOfBoundsException e) { throw new ResultException(ResultCode.REQUIRED_VALUES_MISSING); } } /** * Retrieves Duration information from the Duration COMPREHENSION-TLV * object. * * @param ctlv A Text Attribute COMPREHENSION-TLV object * @return A Duration object * @throws ResultException */ static Duration retrieveDuration(ComprehensionTlv ctlv) throws ResultException { int timeInterval = 0; TimeUnit timeUnit = TimeUnit.SECOND; byte[] rawValue = ctlv.getRawValue(); int valueIndex = ctlv.getValueIndex(); try { timeUnit = TimeUnit.values()[(rawValue[valueIndex] & 0xff)]; timeInterval = rawValue[valueIndex + 1] & 0xff; } catch (IndexOutOfBoundsException e) { throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); } return new Duration(timeInterval, timeUnit); } /** * Retrieves Item information from the COMPREHENSION-TLV object. * * @param ctlv A Text Attribute COMPREHENSION-TLV object * @return An Item * @throws ResultException */ static Item retrieveItem(ComprehensionTlv ctlv) throws ResultException { Item item = null; byte[] rawValue = ctlv.getRawValue(); int valueIndex = ctlv.getValueIndex(); int length = ctlv.getLength(); if (length != 0) { int textLen = length - 1; try { int id = rawValue[valueIndex] & 0xff; String text = IccUtils.adnStringFieldToString(rawValue, valueIndex + 1, textLen); item = new Item(id, text); } catch (IndexOutOfBoundsException e) { throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); } } return item; } /** * Retrieves Item id information from the COMPREHENSION-TLV object. * * @param ctlv A Text Attribute COMPREHENSION-TLV object * @return An Item id * @throws ResultException */ static int retrieveItemId(ComprehensionTlv ctlv) throws ResultException { int id = 0; byte[] rawValue = ctlv.getRawValue(); int valueIndex = ctlv.getValueIndex(); try { id = rawValue[valueIndex] & 0xff; } catch (IndexOutOfBoundsException e) { throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); } return id; } /** * Retrieves icon id from an Icon Identifier COMPREHENSION-TLV object * * @param ctlv An Icon Identifier COMPREHENSION-TLV object * @return IconId instance * @throws ResultException */ static IconId retrieveIconId(ComprehensionTlv ctlv) throws ResultException { IconId id = new IconId(); byte[] rawValue = ctlv.getRawValue(); int valueIndex = ctlv.getValueIndex(); try { id.selfExplanatory = (rawValue[valueIndex++] & 0xff) == 0x00; id.recordNumber = rawValue[valueIndex] & 0xff; } catch (IndexOutOfBoundsException e) { throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); } return id; } /** * Retrieves item icons id from an Icon Identifier List COMPREHENSION-TLV * object * * @param ctlv An Item Icon List Identifier COMPREHENSION-TLV object * @return ItemsIconId instance * @throws ResultException */ static ItemsIconId retrieveItemsIconId(ComprehensionTlv ctlv) throws ResultException { CatLog.d("ValueParser", "retrieveItemsIconId:"); ItemsIconId id = new ItemsIconId(); byte[] rawValue = ctlv.getRawValue(); int valueIndex = ctlv.getValueIndex(); int numOfItems = ctlv.getLength() - 1; id.recordNumbers = new int[numOfItems]; try { // get icon self-explanatory id.selfExplanatory = (rawValue[valueIndex++] & 0xff) == 0x00; for (int index = 0; index < numOfItems;) { id.recordNumbers[index++] = rawValue[valueIndex++]; } } catch (IndexOutOfBoundsException e) { throw new ResultException(ResultCode.CMD_DATA_NOT_UNDERSTOOD); } return id; } /** * Retrieves text attribute information from the Text Attribute * COMPREHENSION-TLV object. * * @param ctlv A Text Attribute COMPREHENSION-TLV object * @return A list of TextAttribute objects * @throws ResultException */ static List<TextAttribute> retrieveTextAttribute(ComprehensionTlv ctlv) throws ResultException { ArrayList<TextAttribute> lst = new ArrayList Other Android examples (source code examples)Here is a short list of links related to this Android ValueParser.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.