Example usage for android.appwidget AppWidgetProviderInfo loadIcon

List of usage examples for android.appwidget AppWidgetProviderInfo loadIcon

Introduction

In this page you can find the example usage for android.appwidget AppWidgetProviderInfo loadIcon.

Prototype

public final Drawable loadIcon(@NonNull Context context, int density) 

Source Link

Document

Loads the icon to display for this AppWidget in the AppWidget picker.

Usage

From source file:com.farmerbb.taskbar.service.DashboardService.java

private void addPlaceholder(int cellId) {
    FrameLayout placeholder = (FrameLayout) cells.get(cellId).findViewById(R.id.placeholder);
    SharedPreferences pref = U.getSharedPreferences(this);
    String providerName = pref.getString("dashboard_widget_" + Integer.toString(cellId) + "_provider", "null");

    if (!providerName.equals("null")) {
        ImageView imageView = (ImageView) placeholder.findViewById(R.id.placeholder_image);
        ComponentName componentName = ComponentName.unflattenFromString(providerName);

        List<AppWidgetProviderInfo> providerInfoList = mAppWidgetManager
                .getInstalledProvidersForProfile(Process.myUserHandle());
        for (AppWidgetProviderInfo info : providerInfoList) {
            if (info.provider.equals(componentName)) {
                Drawable drawable = info.loadPreviewImage(this, -1);
                if (drawable == null)
                    drawable = info.loadIcon(this, -1);

                ColorMatrix matrix = new ColorMatrix();
                matrix.setSaturation(0);

                imageView.setImageDrawable(drawable);
                imageView.setColorFilter(new ColorMatrixColorFilter(matrix));
                break;
            }// www .  j  a  va 2s .com
        }
    }

    placeholder.setVisibility(View.VISIBLE);
}