Question

I have an appwidget application and would like to enable users to create skins which can be applied at runtime. My preferred solution is to use apk files with nine patch png images that stretch to fit the ImageView's of widget, however its starting to look like I might have to use another packaging technique (e.g. zip files).

What I've tried: Importing nine patch resources as Drawable with context.getResourcesForApplication(my.app).getResources..., converting them to bitmaps using a canvas and setting the bitmap to the RemoteView using setImageViewBitap. This didn't work because I needed to specify the size of the resulting view (myBitmap.setBounds(..,..)) during conversion and some of the widths/heights in my appwidget aren't fixed. Perhaps there is a way to get the heights etc that I missed.

Importing resources directly to the RemoteView using setImageViewUri() This doesn't work because the function doesn't seem to read android.resource:// Uri's anymore (I poked around in the ImageView source and it only seems to read files paths and content:// Uri's)

Importing resources directly to the RemoteView using setImageViewResource() which didn't work because the id retrieved from the external package obviously doesn't include a package reference.

What I'm trying to avoid is hard coding all my appwidget width's and height's, or using a separate packaging scheme.

Has anyone implemented appwidget skins nicely and want to share the knowledge? Alternately there might be a hole in my logic somewhere that can be pointed out.

I can provide code if required though I don't have any here right now.

Was it helpful?

Solution

I found this sample solution http://www.siroccosoftware.com/devblog/?p=10

ImageView

Uri path = Uri.parse("android.resource://PACKAGE_NAME/RESOURCE_ID");

views.setImageViewUri(ID, path); 

RemoteView

RemoteViews views = new RemoteViews("PACKAGE_NAME", "LAYOUT_RESOURCE_ID");

OTHER TIPS

I ran across the code for ImageView while I was trying to fix this problem.

It turns out that if the URI isn't a "content" URI, then ImageView attempts to open it by a call to Drawable.createFromPath(mUri.toString()), which essentially wants a path rather than a URI.

If you strip out the "file:///" section of your URI, it'll work just fine.

So you could update your code as follows:

views.setImageViewUri(R.id.alarm, Uri.parse(f.getAbsolutePath()); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top