Search in sources :

Example 51 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Launcher3 by chislon.

the class WidgetPreviewLoader method getObjectName.

private static String getObjectName(Object o) {
    // should cache the string builder
    StringBuilder sb = new StringBuilder();
    String output;
    if (o instanceof AppWidgetProviderInfo) {
        sb.append(WIDGET_PREFIX);
        sb.append(((AppWidgetProviderInfo) o).provider.flattenToString());
        output = sb.toString();
        sb.setLength(0);
    } else {
        sb.append(SHORTCUT_PREFIX);
        ResolveInfo info = (ResolveInfo) o;
        sb.append(new ComponentName(info.activityInfo.packageName, info.activityInfo.name).flattenToString());
        output = sb.toString();
        sb.setLength(0);
    }
    return output;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) ComponentName(android.content.ComponentName)

Example 52 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project ADWLauncher2 by boombuler.

the class Launcher method completeAddAppWidget.

/**
     * Add a widget to the workspace.
     *
     * @param data The intent describing the appWidgetId.
     * @param cellInfo The position on screen where to create the widget.
     */
private void completeAddAppWidget(Intent data, CellLayout.CellInfo cellInfo) {
    Bundle extras = data.getExtras();
    int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    if (LOGD)
        Log.d(TAG, "dumping extras content=" + extras.toString());
    AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
    // Calculate the grid spans needed to fit this widget
    CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen);
    int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight);
    // Try finding open space on Launcher screen
    final int[] xy = mCellCoordinates;
    if (!findSlot(cellInfo, xy, spans[0], spans[1])) {
        if (appWidgetId != -1)
            mAppWidgetHost.deleteAppWidgetId(appWidgetId);
        return;
    }
    // Build Launcher-specific widget info and save to database
    LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId);
    launcherInfo.spanX = spans[0];
    launcherInfo.spanY = spans[1];
    mModel.addItemToDatabase(this, launcherInfo, LauncherSettings.Favorites.CONTAINER_DESKTOP, mWorkspace.getCurrentScreen(), xy[0], xy[1], false);
    if (!mRestoring) {
        mDesktopItems.add(launcherInfo);
        // Perform actual inflation because we're live
        launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
        launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo);
        launcherInfo.hostView.setTag(launcherInfo);
        mWorkspace.addInCurrentScreen(launcherInfo.hostView, xy[0], xy[1], launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked());
        mModel.mAppWidgets.add(launcherInfo);
        // finish load a widget, send it an intent
        if (appWidgetInfo != null)
            appwidgetReadyBroadcast(appWidgetId, appWidgetInfo.provider);
    }
}
Also used : Bundle(android.os.Bundle) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo)

Example 53 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project ADWLauncher2 by boombuler.

the class Launcher method onConfigurationChanged.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    mWorkspaceLoading = true;
    final int currScreen = mWorkspace.getCurrentScreen();
    checkForLocaleChange();
    setWallpaperDimension();
    final int count = mWorkspace.getChildCount();
    //get icons properties
    final Resources r = getResources();
    final int margintop = r.getDimensionPixelSize(R.dimen.icon_layout_marginTop);
    final int marginbottom = r.getDimensionPixelSize(R.dimen.icon_layout_marginBottom);
    final int marginleft = r.getDimensionPixelSize(R.dimen.icon_layout_marginLeft);
    final int marginright = r.getDimensionPixelSize(R.dimen.icon_layout_marginRight);
    final int paddingtop = r.getDimensionPixelSize(R.dimen.icon_paddingTop);
    final int paddingbottom = r.getDimensionPixelSize(R.dimen.icon_paddingBottom);
    final int paddingleft = r.getDimensionPixelSize(R.dimen.icon_paddingLeft);
    final int paddingright = r.getDimensionPixelSize(R.dimen.icon_paddingRight);
    final int drawablePadding = r.getDimensionPixelSize(R.dimen.icon_drawablePadding);
    for (int i = 0; i < count; i++) {
        CellLayout screen = (CellLayout) mWorkspace.getChildAt(i);
        for (int j = 0; j < screen.getChildCount(); j++) {
            if (screen.getChildAt(j) instanceof BubbleTextView) {
                final BubbleTextView v = (BubbleTextView) screen.getChildAt(j);
                CellLayout.LayoutParams lp = (CellLayout.LayoutParams) v.getLayoutParams();
                lp.topMargin = margintop;
                lp.bottomMargin = marginbottom;
                lp.leftMargin = marginleft;
                lp.rightMargin = marginright;
                v.setLayoutParams(lp);
                v.setPadding(paddingleft, paddingtop, paddingright, paddingbottom);
                v.setCompoundDrawablePadding(drawablePadding);
            }
        }
        screen.reMeasure(this);
    }
    //setContentView(R.layout.launcher);
    //setupViews();
    //mModel.startLoader(this, false);
    mAppWidgetHost.stopListening();
    for (LauncherAppWidgetInfo w : mModel.mAppWidgets) {
        final int appWidgetId = w.appWidgetId;
        final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
        if (mWorkspace.isWidgetScrollable(appWidgetId))
            mWorkspace.unbindWidgetScrollableId(appWidgetId);
        CellLayout screen = (CellLayout) mWorkspace.getChildAt(w.screen);
        screen.removeViewInLayout(w.hostView);
        w.unbind();
        w.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
        w.hostView.setAppWidget(appWidgetId, appWidgetInfo);
        w.hostView.setTag(w);
        mWorkspace.addInScreen(w.hostView, w.screen, w.cellX, w.cellY, w.spanX, w.spanY, false);
    }
    mAppWidgetHost.startListening();
    final Workspace workspace = mWorkspace;
    mWorkspace.setAfterLayoutListener(new Runnable() {

        @Override
        public void run() {
            if (!workspace.isLayoutRequested()) {
                workspace.setCurrentScreen(currScreen);
                for (LauncherAppWidgetInfo w : mModel.mAppWidgets) {
                    if (w.hostView != null) {
                        AppWidgetProviderInfo info = w.hostView.getAppWidgetInfo();
                        if (info != null && info.provider != null) {
                            appwidgetReadyBroadcast(w.appWidgetId, info.provider);
                        }
                    }
                }
                workspace.setAfterLayoutListener(null);
                mWorkspaceLoading = false;
            }
        }
    });
    workspace.requestLayout();
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Resources(android.content.res.Resources)

Example 54 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Launcher3 by chislon.

the class LauncherTransitionable method bindAppWidget.

/**
     * Add the views for a widget to the workspace.
     *
     * Implementation of the method from LauncherModel.Callbacks.
     */
public void bindAppWidget(final LauncherAppWidgetInfo item) {
    Runnable r = new Runnable() {

        public void run() {
            bindAppWidget(item);
        }
    };
    if (waitUntilResume(r)) {
        return;
    }
    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.screenId, 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) Point(android.graphics.Point)

Example 55 with AppWidgetProviderInfo

use of android.appwidget.AppWidgetProviderInfo in project Launcher3 by chislon.

the class LauncherBackupHelper method findAppWidgetProviderInfo.

private AppWidgetProviderInfo findAppWidgetProviderInfo(ComponentName component) {
    if (mWidgetMap == null) {
        List<AppWidgetProviderInfo> widgets = AppWidgetManager.getInstance(mContext).getInstalledProviders();
        mWidgetMap = new HashMap<ComponentName, AppWidgetProviderInfo>(widgets.size());
        for (AppWidgetProviderInfo info : widgets) {
            mWidgetMap.put(info.provider, info);
        }
    }
    return mWidgetMap.get(component);
}
Also used : AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) ComponentName(android.content.ComponentName)

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