0

I'm doing an home screen widget for android and I want to use a Lottie animation on the widget. I know the LottieAnimationView is not supported as the widget only supports some views. But can I use this custom drawable LottieDrawable to use in an ImageView on the widget?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Pedro Romano Barbosa
  • 587
  • 3
  • 11
  • 29

2 Answers2

3

No, sorry. You can only use drawable resources or bitmaps, not a Drawable object.

While your app has Lottie, your app is not rendering the app widget. The home screen renders the app widget. Hence, the RemoteViews system limits you to things that are part of the framework, that any home screen will be able to use.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I did not know the difference between drawable resources and drawable object. Is there any document confirming that? Thanks! – Pedro Romano Barbosa Jun 25 '19 at 18:29
  • @PedroRomanoBarbosa: If you look at [the JavaDocs for `RemoteViews`](https://developer.android.com/reference/android/widget/RemoteViews), you will not find any methods that take a `Drawable` parameter. – CommonsWare Jun 25 '19 at 18:31
0

Yes it is possible. Try something like this:

Paint p = new Paint(); 
p.setAntiAlias(true);
p.setStyle(Style.STROKE);
p.setStrokeWidth(8);
p.setColor(0xFFFF0000);

Bitmap bitmap = Bitmap.createBitmap(100, 100, 
Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawArc(new RectF(10, 10, 90, 90), 0, 270, false, p);

RemoteViews views = new 
RemoteViews(updateService.getPackageName(), R.layout.main);
views.setImageViewBitmap(R.id.canvas, bitmap);

ComponentName componentName = new 
ComponentName(updateService, 
DashboardAppWidgetProvider.class);
AppWidgetManager appWidgetManager = 
AppWidgetManager.getInstance(updateService);
appWidgetManager.updateAppWidget(componentName, 
views);
TylerH
  • 20,799
  • 66
  • 75
  • 101
Anupam
  • 2,845
  • 2
  • 16
  • 30