Example usage for android.appwidget AppWidgetManager EXTRA_APPWIDGET_PROVIDER

List of usage examples for android.appwidget AppWidgetManager EXTRA_APPWIDGET_PROVIDER

Introduction

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

Prototype

String EXTRA_APPWIDGET_PROVIDER

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

Click Source Link

Document

An intent extra that contains the component name of a AppWidget provider.

Usage

From source file:g7.bluesky.launcher3.Launcher.java

/**
 * Process a widget drop./* www. java  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 = 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.launcher3.Launcher.java

/**
 * Event handler for the app widget view which has not fully restored.
 *//*w w w  .ja  v a 2  s .c o  m*/
public void onClickPendingWidget(final PendingAppWidgetHostView v) {
    if (mIsSafeModeEnabled) {
        Toast.makeText(this, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show();
        return;
    }

    final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
    if (v.isReadyForClickSetup()) {
        if (info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_NOT_VALID)) {
            if (!info.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_ID_ALLOCATED)) {
                // This should not happen, as we make sure that an Id is allocated during bind.
                return;
            }
            LauncherAppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.findProvider(info.providerName,
                    info.user);
            if (appWidgetInfo != null) {
                setWaitingForResult(PendingRequestArgs.forWidgetInfo(info.appWidgetId, appWidgetInfo, info));

                Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, info.appWidgetId);
                intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, appWidgetInfo.provider);
                mAppWidgetManager.getUser(appWidgetInfo).addToIntent(intent,
                        AppWidgetManager.EXTRA_APPWIDGET_PROVIDER_PROFILE);
                startActivityForResult(intent, REQUEST_BIND_PENDING_APPWIDGET);
            }
        } else {
            LauncherAppWidgetProviderInfo appWidgetInfo = mAppWidgetManager
                    .getLauncherAppWidgetInfo(info.appWidgetId);
            if (appWidgetInfo != null) {
                startRestoredWidgetReconfigActivity(appWidgetInfo, info);
            }
        }
    } else if (info.installProgress < 0) {
        // The install has not been queued
        final String packageName = info.providerName.getPackageName();
        showBrokenAppInstallDialog(packageName, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
            }
        });
    } else {
        // Download has started.
        final String packageName = info.providerName.getPackageName();
        startActivitySafely(v, LauncherModel.getMarketIntent(packageName), info);
    }
}