Search in sources :

Example 21 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Fairphone by Kwamecorp.

the class AppsCustomizePagedView method loadWidgetPreviewsInBackground.

private void loadWidgetPreviewsInBackground(AppsCustomizeAsyncTask task, AsyncTaskPageData data) {
    // previews synchronously
    if (task != null) {
        // Ensure that this task starts running at the correct priority
        task.syncThreadPriority();
    }
    // Load each of the widget/shortcut previews
    ArrayList<Object> items = data.items;
    ArrayList<Bitmap> images = data.generatedImages;
    int count = items.size();
    for (int i = 0; i < count; ++i) {
        if (task != null) {
            // Ensure we haven't been cancelled yet
            if (task.isCancelled())
                break;
            // Before work on each item, ensure that this task is running at the correct
            // priority
            task.syncThreadPriority();
        }
        Object rawInfo = items.get(i);
        if (rawInfo instanceof AppWidgetProviderInfo) {
            AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo;
            int[] cellSpans = Launcher.getSpanForWidget(mLauncher, info);
            int maxWidth = Math.min(data.maxImageWidth, mWidgetSpacingLayout.estimateCellWidth(cellSpans[0]));
            int maxHeight = Math.min(data.maxImageHeight, mWidgetSpacingLayout.estimateCellHeight(cellSpans[1]));
            Bitmap b = getWidgetPreview(info.provider, info.previewImage, info.icon, cellSpans[0], cellSpans[1], maxWidth, maxHeight);
            images.add(b);
        } else if (rawInfo instanceof ResolveInfo) {
            // Fill in the shortcuts information
            ResolveInfo info = (ResolveInfo) rawInfo;
            images.add(getShortcutPreview(info, data.maxImageWidth, data.maxImageHeight));
        }
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Bitmap(android.graphics.Bitmap) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) DragObject(org.fairphone.launcher.DropTarget.DragObject) Paint(android.graphics.Paint)

Example 22 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Fairphone by Kwamecorp.

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(org.fairphone.launcher.InstallWidgetReceiver.WidgetMimeTypeHandlerData) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) ComponentName(android.content.ComponentName) WidgetMimeTypeHandlerData(org.fairphone.launcher.InstallWidgetReceiver.WidgetMimeTypeHandlerData)

Example 23 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project android_frameworks_base by ParanoidAndroid.

the class AppWidgetServiceImpl method getInstalledProviders.

public List<AppWidgetProviderInfo> getInstalledProviders(int categoryFilter) {
    synchronized (mAppWidgetIds) {
        if (!mHasFeature) {
            return new ArrayList<AppWidgetProviderInfo>(0);
        }
        ensureStateLoadedLocked();
        final int N = mInstalledProviders.size();
        ArrayList<AppWidgetProviderInfo> result = new ArrayList<AppWidgetProviderInfo>(N);
        for (int i = 0; i < N; i++) {
            Provider p = mInstalledProviders.get(i);
            if (!p.zombie && (p.info.widgetCategory & categoryFilter) != 0) {
                result.add(cloneIfLocalBinder(p.info));
            }
        }
        return result;
    }
}
Also used : ArrayList(java.util.ArrayList) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Point(android.graphics.Point)

Example 24 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project android_frameworks_base by ParanoidAndroid.

the class AppWidgetServiceImpl method dumpProvider.

private void dumpProvider(Provider p, int index, PrintWriter pw) {
    AppWidgetProviderInfo info = p.info;
    pw.print("  [");
    pw.print(index);
    pw.print("] provider ");
    pw.print(info.provider.flattenToShortString());
    pw.println(':');
    pw.print("    min=(");
    pw.print(info.minWidth);
    pw.print("x");
    pw.print(info.minHeight);
    pw.print(")   minResize=(");
    pw.print(info.minResizeWidth);
    pw.print("x");
    pw.print(info.minResizeHeight);
    pw.print(") updatePeriodMillis=");
    pw.print(info.updatePeriodMillis);
    pw.print(" resizeMode=");
    pw.print(info.resizeMode);
    pw.print(info.widgetCategory);
    pw.print(" autoAdvanceViewId=");
    pw.print(info.autoAdvanceViewId);
    pw.print(" initialLayout=#");
    pw.print(Integer.toHexString(info.initialLayout));
    pw.print(" uid=");
    pw.print(p.uid);
    pw.print(" zombie=");
    pw.println(p.zombie);
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 25 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project android_frameworks_base by ParanoidAndroid.

the class AppWidgetServiceImpl method parseProviderInfoXml.

private Provider parseProviderInfoXml(ComponentName component, ResolveInfo ri) {
    Provider p = null;
    ActivityInfo activityInfo = ri.activityInfo;
    XmlResourceParser parser = null;
    try {
        parser = activityInfo.loadXmlMetaData(mContext.getPackageManager(), AppWidgetManager.META_DATA_APPWIDGET_PROVIDER);
        if (parser == null) {
            Slog.w(TAG, "No " + AppWidgetManager.META_DATA_APPWIDGET_PROVIDER + " meta-data for " + "AppWidget provider '" + component + '\'');
            return null;
        }
        AttributeSet attrs = Xml.asAttributeSet(parser);
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
        // drain whitespace, comments, etc.
        }
        String nodeName = parser.getName();
        if (!"appwidget-provider".equals(nodeName)) {
            Slog.w(TAG, "Meta-data does not start with appwidget-provider tag for" + " AppWidget provider '" + component + '\'');
            return null;
        }
        p = new Provider();
        AppWidgetProviderInfo info = p.info = new AppWidgetProviderInfo();
        info.provider = component;
        p.uid = activityInfo.applicationInfo.uid;
        Resources res = mContext.getPackageManager().getResourcesForApplicationAsUser(activityInfo.packageName, mUserId);
        TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AppWidgetProviderInfo);
        // These dimensions has to be resolved in the application's context.
        // We simply send back the raw complex data, which will be
        // converted to dp in {@link AppWidgetManager#getAppWidgetInfo}.
        TypedValue value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minWidth);
        info.minWidth = value != null ? value.data : 0;
        value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minHeight);
        info.minHeight = value != null ? value.data : 0;
        value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeWidth);
        info.minResizeWidth = value != null ? value.data : info.minWidth;
        value = sa.peekValue(com.android.internal.R.styleable.AppWidgetProviderInfo_minResizeHeight);
        info.minResizeHeight = value != null ? value.data : info.minHeight;
        info.updatePeriodMillis = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_updatePeriodMillis, 0);
        info.initialLayout = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_initialLayout, 0);
        info.initialKeyguardLayout = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_initialKeyguardLayout, 0);
        String className = sa.getString(com.android.internal.R.styleable.AppWidgetProviderInfo_configure);
        if (className != null) {
            info.configure = new ComponentName(component.getPackageName(), className);
        }
        info.label = activityInfo.loadLabel(mContext.getPackageManager()).toString();
        info.icon = ri.getIconResource();
        info.previewImage = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_previewImage, 0);
        info.autoAdvanceViewId = sa.getResourceId(com.android.internal.R.styleable.AppWidgetProviderInfo_autoAdvanceViewId, -1);
        info.resizeMode = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_resizeMode, AppWidgetProviderInfo.RESIZE_NONE);
        info.widgetCategory = sa.getInt(com.android.internal.R.styleable.AppWidgetProviderInfo_widgetCategory, AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN);
        sa.recycle();
    } catch (Exception e) {
        // Ok to catch Exception here, because anything going wrong because
        // of what a client process passes to us should not be fatal for the
        // system process.
        Slog.w(TAG, "XML parsing failed for AppWidget provider '" + component + '\'', e);
        return null;
    } finally {
        if (parser != null)
            parser.close();
    }
    return p;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) ComponentName(android.content.ComponentName) Resources(android.content.res.Resources) Point(android.graphics.Point) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) RemoteException(android.os.RemoteException) IOException(java.io.IOException) TypedValue(android.util.TypedValue)

Aggregations

AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)91 Point (android.graphics.Point)24 ComponentName (android.content.ComponentName)21 AppWidgetHostView (android.appwidget.AppWidgetHostView)18 Bundle (android.os.Bundle)18 WidgetBackupProvider (com.android.server.WidgetBackupProvider)15 ActivityInfo (android.content.pm.ActivityInfo)14 ResolveInfo (android.content.pm.ResolveInfo)14 ArrayList (java.util.ArrayList)13 IOException (java.io.IOException)12 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)12 Intent (android.content.Intent)10 PackageManager (android.content.pm.PackageManager)9 Resources (android.content.res.Resources)7 View (android.view.View)7 Context (android.content.Context)6 IPackageManager (android.content.pm.IPackageManager)6 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)6 TypedArray (android.content.res.TypedArray)6 XmlResourceParser (android.content.res.XmlResourceParser)6