android.appwidget.AppWidgetHost类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(232)

本文整理了Java中android.appwidget.AppWidgetHost类的一些代码示例,展示了AppWidgetHost类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AppWidgetHost类的具体详情如下:
包路径:android.appwidget.AppWidgetHost
类名称:AppWidgetHost

AppWidgetHost介绍

暂无

代码示例

代码示例来源:origin: robolectric/robolectric

@Before
public void setup() throws Exception {
 context = ApplicationProvider.getApplicationContext();
 appWidgetHost = new AppWidgetHost(context, 404);
 shadowAppWidgetHost = shadowOf(appWidgetHost);
}

代码示例来源:origin: Neamar/KISS

boolean onOptionsItemSelected(MenuItem item) {
  if (item.getItemId() == R.id.widget) {
    if (!widgetUsed) {
      // request widget picker, a selection will lead to a call of onActivityResult
      int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
      Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
      pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
      mainActivity.startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
    } else {
      // if we already have a widget we remove it
      removeAllWidgets();
    }
    return true;
  }
  return false;
}

代码示例来源:origin: Neamar/KISS

/**
 * Removes a single widget and deletes it from persistent prefs
 *
 * @param hostView instance of a displayed widget
 */
private void removeAppWidget(AppWidgetHostView hostView) {
  // remove widget from view
  int appWidgetId = hostView.getAppWidgetId();
  mAppWidgetHost.deleteAppWidgetId(appWidgetId);
  widgetArea.removeView(hostView);
  // remove widget id from persistent prefs
  SharedPreferences.Editor widgetPrefsEditor = widgetPrefs.edit();
  widgetPrefsEditor.remove(String.valueOf(appWidgetId));
  widgetPrefsEditor.apply();
  // only one widget allowed so widgetUsed is false now
  widgetUsed = false;
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

long insertedId = -1;
try {
  int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
    mAppWidgetHost.deleteAppWidgetId(appWidgetId);
    return -1;
  insertedId = mCallback.insertAndCheck(mDb, mValues);
  if (insertedId < 0) {
    mAppWidgetHost.deleteAppWidgetId(appWidgetId);
    return insertedId;

代码示例来源:origin: klinker24/Android-Blur-Launcher

final ContentResolver cr = context.getContentResolver();
final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
AppWidgetHost appWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
      if (!cursor.moveToFirst()) {
        appWidgetHost.deleteAppWidgetId(newWidgetIds[i]);

代码示例来源:origin: robolectric/robolectric

@Test
public void createView_shouldReturnAppWidgetHostView() throws Exception {
 AppWidgetHostView hostView = appWidgetHost.createView(context, 0, null);
 assertNotNull(hostView);
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

int appWidgetId = new AppWidgetHost(getContext(), Launcher.APPWIDGET_HOST_ID)
    .allocateAppWidgetId();
values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,cn)) {

代码示例来源:origin: MoMoWait/LeanbackLauncher

options.putInt("appWidgetMinHeight", height);
options.putInt("appWidgetMaxHeight", height);
appWidgetId = this.mAppWidgetHost.allocateAppWidgetId();
z = this.mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, appWidgetInfo.provider, options);
this.mAppWidgetHostView = this.mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
this.mAppWidgetHostView.setAppWidget(appWidgetId, appWidgetInfo);
wrapper.addView(this.mAppWidgetHostView);

代码示例来源:origin: clemensbartz/essential-launcher

appWidgetHost = new AppWidgetHost(this, R.id.frWidget);
appWidgetHost.startListening();

代码示例来源:origin: Neamar/KISS

void onStart() {
  // Start listening for widget update
  mAppWidgetHost.startListening();
}

代码示例来源:origin: Neamar/KISS

void onStop() {
  // Stop listening for widget update
  mAppWidgetHost.stopListening();
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

/**
 * Overriden in tests.
 */
protected void onEmptyDbCreated() {
  // Database was just created, so wipe any previous widgets
  if (mWidgetHostResetHandler != null) {
    new AppWidgetHost(mContext, Launcher.APPWIDGET_HOST_ID).deleteHost();
    mWidgetHostResetHandler.sendMessage(Message.obtain(
        mWidgetHostResetHandler,
        ChangeListenerWrapper.MSG_APP_WIDGET_HOST_RESET,
        mContext
    ));
  }
  // Set the flag for empty DB
  Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).commit();
  // When a new DB is created, remove all previously stored managed profile information.
  ManagedProfileHeuristic.processAllUsers(Collections.<UserHandleCompat>emptyList(),
      mContext);
}

代码示例来源:origin: klinker24/Android-Blur-Launcher

@Override
public void startConfigActivity(AppWidgetProviderInfo info, int widgetId, Activity activity,
    AppWidgetHost host, int requestCode) {
  try {
    host.startAppWidgetConfigureActivityForResult(activity, widgetId, 0, requestCode, null);
  } catch (ActivityNotFoundException | SecurityException e) {
    Toast.makeText(activity, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
  }
}

代码示例来源:origin: enricocid/LaunchEnr

/**
 * Overriden in tests.
 */
void onEmptyDbCreated() {
  // Database was just created, so wipe any previous widgets
  if (mWidgetHostResetHandler != null) {
    newLauncherWidgetHost().deleteHost();
    mWidgetHostResetHandler.sendEmptyMessage(
        ChangeListenerWrapper.MSG_APP_WIDGET_HOST_RESET);
  }
  // Set the flag for empty DB
  Utilities.getPrefs(mContext).edit().putBoolean(EMPTY_DATABASE_CREATED, true).apply();
  // When a new DB is created, remove all previously stored managed profile information.
  ManagedProfileHeuristic.processAllUsers(Collections.<UserHandle>emptyList(),
      mContext);
}

代码示例来源:origin: fookwood/Launcher3

/**
   * Called when the AppWidget provider for a AppWidget has been upgraded to a new apk.
   */
  @Override
  protected void onProviderChanged(int appWidgetId, AppWidgetProviderInfo appWidget) {
    LauncherAppWidgetProviderInfo info = LauncherAppWidgetProviderInfo.fromProviderInfo(
        mLauncher, appWidget);
    super.onProviderChanged(appWidgetId, info);
  }
}

代码示例来源:origin: enricocid/LaunchEnr

long insertedId = -1;
try {
  int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
    mAppWidgetHost.deleteAppWidgetId(appWidgetId);
    return -1;
  insertedId = mCallback.insertAndCheck(mDb, mValues);
  if (insertedId < 0) {
    mAppWidgetHost.deleteAppWidgetId(appWidgetId);
    return insertedId;

代码示例来源:origin: klinker24/launcher3

final ContentResolver cr = context.getContentResolver();
final AppWidgetManager widgets = AppWidgetManager.getInstance(context);
AppWidgetHost appWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
      if (!cursor.moveToFirst()) {
        appWidgetHost.deleteAppWidgetId(newWidgetIds[i]);

代码示例来源:origin: robolectric/robolectric

@Test
public void createView_shouldSetViewsAppWidgetId() throws Exception {
 AppWidgetHostView hostView = appWidgetHost.createView(context, 765, null);
 assertThat(hostView.getAppWidgetId()).isEqualTo(765);
}

代码示例来源:origin: klinker24/launcher3

int appWidgetId = new AppWidgetHost(getContext(), Launcher.APPWIDGET_HOST_ID)
    .allocateAppWidgetId();
values.put(LauncherSettings.Favorites.APPWIDGET_ID, appWidgetId);
if (!appWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId,cn)) {

代码示例来源:origin: rockon999/LeanbackLauncher

options.putInt("appWidgetMinHeight", height);
options.putInt("appWidgetMaxHeight", height);
appWidgetId = this.mAppWidgetHost.allocateAppWidgetId();
success = this.mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, appWidgetInfo.provider, options);
this.mAppWidgetHostView = this.mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
this.mAppWidgetHostView.setAppWidget(appWidgetId, appWidgetInfo);
wrapper.addView(this.mAppWidgetHostView);

相关文章