FileDocCategorySizeDatePackage
DocumentsApplication.javaAPI DocAndroid 5.1 API4098Thu Mar 12 22:22:40 GMT 2015com.android.documentsui

DocumentsApplication

public class DocumentsApplication extends android.app.Application

Fields Summary
private static final long
PROVIDER_ANR_TIMEOUT
private RootsCache
mRoots
private android.graphics.Point
mThumbnailsSize
private ThumbnailCache
mThumbnails
private android.content.BroadcastReceiver
mCacheReceiver
Constructors Summary
Methods Summary
public static android.content.ContentProviderClientacquireUnstableProviderOrThrow(android.content.ContentResolver resolver, java.lang.String authority)

        final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
                authority);
        if (client == null) {
            throw new RemoteException("Failed to acquire provider for " + authority);
        }
        client.setDetectNotResponding(PROVIDER_ANR_TIMEOUT);
        return client;
    
public static RootsCachegetRootsCache(android.content.Context context)


         
        return ((DocumentsApplication) context.getApplicationContext()).mRoots;
    
public static ThumbnailCachegetThumbnailsCache(android.content.Context context, android.graphics.Point size)

        final DocumentsApplication app = (DocumentsApplication) context.getApplicationContext();
        final ThumbnailCache thumbnails = app.mThumbnails;
        if (!size.equals(app.mThumbnailsSize)) {
            thumbnails.evictAll();
            app.mThumbnailsSize = size;
        }
        return thumbnails;
    
public voidonCreate()

        final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        final int memoryClassBytes = am.getMemoryClass() * 1024 * 1024;

        mRoots = new RootsCache(this);
        mRoots.updateAsync();

        mThumbnails = new ThumbnailCache(memoryClassBytes / 4);

        final IntentFilter packageFilter = new IntentFilter();
        packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
        packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
        packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
        packageFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
        packageFilter.addDataScheme("package");
        registerReceiver(mCacheReceiver, packageFilter);

        final IntentFilter localeFilter = new IntentFilter();
        localeFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
        registerReceiver(mCacheReceiver, localeFilter);
    
public voidonTrimMemory(int level)

        super.onTrimMemory(level);

        if (level >= TRIM_MEMORY_MODERATE) {
            mThumbnails.evictAll();
        } else if (level >= TRIM_MEMORY_BACKGROUND) {
            mThumbnails.trimToSize(mThumbnails.size() / 2);
        }