Example usage for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID

List of usage examples for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID

Introduction

In this page you can find the example usage for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID.

Prototype

String EXTRA_APPWIDGET_ID

To view the source code for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID.

Click Source Link

Document

An intent extra that contains one appWidgetId.

Usage

From source file:com.cognizant.trumobi.PersonaLauncher.java

/**
 * Add a widget to the workspace./*from ww w .ja  v  a  2 s .  c  o m*/
 * 
 * @param data
 *            The intent describing the appWidgetId.
 * @param cellInfo
 *            The position on screen where to create the widget.
 */
private void completeAddAppWidget(Intent data, PersonaCellLayout.CellInfo cellInfo,
        final boolean insertAtFirst) {

    Bundle extras = data.getExtras();
    final int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);

    if (LOGD)
        PersonaLog.d(LOG_TAG, "dumping extras content=" + extras.toString());

    final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);

    // Calculate the grid spans needed to fit this widget
    PersonaCellLayout layout = (PersonaCellLayout) mWorkspace.getChildAt(cellInfo.screen);
    final int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight);
    final PersonaCellLayout.CellInfo cInfo = cellInfo;
    AlertDialog.Builder builder;
    AlertDialog alertDialog;

    final View dlg_layout = View.inflate(PersonaLauncher.this, R.layout.pr_widget_span_setup, null);
    final PersonaNumberPicker ncols = (PersonaNumberPicker) dlg_layout.findViewById(R.id.widget_columns_span);
    ncols.setRange(1, mWorkspace.currentDesktopColumns());
    ncols.setCurrent(spans[0]);
    final PersonaNumberPicker nrows = (PersonaNumberPicker) dlg_layout.findViewById(R.id.widget_rows_span);
    nrows.setRange(1, mWorkspace.currentDesktopRows());
    nrows.setCurrent(spans[1]);
    // 290661 changes
    spans[0] = 3;
    spans[1] = 2;
    realAddWidget(appWidgetInfo, cInfo, spans, appWidgetId, insertAtFirst);

    /*
     * builder = new AlertDialog.Builder(PersonaLauncher.this);
     * builder.setView(dlg_layout); alertDialog = builder.create();
     * alertDialog
     * .setTitle(getResources().getString(R.string.widget_config_dialog_title
     * )); alertDialog.setMessage(getResources().getString(R.string.
     * widget_config_dialog_summary));
     * alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
     * getResources().getString(android.R.string.ok), new
     * DialogInterface.OnClickListener() { public void
     * onClick(DialogInterface dialog, int which) {
     * spans[0]=ncols.getCurrent(); spans[1]=nrows.getCurrent();
     * realAddWidget(appWidgetInfo,cInfo,spans,appWidgetId,insertAtFirst); }
     * }); alertDialog.show();
     */
}

From source file:com.android.leanlauncher.LauncherTransitionable.java

/**
 * Process a widget drop.//from   w w  w  .  j  a va  2s .c o  m
 *
 * @param info The PendingAppWidgetInfo of the widget being added.
 * @param cell The cell it should be added to, optional
 */
void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int[] cell, int[] span, int[] loc) {
    resetAddInfo();
    mPendingAddInfo.container = info.container = container;
    mPendingAddInfo.dropPos = loc;
    mPendingAddInfo.minSpanX = info.minSpanX;
    mPendingAddInfo.minSpanY = info.minSpanY;

    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }
    if (span != null) {
        mPendingAddInfo.spanX = span[0];
        mPendingAddInfo.spanY = span[1];
    }

    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetImpl(appWidgetId, info, hostView, info.info);
    } else {
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;

        boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.info, options);
        if (success) {
            addAppWidgetImpl(appWidgetId, info, null, info.info);
        } else {
            mPendingAddWidgetInfo = info.info;
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            mAppWidgetManager.getUser(mPendingAddWidgetInfo).addToIntent(intent,
                    AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
            // TODO: we need to make sure that this accounts for the options bundle.
            // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}

From source file:com.android.launcher2.Launcher.java

void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
        AppWidgetProviderInfo appWidgetInfo) {
    if (appWidgetInfo.configure != null) {
        mPendingAddWidgetInfo = appWidgetInfo;

        // Launch over to configure widget, if needed
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
        intent.setComponent(appWidgetInfo.configure);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET);
    } else {/*from w w  w.  j  av a  2  s.  co m*/
        // Otherwise just add it
        completeAddAppWidget(appWidgetId, info.container, info.screen, boundWidget, appWidgetInfo);
        // Exit spring loaded mode if necessary after adding the widget
        exitSpringLoadedDragModeDelayed(true, false, null);
    }
}

From source file:com.android.launcher2.Launcher.java

/**
 * Process a widget drop./*from   w  ww  .ja  va2 s  . c o  m*/
 *
 * @param info The PendingAppWidgetInfo of the widget being added.
 * @param screen The screen where it should be added
 * @param cell The cell it should be added to, optional
 * @param position The location on the screen where it was dropped, optional
 */
void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen, int[] cell, int[] span,
        int[] loc) {
    resetAddInfo();
    mPendingAddInfo.container = info.container = container;
    mPendingAddInfo.screen = info.screen = screen;
    mPendingAddInfo.dropPos = loc;
    mPendingAddInfo.minSpanX = info.minSpanX;
    mPendingAddInfo.minSpanY = info.minSpanY;

    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }
    if (span != null) {
        mPendingAddInfo.spanX = span[0];
        mPendingAddInfo.spanY = span[1];
    }

    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetImpl(appWidgetId, info, hostView, info.info);
    } else {
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();

        if (!UiUtils.hasJellyBean()) {
            addAppWidgetImpl(appWidgetId, info, null, info.info);
            return;
        }
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        Bundle options = info.bindOptions;

        if (AppWidgetManagerCompat.bindAppWidgetIdIfAllowed(mAppWidgetManager, appWidgetId, info.componentName,
                options)) {
            addAppWidgetImpl(appWidgetId, info, null, info.info);
        } else {
            mPendingAddWidgetInfo = info.info;
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            // TODO: we need to make sure that this accounts for the options bundle.
            // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}

From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java

/**
 * Process a widget drop.//from  w  w w.  j  a va2s .c  o m
 *
 * @param info The PendingAppWidgetInfo of the widget being added.
 * @param screen The screen where it should be added
 * @param cell The cell it should be added to, optional
 * @param position The location on the screen where it was dropped, optional
 */
void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen, int[] cell, int[] span,
        int[] loc) {
    resetAddInfo();
    mPendingAddInfo.container = info.container = container;
    mPendingAddInfo.screen = info.screen = screen;
    mPendingAddInfo.dropPos = loc;
    mPendingAddInfo.minSpanX = info.minSpanX;
    mPendingAddInfo.minSpanY = info.minSpanY;

    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }
    if (span != null) {
        mPendingAddInfo.spanX = span[0];
        mPendingAddInfo.spanY = span[1];
    }

    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetImpl(appWidgetId, info, hostView, info.info);
    } else {
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;

        boolean success = false;
        if (options != null) {
            //TODO add options bundle for 4.2+
            success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName);

            //                success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,
            //                        info.componentName, options);
        } else {
            success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName);
        }
        if (success) {
            addAppWidgetImpl(appWidgetId, info, null, info.info);
        } else {
            mPendingAddWidgetInfo = info.info;
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            // TODO: we need to make sure that this accounts for the options bundle.
            // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@SuppressWarnings("unused")
void addAppWidget(final Intent data) {
    // TODO: catch bad widget exception when sent
    int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);

    String customWidget = data.getStringExtra(EXTRA_CUSTOM_WIDGET);
    /*/*from   ww  w .j a  v  a2 s  . c  o m*/
     * if (SEARCH_WIDGET.equals(customWidget)) { // We don't need this any
     * more, since this isn't a real app widget.
     * mAppWidgetHost.deleteAppWidgetId(appWidgetId); // add the search
     * widget addSearch(); } else {
     */
    AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);

    try {
        Bundle metadata = getPackageManager().getReceiverInfo(appWidget.provider,
                PackageManager.GET_META_DATA).metaData;
        if (metadata != null) {
            if (metadata.containsKey(PersonaLauncherMetadata.Requirements.APIVersion)) {
                int requiredApiVersion = metadata.getInt(PersonaLauncherMetadata.Requirements.APIVersion);
                if (requiredApiVersion > PersonaLauncherMetadata.CurrentAPIVersion) {
                    onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_CANCELED, data);
                    // Show a nice toast here to tell the user why the
                    // widget is rejected.
                    new AlertDialog.Builder(this).setTitle(R.string.adw_version).setCancelable(true)
                            .setIcon(R.drawable.pr_app_icon)
                            .setPositiveButton(getString(android.R.string.ok), null)
                            .setMessage(getString(R.string.scrollable_api_required)).create().show();
                    return;
                }
            }
        }
    } catch (PackageManager.NameNotFoundException expt) {
        // No Metadata available... then it is all OK...
    }
    configureOrAddAppWidget(data);
}

From source file:com.android.soma.Launcher.java

void addAppWidgetImpl(final int appWidgetId, ItemInfo info, AppWidgetHostView boundWidget,
        AppWidgetProviderInfo appWidgetInfo) {
    if (appWidgetInfo.configure != null) {
        mPendingAddWidgetInfo = appWidgetInfo;

        // Launch over to configure widget, if needed
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
        intent.setComponent(appWidgetInfo.configure);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
        Utilities.startActivityForResultSafely(this, intent, REQUEST_CREATE_APPWIDGET);
    } else {//from   w ww  .  ja  va  2s  .  c  o  m
        // Otherwise just add it
        completeAddAppWidget(appWidgetId, info.container, info.screenId, boundWidget, appWidgetInfo);
        // Exit spring loaded mode if necessary after adding the widget
        exitSpringLoadedDragModeDelayed(true, false, null);
    }
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

private void configureOrAddAppWidget(Intent data) {
    int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
    if (appWidget.configure != null) {
        // Launch over to configure widget, if needed
        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
        intent.setComponent(appWidget.configure);
        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

        startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
    } else {/*from   w w w.ja va  2 s.c  o m*/
        // Otherwise just add it
        onActivityResult(REQUEST_CREATE_APPWIDGET, Activity.RESULT_OK, data);
    }
}

From source file:com.android.soma.Launcher.java

/**
 * Process a widget drop./*from   w  w  w  . j  a v a  2 s . c  o m*/
 *
 * @param info The PendingAppWidgetInfo of the widget being added.
 * @param screenId The ID of the screen where it should be added
 * @param cell The cell it should be added to, optional
 * @param position The location on the screen where it was dropped, optional
 */
void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, int[] cell, int[] span,
        int[] loc) {
    resetAddInfo();
    mPendingAddInfo.container = info.container = container;
    mPendingAddInfo.screenId = info.screenId = screenId;
    mPendingAddInfo.dropPos = loc;
    mPendingAddInfo.minSpanX = info.minSpanX;
    mPendingAddInfo.minSpanY = info.minSpanY;

    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }
    if (span != null) {
        mPendingAddInfo.spanX = span[0];
        mPendingAddInfo.spanY = span[1];
    }

    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetImpl(appWidgetId, info, hostView, info.info);
    } else {
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;

        boolean success = false;
        if (options != null) {
            success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName, options);
        } else {
            success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName);
        }
        if (success) {
            addAppWidgetImpl(appWidgetId, info, null, info.info);
        } else {
            mPendingAddWidgetInfo = info.info;
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            // TODO: we need to make sure that this accounts for the options bundle.
            // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

/**
 * Process a widget drop./* w  w  w. j av  a2 s. c o m*/
 *
 * @param info The PendingAppWidgetInfo of the widget being added.
 * @param screenId The ID of the screen where it should be added
 * @param cell The cell it should be added to, optional
 */
private void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, long screenId, int[] cell,
        int[] span) {
    resetAddInfo();
    mPendingAddInfo.container = info.container = container;
    mPendingAddInfo.screenId = info.screenId = screenId;
    mPendingAddInfo.dropPos = null;
    mPendingAddInfo.minSpanX = info.minSpanX;
    mPendingAddInfo.minSpanY = info.minSpanY;

    if (cell != null) {
        mPendingAddInfo.cellX = cell[0];
        mPendingAddInfo.cellY = cell[1];
    }
    if (span != null) {
        mPendingAddInfo.spanX = span[0];
        mPendingAddInfo.spanY = span[1];
    }

    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetImpl(appWidgetId, info, hostView, info.info);

        // Clear the boundWidget so that it doesn't get destroyed.
        info.boundWidget = null;
    } else {
        // In this case, we either need to start an activity to get permission to bind
        // the widget, or we need to start an activity to configure the widget, or both.
        appWidgetId = getAppWidgetHost().allocateAppWidgetId();
        Bundle options = info.bindOptions;

        boolean success = mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.info, options);
        if (success) {
            addAppWidgetImpl(appWidgetId, info, null, info.info);
        } else {
            mPendingAddWidgetInfo = info.info;
            Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName);
            mAppWidgetManager.getUser(mPendingAddWidgetInfo).addToIntent(intent,
                    AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
            // TODO: we need to make sure that this accounts for the options bundle.
            // intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_OPTIONS, options);
            startActivityForResult(intent, REQUEST_BIND_APPWIDGET);
        }
    }
}