Search in sources :

Example 1 with WidgetMimeTypeHandlerData

use of com.android.launcher3.InstallWidgetReceiver.WidgetMimeTypeHandlerData in project Launcher3 by chislon.

the class LauncherModel method resolveWidgetsForMimeType.

/**
     * Returns a list of all the widgets that can handle configuration with a particular mimeType.
     */
List<WidgetMimeTypeHandlerData> resolveWidgetsForMimeType(Context context, String mimeType) {
    final PackageManager packageManager = context.getPackageManager();
    final List<WidgetMimeTypeHandlerData> supportedConfigurationActivities = new ArrayList<WidgetMimeTypeHandlerData>();
    final Intent supportsIntent = new Intent(InstallWidgetReceiver.ACTION_SUPPORTS_CLIPDATA_MIMETYPE);
    supportsIntent.setType(mimeType);
    // Create a set of widget configuration components that we can test against
    final List<AppWidgetProviderInfo> widgets = AppWidgetManager.getInstance(context).getInstalledProviders();
    final HashMap<ComponentName, AppWidgetProviderInfo> configurationComponentToWidget = new HashMap<ComponentName, AppWidgetProviderInfo>();
    for (AppWidgetProviderInfo info : widgets) {
        configurationComponentToWidget.put(info.configure, info);
    }
    // Run through each of the intents that can handle this type of clip data, and cross
    // reference them with the components that are actual configuration components
    final List<ResolveInfo> activities = packageManager.queryIntentActivities(supportsIntent, PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo info : activities) {
        final ActivityInfo activityInfo = info.activityInfo;
        final ComponentName infoComponent = new ComponentName(activityInfo.packageName, activityInfo.name);
        if (configurationComponentToWidget.containsKey(infoComponent)) {
            supportedConfigurationActivities.add(new InstallWidgetReceiver.WidgetMimeTypeHandlerData(info, configurationComponentToWidget.get(infoComponent)));
        }
    }
    return supportedConfigurationActivities;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WidgetMimeTypeHandlerData(com.android.launcher3.InstallWidgetReceiver.WidgetMimeTypeHandlerData) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) WidgetMimeTypeHandlerData(com.android.launcher3.InstallWidgetReceiver.WidgetMimeTypeHandlerData)

Example 2 with WidgetMimeTypeHandlerData

use of com.android.launcher3.InstallWidgetReceiver.WidgetMimeTypeHandlerData in project android_packages_apps_Launcher2 by CyanogenMod.

the class LauncherModel method resolveWidgetsForMimeType.

/**
     * Returns a list of all the widgets that can handle configuration with a particular mimeType.
     */
List<WidgetMimeTypeHandlerData> resolveWidgetsForMimeType(Context context, String mimeType) {
    final PackageManager packageManager = context.getPackageManager();
    final List<WidgetMimeTypeHandlerData> supportedConfigurationActivities = new ArrayList<WidgetMimeTypeHandlerData>();
    final Intent supportsIntent = new Intent(InstallWidgetReceiver.ACTION_SUPPORTS_CLIPDATA_MIMETYPE);
    supportsIntent.setType(mimeType);
    // Create a set of widget configuration components that we can test against
    final List<AppWidgetProviderInfo> widgets = AppWidgetManager.getInstance(context).getInstalledProviders();
    final HashMap<ComponentName, AppWidgetProviderInfo> configurationComponentToWidget = new HashMap<ComponentName, AppWidgetProviderInfo>();
    for (AppWidgetProviderInfo info : widgets) {
        configurationComponentToWidget.put(info.configure, info);
    }
    // Run through each of the intents that can handle this type of clip data, and cross
    // reference them with the components that are actual configuration components
    final List<ResolveInfo> activities = packageManager.queryIntentActivities(supportsIntent, PackageManager.MATCH_DEFAULT_ONLY);
    for (ResolveInfo info : activities) {
        final ActivityInfo activityInfo = info.activityInfo;
        final ComponentName infoComponent = new ComponentName(activityInfo.packageName, activityInfo.name);
        if (configurationComponentToWidget.containsKey(infoComponent)) {
            supportedConfigurationActivities.add(new InstallWidgetReceiver.WidgetMimeTypeHandlerData(info, configurationComponentToWidget.get(infoComponent)));
        }
    }
    return supportedConfigurationActivities;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Intent(android.content.Intent) WidgetMimeTypeHandlerData(com.android.launcher2.InstallWidgetReceiver.WidgetMimeTypeHandlerData) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) ComponentName(android.content.ComponentName) WidgetMimeTypeHandlerData(com.android.launcher2.InstallWidgetReceiver.WidgetMimeTypeHandlerData)

Aggregations

AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)2 ActivityInfo (android.content.pm.ActivityInfo)2 PackageManager (android.content.pm.PackageManager)2 ResolveInfo (android.content.pm.ResolveInfo)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 WidgetMimeTypeHandlerData (com.android.launcher2.InstallWidgetReceiver.WidgetMimeTypeHandlerData)1 WidgetMimeTypeHandlerData (com.android.launcher3.InstallWidgetReceiver.WidgetMimeTypeHandlerData)1