下面列出了android.util.SparseArray#clear ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void load(
HashMap<String, CachedContent> content, SparseArray<@NullableType String> idToKey) {
Assertions.checkState(!changed);
if (!readFile(content, idToKey)) {
content.clear();
idToKey.clear();
atomicFile.delete();
}
}
void clear() {
final SparseArray<View> scrapHeap = mScrapHeap;
final int count = scrapHeap.size();
for (int i = 0; i < count; i++) {
final View view = scrapHeap.valueAt(i);
if (view != null) {
removeDetachedView(view, true);
}
}
scrapHeap.clear();
}
void clear() {
final SparseArray<View> scrapHeap = mScrapHeap;
final int count = scrapHeap.size();
for (int i = 0; i < count; i++) {
final View view = scrapHeap.valueAt(i);
if (view != null) {
removeDetachedView(view, true);
}
}
scrapHeap.clear();
}
/**
* Close device
* This also close interfaces if they are opened in Java side
*/
public synchronized void close() {
if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");
if (mConnection != null) {
final int n = mInterfaces.size();
for (int i = 0; i < n; i++) {
final SparseArray<UsbInterface> intfs = mInterfaces.valueAt(i);
if (intfs != null) {
final int m = intfs.size();
for (int j = 0; j < m; j++) {
final UsbInterface intf = intfs.valueAt(j);
mConnection.releaseInterface(intf);
}
intfs.clear();
}
}
mInterfaces.clear();
mConnection.close();
mConnection = null;
final USBMonitor monitor = mWeakMonitor.get();
if (monitor != null) {
if (monitor.mOnDeviceConnectListener != null) {
monitor.mOnDeviceConnectListener.onDisconnect(mWeakDevice.get(), UsbControlBlock.this);
}
monitor.mCtrlBlocks.remove(getDevice());
}
}
}
private <V> void copyTo(SparseArray<V> fromArray, SparseArray<V> toArray) {
toArray.clear();
for (int i = 0; i < fromArray.size(); i++) {
toArray.append(fromArray.keyAt(i), fromArray.valueAt(i));
}
}
/**
* デバイスを閉じる
* Java内でインターフェースをopenして使う時は開いているインターフェースも閉じる
*/
public void close() {
if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");
UsbDeviceConnection connection;
synchronized (this) {
connection = mConnection;
mConnection = null;
}
if (connection != null) {
// 2015/01/06 closeしてからonDisconnectを呼び出すように変更
// openしているinterfaceが有れば閉じる XXX Java側でインターフェースを使う時
final int n = mInterfaces.size();
for (int i = 0; i < n; i++) {
final SparseArray<UsbInterface> intfs = mInterfaces.valueAt(i);
if (intfs != null) {
final int m = intfs.size();
for (int j = 0; j < m; j++) {
final UsbInterface intf = intfs.valueAt(j);
connection.releaseInterface(intf);
}
intfs.clear();
}
}
mInterfaces.clear();
connection.close();
final USBMonitor monitor = getMonitor();
final UsbDevice device = getDevice();
if ((monitor != null) && (device != null)) {
monitor.callOnDisconnect(device, this);
}
}
}
private void handlePendingEvents(NotificationEvent.Source source) {
SparseArray<NotificationEvent> pending = pendingEvents.get(source);
if (pending != null && pending.size() > 0) {
List<NotificationEvent> events = new ArrayList<>();
for (int i = 0; i < pending.size(); i++) {
events.add(pending.valueAt(i));
}
hardHandleEvent(events, source);
pending.clear();
}
}
void clear() {
final SparseArray<View> scrapHeap = mScrapHeap;
final int count = scrapHeap.size();
for (int i = 0; i < count; i++) {
final View view = scrapHeap.valueAt(i);
if (view != null) {
removeDetachedView(view, true);
}
}
scrapHeap.clear();
}
/**
* Close device
* This also close interfaces if they are opened in Java side
*/
public synchronized void close() {
if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");
if (mConnection != null) {
final int n = mInterfaces.size();
for (int i = 0; i < n; i++) {
final SparseArray<UsbInterface> intfs = mInterfaces.valueAt(i);
if (intfs != null) {
final int m = intfs.size();
for (int j = 0; j < m; j++) {
final UsbInterface intf = intfs.valueAt(j);
mConnection.releaseInterface(intf);
}
intfs.clear();
}
}
mInterfaces.clear();
mConnection.close();
mConnection = null;
final USBMonitor monitor = mWeakMonitor.get();
if (monitor != null) {
if (monitor.mOnDeviceConnectListener != null) {
monitor.mOnDeviceConnectListener.onDisconnect(mWeakDevice.get(), UsbControlBlock.this);
}
monitor.mCtrlBlocks.remove(getDevice());
}
}
}
void clear() {
final SparseArray<View> scrapHeap = mScrapHeap;
final int count = scrapHeap.size();
for (int i = 0; i < count; i++) {
final View view = scrapHeap.valueAt(i);
if (view != null) {
removeDetachedView(view, true);
}
}
scrapHeap.clear();
}
@Override
public void load(
HashMap<String, CachedContent> content, SparseArray<@NullableType String> idToKey) {
Assertions.checkState(!changed);
if (!readFile(content, idToKey)) {
content.clear();
idToKey.clear();
atomicFile.delete();
}
}
void clear() {
final SparseArray<View> scrapHeap = mScrapHeap;
final int count = scrapHeap.size();
for (int i = 0; i < count; i++) {
final View view = scrapHeap.valueAt(i);
if (view != null) {
removeDetachedView(view, true);
}
}
scrapHeap.clear();
}
@Override
public void load(
HashMap<String, CachedContent> content, SparseArray<@NullableType String> idToKey) {
Assertions.checkState(!changed);
if (!readFile(content, idToKey)) {
content.clear();
idToKey.clear();
atomicFile.delete();
}
}
void clear() {
final SparseArray<View> scrapHeap = mScrapHeap;
final int count = scrapHeap.size();
for (int i = 0; i < count; i++) {
final View view = scrapHeap.valueAt(i);
if (view != null) {
removeDetachedView(view, true);
}
}
scrapHeap.clear();
}
@Override
public void load(
HashMap<String, CachedContent> content, SparseArray<@NullableType String> idToKey)
throws IOException {
Assertions.checkState(pendingUpdates.size() == 0);
try {
int version =
VersionTable.getVersion(
databaseProvider.getReadableDatabase(),
VersionTable.FEATURE_CACHE_CONTENT_METADATA,
hexUid);
if (version != TABLE_VERSION) {
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
writableDatabase.beginTransactionNonExclusive();
try {
initializeTable(writableDatabase);
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
try (Cursor cursor = getCursor()) {
while (cursor.moveToNext()) {
int id = cursor.getInt(COLUMN_INDEX_ID);
String key = cursor.getString(COLUMN_INDEX_KEY);
byte[] metadataBytes = cursor.getBlob(COLUMN_INDEX_METADATA);
ByteArrayInputStream inputStream = new ByteArrayInputStream(metadataBytes);
DataInputStream input = new DataInputStream(inputStream);
DefaultContentMetadata metadata = readContentMetadata(input);
CachedContent cachedContent = new CachedContent(id, key, metadata);
content.put(cachedContent.key, cachedContent);
idToKey.put(cachedContent.id, cachedContent.key);
}
}
} catch (SQLiteException e) {
content.clear();
idToKey.clear();
throw new DatabaseIOException(e);
}
}
void clear() {
final SparseArray<View> scrapHeap = mScrapHeap;
scrapHeap.clear();
}
public void clear(Class<? extends Context> cls) {
SparseArray<Window> l2 = sWindows.remove(cls);
if(l2 != null && l2.size() > 0) {
l2.clear();
}
}
void clear() {
final SparseArray<View> scrapHeap = mScrapHeap;
scrapHeap.clear();
}
@Override
public void load(
HashMap<String, CachedContent> content, SparseArray<@NullableType String> idToKey)
throws IOException {
Assertions.checkState(pendingUpdates.size() == 0);
try {
int version =
VersionTable.getVersion(
databaseProvider.getReadableDatabase(),
VersionTable.FEATURE_CACHE_CONTENT_METADATA,
hexUid);
if (version != TABLE_VERSION) {
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
writableDatabase.beginTransaction();
try {
initializeTable(writableDatabase);
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
try (Cursor cursor = getCursor()) {
while (cursor.moveToNext()) {
int id = cursor.getInt(COLUMN_INDEX_ID);
String key = cursor.getString(COLUMN_INDEX_KEY);
byte[] metadataBytes = cursor.getBlob(COLUMN_INDEX_METADATA);
ByteArrayInputStream inputStream = new ByteArrayInputStream(metadataBytes);
DataInputStream input = new DataInputStream(inputStream);
DefaultContentMetadata metadata = readContentMetadata(input);
CachedContent cachedContent = new CachedContent(id, key, metadata);
content.put(cachedContent.key, cachedContent);
idToKey.put(cachedContent.id, cachedContent.key);
}
}
} catch (SQLiteException e) {
content.clear();
idToKey.clear();
throw new DatabaseIOException(e);
}
}
@Override
public void load(
HashMap<String, CachedContent> content, SparseArray<@NullableType String> idToKey)
throws IOException {
Assertions.checkState(pendingUpdates.size() == 0);
try {
int version =
VersionTable.getVersion(
databaseProvider.getReadableDatabase(),
VersionTable.FEATURE_CACHE_CONTENT_METADATA,
hexUid);
if (version != TABLE_VERSION) {
SQLiteDatabase writableDatabase = databaseProvider.getWritableDatabase();
writableDatabase.beginTransaction();
try {
initializeTable(writableDatabase);
writableDatabase.setTransactionSuccessful();
} finally {
writableDatabase.endTransaction();
}
}
try (Cursor cursor = getCursor()) {
while (cursor.moveToNext()) {
int id = cursor.getInt(COLUMN_INDEX_ID);
String key = cursor.getString(COLUMN_INDEX_KEY);
byte[] metadataBytes = cursor.getBlob(COLUMN_INDEX_METADATA);
ByteArrayInputStream inputStream = new ByteArrayInputStream(metadataBytes);
DataInputStream input = new DataInputStream(inputStream);
DefaultContentMetadata metadata = readContentMetadata(input);
CachedContent cachedContent = new CachedContent(id, key, metadata);
content.put(cachedContent.key, cachedContent);
idToKey.put(cachedContent.id, cachedContent.key);
}
}
} catch (SQLiteException e) {
content.clear();
idToKey.clear();
throw new DatabaseIOException(e);
}
}