Cannot handle action events on Labels?

124 views
Skip to first unread message

Malvik Majithia

unread,
Jun 28, 2014, 5:12:14 AM6/28/14
to codenameone...@googlegroups.com

I've dynamically created a horizontal scrolling list of labels (with icon and bottom text) within a container in a tab.

However, I cannot seem to bind any action to this Label - I want touch, long press, options(commands), drag, etc

If I use Button instead of Label, I cannot seem to use URLImage to grab the icon from a url and save it to storage and use that as the button icon. It always uses only the placeholder from:

Image img = URLImage.createToStorage(placeholder, counter+"_thumbnail", thumbnailURL, URLImage.RESIZE_SCALE);

How do I grab events on the Labels? Here is a snippet of how I'm adding the labels to the container:

Container c = StateMachine.instance.findFirstListContainer();
for(...){
    Label l = new Label();
    l.setText(title);  
    l.setIcon(img);
    l.setUIID("listItem");
    l.setTextPosition(2);
    c.addComponent(l);
}


Shai Almog

unread,
Jun 28, 2014, 12:26:08 PM6/28/14
to codenameone...@googlegroups.com
Use a Button, then btn.setUIID("Label"); to make it look like a label.

Malvik Majithia

unread,
Jun 28, 2014, 12:30:18 PM6/28/14
to codenameone...@googlegroups.com
Yup ... that is the first thing I tried but as I mentioned earlier, If I use Button instead of Label, I cannot seem to use URLImage to grab the icon from a url and save it to storage and use that as the button icon. It always uses only the placeholder from:
Image img = URLImage.createToStorage(placeholder, counter+"_thumbnail", thumbnailURL, URLImage.RESIZE_SCALE);


Shai Almog

unread,
Jun 29, 2014, 1:55:32 AM6/29/14
to codenameone...@googlegroups.com
I suggest going back to that issue rather than using a label.
Are you sure you are using the right setIcon variant since a Label has only one icon but a button has several.

Malvik Majithia

unread,
Jun 29, 2014, 3:11:47 AM6/29/14
to codenameone...@googlegroups.com
Ok...so I set every Icon possible to the URLImage I'm using...which is a youtube video thumbnail...here is my code:

                Image img = URLImage.createToStorage(placeholder, videoId+"_thumbnail", defaultThumbnailURL, URLImage.RESIZE_SCALE);
                Button l = new Button();  
                l.setText(videoTitle);  
                l.setIcon(img);
                l.setDisabledIcon(img);
                l.setRolloverIcon(img);
                l.setPressedIcon(img);
                l.setRolloverPressedIcon(img);
                l.setFocusable(false);
                l.setUIID("label");
                l.setTextPosition(2);
                l.setEnabled(true);
                l.setName(videoId);
                l.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent evt) {
                        System.out.println("blah blah");                        
                    }
                }); 
                c.addComponent(l); 

on another issue, I can't seem to make the Media Player stream a YouTube video. Is there any resource I can read to figure that out? SetDataSource(String uri) does nothing at all on the simulator as well as on my Nexus5

Malvik Majithia

unread,
Jun 29, 2014, 3:13:18 AM6/29/14
to codenameone...@googlegroups.com
Setting every icon didn't work either...that is what I'm trying to say. It still shows only the placeholder image

Shai Almog

unread,
Jun 29, 2014, 10:10:43 AM6/29/14
to codenameone...@googlegroups.com
Assuming this is on the simulator as well as a device, can you write code that I can try?
With a hardcoded URL I can just paste this into a test case and see if I spot something?

Malvik Majithia

unread,
Jun 29, 2014, 10:38:39 AM6/29/14
to codenameone...@googlegroups.com
Yup simulator and device. Here is the code I'm using:
                
                defaultThumbnailURL = "https://i.ytimg.com/vi/wVi5NeY3veM/hqdefault.jpg";
                Image img2 = URLImage.createToStorage(placeholder, videoId+"_thumbnail", defaultThumbnailURL, URLImage.RESIZE_SCALE);
                Container c = StateMachine.instance.findContainer();
                c.setFocusable(false);
                Button l = new Button();  
                l.setText("xyz");  
                l.setIcon(img2);
                l.setDisabledIcon(img2);
                l.setRolloverIcon(img2);
                l.setPressedIcon(img2);
                l.setRolloverPressedIcon(img2);                
                l.setFocusable(false);
                l.setUIID("label");
                l.setTextPosition(2);
                l.setEnabled(true);
                l.addActionListener(new ActionListener() {

                    public void actionPerformed(ActionEvent evt) {
                        System.out.println("Yes");                        
                    }
                }); 
                c.addComponent(l);


On Sun, Jun 29, 2014 at 7:40 PM, Shai Almog <shai....@gmail.com> wrote:
Assuming this is on the simulator as well as a device, can you write code that I can try?
With a hardcoded URL I can just paste this into a test case and see if I spot something?

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/5HoDEFjB5II/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit https://groups.google.com/d/msgid/codenameone-discussions/ab1457f2-09b8-45fc-a5b9-cdc832397d86%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Malvik Majithia
(C)  91 9320027660

Shai Almog

unread,
Jun 30, 2014, 1:06:24 AM6/30/14
to codenameone...@googlegroups.com
Thanks, we'll look into that.

Malvik Majithia

unread,
Jun 30, 2014, 1:18:13 AM6/30/14
to codenameone...@googlegroups.com

Great. Anything you know about being able to stream YouTube videos in the MediaPlayer? It seems to support only local file playback?

On Jun 30, 2014 10:36 AM, "Shai Almog" <shai....@gmail.com> wrote:
Thanks, we'll look into that.

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/5HoDEFjB5II/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.

Shai Almog

unread,
Jun 30, 2014, 10:09:12 AM6/30/14
to codenameone...@googlegroups.com
We fixed this issue, its related to image locking which is a good thing since we also slightly improved performance for some test cases.
Media player supports HTTP for streaming. Streaming Youtube videos is against Googles terms of service. You can only show the videos in a web browser, they already blocked Microsoft on this several times.

Malvik Majithia

unread,
Jun 30, 2014, 10:18:59 AM6/30/14
to codenameone-discussions
Thats great! I'm still waiting on an update from my NetBeans though. I guess it isn't pushed to the SVN yet. Will try again later.

I guess using the WebBrowser with any JS Bridge is the only way forward for me. 

Thanks for the support.


On Mon, Jun 30, 2014 at 7:39 PM, Shai Almog <shai....@gmail.com> wrote:
We fixed this issue, its related to image locking which is a good thing since we also slightly improved performance for some test cases.
Media player supports HTTP for streaming. Streaming Youtube videos is against Googles terms of service. You can only show the videos in a web browser, they already blocked Microsoft on this several times.

--
You received this message because you are subscribed to a topic in the Google Groups "CodenameOne Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/codenameone-discussions/5HoDEFjB5II/unsubscribe.
To unsubscribe from this group and all its topics, send an email to codenameone-discu...@googlegroups.com.
Visit this group at http://groups.google.com/group/codenameone-discussions.

For more options, visit https://groups.google.com/d/optout.

Shai Almog

unread,
Jul 1, 2014, 1:00:45 AM7/1/14
to codenameone...@googlegroups.com
NetBeans is updated every 2-3 weeks, not from the SVN.
Yes, that's a YouTube restriction in the license level although they sometimes enforce it by manually blocking specific apps.
Reply all
Reply to author
Forward
0 new messages