Example usage for android.appwidget AppWidgetHostView getAppWidgetId

List of usage examples for android.appwidget AppWidgetHostView getAppWidgetId

Introduction

In this page you can find the example usage for android.appwidget AppWidgetHostView getAppWidgetId.

Prototype

public int getAppWidgetId() 

Source Link

Usage

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

/**
 * Process a widget drop./*from  ww  w  .j a v a2 s  .  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

/**
 * Process a widget drop./*w w w.  ja va  2s .  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./*  w  w w .  j av a2  s.  co  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.klinker.android.launcher.launcher3.Launcher.java

/**
 * Process a widget drop.//from   w w w. ja  v  a 2s. 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);
        }
    }
}

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

/**
 * Process a widget drop.//from   ww w . j av a  2s  .  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.android.launcher3.Launcher.java

/**
 * Process a widget drop.//from  w w w.j  av a2 s  .  c  o  m
 */
private void addAppWidgetFromDrop(PendingAddWidgetInfo info) {
    AppWidgetHostView hostView = info.boundWidget;
    int appWidgetId;
    if (hostView != null) {
        // In the case where we've prebound the widget, we remove it from the DragLayer
        if (LOGD) {
            Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
        }
        getDragLayer().removeView(hostView);

        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetFromDropImpl(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) {
            addAppWidgetFromDropImpl(appWidgetId, info, null, info.info);
        } else {
            setWaitingForResult(PendingRequestArgs.forWidgetInfo(appWidgetId, info.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(info.info).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:xyz.klinker.blur.launcher3.Launcher.java

/**
 * Process a widget drop./* ww w  .  j a  v  a  2s  .  com*/
 *
 * @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) {
        // In the case where we've prebound the widget, we remove it from the DragLayer
        if (LOGD) {
            Log.d(TAG, "Removing widget view from drag layer and setting boundWidget to null");
        }
        getDragLayer().removeView(hostView);

        appWidgetId = hostView.getAppWidgetId();
        addAppWidgetFromDropImpl(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) {
            addAppWidgetFromDropImpl(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:g7.bluesky.launcher3.Launcher.java

/**
 * Process a widget drop./*www .j  a v  a  2s.c  om*/
 *
 * @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);
        }
    }
}