@Test(expected = NullPointerException.class) public void testThrowsWhenGivenNullRemoteViewsWithWidgetIds() { new AppWidgetTarget(RuntimeEnvironment.application, viewId, null /*remoteViews*/, 1 /*widgetIds*/); }
@Override public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) { this.remoteViews.setImageViewBitmap(this.viewId, resource); this.update(); } }
@Test public void testSetsBitmapOnRemoteViewsWithViewIdWhenCreatedWithComponentName() { ComponentName componentName = mock(ComponentName.class); AppWidgetTarget target = new AppWidgetTarget(RuntimeEnvironment.application, viewId, views, componentName); Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); target.onResourceReady(bitmap, null /*glideAnimation*/); verify(views).setImageViewBitmap(eq(viewId), eq(bitmap)); }
@Test(expected = NullPointerException.class) public void testThrowsWhenGivenNullContextWithComponentName() { new AppWidgetTarget(null /*context*/, 1234 /*viewId*/, views, mock(ComponentName.class)); }
@Test public void testSetsBitmapOnRemoteViewsWithViewIdWhenCreatedWithWidgetIds() { int[] widgetIds = new int[] { 1 }; AppWidgetTarget target = new AppWidgetTarget(RuntimeEnvironment.application, viewId, views, widgetIds); Bitmap bitmap = Bitmap.createBitmap(100, 200, Bitmap.Config.RGB_565); target.onResourceReady(bitmap, null /*glideAnimation*/); verify(views).setImageViewBitmap(eq(viewId), eq(bitmap)); }
@Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { this.remoteViews.setImageViewBitmap(this.viewId, resource); this.update(); } }
@Test(expected = IllegalArgumentException.class) public void testThrowsWhenGivenEmptyWidgetIds() { new AppWidgetTarget(RuntimeEnvironment.application, viewId, views); }
@Test public void testUpdatesAppWidgetWhenCreatedWithComponentName() { ComponentName componentName = mock(ComponentName.class); AppWidgetTarget target = new AppWidgetTarget(RuntimeEnvironment.application, viewId, views, componentName); target.onResourceReady(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888), null /*glideAnimation*/); assertEquals(componentName, shadowManager.updatedComponentName); assertEquals(views, shadowManager.updatedRemoteViews); }
@Override public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) { this.remoteViews.setImageViewBitmap(this.viewId, resource); this.update(); } }
@Test(expected = NullPointerException.class) public void testThrowsWhenGivenNullRemoteViewsWithComponentName() { new AppWidgetTarget(RuntimeEnvironment.application, viewId, null /*remoteViews*/, mock(ComponentName.class)); }
@Test public void testUpdatesAppWidgetWhenCreatedWithWidgetIds() { int[] widgetIds = new int[] { 1 }; AppWidgetTarget target = new AppWidgetTarget(RuntimeEnvironment.application, viewId, views, widgetIds); target.onResourceReady(Bitmap.createBitmap(200, 100, Bitmap.Config.ARGB_8888), null /*glideAnimation*/); assertThat(widgetIds).isEqualTo(shadowManager.updatedWidgetIds); assertEquals(views, shadowManager.updatedRemoteViews); }
@Test(expected = NullPointerException.class) public void testThrowsWhenGivenNullWidgetIds() { new AppWidgetTarget(RuntimeEnvironment.application, viewId, views, (int[]) null /*widgetIds*/); }
@Test(expected = NullPointerException.class) public void testThrowsWhenGivenNullComponentName() { new AppWidgetTarget(RuntimeEnvironment.application, viewId, views, (ComponentName) null); }
@Test(expected = NullPointerException.class) public void testThrowsWhenGivenNullContextWithWidgetIds() { new AppWidgetTarget(null /*context*/, 1234 /*viewId*/, views, 1 /*widgetIds*/); }
private static void loadImageForSingleThing( Context context, String pathName, RemoteViews remoteViews, int appWidgetId) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(pathName, options); if (options.outWidth <= 0) { return; } Glide.with(context) .load(pathName) .asBitmap() .override(options.outWidth, options.outWidth * 3 / 4) .centerCrop() .into(new AppWidgetTarget( context, remoteViews, IV_IMAGE_ATTACHMENT, new int[] { appWidgetId })); }
@Override public boolean onResourceReady(Bitmap resource, Object model, Target<Bitmap> target, DataSource dataSource, boolean isFirstResource) { views.setViewVisibility(R.id.widget_progress, View.GONE); appWidgetManager.updateAppWidget(appWidgetId, views); Glide.with(context) .asBitmap() .load(cachedUrl) .apply(new RequestOptions().dontAnimate()) .into(new AppWidgetTarget(context, R.id.widget_image, views, appWidgetId)); return false; } })
.load(cachedUrl) .apply(new RequestOptions().dontAnimate()) .into(new AppWidgetTarget(context, R.id.widget_image, views, appWidgetId)); return false; .into(new AppWidgetTarget(context, R.id.widget_image, views, appWidgetId));