Look for an elegant appwidget skin solution

I have an appwidget application and you want users to be able to create skins that can be applied at runtime. My preferred solution is to use apk files with nine patches of png images that are stretched to fit the ImageView widget, however it began to look like I might have to use a different packaging method (e.g. zip files).

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

Importing resources directly to RemoteView using setImageViewUri () This does not work, because the function does not seem to read android.resource: // Uri anymore (I poked at the ImageView source code and seemed to only read the paths to the files and contents: / / Uri's)

Importing resources directly to RemoteView using setImageViewResource (), which did not work because the identifier obtained from the external package does not explicitly contain a link to the package.

What I'm trying to avoid is hard coding the entire width and height of the application, or using a separate packaging scheme.

Has anyone implemented appwidget skins nicely and want to share knowledge? Alternatively, there may be a hole in my logic where you can specify.

I can provide the code if necessary, although I don’t have it now.

+3
source share
2 answers

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");
+2
source

ImageView, .

, URI "" URI, ImageView Drawable.createFromPath(mUri.toString()), , URI.

":///" URI, .

, :

views.setImageViewUri(R.id.alarm, Uri.parse(f.getAbsolutePath()); 
+1

Source: https://habr.com/ru/post/1732456/


All Articles