Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load images through RemoteViews in widget #242

Closed
pavlospt opened this issue Nov 9, 2014 · 7 comments
Closed

Load images through RemoteViews in widget #242

pavlospt opened this issue Nov 9, 2014 · 7 comments
Labels
Milestone

Comments

@pavlospt
Copy link
Contributor

pavlospt commented Nov 9, 2014

Is there any chance that this feature request would be implemented in a next release?

I have searched but did not find anything about RemoteViews and Glide.

@sjudd
Copy link
Collaborator

sjudd commented Nov 9, 2014

The odds of this feature making it in are definitely higher if you implement it and put up a pull request! :).

You're correct however that Glide doesn't currently offer an API specifically for RemoteViews. Take a look at SimpleTarget. You can implement obtaining the size of the RemoteView and setting your Bitmap or Drawable result relatively easily. If your solution seems generally, please do consider putting it up as a pull request. I'm happy to answer more questions if you have any trouble.

@pavlospt
Copy link
Contributor Author

pavlospt commented Nov 9, 2014

Sure will do it when i get some free time! I hope to make a pull request asap! Thank you for the response!

@pavlospt
Copy link
Contributor Author

pavlospt commented Nov 9, 2014

Actually as i am searching for ways to do this i can't seem to find a way to get a height and width of a RemoteView, so i will just try it on the blind for the moment and report back!

@TWiStErRob
Copy link
Collaborator

There's no way to get anything back from the RemoteViews. You can only operate on things you know (i.e. hardcoded in the layout XML).
You can't even get how many dps your 1x1 widget is, it doesn't just differ by device it differs by installed launcher app.

RemoteViews is just a list of things to set on remote Views. Essentially a Map<int:viewId, Map<Method:setter, Object:value>>. You can't store state in a widget and can't call getters because the above mentioned map is applied to a View via findViewById-ing the views and then calling reflective methods (in an other process). Every time you update the widget you're reinflating the layout as far as I know, but I didn't test that. You may have to delay updating the widget to when the images is available to prevent clearing texts and colours you may have set.

So at best the generic solution would involve a call to override or equivalent to let Glide know of view size. There's a limitation too, a RemoteViews can only store screeSize*2 pixels in Bitmaps so you should use the smallest possible size if you have multiple images. Glide's defaulting to screen size is not a good idea here.

I learned all of the above while I was trying to make text the biggest possible without a linebreak and while it's "trivial" in a normal layout, it is impossible in widgets: you don't have any clue about widget size nor TextView size, not to mention sps (i.e. the user can break your pixel perfect widget layout with a simple setting change) so I started using dp as font size for widgets.

I would be happiest to be proven wrong though, good luck with widgets!

@pavlospt
Copy link
Contributor Author

pavlospt commented Nov 9, 2014

@TWiStErRob Υes, that's why at the moment i am not going to deal with ImageView's size and use something built-in from Glide! I have written a new custom class extending BaseTarget but dealing with RemoteViews. Though I need to test it because it's only a theory for the moment and code in paper.

@pavlospt
Copy link
Contributor Author

10806268_10205090426599733_4966405790972209676_n
UPDATE: Actually i managed to implement it and it works pretty fine! The only drawback though is that the user has to arbitrary set the size because of the limitations that RemoteViews are having as explained by @TWiStErRob. Will make a pull request ASAP, need to document the usage and make some samples!

sjudd pushed a commit to sjudd/glide that referenced this issue Nov 16, 2014
Ability to load a bitmap into an ImageView of a Widget using
RemoteViews.

Example of usage on the following gist
https://gist.github.com/pavlospt/00242d5102ac8f76e169
@sjudd sjudd added this to the 3.5 milestone Nov 16, 2014
@TWiStErRob
Copy link
Collaborator

#248 has been merged and closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants