当前位置: 首页>>代码示例>>Java>>正文


Java AppWidgetHost.deleteAppWidgetId方法代码示例

本文整理汇总了Java中android.appwidget.AppWidgetHost.deleteAppWidgetId方法的典型用法代码示例。如果您正苦于以下问题:Java AppWidgetHost.deleteAppWidgetId方法的具体用法?Java AppWidgetHost.deleteAppWidgetId怎么用?Java AppWidgetHost.deleteAppWidgetId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.appwidget.AppWidgetHost的用法示例。


在下文中一共展示了AppWidgetHost.deleteAppWidgetId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createWidgetInfo

import android.appwidget.AppWidgetHost; //导入方法依赖的package包/类
/**
 * Creates a LauncherAppWidgetInfo corresponding to {@param info}
 * @param bindWidget if true the info is bound and a valid widgetId is assigned to
 *                   the LauncherAppWidgetInfo
 */
private LauncherAppWidgetInfo createWidgetInfo(
        LauncherAppWidgetProviderInfo info, boolean bindWidget) {
    LauncherAppWidgetInfo item = new LauncherAppWidgetInfo(
            LauncherAppWidgetInfo.NO_ID, info.provider);
    item.spanX = info.minSpanX;
    item.spanY = info.minSpanY;
    item.minSpanX = info.minSpanX;
    item.minSpanY = info.minSpanY;
    item.user = mWidgetManager.getUser(info);
    item.cellX = 0;
    item.cellY = 1;
    item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;

    if (bindWidget) {
        PendingAddWidgetInfo pendingInfo = new PendingAddWidgetInfo(mTargetContext, info);
        pendingInfo.spanX = item.spanX;
        pendingInfo.spanY = item.spanY;
        pendingInfo.minSpanX = item.minSpanX;
        pendingInfo.minSpanY = item.minSpanY;
        Bundle options = WidgetHostViewLoader.getDefaultOptionsForWidget(mTargetContext, pendingInfo);

        AppWidgetHost host = new AppWidgetHost(mTargetContext, Launcher.APPWIDGET_HOST_ID);
        int widgetId = host.allocateAppWidgetId();
        if (!mWidgetManager.bindAppWidgetIdIfAllowed(widgetId, info, options)) {
            host.deleteAppWidgetId(widgetId);
            throw new IllegalArgumentException("Unable to bind widget id");
        }
        item.appWidgetId = widgetId;
    }
    return item;
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:37,代码来源:BindWidgetTest.java

示例2: delete

import android.appwidget.AppWidgetHost; //导入方法依赖的package包/类
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
    createDbIfNotExists();
    SqlArguments args = new SqlArguments(uri, selection, selectionArgs);

    SQLiteDatabase db = mOpenHelper.getWritableDatabase();

    if (Binder.getCallingPid() != Process.myPid()
            && Favorites.TABLE_NAME.equalsIgnoreCase(args.table)) {
        String widgetSelection = TextUtils.isEmpty(args.where) ? "1=1" : args.where;
        widgetSelection = String.format(Locale.ENGLISH, "%1$s = %2$d AND ( %3$s )",
                Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET, widgetSelection);
        try (Cursor c = db.query(Favorites.TABLE_NAME, new String[] { Favorites.APPWIDGET_ID },
                widgetSelection, args.args, null, null, null)) {
            AppWidgetHost host = new AppWidgetHost(getContext(), Launcher.APPWIDGET_HOST_ID);
            while (c.moveToNext()) {
                int widgetId = c.getInt(0);
                if (widgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
                    try {
                        host.deleteAppWidgetId(widgetId);
                    } catch (RuntimeException e) {
                        Log.e(TAG, "Error deleting widget id " + widgetId, e);
                    }
                }
            }
        }
    }
    int count = db.delete(args.table, args.where, args.args);
    if (count > 0) {
        notifyListeners();
        reloadLauncherIfExternal();
    }
    return count;
}
 
开发者ID:TeamBrainStorm,项目名称:SimpleUILauncher,代码行数:35,代码来源:LauncherProvider.java

示例3: doDelete

import android.appwidget.AppWidgetHost; //导入方法依赖的package包/类
@Thunk void doDelete() {
  try {
    AppWidgetHost host = new AppWidgetHost(mContext.getApplicationContext(), 0);
    host.deleteAppWidgetId(mItemUnderAction.widgetId);
    mAdapter.remove(mItemUnderAction);
  } catch (Throwable e) {
    Debug.log(e);
    Toast.makeText(mContext, R.string.msg_unknown_error, Toast.LENGTH_LONG).show();
  }
}
 
开发者ID:sunnygoyal,项目名称:PowerToggles,代码行数:11,代码来源:HomeFrag.java

示例4: forceUpdate

import android.appwidget.AppWidgetHost; //导入方法依赖的package包/类
/**
 * Force update of widgets with current values
 *
 * @param context
 *          Application context.
 * @param temp
 *          Temperature value
 * @param press
 *          Pressure value
 * @param humid
 *          Humidity value
 */
public static void forceUpdate(Context context,
                               float temp,
                               float press,
                               float humid) {
	/** AppWidgetManager for this widget */
	AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
	/** ComponentName for this widget */
	ComponentName thisAppWidget = new ComponentName(context.getPackageName(),
			WidgetValues.class.getName());
	/** Array of existing widgets */
	int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);

	/** Access to shared preferences of the app widgets */
	SharedPreferences wPrefs = context.getSharedPreferences("WidgetValues", 0);
	/** Flag if the found widget is a ghost widget that the system didn't remove */
	boolean isGhostWidget = true;
	/** Pointer to host of the widgets */
	AppWidgetHost appWidgetHost = new AppWidgetHost(context, 1);

	for (int i = 0; i < appWidgetIds.length-1; i++) {
		/** Number of this widget */
		int widgetNum = wPrefs.getInt("wID"+appWidgetIds[i],9999);
		if (widgetNum != 9999) {
			isGhostWidget = false;
		}
		if (isGhostWidget) {
			appWidgetHost.deleteAppWidgetId(appWidgetIds[i]);
		}
	}

	for (int appWidgetId : appWidgetIds) {
		WidgetValues.updateAppWidget(context, appWidgetManager, appWidgetId,
				temp,
				press,
				humid);
	}
}
 
开发者ID:beegee-tokyo,项目名称:WeatherStation,代码行数:50,代码来源:WidgetValues.java

示例5: onDestroy

import android.appwidget.AppWidgetHost; //导入方法依赖的package包/类
@Override protected void onDestroy() {
  super.onDestroy();
  if (mResult == RESULT_CANCELED) {
    try {
      // Phantom widget fix (kinda)
      AppWidgetHost host = new AppWidgetHost(getApplicationContext(), Integer.MAX_VALUE);
      host.deleteAppWidgetId(mAppWidgetId);
    } catch (Exception e) {
      Timber.e(e, "Widget configuration canceled, id deletion went wrong");
    }
  }
}
 
开发者ID:drymarev,项目名称:rxbsuir,代码行数:13,代码来源:AppWidgetConfigActivity.java

示例6: restoreAppWidgetIds

import android.appwidget.AppWidgetHost; //导入方法依赖的package包/类
/**
 * Updates the app widgets whose id has changed during the restore process.
 */
static void restoreAppWidgetIds(Context context, PendingResult asyncResult,
        int[] oldWidgetIds, int[] newWidgetIds) {
    final ContentResolver cr = context.getContentResolver();
    final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
    AppWidgetHost appWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);

    for (int i = 0; i < oldWidgetIds.length; i++) {

        final AppWidgetProviderInfo provider = widgets.getAppWidgetInfo(newWidgetIds[i]);
        final int state;
        if (LauncherModel.isValidProvider(provider)) {
            // This will ensure that we show 'Click to setup' UI if required.
            state = LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
        } else {
            state = LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
        }

        String[] widgetIdParams = new String[] { Integer.toString(oldWidgetIds[i]) };
        int result = new ContentWriter(context, new ContentWriter.CommitParams(
                "appWidgetId=? and (restored & 1) = 1", widgetIdParams))
                .put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i])
                .put(LauncherSettings.Favorites.RESTORED, state)
                .commit();

        if (result == 0) {
            Cursor cursor = cr.query(Favorites.CONTENT_URI,
                    new String[] {Favorites.APPWIDGET_ID},
                    "appWidgetId=?", widgetIdParams, null);
            try {
                if (!cursor.moveToFirst()) {
                    // The widget no long exists.
                    appWidgetHost.deleteAppWidgetId(newWidgetIds[i]);
                }
            } finally {
                cursor.close();
            }
        }
    }

    LauncherAppState app = LauncherAppState.getInstanceNoCreate();
    if (app != null) {
        app.getModel().forceReload();
    }
    asyncResult.finish();
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:49,代码来源:AppWidgetsRestoredReceiver.java

示例7: restoreAppWidgetIds

import android.appwidget.AppWidgetHost; //导入方法依赖的package包/类
/**
 * Updates the app widgets whose id has changed during the restore process.
 */
static void restoreAppWidgetIds(Context context, int[] oldWidgetIds, int[] newWidgetIds) {
    final ContentResolver cr = context.getContentResolver();
    final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
    AppWidgetHost appWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);

    for (int i = 0; i < oldWidgetIds.length; i++) {
        Log.i(TAG, "Widget state restore id " + oldWidgetIds[i] + " => " + newWidgetIds[i]);

        final AppWidgetProviderInfo provider = widgets.getAppWidgetInfo(newWidgetIds[i]);
        final int state;
        if (LauncherModel.isValidProvider(provider)) {
            // This will ensure that we show 'Click to setup' UI if required.
            state = LauncherAppWidgetInfo.FLAG_UI_NOT_READY;
        } else {
            state = LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
        }

        ContentValues values = new ContentValues();
        values.put(LauncherSettings.Favorites.APPWIDGET_ID, newWidgetIds[i]);
        values.put(LauncherSettings.Favorites.RESTORED, state);

        String[] widgetIdParams = new String[] { Integer.toString(oldWidgetIds[i]) };

        int result = cr.update(Favorites.CONTENT_URI, values,
                "appWidgetId=? and (restored & 1) = 1", widgetIdParams);
        if (result == 0) {
            Cursor cursor = cr.query(Favorites.CONTENT_URI,
                    new String[] {Favorites.APPWIDGET_ID},
                    "appWidgetId=?", widgetIdParams, null);
            try {
                if (!cursor.moveToFirst()) {
                    // The widget no long exists.
                    appWidgetHost.deleteAppWidgetId(newWidgetIds[i]);
                }
            } finally {
                cursor.close();
            }
        }
    }

    LauncherAppState app = LauncherAppState.getInstanceNoCreate();
    if (app != null) {
        app.reloadWorkspace();
    }
}
 
开发者ID:michelelacorte,项目名称:FlickLauncher,代码行数:49,代码来源:AppWidgetsRestoredReceiver.java

示例8: onReceive

import android.appwidget.AppWidgetHost; //导入方法依赖的package包/类
@Override
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
	//*******************************************************
	// Receiver for the widget (click on widget, update service,
	// disable, ... we handle only the update requests here
	//*******************************************************

	super.onReceive(context, intent);

	/** App widget manager for all widgets of this app */
	AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
	/** Component name of this widget */
	ComponentName thisAppWidget = new ComponentName(context.getPackageName(),
			WidgetValues.class.getName());
	/** List of all active widgets */
	int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);

	/** Remote views of the widgets */
	RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_values);

	if (WIDGET_VALUE_UPDATE.equals(intent.getAction())) {

		/** Access to shared preferences of the app widgets */
		SharedPreferences wPrefs = context.getSharedPreferences("WidgetValues", 0);
		/** Flag if the found widget is a ghost widget that the system didn't remove */
		boolean isGhostWidget = true;
		/** Pointer to host of the widgets */
		AppWidgetHost appWidgetHost = new AppWidgetHost(context, 1);

		for (int i = 0; i < appWidgetIds.length-1; i++) {
			/** Number of this widget */
			int widgetNum = wPrefs.getInt("wID"+appWidgetIds[i],9999);
			if (widgetNum != 9999) {
				isGhostWidget = false;
			}
			if (isGhostWidget) {
				appWidgetHost.deleteAppWidgetId(appWidgetIds[i]);
			}
		}

		for (int appWidgetId : appWidgetIds) {
			appWidgetManager.updateAppWidget(appWidgetId, views);
		}

		onUpdate(context, appWidgetManager, appWidgetIds);
	}
}
 
开发者ID:beegee-tokyo,项目名称:WeatherStation,代码行数:48,代码来源:WidgetValues.java


注:本文中的android.appwidget.AppWidgetHost.deleteAppWidgetId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。