Example usage for android.appwidget AppWidgetHostView setTag

List of usage examples for android.appwidget AppWidgetHostView setTag

Introduction

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

Prototype

public void setTag(final Object tag) 

Source Link

Document

Sets the tag associated with this view.

Usage

From source file:com.farmerbb.taskbar.service.DashboardService.java

private void addWidget(int appWidgetId, int cellId, boolean shouldSave) {
    AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);

    final DashboardCell cellLayout = cells.get(cellId);
    final AppWidgetHostView hostView = mAppWidgetHost.createView(DashboardService.this, appWidgetId,
            appWidgetInfo);//from w  w w . j  av  a 2 s.  c  om
    hostView.setAppWidget(appWidgetId, appWidgetInfo);

    Bundle bundle = new Bundle();
    bundle.putInt("cellId", cellId);
    hostView.setTag(bundle);

    cellLayout.findViewById(R.id.empty).setVisibility(View.GONE);
    cellLayout.findViewById(R.id.placeholder).setVisibility(View.GONE);
    cellLayout.setOnLongClickListener(olcl);
    cellLayout.setOnGenericMotionListener(ogml);
    cellLayout.setOnInterceptedLongPressListener(listener);

    LinearLayout linearLayout = (LinearLayout) cellLayout.findViewById(R.id.dashboard);
    linearLayout.addView(hostView);

    Bundle bundle2 = (Bundle) cellLayout.getTag();
    bundle2.putInt("appWidgetId", appWidgetId);
    cellLayout.setTag(bundle2);

    widgets.put(cellId, hostView);

    if (shouldSave) {
        SharedPreferences pref = U.getSharedPreferences(this);
        SharedPreferences.Editor editor = pref.edit();
        editor.putInt("dashboard_widget_" + Integer.toString(cellId), appWidgetId);
        editor.putString("dashboard_widget_" + Integer.toString(cellId) + "_provider",
                appWidgetInfo.provider.flattenToString());
        editor.remove("dashboard_widget_" + Integer.toString(cellId) + "_placeholder");
        editor.apply();
    }

    new Handler().post(() -> {
        ViewGroup.LayoutParams params = hostView.getLayoutParams();
        params.width = cellLayout.getWidth();
        params.height = cellLayout.getHeight();
        hostView.setLayoutParams(params);
        hostView.updateAppWidgetSize(null, cellLayout.getWidth(), cellLayout.getHeight(), cellLayout.getWidth(),
                cellLayout.getHeight());
    });
}

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

private void addAppWidgetToWorkspace(AppWidgetHostView hostView, LauncherAppWidgetInfo item,
        LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
    hostView.setTag(item);
    item.onBindAppWidget(this, hostView);

    hostView.setFocusable(true);//from  w  ww  .j a va 2 s .co  m
    hostView.setOnFocusChangeListener(mFocusHandler);

    mWorkspace.addInScreen(hostView, item.container, item.screenId, item.cellX, item.cellY, item.spanX,
            item.spanY, insert);

    if (!item.isCustomWidget()) {
        addWidgetToAutoAdvanceIfNeeded(hostView, appWidgetInfo);
    }
}