Search in sources :

Example 61 with AppWidgetProviderInfo

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

the class KeyguardWidgetPager method addWidget.

/*
     * We wrap widgets in a special frame which handles drawing the over scroll foreground.
     */
public void addWidget(View widget, int pageIndex) {
    KeyguardWidgetFrame frame;
    // All views contained herein should be wrapped in a KeyguardWidgetFrame
    if (!(widget instanceof KeyguardWidgetFrame)) {
        frame = new KeyguardWidgetFrame(getContext());
        FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        lp.gravity = Gravity.TOP;
        // The framework adds a default padding to AppWidgetHostView. We don't need this padding
        // for the Keyguard, so we override it to be 0.
        widget.setPadding(0, 0, 0, 0);
        frame.addView(widget, lp);
        // We set whether or not this widget supports vertical resizing.
        if (widget instanceof AppWidgetHostView) {
            AppWidgetHostView awhv = (AppWidgetHostView) widget;
            AppWidgetProviderInfo info = awhv.getAppWidgetInfo();
            if ((info.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0) {
                frame.setWidgetLockedSmall(false);
            } else {
                // Lock the widget to be small.
                frame.setWidgetLockedSmall(true);
                if (mCenterSmallWidgetsVertically) {
                    lp.gravity = Gravity.CENTER;
                }
            }
        }
    } else {
        frame = (KeyguardWidgetFrame) widget;
    }
    ViewGroup.LayoutParams pageLp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    frame.setOnLongClickListener(this);
    frame.setWorkerHandler(mBackgroundWorkerHandler);
    if (pageIndex == -1) {
        addView(frame, pageLp);
    } else {
        addView(frame, pageIndex, pageLp);
    }
    // Update the frame content description.
    View content = (widget == frame) ? frame.getContent() : widget;
    if (content != null) {
        String contentDescription = mContext.getString(com.android.internal.R.string.keyguard_accessibility_widget, content.getContentDescription());
        frame.setContentDescription(contentDescription);
    }
    updateWidgetFrameImportantForAccessibility(frame);
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View)

Example 62 with AppWidgetProviderInfo

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

the class AppWidgetHostActivity method handleAppWidgetConfigureResult.

void handleAppWidgetConfigureResult(int resultCode, Intent data) {
    int appWidgetId = getPreferences(0).getInt(PENDING_APPWIDGET_ID, -1);
    Log.d(TAG, "resultCode=" + resultCode + " appWidgetId=" + appWidgetId);
    if (appWidgetId < 0) {
        Log.w(TAG, "was no preference for PENDING_APPWIDGET_ID");
        return;
    }
    if (resultCode == RESULT_OK) {
        AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
        addAppWidgetView(appWidgetId, appWidget);
    } else {
        mHost.deleteAppWidgetId(appWidgetId);
    }
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 63 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project android_packages_apps_Launcher2 by CyanogenMod.

the class LauncherTransitionable method bindAppWidget.

/**
     * Add the views for a widget to the workspace.
     *
     * Implementation of the method from LauncherModel.Callbacks.
     */
public void bindAppWidget(LauncherAppWidgetInfo item) {
    setLoadOnResume();
    final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0;
    if (DEBUG_WIDGETS) {
        Log.d(TAG, "bindAppWidget: " + item);
    }
    final Workspace workspace = mWorkspace;
    final int appWidgetId = item.appWidgetId;
    final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
    if (DEBUG_WIDGETS) {
        Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider);
    }
    item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
    item.hostView.setTag(item);
    item.onBindAppWidget(this);
    workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX, item.cellY, item.spanX, item.spanY, false);
    addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
    workspace.requestLayout();
    if (DEBUG_WIDGETS) {
        Log.d(TAG, "bound widget id=" + item.appWidgetId + " in " + (SystemClock.uptimeMillis() - start) + "ms");
    }
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 64 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project android_packages_apps_Launcher2 by CyanogenMod.

the class AppsCustomizePagedView method preloadWidget.

private void preloadWidget(final PendingAddWidgetInfo info) {
    final AppWidgetProviderInfo pInfo = info.info;
    final Bundle options = getDefaultOptionsForWidget(mLauncher, info);
    if (pInfo.configure != null) {
        info.bindOptions = options;
        return;
    }
    mWidgetCleanupState = WIDGET_PRELOAD_PENDING;
    mBindWidgetRunnable = new Runnable() {

        @Override
        public void run() {
            mWidgetLoadingId = mLauncher.getAppWidgetHost().allocateAppWidgetId();
            // SDK level check.
            if (options == null) {
                if (AppWidgetManager.getInstance(mLauncher).bindAppWidgetIdIfAllowed(mWidgetLoadingId, info.componentName)) {
                    mWidgetCleanupState = WIDGET_BOUND;
                }
            } else {
                if (AppWidgetManager.getInstance(mLauncher).bindAppWidgetIdIfAllowed(mWidgetLoadingId, info.componentName, options)) {
                    mWidgetCleanupState = WIDGET_BOUND;
                }
            }
        }
    };
    post(mBindWidgetRunnable);
    mInflateWidgetRunnable = new Runnable() {

        @Override
        public void run() {
            if (mWidgetCleanupState != WIDGET_BOUND) {
                return;
            }
            AppWidgetHostView hostView = mLauncher.getAppWidgetHost().createView(getContext(), mWidgetLoadingId, pInfo);
            info.boundWidget = hostView;
            mWidgetCleanupState = WIDGET_INFLATED;
            hostView.setVisibility(INVISIBLE);
            int[] unScaledSize = mLauncher.getWorkspace().estimateItemSize(info.spanX, info.spanY, info, false);
            // We want the first widget layout to be the correct size. This will be important
            // for width size reporting to the AppWidgetManager.
            DragLayer.LayoutParams lp = new DragLayer.LayoutParams(unScaledSize[0], unScaledSize[1]);
            lp.x = lp.y = 0;
            lp.customPosition = true;
            hostView.setLayoutParams(lp);
            mLauncher.getDragLayer().addView(hostView);
        }
    };
    post(mInflateWidgetRunnable);
}
Also used : AppWidgetHostView(android.appwidget.AppWidgetHostView) Bundle(android.os.Bundle) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 65 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project android_packages_apps_Launcher2 by CyanogenMod.

the class AppsCustomizePagedView method onPackagesUpdated.

public void onPackagesUpdated() {
    // Get the list of widgets and shortcuts
    mWidgets.clear();
    List<AppWidgetProviderInfo> widgets = AppWidgetManager.getInstance(mLauncher).getInstalledProviders();
    Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
    List<ResolveInfo> shortcuts = mPackageManager.queryIntentActivities(shortcutsIntent, 0);
    for (AppWidgetProviderInfo widget : widgets) {
        if (widget.minWidth > 0 && widget.minHeight > 0) {
            // Ensure that all widgets we show can be added on a workspace of this size
            int[] spanXY = Launcher.getSpanForWidget(mLauncher, widget);
            int[] minSpanXY = Launcher.getMinSpanForWidget(mLauncher, widget);
            int minSpanX = Math.min(spanXY[0], minSpanXY[0]);
            int minSpanY = Math.min(spanXY[1], minSpanXY[1]);
            if (minSpanX <= LauncherModel.getCellCountX() && minSpanY <= LauncherModel.getCellCountY()) {
                mWidgets.add(widget);
            } else {
                Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" + widget.minWidth + ", " + widget.minHeight + ")");
            }
        } else {
            Log.e(TAG, "Widget " + widget.provider + " has invalid dimensions (" + widget.minWidth + ", " + widget.minHeight + ")");
        }
    }
    mWidgets.addAll(shortcuts);
    Collections.sort(mWidgets, new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager));
    updatePageCounts();
    invalidateOnDataChange();
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Intent(android.content.Intent) Paint(android.graphics.Paint)

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