List of usage examples for android.util SparseArray SparseArray
public SparseArray()
From source file:com.althink.android.ossw.ble.ScanRecord.java
/** * Parse scan record bytes to {@link ScanRecord}. * <p>//from w w w. j a v a 2s . c o m * The format is defined in Bluetooth 4.1 specification, Volume 3, Part C, Section 11 and 18. * <p> * All numerical multi-byte entities and values shall use little-endian <strong>byte</strong> * order. * * @param scanRecord The scan record of Bluetooth LE advertisement and/or scan response. * @hide */ public static ScanRecord parseFromBytes(byte[] scanRecord) { if (scanRecord == null) { return null; } int currentPos = 0; int advertiseFlag = -1; List<ParcelUuid> serviceUuids = new ArrayList<ParcelUuid>(); String localName = null; int txPowerLevel = Integer.MIN_VALUE; SparseArray<byte[]> manufacturerData = new SparseArray<byte[]>(); Map<ParcelUuid, byte[]> serviceData = new ArrayMap<>(); try { while (currentPos < scanRecord.length) { // length is unsigned int. int length = scanRecord[currentPos++] & 0xFF; if (length == 0) { break; } // Note the length includes the length of the field type itself. int dataLength = length - 1; // fieldType is unsigned int. int fieldType = scanRecord[currentPos++] & 0xFF; switch (fieldType) { case DATA_TYPE_FLAGS: advertiseFlag = scanRecord[currentPos] & 0xFF; break; case DATA_TYPE_SERVICE_UUIDS_16_BIT_PARTIAL: case DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE: parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_16_BIT, serviceUuids); break; case DATA_TYPE_SERVICE_UUIDS_32_BIT_PARTIAL: case DATA_TYPE_SERVICE_UUIDS_32_BIT_COMPLETE: parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_32_BIT, serviceUuids); break; case DATA_TYPE_SERVICE_UUIDS_128_BIT_PARTIAL: case DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE: parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_128_BIT, serviceUuids); break; case DATA_TYPE_LOCAL_NAME_SHORT: case DATA_TYPE_LOCAL_NAME_COMPLETE: localName = new String(extractBytes(scanRecord, currentPos, dataLength)); break; case DATA_TYPE_TX_POWER_LEVEL: txPowerLevel = scanRecord[currentPos]; break; case DATA_TYPE_SERVICE_DATA: // The first two bytes of the service data are service data UUID in little // endian. The rest bytes are service data. int serviceUuidLength = BluetoothUuid.UUID_BYTES_16_BIT; byte[] serviceDataUuidBytes = extractBytes(scanRecord, currentPos, serviceUuidLength); ParcelUuid serviceDataUuid = BluetoothUuid.parseUuidFrom(serviceDataUuidBytes); byte[] serviceDataArray = extractBytes(scanRecord, currentPos + serviceUuidLength, dataLength - serviceUuidLength); serviceData.put(serviceDataUuid, serviceDataArray); break; case DATA_TYPE_MANUFACTURER_SPECIFIC_DATA: // The first two bytes of the manufacturer specific data are // manufacturer ids in little endian. int manufacturerId = ((scanRecord[currentPos + 1] & 0xFF) << 8) + (scanRecord[currentPos] & 0xFF); byte[] manufacturerDataBytes = extractBytes(scanRecord, currentPos + 2, dataLength - 2); manufacturerData.put(manufacturerId, manufacturerDataBytes); break; default: // Just ignore, we don't handle such data type. break; } currentPos += dataLength; } if (serviceUuids.isEmpty()) { serviceUuids = null; } return new ScanRecord(serviceUuids, manufacturerData, serviceData, advertiseFlag, txPowerLevel, localName, scanRecord); } catch (Exception e) { //Log.e(TAG, "unable to parse scan record: " + Arrays.toString(scanRecord)); // As the record is invalid, ignore all the parsed results for this packet // and return an empty record with raw scanRecord bytes in results return new ScanRecord(null, null, null, -1, Integer.MIN_VALUE, null, scanRecord); } }
From source file:io.github.clendy.leanback.widget.ViewsStateBundle.java
public final Bundle saveOnScreenView(Bundle bundle, View view, int id) { if (mSavePolicy != BaseGridView.SAVE_NO_CHILD) { String key = getSaveStatesKey(id); SparseArray<Parcelable> container = new SparseArray<Parcelable>(); view.saveHierarchyState(container); if (bundle == null) { bundle = new Bundle(); }//from w w w . j a v a 2 s . c o m bundle.putSparseParcelableArray(key, container); } return bundle; }
From source file:retrotooth.model.ScanRecord.java
/** * Parse scan record bytes to {@link ScanRecord}. * <p/>//from w w w .ja v a2s. co m * The format is defined in Bluetooth 4.1 specification, Volume 3, Part C, Section 11 and 18. * <p/> * All numerical multi-byte entities and values shall use little-endian <strong>byte</strong> * order. * * @param scanRecord The scan record of Bluetooth LE advertisement and/or scan response. * @hide */ public static ScanRecord parseFromBytes(byte[] scanRecord) { if (scanRecord == null) { return null; } int currentPos = 0; int advertiseFlag = -1; List<ParcelUuid> serviceUuids = new ArrayList<ParcelUuid>(); String localName = null; int txPowerLevel = Integer.MIN_VALUE; SparseArray<byte[]> manufacturerData = new SparseArray<byte[]>(); Map<ParcelUuid, byte[]> serviceData = new ArrayMap<ParcelUuid, byte[]>(); try { while (currentPos < scanRecord.length) { // length is unsigned int. int length = scanRecord[currentPos++] & 0xFF; if (length == 0) { break; } // Note the length includes the length of the field type itself. int dataLength = length - 1; // fieldType is unsigned int. int fieldType = scanRecord[currentPos++] & 0xFF; switch (fieldType) { case DATA_TYPE_FLAGS: advertiseFlag = scanRecord[currentPos] & 0xFF; break; case DATA_TYPE_SERVICE_UUIDS_16_BIT_PARTIAL: case DATA_TYPE_SERVICE_UUIDS_16_BIT_COMPLETE: parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_16_BIT, serviceUuids); break; case DATA_TYPE_SERVICE_UUIDS_32_BIT_PARTIAL: case DATA_TYPE_SERVICE_UUIDS_32_BIT_COMPLETE: parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_32_BIT, serviceUuids); break; case DATA_TYPE_SERVICE_UUIDS_128_BIT_PARTIAL: case DATA_TYPE_SERVICE_UUIDS_128_BIT_COMPLETE: parseServiceUuid(scanRecord, currentPos, dataLength, BluetoothUuid.UUID_BYTES_128_BIT, serviceUuids); break; case DATA_TYPE_LOCAL_NAME_SHORT: case DATA_TYPE_LOCAL_NAME_COMPLETE: localName = new String(extractBytes(scanRecord, currentPos, dataLength)); break; case DATA_TYPE_TX_POWER_LEVEL: txPowerLevel = scanRecord[currentPos]; break; case DATA_TYPE_SERVICE_DATA: // The first two bytes of the service data are service data UUID in little // endian. The rest bytes are service data. int serviceUuidLength = BluetoothUuid.UUID_BYTES_16_BIT; byte[] serviceDataUuidBytes = extractBytes(scanRecord, currentPos, serviceUuidLength); ParcelUuid serviceDataUuid = BluetoothUuid.parseUuidFrom(serviceDataUuidBytes); byte[] serviceDataArray = extractBytes(scanRecord, currentPos + serviceUuidLength, dataLength - serviceUuidLength); serviceData.put(serviceDataUuid, serviceDataArray); break; case DATA_TYPE_MANUFACTURER_SPECIFIC_DATA: // The first two bytes of the manufacturer specific data are // manufacturer ids in little endian. int manufacturerId = ((scanRecord[currentPos + 1] & 0xFF) << 8) + (scanRecord[currentPos] & 0xFF); byte[] manufacturerDataBytes = extractBytes(scanRecord, currentPos + 2, dataLength - 2); manufacturerData.put(manufacturerId, manufacturerDataBytes); break; default: // Just ignore, we don't handle such data type. break; } currentPos += dataLength; } if (serviceUuids.isEmpty()) { serviceUuids = null; } return new ScanRecord(serviceUuids, manufacturerData, serviceData, advertiseFlag, txPowerLevel, localName, scanRecord); } catch (Exception e) { Log.e(TAG, "unable to parse scan record: " + Arrays.toString(scanRecord)); // As the record is invalid, ignore all the parsed results for this packet // and return an empty record with raw scanRecord bytes in results return new ScanRecord(null, null, null, -1, Integer.MIN_VALUE, null, scanRecord); } }
From source file:com.bilibili.magicasakura.utils.TintManager.java
@Nullable public Drawable getDrawable(@DrawableRes int resId) { final Context context = mContextRef.get(); if (context == null) return null; if (resId == 0) return null; if (mSkipDrawableIdTags != null) { final String cachedTagName = mSkipDrawableIdTags.get(resId); if (SKIP_DRAWABLE_TAG.equals(cachedTagName)) { printLog("[Match Skip DrawableTag] Skip the drawable which is matched with the skip tag."); return null; }/*from w w w.j a v a2 s . co m*/ } else { // Create an id cache as we'll need one later mSkipDrawableIdTags = new SparseArray<>(); } // Try the cache first (if it exists) Drawable drawable = getCacheDrawable(context, resId); if (drawable == null) { drawable = DrawableUtils.createDrawable(context, resId); if (drawable != null && !(drawable instanceof ColorDrawable)) { if (addCachedDrawable(resId, drawable)) { printLog("[loadDrawable] Saved drawable to cache: " + context.getResources().getResourceName(resId)); } } } if (drawable == null) { mSkipDrawableIdTags.append(resId, SKIP_DRAWABLE_TAG); } return drawable; }
From source file:com.sim2dial.dialer.HistoryFragment.java
private void initLogsLists(List<LinphoneCallLog> logs) { mLogs = new SparseArray<List<LinphoneCallLog>>(); String[] keys = new String[logs.size()]; for (LinphoneCallLog log : logs) { String groupBy = getCorrespondentDisplayName(log); int key = -1; for (int k = 0; k < keys.length; k++) { if (keys[k] == null || keys[k].equals(groupBy)) { key = k;/* w ww . j ava2 s . c o m*/ keys[k] = groupBy; break; } } List<LinphoneCallLog> group = mLogs.get(key, new ArrayList<LinphoneCallLog>()); group.add(log); if (group.size() == 1) { mLogs.append(key, group); } } }
From source file:com.codetroopers.shakemytours.ui.activity.TripActivity.java
private void initAvailableColors() { mAvailableColors = new SparseArray<>(); mAvailableColors.put(0, getResources().getColor(R.color.map_marker_0)); mAvailableColors.put(1, getResources().getColor(R.color.map_marker_1)); mAvailableColors.put(2, getResources().getColor(R.color.map_marker_2)); mAvailableColors.put(3, getResources().getColor(R.color.map_marker_3)); mAvailableColors.put(4, getResources().getColor(R.color.map_marker_4)); }
From source file:com.fabernovel.alertevoirie.NewsActivity.java
@Override public void onRequestcompleted(int requestCode, Object result) { Log.d(Constants.PROJECT_TAG, "resp : " + result); //@formatter:off /**// ww w.j a v a 2s . com */ //@formatter:on try { JSONArray responses; responses = new JSONArray((String) result); response = responses.getJSONObject(0); SparseArray<JSONObject> events = new SparseArray<JSONObject>(); if (requestCode == AVService.REQUEST_JSON) { if (JsonData.VALUE_REQUEST_GET_USERS_ACTVITIES.equals(response.getString(JsonData.PARAM_REQUEST))) { lock = new Vector<Integer>(); logs = new SparseArray<JSONObject>(); logList = new TreeMap<String, JSONObject>(Collections.reverseOrder()); JSONArray incidentLog = response.getJSONObject(JsonData.PARAM_ANSWER) .getJSONArray(JsonData.PARAM_INCIDENT_LOG); for (int i = 0; i < incidentLog.length(); i++) { JSONObject job = incidentLog.getJSONObject(i); logs.put(job.getInt(JsonData.ANSWER_INCIDENT_ID), job); logList.put(job.getString(JsonData.PARAM_INCIDENT_DATE) + job.getLong(JsonData.ANSWER_INCIDENT_ID), job); } JSONArray items = new JSONArray(); JSONArray ongoingIncidents = response.getJSONObject(JsonData.PARAM_ANSWER) .getJSONObject(JsonData.PARAM_INCIDENTS).getJSONArray(JsonData.PARAM_ONGOING_INCIDENTS); for (int i = 0; i < ongoingIncidents.length(); i++) { JSONObject job = ongoingIncidents.getJSONObject(i); int key = job.getInt(JsonData.PARAM_INCIDENT_ID); if (logs.get(key) != null) { Log.d("AlerteVoirie_PM", "add ongoing incident " + key); events.put(key, job);// items.put(job); } } JSONArray updatedIncidents = response.getJSONObject(JsonData.PARAM_ANSWER) .getJSONObject(JsonData.PARAM_INCIDENTS).getJSONArray(JsonData.PARAM_UPDATED_INCIDENTS); for (int i = 0; i < updatedIncidents.length(); i++) { JSONObject job = updatedIncidents.getJSONObject(i); int key = job.getInt(JsonData.PARAM_INCIDENT_ID); if (logs.get(key) != null) { Log.d("AlerteVoirie_PM", "add updated incident " + key); events.put(key, job); } } JSONArray resolvedIncidents = response.getJSONObject(JsonData.PARAM_ANSWER) .getJSONObject(JsonData.PARAM_INCIDENTS) .getJSONArray(JsonData.PARAM_RESOLVED_INCIDENTS); for (int i = 0; i < resolvedIncidents.length(); i++) { JSONObject job = resolvedIncidents.getJSONObject(i); int key = job.getInt(JsonData.PARAM_INCIDENT_ID); if (logs.get(key) != null) { Log.d("AlerteVoirie_PM", "add resolved incident " + key); events.put(key, job); } } for (JSONObject log : logList.values()) { int id = log.getInt(JsonData.ANSWER_INCIDENT_ID); Log.d("AlerteVoirie_PM", "key bug " + id); JSONObject jsonObject = events.get(id); if (jsonObject != null) { String json = jsonObject.toString(); JSONObject job = new JSONObject(json); job.put(JsonData.PARAM_INCIDENT_DATE, log.getString(JsonData.PARAM_INCIDENT_DATE)); items.put(job); if (JsonData.PARAM_UPDATE_INCIDENT_INVALID.equals(log.getString(JsonData.PARAM_STATUS)) || JsonData.PARAM_UPDATE_INCIDENT_RESOLVED .equals(log.getString(JsonData.PARAM_STATUS))) { lock.add(id); } } } setListAdapter(new MagicAdapter(this, items, R.layout.cell_report, new String[] { JsonData.PARAM_INCIDENT_DESCRIPTION, JsonData.PARAM_INCIDENT_ADDRESS }, new int[] { R.id.TextView_title, R.id.TextView_text }, null)); } } } catch (JSONException e) { Log.e(Constants.PROJECT_TAG, "error in onRequestcompleted : ", e); } catch (ClassCastException e) { Log.e(Constants.PROJECT_TAG, "error in onRequestcompleted : CLasscastException", e); } catch (NullPointerException e) { Log.e(Constants.PROJECT_TAG, "error in onRequestcompleted : NullPointerException", e); } finally { if (requestCode == AVService.REQUEST_JSON) dismissDialog(DIALOG_PROGRESS); } }
From source file:com.svpino.longhorn.fragments.StockListFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true);/*from ww w .ja v a2 s .c om*/ this.selectedTiles = new ArrayList<Integer>(); this.tiles = new SparseArray<View>(); }
From source file:android.support.design.internal.NavigationMenuPresenter.java
@Override public Parcelable onSaveInstanceState() { if (Build.VERSION.SDK_INT >= 11) { // API 9-10 does not support ClassLoaderCreator, therefore things can crash if they're // loaded via different loaders. Rather than crash we just won't save state on those // platforms final Bundle state = new Bundle(); if (mMenuView != null) { SparseArray<Parcelable> hierarchy = new SparseArray<>(); mMenuView.saveHierarchyState(hierarchy); state.putSparseParcelableArray(STATE_HIERARCHY, hierarchy); }/*from w w w . java2s .c o m*/ if (mAdapter != null) { state.putBundle(STATE_ADAPTER, mAdapter.createInstanceState()); } if (mHeaderLayout != null) { SparseArray<Parcelable> header = new SparseArray<>(); mHeaderLayout.saveHierarchyState(header); state.putSparseParcelableArray(STATE_HEADER, header); } return state; } return null; }
From source file:ru.gkpromtech.exhibition.organizations.OrganizationsPagerFragment.java
private void fillItems(int maxItemsPerView) { DbHelper db = DbHelper.getInstance(getActivity()); mItems = new ArrayList<>(); Table<Organization> organizationsTable = db.getTableFor(Organization.class); try {/*from w ww .ja v a 2s . c o m*/ List<Pair<Entity[], Organization>> placesOrganizations; if (mType == GROUPED) { placesOrganizations = organizationsTable.selectJoined( new Table.Join[] { new Table.Join("id", PlacesOrganization.class, "organizationid"), new Table.Join(Place.class, "f1.id = f0.placeid"), new Table.Join(Group.class, "f2.id = f1.groupid") }, null, null, "f2.sortorder, t.fullname"); } else { placesOrganizations = organizationsTable.selectJoined( new Table.Join[] { new Table.Join("id", PlacesOrganization.class, "organizationid", "LEFT"), new Table.Join(Place.class, "f1.id = f0.placeid", "LEFT"), new Table.Join(Group.class, "f2.id = f1.groupid", "LEFT") }, null, null, "t.fullname"); } String lastTitle = null; int pos = 0; SparseArray<OrganizationsFragment.Item> itemsCache = new SparseArray<>(); for (Pair<Entity[], Organization> res : placesOrganizations) { Place place = (Place) res.first[1]; Organization organization = res.second; Group group = (Group) res.first[2]; OrganizationsFragment.Item item = null; if (mType == GROUPED) { if (!group.name.equals(lastTitle)) { if (mGroupId != null && mGroupPosition == -1 && mGroupId.equals(group.position)) mGroupPosition = pos; if (!mSingle || mItems.isEmpty()) mItems.add(new ArrayList<OrganizationsFragment.Item>()); mItems.get(mItems.size() - 1).add(new OrganizationsFragment.Item(group.name)); ++pos; lastTitle = group.name; } } else { if (mItems.isEmpty() || (!mSingle && pos == maxItemsPerView)) { mItems.add(new ArrayList<OrganizationsFragment.Item>()); pos = 0; } item = itemsCache.get(organization.id); } if (item == null) { item = new OrganizationsFragment.Item(group, place, organization); item.placesStr = place.name; mItems.get(mItems.size() - 1).add(item); itemsCache.put(organization.id, item); } else { if (item.addPlaces == null) item.addPlaces = new ArrayList<>(); item.addPlaces.add(place); item.placesStr += ", " + place.name; } ++pos; } } catch (Exception e) { e.printStackTrace(); } }