android.util.LongSparseArray#size ( )源码实例Demo

下面列出了android.util.LongSparseArray#size ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: AccessibilityCache.java
/**
 * Clears nodes for the window with the given id
 */
private void clearNodesForWindowLocked(int windowId) {
    if (DEBUG) {
        Log.i(LOG_TAG, "clearNodesForWindowLocked(" + windowId + ")");
    }
    LongSparseArray<AccessibilityNodeInfo> nodes = mNodeCache.get(windowId);
    if (nodes == null) {
        return;
    }
    // Recycle the nodes before clearing the cache.
    final int nodeCount = nodes.size();
    for (int i = nodeCount - 1; i >= 0; i--) {
        AccessibilityNodeInfo info = nodes.valueAt(i);
        nodes.removeAt(i);
        info.recycle();
    }
    mNodeCache.remove(windowId);
}
 
源代码2 项目: android_9.0.0_r45   文件: Transition.java
/**
 * Match start/end values by Adapter item ID. Adds matched values to mStartValuesList
 * and mEndValuesList and removes them from unmatchedStart and unmatchedEnd, using
 * startItemIds and endItemIds as a guide for which Views have unique item IDs.
 */
private void matchItemIds(ArrayMap<View, TransitionValues> unmatchedStart,
        ArrayMap<View, TransitionValues> unmatchedEnd,
        LongSparseArray<View> startItemIds, LongSparseArray<View> endItemIds) {
    int numStartIds = startItemIds.size();
    for (int i = 0; i < numStartIds; i++) {
        View startView = startItemIds.valueAt(i);
        if (startView != null && isValidTarget(startView)) {
            View endView = endItemIds.get(startItemIds.keyAt(i));
            if (endView != null && isValidTarget(endView)) {
                TransitionValues startValues = unmatchedStart.get(startView);
                TransitionValues endValues = unmatchedEnd.get(endView);
                if (startValues != null && endValues != null) {
                    mStartValuesList.add(startValues);
                    mEndValuesList.add(endValues);
                    unmatchedStart.remove(startView);
                    unmatchedEnd.remove(endView);
                }
            }
        }
    }
}
 
源代码3 项目: ticdesign   文件: TrackSelectionAdapterWrapper.java
/**
 * Returns the set of checked items ids. The result is only valid if the
 * choice mode has not been set to {@link AbsListView#CHOICE_MODE_NONE} and the adapter
 * has stable IDs. ({@link ListAdapter#hasStableIds()} == {@code true})
 *
 * @return A new array which contains the id of each checked item in the
 *         list.
 */
public long[] getCheckedItemIds() {
    if (mChoiceMode == AbsListView.CHOICE_MODE_NONE || mCheckedIdStates == null) {
        return new long[0];
    }

    final LongSparseArray<Integer> idStates = mCheckedIdStates;
    final int count = idStates.size();
    final long[] ids = new long[count];

    for (int i = 0; i < count; i++) {
        ids[i] = idStates.keyAt(i);
    }

    return ids;
}
 
源代码4 项目: android_9.0.0_r45   文件: ProcessStatsService.java
@GuardedBy("mAm")
public boolean setMemFactorLocked(int memFactor, boolean screenOn, long now) {
    mMemFactorLowered = memFactor < mLastMemOnlyState;
    mLastMemOnlyState = memFactor;
    if (mInjectedScreenState != null) {
        screenOn = mInjectedScreenState;
    }
    if (screenOn) {
        memFactor += ProcessStats.ADJ_SCREEN_ON;
    }
    if (memFactor != mProcessStats.mMemFactor) {
        if (mProcessStats.mMemFactor != ProcessStats.STATE_NOTHING) {
            mProcessStats.mMemFactorDurations[mProcessStats.mMemFactor]
                    += now - mProcessStats.mStartTime;
        }
        mProcessStats.mMemFactor = memFactor;
        mProcessStats.mStartTime = now;
        final ArrayMap<String, SparseArray<LongSparseArray<ProcessStats.PackageState>>> pmap
                = mProcessStats.mPackages.getMap();
        for (int ipkg=pmap.size()-1; ipkg>=0; ipkg--) {
            final SparseArray<LongSparseArray<ProcessStats.PackageState>> uids =
                    pmap.valueAt(ipkg);
            for (int iuid=uids.size()-1; iuid>=0; iuid--) {
                final LongSparseArray<ProcessStats.PackageState> vers = uids.valueAt(iuid);
                for (int iver=vers.size()-1; iver>=0; iver--) {
                    final ProcessStats.PackageState pkg = vers.valueAt(iver);
                    final ArrayMap<String, ServiceState> services = pkg.mServices;
                    for (int isvc=services.size()-1; isvc>=0; isvc--) {
                        final ServiceState service = services.valueAt(isvc);
                        service.setMemFactor(memFactor, now);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
 
源代码5 项目: android_9.0.0_r45   文件: ThemedResourceCache.java
private boolean pruneEntriesLocked(@Nullable LongSparseArray<WeakReference<T>> entries,
        @Config int configChanges) {
    if (entries == null) {
        return true;
    }

    for (int i = entries.size() - 1; i >= 0; i--) {
        final WeakReference<T> ref = entries.valueAt(i);
        if (ref == null || pruneEntryLocked(ref.get(), configChanges)) {
            entries.removeAt(i);
        }
    }

    return entries.size() == 0;
}
 
源代码6 项目: trekarta   文件: LongSparseArrayIterator.java
private LongSparseArrayIterator(LongSparseArray<E> array, int location) {
    this.array = array;
    if (location < 0) {
        cursor = -1;
        cursorNowhere = true;
    } else if (location < array.size()) {
        cursor = location;
        cursorNowhere = false;
    } else {
        cursor = array.size() - 1;
        cursorNowhere = true;
    }
}
 
源代码7 项目: deagle   文件: SparseArrays.java
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
public static <T> Iterable<T> iterate(final LongSparseArray<T> array) {
	return new Iterable<T>() { @Override public Iterator<T> iterator() {
		return new Iterator<T>() {
			@Override public boolean hasNext() { return i < array.size(); }
			@Override public T next() { return array.valueAt(i ++); }
			int i = 0;
		};
	}};
}
 
private void enforceNodeTreeConsistent(List<AccessibilityNodeInfo> nodes) {
    LongSparseArray<AccessibilityNodeInfo> nodeMap =
            new LongSparseArray<AccessibilityNodeInfo>();
    final int nodeCount = nodes.size();
    for (int i = 0; i < nodeCount; i++) {
        AccessibilityNodeInfo node = nodes.get(i);
        nodeMap.put(node.getSourceNodeId(), node);
    }

    // If the nodes are a tree it does not matter from
    // which node we start to search for the root.
    AccessibilityNodeInfo root = nodeMap.valueAt(0);
    AccessibilityNodeInfo parent = root;
    while (parent != null) {
        root = parent;
        parent = nodeMap.get(parent.getParentNodeId());
    }

    // Traverse the tree and do some checks.
    AccessibilityNodeInfo accessFocus = null;
    AccessibilityNodeInfo inputFocus = null;
    HashSet<AccessibilityNodeInfo> seen = new HashSet<AccessibilityNodeInfo>();
    Queue<AccessibilityNodeInfo> fringe = new LinkedList<AccessibilityNodeInfo>();
    fringe.add(root);

    while (!fringe.isEmpty()) {
        AccessibilityNodeInfo current = fringe.poll();

        // Check for duplicates
        if (!seen.add(current)) {
            throw new IllegalStateException("Duplicate node: "
                    + current + " in window:"
                    + mViewRootImpl.mAttachInfo.mAccessibilityWindowId);
        }

        // Check for one accessibility focus.
        if (current.isAccessibilityFocused()) {
            if (accessFocus != null) {
                throw new IllegalStateException("Duplicate accessibility focus:"
                        + current
                        + " in window:" + mViewRootImpl.mAttachInfo.mAccessibilityWindowId);
            } else {
                accessFocus = current;
            }
        }

        // Check for one input focus.
        if (current.isFocused()) {
            if (inputFocus != null) {
                throw new IllegalStateException("Duplicate input focus: "
                    + current + " in window:"
                    + mViewRootImpl.mAttachInfo.mAccessibilityWindowId);
            } else {
                inputFocus = current;
            }
        }

        final int childCount = current.getChildCount();
        for (int j = 0; j < childCount; j++) {
            final long childId = current.getChildId(j);
            final AccessibilityNodeInfo child = nodeMap.get(childId);
            if (child != null) {
                fringe.add(child);
            }
        }
    }

    // Check for disconnected nodes.
    for (int j = nodeMap.size() - 1; j >= 0; j--) {
        AccessibilityNodeInfo info = nodeMap.valueAt(j);
        if (!seen.contains(info)) {
            throw new IllegalStateException("Disconnected node: " + info);
        }
    }
}
 
源代码9 项目: decorator-wechat   文件: MessagingBuilder.java
@Nullable MessagingStyle buildFromArchive(final Conversation conversation, final Notification n, final CharSequence title, final List<StatusBarNotification> archive) {
	// Chat history in big content view
	if (archive.isEmpty()) {
		Log.d(TAG, "No history");
		return null;
	}

	final LongSparseArray<Pair<CharSequence/* text */, CharSequence/* ticker */>> lines = new LongSparseArray<>(MAX_NUM_HISTORICAL_LINES);
	int count = 0, num_lines_with_colon = 0;
	final String redundant_prefix = title.toString() + SENDER_MESSAGE_SEPARATOR;
	for (final StatusBarNotification each : archive) {
		final Notification notification = each.getNotification();
		final Bundle its_extras = notification.extras;
		final CharSequence its_title = EmojiTranslator.translate(its_extras.getCharSequence(Notification.EXTRA_TITLE));
		if (! title.equals(its_title)) {
			Log.d(TAG, "Skip other conversation with the same key in archive: " + its_title);	// ID reset by WeChat due to notification removal in previous evolving
			continue;
		}
		final CharSequence its_text = its_extras.getCharSequence(EXTRA_TEXT);
		if (its_text == null) {
			Log.w(TAG, "No text in archived notification.");
			continue;
		}
		final int result = trimAndExtractLeadingCounter(its_text);
		if (result >= 0) {
			count = result & 0xFFFF;
			CharSequence trimmed_text = its_text.subSequence(result >> 16, its_text.length());
			if (trimmed_text.toString().startsWith(redundant_prefix))	// Remove redundant prefix
				trimmed_text = trimmed_text.subSequence(redundant_prefix.length(), trimmed_text.length());
			else if (trimmed_text.toString().indexOf(SENDER_MESSAGE_SEPARATOR) > 0) num_lines_with_colon ++;
			lines.put(notification.when, new Pair<>(trimmed_text, notification.tickerText));
		} else {
			count = 1;
			lines.put(notification.when, new Pair<>(its_text, n.tickerText));
			if (its_text.toString().indexOf(SENDER_MESSAGE_SEPARATOR) > 0) num_lines_with_colon ++;
		}
	}
	n.number = count;
	if (lines.size() == 0) {
		Log.w(TAG, "No lines extracted, expected " + count);
		return null;
	}

	final MessagingStyle messaging = new MessagingStyle(mUserSelf);
	final boolean sender_inline = num_lines_with_colon == lines.size();
	for (int i = 0, size = lines.size(); i < size; i ++) {            // All lines have colon in text
		final Pair<CharSequence/* Text */, CharSequence/* Ticker */> line = lines.valueAt(i);
		messaging.addMessage(buildMessage(conversation, lines.keyAt(i), line.second, line.first, sender_inline ? null : title.toString()));
	}
	return messaging;
}
 
源代码10 项目: ChannelSurfer   文件: SyncAdapter.java
public void performSync(TvInputProvider provider, String inputId) {
    Log.d(TAG, "Actually begin the sync");
    List<Channel> allChannels = provider.getAllChannels(getContext());
    if(allChannels == null) {
        //You have no channels!!
        return;
    }
    Log.d(TAG, allChannels.toString());
    for (int i = 0; i < allChannels.size(); i++) {
        if (allChannels.get(i).getOriginalNetworkId() == 0)
            allChannels.get(i).setOriginalNetworkId(i + 1);
        if (allChannels.get(i).getTransportStreamId() == 0)
            allChannels.get(i).setTransportStreamId(i + 1);
    }
    TvContractUtils.updateChannels(getContext(), inputId, allChannels);

    LongSparseArray<Channel> channelMap = TvContractUtils.buildChannelMap(
            mContext.getContentResolver(), inputId, allChannels);
    if (channelMap == null) {
        Log.d(TAG, "?");
        Handler h = new Handler(Looper.getMainLooper()) {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                Toast.makeText(getContext(), "Couldn't find any channels. Uh-oh.", Toast.LENGTH_SHORT).show();
            }
        };
        h.sendEmptyMessage(0);
        //Let's not continue running
        return;
    }
    long startMs = new Date().getTime();
    long endMs = startMs + FULL_SYNC_WINDOW_SEC * 1000;
    Log.d(TAG, "Now start to get programs");
    for (int i = 0; i < channelMap.size(); ++i) {
        Uri channelUri = TvContract.buildChannelUri(channelMap.keyAt(i));
        List<Program> programList = provider.getProgramsForChannel(getContext(), channelUri, channelMap.valueAt(i), startMs, endMs);
        Log.d(TAG, "Okay, we NEED to set the channel id first");
        for(Program p: programList) {
            p.setChannelId(channelMap.keyAt(i));
        }
        Log.d(TAG, "For " + channelMap.valueAt(i).toString());
        Log.d(TAG, programList.toString());
        updatePrograms(channelUri, programList);
        //Let's double check programs
        Uri programEditor = TvContract.buildProgramsUriForChannel(channelUri);
    }
    Log.d(TAG, "Sync performed");
}
 
 方法所在类