FileDocCategorySizeDatePackage
MediaInserter.javaAPI DocAndroid 5.1 API3448Thu Mar 12 22:22:30 GMT 2015android.media

MediaInserter

public 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 voidflush(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 voidflushAll()

        flushAllPriority();
        for (Uri tableUri : mRowMap.keySet()){
            List<ContentValues> list = mRowMap.get(tableUri);
            flush(tableUri, list);
        }
        mRowMap.clear();
    
private voidflushAllPriority()

        for (Uri tableUri : mPriorityRowMap.keySet()){
            List<ContentValues> list = mPriorityRowMap.get(tableUri);
            flush(tableUri, list);
        }
        mPriorityRowMap.clear();
    
public voidinsert(android.net.Uri tableUri, android.content.ContentValues values)

        insert(tableUri, values, false);
    
private voidinsert(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 voidinsertwithPriority(android.net.Uri tableUri, android.content.ContentValues values)

        insert(tableUri, values, true);