下面列出了android.util.SparseBooleanArray#append ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void readSparseBooleanArrayInternal(SparseBooleanArray outVal, int N) {
while (N > 0) {
int key = readInt();
boolean value = this.readByte() == 1;
//Log.i(TAG, "Unmarshalling key=" + key + " value=" + value);
outVal.append(key, value);
N--;
}
}
/**
* Extracts the tab information from a given tab state stream.
*
* @param stream The stream pointing to the tab state file to be parsed.
* @param callback A callback to be streamed updates about the tab state information being read.
* @param tabIds A mapping of tab ID to whether the tab is an off the record tab.
* @param forMerge Whether this state file was read as part of a merge.
* @return The next available tab ID based on the maximum ID referenced in this state file.
*/
public static int readSavedStateFile(
DataInputStream stream, @Nullable OnTabStateReadCallback callback,
@Nullable SparseBooleanArray tabIds, boolean forMerge) throws IOException {
if (stream == null) return 0;
long time = SystemClock.uptimeMillis();
int nextId = 0;
boolean skipUrlRead = false;
boolean skipIncognitoCount = false;
final int version = stream.readInt();
if (version != SAVED_STATE_VERSION) {
// We don't support restoring Tab data from before M18.
if (version < 3) return 0;
// Older versions are missing newer data.
if (version < 5) skipIncognitoCount = true;
if (version < 4) skipUrlRead = true;
}
final int count = stream.readInt();
final int incognitoCount = skipIncognitoCount ? -1 : stream.readInt();
final int incognitoActiveIndex = stream.readInt();
final int standardActiveIndex = stream.readInt();
if (count < 0 || incognitoActiveIndex >= count || standardActiveIndex >= count) {
throw new IOException();
}
for (int i = 0; i < count; i++) {
int id = stream.readInt();
String tabUrl = skipUrlRead ? "" : stream.readUTF();
if (id >= nextId) nextId = id + 1;
if (tabIds != null) tabIds.append(id, true);
Boolean isIncognito = (incognitoCount < 0) ? null : i < incognitoCount;
if (callback != null) {
callback.onDetailsRead(i, id, tabUrl, isIncognito,
i == standardActiveIndex, i == incognitoActiveIndex);
}
}
if (forMerge) {
logExecutionTime("ReadMergedStateTime", time);
int tabCount = count + ((incognitoCount > 0) ? incognitoCount : 0);
RecordHistogram.recordLinearCountHistogram(
"Android.TabPersistentStore.MergeStateTabCount",
tabCount, 1, 200, 200);
}
logExecutionTime("ReadSavedStateTime", time);
return nextId;
}
/**
* Extracts the tab information from a given tab state stream.
*
* @param stream The stream pointing to the tab state file to be parsed.
* @param callback A callback to be streamed updates about the tab state information being read.
* @param tabIds A mapping of tab ID to whether the tab is an off the record tab.
* @param forMerge Whether this state file was read as part of a merge.
* @return The next available tab ID based on the maximum ID referenced in this state file.
*/
public static int readSavedStateFile(
DataInputStream stream, @Nullable OnTabStateReadCallback callback,
@Nullable SparseBooleanArray tabIds, boolean forMerge) throws IOException {
if (stream == null) return 0;
long time = SystemClock.uptimeMillis();
int nextId = 0;
boolean skipUrlRead = false;
boolean skipIncognitoCount = false;
final int version = stream.readInt();
if (version != SAVED_STATE_VERSION) {
// We don't support restoring Tab data from before M18.
if (version < 3) return 0;
// Older versions are missing newer data.
if (version < 5) skipIncognitoCount = true;
if (version < 4) skipUrlRead = true;
}
final int count = stream.readInt();
final int incognitoCount = skipIncognitoCount ? -1 : stream.readInt();
final int incognitoActiveIndex = stream.readInt();
final int standardActiveIndex = stream.readInt();
if (count < 0 || incognitoActiveIndex >= count || standardActiveIndex >= count) {
throw new IOException();
}
for (int i = 0; i < count; i++) {
int id = stream.readInt();
String tabUrl = skipUrlRead ? "" : stream.readUTF();
if (id >= nextId) nextId = id + 1;
if (tabIds != null) tabIds.append(id, true);
Boolean isIncognito = (incognitoCount < 0) ? null : i < incognitoCount;
if (callback != null) {
callback.onDetailsRead(i, id, tabUrl, isIncognito,
i == standardActiveIndex, i == incognitoActiveIndex);
}
}
if (forMerge) {
logExecutionTime("ReadMergedStateTime", time);
int tabCount = count + ((incognitoCount > 0) ? incognitoCount : 0);
RecordHistogram.recordLinearCountHistogram(
"Android.TabPersistentStore.MergeStateTabCount",
tabCount, 1, 200, 200);
}
logExecutionTime("ReadSavedStateTime", time);
return nextId;
}