Search in sources :

Example 16 with SparseArray

use of android.util.SparseArray in project KeepScore by nolanlawson.

the class GameDBHelper method findAllGameSummaries.

public List<GameSummary> findAllGameSummaries() {
    synchronized (GameDBHelper.class) {
        String[] columns = { "g." + COLUMN_ID, "g." + COLUMN_NAME, "g." + COLUMN_DATE_SAVED, // and put it into the proper order, since group_concat is always unordered in sqlite
        "group_concat((ps.name || '" + GROUP_CONCAT_INNER_SEPARATOR + "' || ps.playerNumber), '" + GROUP_CONCAT_SEPARATOR + "')", // num rounds
        "max(length(ps.history) - length(replace(ps.history, ',', '')) + 1)" };
        String table = TABLE_GAMES + " g join " + TABLE_PLAYER_SCORES + " ps " + " on g." + COLUMN_ID + " = ps." + COLUMN_GAME_ID;
        String groupBy = "g." + COLUMN_ID;
        Cursor cursor = null;
        try {
            cursor = db.query(table, columns, null, null, groupBy, null, null);
            List<GameSummary> result = new ArrayList<GameSummary>();
            // re-use sparse array for performance
            SparseArray<String> playerNumbersToNames = new SparseArray<String>();
            while (cursor.moveToNext()) {
                GameSummary gameSummary = new GameSummary();
                gameSummary.setId(cursor.getInt(0));
                gameSummary.setName(cursor.getString(1));
                gameSummary.setDateSaved(cursor.getLong(2));
                String playerNumbersAndNames = cursor.getString(3);
                // sort by player number, get player names in order (no way to do this in sqlite, unfortunately)
                playerNumbersToNames.clear();
                for (String playerNumberAndName : StringUtil.split(playerNumbersAndNames, GROUP_CONCAT_SEPARATOR)) {
                    int idx = playerNumberAndName.indexOf(GROUP_CONCAT_INNER_SEPARATOR);
                    String playerName = playerNumberAndName.substring(0, idx);
                    int playerNumber = Integer.parseInt(playerNumberAndName.substring(idx + GROUP_CONCAT_INNER_SEPARATOR.length()));
                    playerNumbersToNames.put(playerNumber, playerName);
                }
                List<String> playerNames = new ArrayList<String>(playerNumbersToNames.size());
                for (int i = 0, len = playerNumbersToNames.size(); i < len; i++) {
                    int playerNumber = playerNumbersToNames.keyAt(i);
                    playerNames.add(playerNumbersToNames.get(playerNumber));
                }
                gameSummary.setPlayerNames(playerNames);
                gameSummary.setNumRounds(cursor.getInt(4));
                result.add(gameSummary);
            }
            return result;
        } finally {
            if (cursor != null) {
                cursor.close();
            }
        }
    }
}
Also used : SparseArray(android.util.SparseArray) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Example 17 with SparseArray

use of android.util.SparseArray in project instant-adapter by ragunathjawahar.

the class InstantAdapterCore method createNewView.

/**
     * Create a new view by inflating the associated XML layout.
     * 
     * @param context The {@link Context} to use.
     * @param parent The inflated view's parent.
     * @return The {@link View} that was inflated from the layout.
     */
public final View createNewView(final Context context, final ViewGroup parent) {
    View view = mLayoutInflater.inflate(mLayoutResourceId, parent, false);
    SparseArray<Holder> holders = new SparseArray<Holder>();
    int size = mViewIdsAndMetaCache.size();
    for (int i = 0; i < size; i++) {
        int viewId = mViewIdsAndMetaCache.keyAt(i);
        Meta meta = mViewIdsAndMetaCache.get(viewId);
        View viewFromLayout = view.findViewById(viewId);
        if (viewFromLayout == null) {
            String message = String.format("Cannot find View, check the 'viewId' " + "attribute on method %s.%s()", mDataType.getName(), meta.method.getName());
            throw new IllegalStateException(message);
        }
        holders.append(viewId, new Holder(viewFromLayout, meta));
        mAnnotatedViewIds.add(viewId);
    }
    view.setTag(mLayoutResourceId, holders);
    return view;
}
Also used : SparseArray(android.util.SparseArray) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 18 with SparseArray

use of android.util.SparseArray in project platform_frameworks_base by android.

the class ActivityManagerService method findProcessLocked.

private ProcessRecord findProcessLocked(String process, int userId, String callName) {
    userId = mUserController.handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(), userId, true, ALLOW_FULL_ONLY, callName, null);
    ProcessRecord proc = null;
    try {
        int pid = Integer.parseInt(process);
        synchronized (mPidsSelfLocked) {
            proc = mPidsSelfLocked.get(pid);
        }
    } catch (NumberFormatException e) {
    }
    if (proc == null) {
        ArrayMap<String, SparseArray<ProcessRecord>> all = mProcessNames.getMap();
        SparseArray<ProcessRecord> procs = all.get(process);
        if (procs != null && procs.size() > 0) {
            proc = procs.valueAt(0);
            if (userId != UserHandle.USER_ALL && proc.userId != userId) {
                for (int i = 1; i < procs.size(); i++) {
                    ProcessRecord thisProc = procs.valueAt(i);
                    if (thisProc.userId == userId) {
                        proc = thisProc;
                        break;
                    }
                }
            }
        }
    }
    return proc;
}
Also used : SparseArray(android.util.SparseArray) Point(android.graphics.Point)

Example 19 with SparseArray

use of android.util.SparseArray in project platform_frameworks_base by android.

the class ModelBackedDocumentsAdapter method hide.

@Override
public SparseArray<String> hide(String... ids) {
    if (DEBUG)
        Log.d(TAG, "Hiding ids: " + ids);
    Set<String> toHide = Sets.newHashSet(ids);
    // Proceed backwards through the list of items, because each removal causes the
    // positions of all subsequent items to change.
    SparseArray<String> hiddenItems = new SparseArray<>();
    for (int i = mModelIds.size() - 1; i >= 0; --i) {
        String id = mModelIds.get(i);
        if (toHide.contains(id)) {
            mHiddenIds.add(id);
            hiddenItems.put(i, mModelIds.remove(i));
            notifyItemRemoved(i);
        }
    }
    return hiddenItems;
}
Also used : SparseArray(android.util.SparseArray) DocumentInfo.getCursorString(com.android.documentsui.model.DocumentInfo.getCursorString)

Example 20 with SparseArray

use of android.util.SparseArray in project platform_frameworks_base by android.

the class ScanRecord method parseFromBytes.

/**
     * Parse scan record bytes to {@link ScanRecord}.
     * <p>
     * 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));
        // and return an empty record with raw scanRecord bytes in results
        return new ScanRecord(null, null, null, -1, Integer.MIN_VALUE, null, scanRecord);
    }
}
Also used : ParcelUuid(android.os.ParcelUuid) SparseArray(android.util.SparseArray) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap)

Aggregations

SparseArray (android.util.SparseArray)250 ArrayList (java.util.ArrayList)75 ProcessState (com.android.internal.app.procstats.ProcessState)41 Parcelable (android.os.Parcelable)37 View (android.view.View)35 ServiceState (com.android.internal.app.procstats.ServiceState)31 RemoteException (android.os.RemoteException)24 Point (android.graphics.Point)19 ArraySet (android.util.ArraySet)17 HashMap (java.util.HashMap)17 ComponentName (android.content.ComponentName)15 ProcessStats (com.android.internal.app.procstats.ProcessStats)15 UserHandle (android.os.UserHandle)14 ArrayMap (android.util.ArrayMap)14 UserInfo (android.content.pm.UserInfo)13 Paint (android.graphics.Paint)13 Bitmap (android.graphics.Bitmap)12 IOException (java.io.IOException)12 ApplicationInfo (android.content.pm.ApplicationInfo)11 SparseIntArray (android.util.SparseIntArray)11