Search in sources :

Example 36 with LongSparseArray

use of android.util.LongSparseArray in project android_frameworks_base by crdroidandroid.

the class AbsListView method onSaveInstanceState.

@Override
public Parcelable onSaveInstanceState() {
    /*
         * This doesn't really make sense as the place to dismiss the
         * popups, but there don't seem to be any other useful hooks
         * that happen early enough to keep from getting complaints
         * about having leaked the window.
         */
    dismissPopup();
    Parcelable superState = super.onSaveInstanceState();
    SavedState ss = new SavedState(superState);
    if (mPendingSync != null) {
        // Just keep what we last restored.
        ss.selectedId = mPendingSync.selectedId;
        ss.firstId = mPendingSync.firstId;
        ss.viewTop = mPendingSync.viewTop;
        ss.position = mPendingSync.position;
        ss.height = mPendingSync.height;
        ss.filter = mPendingSync.filter;
        ss.inActionMode = mPendingSync.inActionMode;
        ss.checkedItemCount = mPendingSync.checkedItemCount;
        ss.checkState = mPendingSync.checkState;
        ss.checkIdState = mPendingSync.checkIdState;
        return ss;
    }
    boolean haveChildren = getChildCount() > 0 && mItemCount > 0;
    long selectedId = getSelectedItemId();
    ss.selectedId = selectedId;
    ss.height = getHeight();
    if (selectedId >= 0) {
        // Remember the selection
        ss.viewTop = mSelectedTop;
        ss.position = getSelectedItemPosition();
        ss.firstId = INVALID_POSITION;
    } else {
        if (haveChildren && mFirstPosition > 0) {
            // Remember the position of the first child.
            // We only do this if we are not currently at the top of
            // the list, for two reasons:
            // (1) The list may be in the process of becoming empty, in
            // which case mItemCount may not be 0, but if we try to
            // ask for any information about position 0 we will crash.
            // (2) Being "at the top" seems like a special case, anyway,
            // and the user wouldn't expect to end up somewhere else when
            // they revisit the list even if its content has changed.
            View v = getChildAt(0);
            ss.viewTop = v.getTop();
            int firstPos = mFirstPosition;
            if (firstPos >= mItemCount) {
                firstPos = mItemCount - 1;
            }
            ss.position = firstPos;
            ss.firstId = mAdapter.getItemId(firstPos);
        } else {
            ss.viewTop = 0;
            ss.firstId = INVALID_POSITION;
            ss.position = 0;
        }
    }
    ss.filter = null;
    if (mFiltered) {
        final EditText textFilter = mTextFilter;
        if (textFilter != null) {
            Editable filterText = textFilter.getText();
            if (filterText != null) {
                ss.filter = filterText.toString();
            }
        }
    }
    ss.inActionMode = mChoiceMode == CHOICE_MODE_MULTIPLE_MODAL && mChoiceActionMode != null;
    if (mCheckStates != null) {
        ss.checkState = mCheckStates.clone();
    }
    if (mCheckedIdStates != null) {
        final LongSparseArray<Integer> idState = new LongSparseArray<Integer>();
        final int count = mCheckedIdStates.size();
        for (int i = 0; i < count; i++) {
            idState.put(mCheckedIdStates.keyAt(i), mCheckedIdStates.valueAt(i));
        }
        ss.checkIdState = idState;
    }
    ss.checkedItemCount = mCheckedItemCount;
    if (mRemoteAdapter != null) {
        mRemoteAdapter.saveRemoteViewsCache();
    }
    return ss;
}
Also used : LongSparseArray(android.util.LongSparseArray) Editable(android.text.Editable) Parcelable(android.os.Parcelable) View(android.view.View)

Example 37 with LongSparseArray

use of android.util.LongSparseArray in project android_frameworks_base by crdroidandroid.

the class KeySetUtils method getKeySetRefCount.

public static int getKeySetRefCount(KeySetManagerService ksms, long keysetId) throws NoSuchFieldException, IllegalAccessException {
    Field ksField = ksms.getClass().getDeclaredField("mKeySets");
    ksField.setAccessible(true);
    LongSparseArray<KeySetHandle> mKeySets = (LongSparseArray<KeySetHandle>) ksField.get(ksms);
    KeySetHandle ksh = mKeySets.get(keysetId);
    if (ksh == null) {
        return 0;
    } else {
        return ksh.getRefCountLPr();
    }
}
Also used : Field(java.lang.reflect.Field) LongSparseArray(android.util.LongSparseArray)

Example 38 with LongSparseArray

use of android.util.LongSparseArray in project android_frameworks_base by crdroidandroid.

the class KeySetUtils method getPubKeyRefCount.

public static int getPubKeyRefCount(KeySetManagerService ksms, long pkId) throws NoSuchFieldException, IllegalAccessException {
    Field pkField = ksms.getClass().getDeclaredField("mPublicKeys");
    pkField.setAccessible(true);
    LongSparseArray<KeySetManagerService.PublicKeyHandle> mPublicKeys = (LongSparseArray<KeySetManagerService.PublicKeyHandle>) pkField.get(ksms);
    KeySetManagerService.PublicKeyHandle pkh = mPublicKeys.get(pkId);
    if (pkh == null) {
        return 0;
    } else {
        return pkh.getRefCountLPr();
    }
}
Also used : Field(java.lang.reflect.Field) LongSparseArray(android.util.LongSparseArray)

Example 39 with LongSparseArray

use of android.util.LongSparseArray in project StreetComplete by westnordost.

the class OverpassMapDataParserTest method testWay.

public void testWay() {
    OsmLatLon[] p = new OsmLatLon[2];
    p[0] = new OsmLatLon(1, 2);
    p[1] = new OsmLatLon(3, 4);
    String xml = "<way id='8' version='1' >\n" + " <nd ref='2' lat='" + p[0].getLatitude() + "' lon='" + p[0].getLongitude() + "' />\n" + " <nd ref='3' lat='" + p[1].getLatitude() + "' lon='" + p[1].getLongitude() + "' />\n" + "</way>";
    LongSparseArray<List<LatLon>> expectedGeometry = new LongSparseArray<>();
    expectedGeometry.put(8, new ArrayList<>(Arrays.asList(p)));
    Element e = parseOne(xml, expectedGeometry);
    assertTrue(e instanceof Way);
    Way way = (Way) e;
    assertEquals(8, way.getId());
    assertEquals(1, way.getVersion());
    assertEquals(2, way.getNodeIds().size());
    assertEquals(2, (long) way.getNodeIds().get(0));
    assertEquals(3, (long) way.getNodeIds().get(1));
}
Also used : LongSparseArray(android.util.LongSparseArray) Element(de.westnordost.osmapi.map.data.Element) ArrayList(java.util.ArrayList) List(java.util.List) OsmLatLon(de.westnordost.osmapi.map.data.OsmLatLon) Way(de.westnordost.osmapi.map.data.Way)

Example 40 with LongSparseArray

use of android.util.LongSparseArray in project android_packages_apps_Dialer by MoKee.

the class PhoneFavoritesTileAdapter method saveCursorToCache.

/**
 * Saves the cursor data to the cache, to speed up UI changes.
 *
 * @param cursor Returned cursor with data to populate the view.
 */
private void saveCursorToCache(Cursor cursor) {
    mContactEntries.clear();
    cursor.moveToPosition(-1);
    final LongSparseArray<Object> duplicates = new LongSparseArray<Object>(cursor.getCount());
    // Track the length of {@link #mContactEntries} and compare to {@link #TILES_SOFT_LIMIT}.
    int counter = 0;
    while (cursor.moveToNext()) {
        final int starred = cursor.getInt(mStarredIndex);
        final long id;
        // whichever is greater.
        if (starred < 1 && counter >= TILES_SOFT_LIMIT) {
            break;
        } else {
            id = cursor.getLong(mContactIdIndex);
        }
        final ContactEntry existing = (ContactEntry) duplicates.get(id);
        if (existing != null) {
            // and label fields so that the disambiguation dialog will show up.
            if (!existing.isDefaultNumber) {
                existing.phoneLabel = null;
                existing.phoneNumber = null;
            }
            continue;
        }
        final String photoUri = cursor.getString(mPhotoUriIndex);
        final String lookupKey = cursor.getString(mLookupIndex);
        final int pinned = cursor.getInt(mPinnedIndex);
        final String name = cursor.getString(mNamePrimaryIndex);
        final String nameAlternative = cursor.getString(mNameAlternativeIndex);
        final boolean isStarred = cursor.getInt(mStarredIndex) > 0;
        final boolean isDefaultNumber = cursor.getInt(mIsDefaultNumberIndex) > 0;
        final ContactEntry contact = new ContactEntry();
        contact.id = id;
        contact.namePrimary = (!TextUtils.isEmpty(name)) ? name : mResources.getString(R.string.missing_name);
        contact.nameAlternative = (!TextUtils.isEmpty(nameAlternative)) ? nameAlternative : mResources.getString(R.string.missing_name);
        contact.nameDisplayOrder = mContactsPreferences.getDisplayOrder();
        contact.photoUri = (photoUri != null ? Uri.parse(photoUri) : null);
        contact.lookupKey = lookupKey;
        contact.lookupUri = ContentUris.withAppendedId(Uri.withAppendedPath(Contacts.CONTENT_LOOKUP_URI, lookupKey), id);
        contact.isFavorite = isStarred;
        contact.isDefaultNumber = isDefaultNumber;
        // Set phone number and label
        final int phoneNumberType = cursor.getInt(mPhoneNumberTypeIndex);
        final String phoneNumberCustomLabel = cursor.getString(mPhoneNumberLabelIndex);
        contact.phoneLabel = (String) Phone.getTypeLabel(mResources, phoneNumberType, phoneNumberCustomLabel);
        contact.phoneNumber = cursor.getString(mPhoneNumberIndex);
        contact.pinned = pinned;
        mContactEntries.add(contact);
        duplicates.put(id, contact);
        counter++;
    }
    mAwaitingRemove = false;
    arrangeContactsByPinnedPosition(mContactEntries);
    notifyDataSetChanged();
}
Also used : LongSparseArray(android.util.LongSparseArray) ContactEntry(com.android.contacts.common.list.ContactEntry)

Aggregations

LongSparseArray (android.util.LongSparseArray)46 Field (java.lang.reflect.Field)23 ArrayList (java.util.ArrayList)12 Parcelable (android.os.Parcelable)7 Editable (android.text.Editable)7 View (android.view.View)7 PendingHostUpdate (android.appwidget.PendingHostUpdate)5 ParceledListSlice (android.content.pm.ParceledListSlice)5 Point (android.graphics.Point)5 IAppWidgetHost (com.android.internal.appwidget.IAppWidgetHost)5 Resources (android.content.res.Resources)4 SparseArray (android.util.SparseArray)4 Method (java.lang.reflect.Method)4 ContactEntry (com.android.contacts.common.list.ContactEntry)2 ProcessMap (com.android.internal.app.ProcessMap)2 IProcessStats (com.android.internal.app.procstats.IProcessStats)2 ProcessState (com.android.internal.app.procstats.ProcessState)2 ProcessStats (com.android.internal.app.procstats.ProcessStats)2 ServiceState (com.android.internal.app.procstats.ServiceState)2 Element (de.westnordost.osmapi.map.data.Element)2