Search in sources :

Example 1 with TestApi

use of android.annotation.TestApi in project android_frameworks_base by AOSPA.

the class PrinterInfo method loadIcon.

/**
     * Get the icon to be used for this printer. If no per printer icon is available, the printer's
     * service's icon is returned. If the printer has a custom icon this icon might get requested
     * asynchronously. Once the icon is loaded the discovery sessions will be notified that the
     * printer changed.
     *
     * @param context The context that will be using the icons
     * @return The icon to be used for the printer or null if no icon could be found.
     * @hide
     */
@TestApi
@Nullable
public Drawable loadIcon(@NonNull Context context) {
    Drawable drawable = null;
    PackageManager packageManager = context.getPackageManager();
    if (mHasCustomPrinterIcon) {
        PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
        Icon icon = printManager.getCustomPrinterIcon(mId);
        if (icon != null) {
            drawable = icon.loadDrawable(context);
        }
    }
    if (drawable == null) {
        try {
            String packageName = mId.getServiceName().getPackageName();
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            ApplicationInfo appInfo = packageInfo.applicationInfo;
            // If no custom icon is available, try the icon from the resources
            if (mIconResourceId != 0) {
                drawable = packageManager.getDrawable(packageName, mIconResourceId, appInfo);
            }
            // Fall back to the printer's service's icon if no per printer icon could be found
            if (drawable == null) {
                drawable = appInfo.loadIcon(packageManager);
            }
        } catch (NameNotFoundException e) {
        }
    }
    return drawable;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Icon(android.graphics.drawable.Icon) TestApi(android.annotation.TestApi) Nullable(android.annotation.Nullable)

Example 2 with TestApi

use of android.annotation.TestApi in project android_frameworks_base by ResurrectionRemix.

the class PrinterInfo method loadIcon.

/**
     * Get the icon to be used for this printer. If no per printer icon is available, the printer's
     * service's icon is returned. If the printer has a custom icon this icon might get requested
     * asynchronously. Once the icon is loaded the discovery sessions will be notified that the
     * printer changed.
     *
     * @param context The context that will be using the icons
     * @return The icon to be used for the printer or null if no icon could be found.
     * @hide
     */
@TestApi
@Nullable
public Drawable loadIcon(@NonNull Context context) {
    Drawable drawable = null;
    PackageManager packageManager = context.getPackageManager();
    if (mHasCustomPrinterIcon) {
        PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
        Icon icon = printManager.getCustomPrinterIcon(mId);
        if (icon != null) {
            drawable = icon.loadDrawable(context);
        }
    }
    if (drawable == null) {
        try {
            String packageName = mId.getServiceName().getPackageName();
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            ApplicationInfo appInfo = packageInfo.applicationInfo;
            // If no custom icon is available, try the icon from the resources
            if (mIconResourceId != 0) {
                drawable = packageManager.getDrawable(packageName, mIconResourceId, appInfo);
            }
            // Fall back to the printer's service's icon if no per printer icon could be found
            if (drawable == null) {
                drawable = appInfo.loadIcon(packageManager);
            }
        } catch (NameNotFoundException e) {
        }
    }
    return drawable;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Icon(android.graphics.drawable.Icon) TestApi(android.annotation.TestApi) Nullable(android.annotation.Nullable)

Example 3 with TestApi

use of android.annotation.TestApi in project platform_frameworks_base by android.

the class PrinterInfo method loadIcon.

/**
     * Get the icon to be used for this printer. If no per printer icon is available, the printer's
     * service's icon is returned. If the printer has a custom icon this icon might get requested
     * asynchronously. Once the icon is loaded the discovery sessions will be notified that the
     * printer changed.
     *
     * @param context The context that will be using the icons
     * @return The icon to be used for the printer or null if no icon could be found.
     * @hide
     */
@TestApi
@Nullable
public Drawable loadIcon(@NonNull Context context) {
    Drawable drawable = null;
    PackageManager packageManager = context.getPackageManager();
    if (mHasCustomPrinterIcon) {
        PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
        Icon icon = printManager.getCustomPrinterIcon(mId);
        if (icon != null) {
            drawable = icon.loadDrawable(context);
        }
    }
    if (drawable == null) {
        try {
            String packageName = mId.getServiceName().getPackageName();
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            ApplicationInfo appInfo = packageInfo.applicationInfo;
            // If no custom icon is available, try the icon from the resources
            if (mIconResourceId != 0) {
                drawable = packageManager.getDrawable(packageName, mIconResourceId, appInfo);
            }
            // Fall back to the printer's service's icon if no per printer icon could be found
            if (drawable == null) {
                drawable = appInfo.loadIcon(packageManager);
            }
        } catch (NameNotFoundException e) {
        }
    }
    return drawable;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Icon(android.graphics.drawable.Icon) TestApi(android.annotation.TestApi) Nullable(android.annotation.Nullable)

Example 4 with TestApi

use of android.annotation.TestApi in project android_frameworks_base by DirtyUnicorns.

the class PrinterInfo method loadIcon.

/**
     * Get the icon to be used for this printer. If no per printer icon is available, the printer's
     * service's icon is returned. If the printer has a custom icon this icon might get requested
     * asynchronously. Once the icon is loaded the discovery sessions will be notified that the
     * printer changed.
     *
     * @param context The context that will be using the icons
     * @return The icon to be used for the printer or null if no icon could be found.
     * @hide
     */
@TestApi
@Nullable
public Drawable loadIcon(@NonNull Context context) {
    Drawable drawable = null;
    PackageManager packageManager = context.getPackageManager();
    if (mHasCustomPrinterIcon) {
        PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
        Icon icon = printManager.getCustomPrinterIcon(mId);
        if (icon != null) {
            drawable = icon.loadDrawable(context);
        }
    }
    if (drawable == null) {
        try {
            String packageName = mId.getServiceName().getPackageName();
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            ApplicationInfo appInfo = packageInfo.applicationInfo;
            // If no custom icon is available, try the icon from the resources
            if (mIconResourceId != 0) {
                drawable = packageManager.getDrawable(packageName, mIconResourceId, appInfo);
            }
            // Fall back to the printer's service's icon if no per printer icon could be found
            if (drawable == null) {
                drawable = appInfo.loadIcon(packageManager);
            }
        } catch (NameNotFoundException e) {
        }
    }
    return drawable;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Icon(android.graphics.drawable.Icon) TestApi(android.annotation.TestApi) Nullable(android.annotation.Nullable)

Example 5 with TestApi

use of android.annotation.TestApi in project android_frameworks_base by crdroidandroid.

the class PrinterInfo method loadIcon.

/**
     * Get the icon to be used for this printer. If no per printer icon is available, the printer's
     * service's icon is returned. If the printer has a custom icon this icon might get requested
     * asynchronously. Once the icon is loaded the discovery sessions will be notified that the
     * printer changed.
     *
     * @param context The context that will be using the icons
     * @return The icon to be used for the printer or null if no icon could be found.
     * @hide
     */
@TestApi
@Nullable
public Drawable loadIcon(@NonNull Context context) {
    Drawable drawable = null;
    PackageManager packageManager = context.getPackageManager();
    if (mHasCustomPrinterIcon) {
        PrintManager printManager = (PrintManager) context.getSystemService(Context.PRINT_SERVICE);
        Icon icon = printManager.getCustomPrinterIcon(mId);
        if (icon != null) {
            drawable = icon.loadDrawable(context);
        }
    }
    if (drawable == null) {
        try {
            String packageName = mId.getServiceName().getPackageName();
            PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
            ApplicationInfo appInfo = packageInfo.applicationInfo;
            // If no custom icon is available, try the icon from the resources
            if (mIconResourceId != 0) {
                drawable = packageManager.getDrawable(packageName, mIconResourceId, appInfo);
            }
            // Fall back to the printer's service's icon if no per printer icon could be found
            if (drawable == null) {
                drawable = appInfo.loadIcon(packageManager);
            }
        } catch (NameNotFoundException e) {
        }
    }
    return drawable;
}
Also used : PackageManager(android.content.pm.PackageManager) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) PackageInfo(android.content.pm.PackageInfo) Drawable(android.graphics.drawable.Drawable) ApplicationInfo(android.content.pm.ApplicationInfo) Icon(android.graphics.drawable.Icon) TestApi(android.annotation.TestApi) Nullable(android.annotation.Nullable)

Aggregations

Nullable (android.annotation.Nullable)5 TestApi (android.annotation.TestApi)5 ApplicationInfo (android.content.pm.ApplicationInfo)5 PackageInfo (android.content.pm.PackageInfo)5 PackageManager (android.content.pm.PackageManager)5 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)5 Drawable (android.graphics.drawable.Drawable)5 Icon (android.graphics.drawable.Icon)5