MediaInserterpublic class MediaInserter extends Object A MediaScanner helper class which enables us to do lazy insertion on the
given provider. This class manages buffers internally and flushes when they
are full. Note that you should call flushAll() after using this class.
{@hide} |
Fields Summary |
---|
private final HashMap | mRowMap | private final HashMap | mPriorityRowMap | private final android.content.IContentProvider | mProvider | private final String | mPackageName | private final int | mBufferSizePerUri |
Constructors Summary |
---|
public MediaInserter(android.content.IContentProvider provider, String packageName, int bufferSizePerUri)
mProvider = provider;
mPackageName = packageName;
mBufferSizePerUri = bufferSizePerUri;
|
Methods Summary |
---|
private void | flush(android.net.Uri tableUri, java.util.List list)
if (!list.isEmpty()) {
ContentValues[] valuesArray = new ContentValues[list.size()];
valuesArray = list.toArray(valuesArray);
mProvider.bulkInsert(mPackageName, tableUri, valuesArray);
list.clear();
}
| public void | flushAll()
flushAllPriority();
for (Uri tableUri : mRowMap.keySet()){
List<ContentValues> list = mRowMap.get(tableUri);
flush(tableUri, list);
}
mRowMap.clear();
| private void | flushAllPriority()
for (Uri tableUri : mPriorityRowMap.keySet()){
List<ContentValues> list = mPriorityRowMap.get(tableUri);
flush(tableUri, list);
}
mPriorityRowMap.clear();
| public void | insert(android.net.Uri tableUri, android.content.ContentValues values)
insert(tableUri, values, false);
| private void | insert(android.net.Uri tableUri, android.content.ContentValues values, boolean priority)
HashMap<Uri, List<ContentValues>> rowmap = priority ? mPriorityRowMap : mRowMap;
List<ContentValues> list = rowmap.get(tableUri);
if (list == null) {
list = new ArrayList<ContentValues>();
rowmap.put(tableUri, list);
}
list.add(new ContentValues(values));
if (list.size() >= mBufferSizePerUri) {
flushAllPriority();
flush(tableUri, list);
}
| public void | insertwithPriority(android.net.Uri tableUri, android.content.ContentValues values)
insert(tableUri, values, true);
|
|