org.robolectric.shadows.ShadowAppWidgetHost Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shadows-core-v17 Show documentation
Show all versions of shadows-core-v17 Show documentation
An alternative Android testing framework.
package org.robolectric.shadows;
import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import org.robolectric.Shadows;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
/**
* Shadow for {@link android.appwidget.AppWidgetHost}.
*/
@Implements(AppWidgetHost.class)
public class ShadowAppWidgetHost {
@RealObject
private AppWidgetHost realAppWidgetHost;
private Context context;
private int hostId;
private int appWidgetIdToAllocate;
public void __constructor__(Context context, int hostId) {
this.context = context;
this.hostId = hostId;
}
public Context getContext() {
return context;
}
public int getHostId() {
return hostId;
}
public void setAppWidgetIdToAllocate(int idToAllocate) {
appWidgetIdToAllocate = idToAllocate;
}
@Implementation
public int allocateAppWidgetId() {
return appWidgetIdToAllocate;
}
@Implementation
public AppWidgetHostView createView(Context context, int appWidgetId,
AppWidgetProviderInfo appWidget) {
AppWidgetHostView hostView = new AppWidgetHostView(context);
hostView.setAppWidget(appWidgetId, appWidget);
Shadows.shadowOf(hostView).setHost(realAppWidgetHost);
return hostView;
}
}