Example usage for android.content.pm ProviderInfo loadIcon

List of usage examples for android.content.pm ProviderInfo loadIcon

Introduction

In this page you can find the example usage for android.content.pm ProviderInfo loadIcon.

Prototype

public Drawable loadIcon(PackageManager pm) 

Source Link

Document

Retrieve the current graphical icon associated with this item.

Usage

From source file:org.opensilk.music.ui3.main.LibraryProviderInfoLoader.java

public Observable<LibraryProviderInfo> makeObservable() {
    return Observable.create(new Observable.OnSubscribe<List<ProviderInfo>>() {
        @Override/*  w  w w  .jav a  2 s  . co  m*/
        public void call(Subscriber<? super List<ProviderInfo>> subscriber) {
            final PackageManager pm = context.getPackageManager();
            final List<ProviderInfo> providerInfos = pm.queryContentProviders(null, 0,
                    PackageManager.GET_META_DATA);
            subscriber.onNext(providerInfos);
            subscriber.onCompleted();
        }
    }).flatMap(new Func1<List<ProviderInfo>, Observable<ProviderInfo>>() {
        @Override
        public Observable<ProviderInfo> call(List<ProviderInfo> providerInfos) {
            return Observable.from(providerInfos);
        }
    }).filter(new Func1<ProviderInfo, Boolean>() {
        @Override
        public Boolean call(ProviderInfo providerInfo) {
            return StringUtils.startsWith(providerInfo.authority, LibraryProvider.AUTHORITY_PFX)
                    //Ignore non exported providers unless they're ours
                    && (StringUtils.equals(providerInfo.packageName, context.getPackageName())
                            || providerInfo.exported);
        }
    }).map(new Func1<ProviderInfo, LibraryProviderInfo>() {
        @Override
        public LibraryProviderInfo call(ProviderInfo providerInfo) {
            final PackageManager pm = context.getPackageManager();
            final String authority = providerInfo.authority;
            final CharSequence title = providerInfo.loadLabel(pm);
            final ComponentName cn = new ComponentName(providerInfo.packageName, providerInfo.name);
            final Drawable icon = providerInfo.loadIcon(pm);
            CharSequence description;
            try {
                Context packageContext = context.createPackageContext(cn.getPackageName(), 0);
                Resources packageRes = packageContext.getResources();
                description = packageRes.getString(providerInfo.descriptionRes);
            } catch (PackageManager.NameNotFoundException e) {
                description = "";
            }
            final LibraryProviderInfo lpi = new LibraryProviderInfo(title.toString(), description.toString(),
                    authority);
            lpi.icon = icon;
            for (String a : settings.readDisabledPlugins()) {
                if (a.equals(lpi.authority)) {
                    lpi.isActive = false;
                    break;
                }
            }
            return lpi;
        }
    });
}