Openhab-android: Add support for Image items

Created on 2 Aug 2016  路  15Comments  路  Source: openhab/openhab-android

A similar request exists for Classic UI and Basic UI: https://github.com/eclipse/smarthome/issues/1800

All 15 comments

I also ran into images not being supported. I switched to the video tag in the sitemap and it works if you using encoding="mjpeg". For some reason it has to be lowercase.

Any chance to support image items ?
You can see how it is handled in Basic UI.

Looking at the current code, it looks like it can only work if a URL is provided (SmartImageView). The image is downloaded from this URL.

Looking at the code, I have finally the feeling that it could be easily implemented by enhancing the claases MySmartImageView and MyWebImage in order to provide a specific getBitmap method that will simply copy data from the item value.

I will install an Android dev env and try myself.

For some reason it has to be lowercase.

@FriedCircuits While is was working on #402 I found the case sensitive check and made it case insensitive. I will open a PR

I was able to make it work.
For testing, I finally used the Android emulator and I connected to my server using myopenhab.
Unfortunately, the refresh of the image is not always working. I can see that the code is called but the image remains sometimes unchanged. When it happens, if I reopen the page, the image displayed is the one expected.
I hope that it is not a problem with the emulator...
I bypassed any cache when using image item so the problem is not in this direction.

Here are the few lines of code added/changed:

                boolean useUrl = true;
                MySmartImageView imageImage = (MySmartImageView) widgetView.findViewById(R.id.imageimage);
                OpenHABItem item = openHABWidget.getItem();
                if (item != null && item.getType().equals("Image") && item.getState() != null) {
                    int idx = item.getState().indexOf(",");
                    if (item.getState().startsWith("data:") && (idx > 0)) {
                        byte[] data = Base64.decode(item.getState().substring(idx + 1), Base64.DEFAULT);
                        Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                        imageImage.setImage(new BitmapImage(bitmap));
                        useUrl = false;
                        Log.d(TAG, "Image from ImageItem");
                    }
                }
                if (useUrl) {
                    imageImage.setImageUrl(ensureAbsoluteURL(openHABBaseUrl, openHABWidget.getUrl()), false,
                        openHABUsername, openHABPassword);
                    Log.d(TAG, "Image from proxy URL");
                }

Any idea ?

Can you upload your code?

What is the issue here? I use image in my sitemap right now! only thing I found is that I have to use the png setting for icons instead of svg otherwise the app doesn't load my image item. But with png icons it displays as it does in basic UI! I just can't tell from these posts how images arn't supported atm.

Code from my sitemap

Frame {
        Image url="http://192.168.0.4:2842/static/whos_home/our_home-00.png" visibility=[Whos_Home==0]
        Image url="http://192.168.0.4:2842/static/whos_home/our_home-01.png" visibility=[Whos_Home==1]
        Image url="http://192.168.0.4:2842/static/whos_home/our_home-02.png" visibility=[Whos_Home==2]
        Image url="http://192.168.0.4:2842/static/whos_home/our_home-03.png" visibility=[Whos_Home==3]
        Image url="http://192.168.0.4:2842/static/whos_home/our_home-04.png" visibility=[Whos_Home==4]
        Image url="http://192.168.0.4:2842/static/whos_home/our_home-05.png" visibility=[Whos_Home==5]
        Image url="http://192.168.0.4:2842/static/whos_home/our_home-06.png" visibility=[Whos_Home==6]
        Image url="http://192.168.0.4:2842/static/whos_home/our_home-07.png" visibility=[Whos_Home==7]
        Image url="http://192.168.0.4:2842/static/whos_home/our_home-08.png" visibility=[Whos_Home==8]
    }

Image Showing as expected
screenshot_20171019-102450

only thing I found is that I have to use the png setting for icons instead of svg otherwise the app doesn't load my image item.

Should be fixed in #372, comes with the new version.

So what is this about does openhab actually support an Image item definition in a .item file? I ask because I would of used such an item if it was listed in the Openhab docs but it wasn't last time I checked!

Subject is the support of items of type Image, something missing until I created my PR.

Good news: in fact, it is working well but I have to be patient and it takes sometimes more time for the image to be refreshed. Maybe it is due to emulator + the remote access through myopenhab.org.
Addtionally, my page contains several data like cover art, title, album and much more. I can see that showPage is called several times and so the REST API for the page is called several times. The first time the REST API is returning the old covert art and the next one the new covert art. It might be because the Sonos binding updates the covert art channel after other channels.
To be sure, I need to update my sitemap to have only one image channel in the page. In this case, I am expecting only one call to the REST API with the right picture returned.

So I will finish the code, remains a little thing to update to bypass the refresh parameter for image items.

@Dracrius How did you change the background?

@mueller-ma It's because I'm on Cyanogenmod and use their Theme Engine and a transparent theme. It works for pretty much any app that doesn't implement it's own backgrounds.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

CrazyIvan359 picture CrazyIvan359  路  13Comments

Bryan76 picture Bryan76  路  8Comments

LinqLover picture LinqLover  路  13Comments

FredericMa picture FredericMa  路  10Comments

magd1978 picture magd1978  路  10Comments