1 package org.robolectric.shadows; 2 3 import android.appwidget.AppWidgetHost; 4 import android.appwidget.AppWidgetHostView; 5 import android.appwidget.AppWidgetProviderInfo; 6 import android.content.Context; 7 import org.robolectric.annotation.Implementation; 8 import org.robolectric.annotation.Implements; 9 import org.robolectric.annotation.RealObject; 10 import org.robolectric.shadow.api.Shadow; 11 12 @Implements(AppWidgetHost.class) 13 public class ShadowAppWidgetHost { 14 @RealObject 15 private AppWidgetHost realAppWidgetHost; 16 17 private Context context; 18 private int hostId; 19 private int appWidgetIdToAllocate; 20 21 @Implementation 22 protected void __constructor__(Context context, int hostId) { 23 this.context = context; 24 this.hostId = hostId; 25 } 26 27 public Context getContext() { 28 return context; 29 } 30 31 public int getHostId() { 32 return hostId; 33 } 34 35 public void setAppWidgetIdToAllocate(int idToAllocate) { 36 appWidgetIdToAllocate = idToAllocate; 37 } 38 39 @Implementation 40 protected int allocateAppWidgetId() { 41 return appWidgetIdToAllocate; 42 } 43 44 @Implementation 45 protected AppWidgetHostView createView( 46 Context context, int appWidgetId, AppWidgetProviderInfo appWidget) { 47 AppWidgetHostView hostView = new AppWidgetHostView(context); 48 hostView.setAppWidget(appWidgetId, appWidget); 49 ShadowAppWidgetHostView shadowAppWidgetHostView = Shadow.extract(hostView); 50 shadowAppWidgetHostView.setHost(realAppWidgetHost); 51 return hostView; 52 } 53 } 54