Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the proper way to implement an Android widget with dynamically drawn content?
    primarykey
    data
    text
    <p>For my first and most awesomest Android project, I want to create a home screen widget which displays one of those <a href="http://www.softpedia.com/progScreenshots/An-Arc-Clock-Screenshot-79251.html" rel="noreferrer">Arc Clocks</a> that all the kids are raving about these days.</p> <p>Based on the limitations of <a href="http://developer.android.com/reference/android/widget/RemoteViews.html" rel="noreferrer">RemoteViews</a>, it looks to me that the appropriate way to get it actually drawn on the screen is to use an <a href="http://developer.android.com/reference/android/widget/ImageView.html" rel="noreferrer">ImageView</a> in the actual layout, then when it is updating, create a <a href="http://developer.android.com/reference/android/graphics/drawable/ShapeDrawable.html" rel="noreferrer">ShapeDrawable</a> or two and draw them onto a newly created <a href="http://developer.android.com/reference/android/graphics/Bitmap.html" rel="noreferrer">Bitmap</a>. Then, set that Bitmap as the source of the ImageView.</p> <p>There is Something about that process that I'm just not grokking, though. The following is the code I tried to use to update the widget. I get nothing drawn on the screen at all. The ImageView has a placeholder image just set by its <code>src</code> property. When I don't run the code to update it to my drawing, the placeholder image stays in place. So, I know this code is doing <em>something</em>, just obviously not the <em>right</em> thing.</p> <pre><code>RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); Bitmap bitmap = Bitmap.createBitmap(100, 100, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); ShapeDrawable drawable = new ShapeDrawable(new ArcShape(0, 360)); drawable.getPaint().setColor(0xffff0000); drawable.getPaint().setStrokeWidth(5.0f); drawable.setIntrinsicWidth(100); drawable.setIntrinsicHeight(100); drawable.draw(canvas); views.setImageViewBitmap(R.id.ImageView01, bitmap); appWidgetManager.updateAppWidget(appWidgetId, views); </code></pre> <p>I knew it couldn't be that easy. So, am I even heading in the right direction?</p> <hr> <p><strong>Update</strong></p> <p>Ok, maybe that was too much information. The question I'm really trying to ask is this:</p> <p>If I want to draw shapes on a widget, should I use an ImageView and create a bitmap from my ShapeDrawable or is there more appropriate way to draw into a widget where it is constrained by RemoteViews?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload