Touch events in Cascades/QML

Hello everyone

I'm "new" in this kind of things of Cascades and a lot is different from that of QtQuick on Symbian, that's why I have one, well two small questions:

(1) how can I manage touch events. For example I want to design an element as a button, but without using the predefined one. Basically, it's a container with color and a label in it. And I want to give a basic animation, I'm searching for equal to onPressed and onReleased, two methods to change the background color, when the user presses the button and make it back to the default color, when it releases.

(2) is there any kind of Qt Assistant for Cascades? I couldn't find the reference to assistance in line/API here, but it is so messed up my opinion and lack features such as research. In the best cases, this documentation is fully downloadable and usable offline.

Hopefully, you can help me...

Best regards

Sebastian

I worked today on a similar question. You can query the key like this event type:

onTouch: {
    if (event.touchType == TouchType.Down) {
      //doStuff
    }
}

I used this to make a whole one button container, regardless of its content.

Tags: BlackBerry Developers

Similar Questions

  • OpenGL + MMR video playback and touch events.

    Hello BB forums natively,.

    We have an openGL application that renders the video using the window mmrenderer child. Surface OpenGL is transparent and makes some elements of overlay the video above. It seems that the touch events are only sent when it arrives on the non-transparent part of the surface of the OpenGL. Is there a way to catch all touch events in this scenario (perhaps of the child window)?

    Thank you!

    Ask yourself properly the events with "screen_request_events..." with the context of the correct screen?

    Did you look in the GoodCitizen OpenGL sample application? It shows how all the events are received and process across the entire screen with a very similar use case;

    Martin

  • dominant touch event handler replaces all other fields

    I have the code following, which uses gestures to perform scrolling on my hfm, but substitution of this hfm, replace essentially all fields on the screen, making them useless. How is this possible, I thought that this specific touchEvent belonged to the hfm? How to work around this problem and just disable scroll for the hfm?

    gallery = new CustomHFM(){
    
                protected void sublayout(int maxWidth, int maxHeight){
                    super.sublayout(maxWidth, 200);
                    setExtent(maxWidth,200);
                }
    
                protected boolean touchEvent(TouchEvent message){
    
                    int eventCode = message.getEvent();
    
                    if(eventCode == TouchEvent.GESTURE){
                        System.out.println("SWIPE GESTURE");
                        TouchGesture g = message.getGesture();
                        int gesturecode = g.getEvent();
                        int direction = g.getSwipeDirection();
    
                            //gallery.setHorizontalScroll(page_two, true);
                        if(direction == TouchGesture.SWIPE_WEST)
                            slideNext();
    
                        if(direction == TouchGesture.SWIPE_EAST)
                            slidePrev();
    
                        pressed = true;
                    }
    
                    if(eventCode == TouchEvent.UP){
                    pressed = false;
    
                    //slide();
                    }
    
                    return true;
                }
            };
    

    I want to just do not use the default scroll and do my own thing! Any suggestion would be appreciated, I'm really in the fire right now.

    OK, this is a different problem.  I suspect that you must reject touch events that are not actually within your HFM.  Then add code like the following at the beginning of your touchEvent method:

    int x = message.getX (1);
    int y = message.getY (1);
    If (x < 0="" ||="" y=""> < 0="" ||="" x=""> getExtent () .width: y > getExtent () .height) {}
    Outside the scope
    Returns false;
    }

    If this is not enough, so be sure that your touchEvent method is called.  If it really is, then I think you have a problem with a Manager.  You have all Directors complicated on your screen.  Try to simplify the screen so that you don't use native components RIM (and nothing implying positioning as AbsoluteFieldmanager and see if the problem persists.)  If so, then see if you can post an example of the sample that shows the problem so that we can all try.

  • Parents and children Touch - event management

    I have a container with some controls.

    I want this is notecard to the container code to run only if no child control has handled the event onTouch.

    Is this possible?

    Thank you

    Jamie

    I solved it.

    Here's how...

    First of all, there are two touch events, I have now, I understand as follows:

    'touchCapture' is received in a container before the spread of children take place.

    'touch' is received in a container after the propagation takes place.

    I've added a property to the container like this:

    Boolean touchHandled property

    I added handlers for the touchCapture and the touch, like this:

    onTouchCapture: {}
    touchHandled = false
    }

    Notecard: {}
    If (! touchHandled) {}
    Manage you like...
    }
    }

    If a child control manages the key event, I the child touchHandled set to true. For example, in one of the children, I manage a TOP event. I have code like this (in children):

    Notecard: {}
    If (event.isUp ()) {}
    Do all that...

    touchHandled = true
    }
    }

    Mission accomplished. Comments are welcome...

    Jamie

  • How to manage touch event in the field

    Hello

    I created field checkbox custom, when am touch event for her manipulation, emphasis is gettting inside, and when I try to click on any other components such as the box native, afer by unchecking the custom check box, the custom box is clicking again.

    How to handle this?

    Thank you

    Rakesh Shankar

    There are certain basics that one needs to understand to effectively manage key events:

    (1) touch events are sent to the field currently has focus and the enveloping managers, including the active screen.

    (2) default response of the system to the event down is to divert attention to the field to the position of touch If there is a focusable it. If there is no focusable point touch field, the field currently has focus is unchanged. There's no "unfocus everything ' method in BlackBerry (there might be, but it is not readily available - there is a protected method focusRemove, but it is supposed to be used in conjunction with a later focusAdd protected in cases where the field has changed its focus rectangle - a classic example is any input field or text such as EditField or RichTextField view)

    (3) the default action of TouchEvent.CLICK is to call trackwheelClick (which, by default, invokes navigationClick) which is a great way to ensure consistency between the 'clicks' and clicks touchpad screen. The same is true for unclicks finally managed by navigationUnclick.

    If you want to disable the click by default if the key is outside all focusable fields and will not disrupt the rest of the system, just return true if the event is to CLICK, but the contact details are outside the scopeand actions super.touchEvent otherwise. And keep your return true; on all UNCLICK events: it's a good idea if you don't want to see the context menu from appearing each time or field click reaction called twice.

    The example of Peter was written when I've heard most of it already, but now I realize that you can do a lot easier. See part highlighted the previos section.

    Good luck!

  • Are the touch events in new broken ripple?

    Hello

    I have a PlayBook application that uses touch events to shake things. I tested it in the stand-alone version of ripple and the physical device.

    Now I think on porting the app to BB10, so I downloaded the verion of ripple Chrome and I found that in the waving of the new, I can't move any object!

    I've identified the problem, but I don't know how to cope. Here is a small HTML file that shows the problem:

    http://www.w3.org/1999/xhtml">
    
    
    
        
    child

    So basically there is a div container that listenes to the touchstart and if this event happens that it displays an alert. In the ripple of old (and on the PlayBook device) If you press the 'child' div the alert is also shown (the event is pushed down and intercepted by containers). In the waving again, it happens.

    Any suggestions? I can force ripple action as does the Playbook? Maybe I should use another technique to capture touch events?

    Hi razorek,

    I'm not sure of the reason (his behavior of WebKit), but the propagation of the event using the AddEventListener method will allow when you use touchstart. Take a look:

    http://www.w3.org/1999/xhtml">
    
    
    
        
    child

    Also, when using ripple for Chrome, please make sure that "Emulate touch events" are not verified, since ripple there are tactile own emulation system and it may come into conflict with it.

    F12 (Open Developer Tools) > click on the gear icon in the lower right > Exceptions tab > emulate the Touch events. I'll also post this work around for that matter https://github.com/blackberry/Ripple-UI/issues/344 github page

  • A touch event image resizing

    Hi I want to resize an image in touch event if the user stretch the image should increase the size of the image and reduces the image should reduce the size of the image, is it possible thanks in advance

    It is, and this example should help you:

    Rotate and scale of bitmaps

    http://supportforums.BlackBerry.com/T5/Java-development/rotate-and-scale-bitmaps/Ta-p/492524

  • stimulate the touch event handling in PRC?

    I want to stimulate the touch event in another application. can someone help me in explaining to me with a code example.

    I'll pass on this one, whenever I give you an answer to a topic, change you what you wanted in the first place.
    First of all, you wanted to listen to the event:
    http://supportforums.BlackBerry.com/T5/native-development/touch-does-not-fire-for-Q10/TD-p/3026980

    Second, you were finally made in the PRC:
    http://supportforums.BlackBerry.com/T5/native-development/touch-event-handling-in-CPP/TD-p/3027043

    Third, you asked to simulate a key event in this thread I made.

    Now, this isn't what you want, you want to simulate a click on a button.

    I'll let someone else answer that one.

  • iLLEGALARGUMENT EXception on touch event

    package mypackage;
    
    import java.util.Vector;
    
    import net.rim.device.api.system.Display;
    import net.rim.device.api.ui.Field;
    import net.rim.device.api.ui.FocusChangeListener;
    import net.rim.device.api.ui.Font;
    import net.rim.device.api.ui.Graphics;
    import net.rim.device.api.ui.Manager;
    import net.rim.device.api.ui.TouchEvent;
    import net.rim.device.api.ui.TouchGesture;
    import net.rim.device.api.ui.UiApplication;
    import net.rim.device.api.ui.XYRect;
    import net.rim.device.api.ui.component.BasicEditField;
    import net.rim.device.api.ui.component.ButtonField;
    import net.rim.device.api.ui.component.LabelField;
    import net.rim.device.api.ui.component.SeparatorField;
    import net.rim.device.api.ui.component.Status;
    import net.rim.device.api.ui.container.HorizontalFieldManager;
    import net.rim.device.api.ui.container.MainScreen;
    import net.rim.device.api.ui.container.VerticalFieldManager;
    
    public class PlaylistTab extends MainScreen  implements FocusChangeListener{
    
        private int _xCoord = 0; //The x coordinate for the top left corner of the image.
        private int _yCoord = 0; //The y coordinate for the top left corner of the image.
        private int _xTouch = 0; //The x coordinate of the previous touch point.
        private int _yTouch = 0; //The y coordinate of the previous touch point.
    
        private LabelField tab1;
    
        private LabelField tab2;
    
        private LabelField tab3;
    
        private LabelField spacer1;
    
        private LabelField spacer2;
    
        private VerticalFieldManager tabArea;
    
        private LabelField tab1Heading;
    
        private BasicEditField tab1Field1;
    
        private BasicEditField tab1Field2;
    
        private LabelField tab2Heading;
    
        private BasicEditField tab2Field1;
    
        private BasicEditField tab2Field2;
    
        private LabelField tab3Heading;
    
        private BasicEditField tab3Field1;
    
        private BasicEditField tab3Field2;
    
        private VerticalFieldManager tab1Manager;
        private VerticalFieldManager tab2Manager;
        private VerticalFieldManager tab3Manager;
        int tabNum = 1;
        public PlaylistTab()
        {
            super(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR);
            //HorizontalFieldManager hManager = new HorizontalFieldManager();
            HorizontalFieldManager hManager = new HorizontalFieldManager(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR | NO_HORIZONTAL_SCROLL  | NO_HORIZONTAL_SCROLLBAR);
            Font font = getFont().derive(Font.PLAIN, 35);
            tab1 = new LabelField("Songs", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT)
            {
                protected boolean navigationClick(int status,int time){
    
                    return true;
                }
                protected void layout(int width, int height) {
                    super.layout(width, height);
                    //    this.setExtent(this.getWidth(), 60);
                    this.setMargin( ( getHeight() - this.getPreferredHeight()), 0, 0, (getWidth() - this.getPreferredWidth()));
                }
            };
            tab2 = new LabelField("Album", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT)
            {
                protected boolean navigationClick(int status,int time){
    
                    return true;
                }
                protected void layout(int width, int height) {
                    super.layout(width, height);
                    //    this.setExtent(this.getWidth(), 60);
                    this.setMargin( ( getHeight() - this.getPreferredHeight()), 0, 0, (getWidth() - this.getPreferredWidth()));
                }
            };
            tab3 = new LabelField("Artist", LabelField.FOCUSABLE | LabelField.HIGHLIGHT_SELECT)
            {
                protected boolean navigationClick(int status,int time){
    
                    return true;
                }
                protected void layout(int width, int height) {
                    super.layout(width, height);
                    //    this.setExtent(this.getWidth(), 60);
                    this.setMargin( ( getHeight() - this.getPreferredHeight()), 0, 0, (getWidth() - this.getPreferredWidth()));
                }
            };
            spacer1 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
            spacer2 = new LabelField(" | ", LabelField.NON_FOCUSABLE);
    
            tab1.setFocusListener(this);
            tab2.setFocusListener(this);
            tab3.setFocusListener(this);
            hManager.add(tab3);
            hManager.add(spacer1);
            hManager.add(tab2);
            hManager.add(spacer2);
            hManager.add(tab1);
    
            add(hManager);
            add(new SeparatorField());
    
            tab1Manager = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR );
            tab2Manager = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR );
            tab3Manager = new VerticalFieldManager(VERTICAL_SCROLL | VERTICAL_SCROLLBAR );
    
            tabArea = displayTab3();
            add(tabArea);
    
        }
        public void focusChanged(Field field, int eventType) {
            if (tabArea != null) {
                if (eventType == FOCUS_GAINED) {
                    if (field == tab1) {
                        System.out.println("Switch to Tab 1");
                        delete(tabArea);
                        tabArea = displayTab1();
                        add(tabArea);
                    } else if (field == tab2) {
                        System.out.println("Switch to Tab 2");
                        System.out.println("Switch to Tab 1");
                        delete(tabArea);
                        tabArea = displayTab2();
                        add(tabArea);
                    } else if (field == tab3) {
                        System.out.println("Switch to Tab 3");
                        System.out.println("Switch to Tab 1");
                        delete(tabArea);
                        tabArea = displayTab3();
                        add(tabArea);
                    }
                }
            }
    
        }
    
        public VerticalFieldManager displayTab1() {
            try
            {
                tabNum = 3;
                final VerticalFieldManager Content= new VerticalFieldManager(Manager.USE_ALL_WIDTH|Manager.VERTICAL_SCROLL);
                Content.setMargin(5,0,0,0);
                int mas  = 0 ;
                Vector oleg = new Vector();
                SQLManager poligs = new SQLManager();
                poligs.getSongDownload(oleg, 0);
                while(mas < oleg.size())
                {
                    Song temp = (Song) oleg.elementAt(mas);
                    Content.add(new A_Song(temp.songId, temp.songName, false,temp.albumCover,temp));
                    mas++;
                }
                tab1Manager.deleteAll();
    
                HorizontalFieldManager topManager = new HorizontalFieldManager()
                {
                    public void paint(Graphics graphics)
                    {
                        graphics.setBackgroundColor(0x00000000);
                        graphics.clear(); super.paint(graphics);
                    }
                    protected void sublayout( int maxWidth, int maxHeight )
                    {
                        int width = Display.getWidth();
                        int height = this.getPreferredHeight();
                        super.sublayout( width, height);
                        setExtent( width, height);
                    }
                };
                CustomTextBox editField = new CustomTextBox();
                int pol = Display.getWidth() / 2;
                editField.setWidth(pol);
                ButtonField button = new ButtonField("Search");
                topManager.add(editField);
                topManager.add(button);
    
                //  tab1Manager.add(topManager);
                tab1Manager.add(Content);
            }
            catch(final Exception e)
            {
    
                e.printStackTrace();
                System.out.println("------------------- ");
            }
            return tab1Manager;
        }
    
        public VerticalFieldManager displayTab2() {
            try
            {
                tabNum = 2;
                final VerticalFieldManager Content= new VerticalFieldManager(Manager.USE_ALL_WIDTH|Manager.VERTICAL_SCROLL);
                Content.setMargin(5,0,0,0);
                int mas  = 0 ;
                Vector oleg = new Vector();
                SQLManager poligs = new SQLManager();
                poligs.getSongDownloads(oleg, 0);
                while(mas < oleg.size())
                {
                    Albums temp = (Albums) oleg.elementAt(mas);
                    Content.add(new A_Album(temp.albumId, temp.albumName, false,temp.albumCover,temp));
                    mas++;
                }
                tab2Manager.deleteAll();
                tab2Manager.add(Content);
            }
            catch(final Exception e)
            {
    
                e.printStackTrace();
                System.out.println("------------------- ");
            }
            return tab2Manager;
        }
    
        public VerticalFieldManager displayTab3() {
            try
            {
                tabNum = 1;
                final VerticalFieldManager Content= new VerticalFieldManager(Manager.USE_ALL_WIDTH|Manager.VERTICAL_SCROLL);
                Content.setMargin(5,0,0,0);
                int mas  = 0 ;
                Vector oleg = new Vector();
                SQLManager poligs = new SQLManager();
                poligs.getSongDownloadss(oleg, 0);
                while(mas < oleg.size())
                {
                    Artist temp = (Artist) oleg.elementAt(mas);
                    //Content.add(new A_AddSingersFM(temp.songId, temp.songName, false,temp.albumCover,temp,-1, tb, logIn,logOut,1,0,0, Register));
                    Content.add(new A_Artisti(temp.artistId, temp.artistName, false,temp.artistPhoto,temp));
                    //  int m = temp.getSongId();
                    mas++;
                }
                tab3Manager.deleteAll();
                tab3Manager.add(Content);
            }
            catch(final Exception e)
            {
    
                e.printStackTrace();
                System.out.println("------------------- ");
            }
            return tab3Manager;
        }
        protected boolean touchEvent(TouchEvent touchEvent)
        {
            int eventCode = touchEvent.getEvent();
    
            if(eventCode == TouchEvent.GESTURE){
                System.out.println("SWIPE GESTURE");
                TouchGesture g = touchEvent.getGesture();
                int gesturecode = g.getEvent();
                int direction = g.getSwipeDirection();
    
                //gallery.setHorizontalScroll(page_two, true);
                if(direction == TouchGesture.SWIPE_WEST)
                {
    
                    if(tabNum == 3)
                    {
                        delete(tabArea);
                        tabArea = displayTab2();
                        add(tabArea);
                    }
                    else if(tabNum == 2)
                    {
                        delete(tabArea);
                        tabArea = displayTab3();
                        add(tabArea);
                    }
                }
    
                if(direction == TouchGesture.SWIPE_EAST)
                {
    
                    if(tabNum == 1)
                    {
                        try
                        {
                            delete(tabArea);
                        }
                        catch(Exception e)
                        {
                            try
                            {
                                tabArea = displayTab2();
                            }
                            catch(Exception ef)
                            {
                                add(tabArea);
                                return false;
                            }
                            add(tabArea);
                            return false;
                        }
                        try
                        {
                            tabArea = displayTab2();
                        }
                        catch(Exception ef)
                        {
                            add(tabArea);
                            return false;
                        }
                        add(tabArea);
                        return false;
    
                    }
                    else if(tabNum == 2)
                    {
                        try
                        {
                            delete(tabArea);
                        }
                        catch(Exception e)
                        {
                            try
                            {
                                tabArea = displayTab1();
                            }
                            catch(Exception ef)
                            {
                                add(tabArea);
                                return false;
                            }
                            add(tabArea);
                            return false;
                        }
                        try
                        {
                            tabArea = displayTab1();
                        }
                        catch(Exception ef)
                        {
                            add(tabArea);
                            return false;
                        }
                        add(tabArea);
                        return false;
                    }
                }
            }
            //The touch event was not consumed.
            return false;
        }
    }
    

    On the sidelines, East or West navigation events I illegalargument exception.and my page crashing.

    However, when I run the same code through the debugger it works fine. I put my debugging inside the touchevent ifs and elses togglepoints.

    And note, if it crashes and I click on an illegal argument exception... I go back to the home page and as if the touchevent function was called twice and 2 strips was skipped.

    It works fine but through debugger.any help?

    very strange, I did this and it worked

    protected boolean touchEvent(TouchEvent message)
        {
            try
            {
                int eventCode = message.getEvent();
    
                if(eventCode == TouchEvent.GESTURE){
                    System.out.println("SWIPE GESTURE");
                    TouchGesture g = message.getGesture();
                    int gesturecode = g.getEvent();
    
                    switch(gesturecode) {
    
                        case TouchGesture.SWIPE:
                            int direction = g.getSwipeDirection();
                        //gallery.setHorizontalScroll(page_two, true);
                        if(direction == TouchGesture.SWIPE_WEST)
                        {
    
                            if(tabNum == 3)
                            {
                            //  delete(tabArea);
                            //  tabArea = displayTab2();
                            //  add(tabArea);
                                tab2.setFocus();
                                return super.touchEvent(message);
                            }
                            else if(tabNum == 2)
                            {
                            //  delete(tabArea);
                            //  tabArea = displayTab3();
                            //  add(tabArea);
                                tab3.setFocus();
                                return super.touchEvent(message);
                            }
                        }
                        else if(direction == TouchGesture.SWIPE_EAST)
                        {
    
                            if(tabNum == 1)
                            {
    
                                        //delete(tabArea);
                                        //tabArea = displayTab2();
                                        //add(tabArea);
                                        tab2.setFocus();
                                        return super.touchEvent(message);
    
                            }
                            else if(tabNum == 2)
                            {
    
                                    //delete(tabArea);
                                    //tabArea = displayTab1();
                                    //add(tabArea);
                                    tab1.setFocus();
                                    return super.touchEvent(message);
    
                            } }
    
                        break;
                    }
                }
                    //The touch event was not consumed.
                    return super.touchEvent(message);
            }
            catch(Exception eol)
            {
                return super.touchEvent(message);
            }
        }
    

    I do this on tab2.setfocus (), if I call setfocus it works... but if icall it separately as it is not and it hangs. very strange

    // delete(tabArea);
                            //  tabArea = displayTab2();
                            //  add(tabArea);
    
    
    
  • Method to apply a style HTTP in Cascades/QML?

    Something like AJAX. What is the equivalent in Cascades/QML? What classes should I Explorer in the API?

    Advice would be greatly appreciated.

    Applications vary.

    http://someservice.com/v1/do/blah

    http://someservice.com/v1/do/meh

    The output of the service is JSON.

    I'll take the exit and probably put it in a list (much like the sample application of stamp collector)

    Help me get started at all help or sample code would be really useful. I imagine that it would be useful for developers who integrate their stunts BB10 app API or data of third parties.

    Thank you!

    Hello

    I wrote a simple example application to show how to create an application that consumes a twitter feed and display JSON content crawled in a standard list view.

    First create a new project named 'Twitter', by selecting file-> New-> BlackBerry Cascades C++ Project, and then choose the option "Empty project" Standard.

    We will start by creating a class called TwitterRequest responsible for the download and let us know through the slots and signals that the twitter JSON data is available. This class must be placed in your src/folder of the project

    TwitterRequest.hpp

    /*
     * Copyright (c) 2011-2012 Research In Motion Limited.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    #ifndef TWITTERREQUEST_HPP_
    #define TWITTERREQUEST_HPP_
    
    #include 
    
    /*
     * This class is responsible for making a REST call to the twitter api
     * to retrieve the latest feed for a twitter screen name. It emits the complete()
     * signal when the request has completed.
     */
    class TwitterRequest : public QObject
    {
        Q_OBJECT
    public:
        TwitterRequest();
        virtual ~TwitterRequest();
    
        /*
         * Makes a network call to retrieve the twitter feed for the specified screenname
         * @param screenname - the screen name of the feed to extract
         * @see onTimelineReply
         */
        void getTimeline(QString screenname);
    
    public slots:
        /*
         * Callback handler for QNetworkReply finished() signal
         */
        void onTimelineReply();
    
    signals:
        /*
         * This signal is emitted when the twitter request is received
         * @param info - on success, this is the json reply from the request
         *               on failure, it is an error string
         * @param success - true if twitter request succeed, false if not
         */
        void complete(QString info, bool success);
    };
    
    #endif /* TWITTERREQUEST_HPP_ */
    

    TwitterRequest.cpp

    /*
     * Copyright (c) 2011-2012 Research In Motion Limited.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */
    
    #include "TwitterRequest.hpp"
    #include 
    #include 
    #include 
    #include 
    #include 
    
    TwitterRequest::TwitterRequest()
    {
    }
    
    TwitterRequest::~TwitterRequest()
    {
    }
    
    void TwitterRequest::getTimeline(QString screenname)
    {
        QNetworkAccessManager* netManager = new QNetworkAccessManager();
        if (!netManager)
        {
            qDebug() << "Unable to create QNetworkAccessManager!";
            emit complete("Unable to create QNetworkAccessManager!", false);
            return;
        }
    
        QString queryUri = "http://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_n...";
        queryUri += screenname;
        QUrl url(queryUri);
        QNetworkRequest req(url);
    
        QNetworkReply* ipReply = netManager->get(req);
        connect(ipReply, SIGNAL(finished()), this, SLOT(onTimelineReply()));
    }
    
    void TwitterRequest::onTimelineReply()
    {
        QNetworkReply* reply = qobject_cast(sender());
        QString response;
        bool success = false;
        if (reply)
        {
            if (reply->error() == QNetworkReply::NoError)
            {
                int available = reply->bytesAvailable();
                if (available > 0)
                {
                    int bufSize = sizeof(char) * available + sizeof(char);
                    QByteArray buffer(bufSize, 0);
                    int read = reply->read(buffer.data(), available);
                    response = QString(buffer);
                    success = true;
                }
            }
            else
            {
                response =  QString("Error: ") + reply->errorString() + QString(" status:") + reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString();
                qDebug() << response;
            }
            reply->deleteLater();
        }
        if (response.trimmed().isEmpty())
        {
            response = "Twitter request failed. Check internet connection";
            qDebug() << response;
        }
        emit complete(response, success);
    }
    

    Then, replace the main.qml with the following content.

    import bb.cascades 1.0
    
    Page {
        content: Container {
            background : Color.DarkRed
            layout : DockLayout {
            }
            ListView {
                layoutProperties : DockLayoutProperties {
                    verticalAlignment : VerticalAlignment.Center
                }
                objectName : "basicTimelineView"
                id : basicTimelineView
                listItemComponents: [
                    ListItemComponent {
                        type: "item"
                        StandardListItem {
                            statusText: {
                                ListItemData.created_at
                            }
                            descriptionText: {
                                ListItemData.text
                                }
                        }
                    }
                ]
            }
        }
        onCreationCompleted: {
            cs.getTimeline("ladygaga");
        }
    }
    

    This is a simple page with a ListView with standard components, indicating the date and the content of the tweet. As you can see, immediately after that page is created a call is made in the c++ code by using the context property 'cs' set in the constructor for the App to retrieve the latest tweets of the usernamed "ladygaga". To learn more about the call c ++ QML here https://bdsc.webapps.blackberry.com/cascades/documentation/ui/integrating_cpp_qml/index.html

    Finally, this linking is the App class. It uses slot machines to handle the "full" signal generated by the class TwitterRequest when data are available, analyzes the data in a model of GroupData and fills the ListView with the recovered data.

    App.HPP

    #ifndef APP_H
    #define APP_H
    
    #include 
    #include 
    
    class App : public QObject
    {
        Q_OBJECT
    
    public:
        App();
    
        /*
         * Called by the QML to get a twitter feed for the screen nane
         */
        Q_INVOKABLE void getTimeline(QString screenName);
    
    public slots:
        /*
         * Handles the complete signal from TwitterRequest when
         * the request is complete
         * @see TwitterRequest::complete()
         */
        void onTwitterTimeline(QString info, bool success);
    
    protected:
        bb::cascades::AbstractPane* m_root;
    };
    
    #endif // ifndef APP_H
    

    App.cpp

    #include 
    #include 
    #include 
    #include 
    #include 
    
    #include "App.hpp"
    #include "TwitterRequest.hpp"
    
    using namespace bb::cascades;
    
    App::App()
    {
        QmlDocument *qml = QmlDocument::create("main.qml");
        qml->setContextProperty("cs", this);
    
        m_root = qml->createRootNode();
        Application::setScene(m_root);
    }
    
    void App::getTimeline(QString screenName)
    {
        //sanitize screenname
        QStringList list = screenName.split(QRegExp("\\s+"), QString::SkipEmptyParts);
        if (list.count() <= 0)
        {
            qDebug() << "please enter a valid screen name";
            return;
        }
        QString twitterid = list[0];
    
        TwitterRequest* tr = new TwitterRequest();
        tr->getTimeline(twitterid);
        connect(tr, SIGNAL(complete(QString, bool)), this, SLOT(onTwitterTimeline(QString, bool)));
    }
    
    void App::onTwitterTimeline(QString info, bool success)
    {
        if (!success)
        {
            qDebug() << "Error retrieving twitter fee: " << info;
            return;
        }
    
        ListView* list = m_root->findChild("basicTimelineView");
        if (!list || list->dataModel() != NULL)
        {
            qDebug() << "basic list already populated";
            return; //if basic timeline list not found or already populated do nothing
        }
    
        // Create a group data model with id as the sorting key
        GroupDataModel* dm = new GroupDataModel(QStringList() << "id_str");
        dm->setGrouping(ItemGrouping::None);
    
        // parse the json response with JsonDataAccess
        bb::data::JsonDataAccess ja;
        QVariant jsonva = ja.loadFromBuffer(info);
    
        // the qvariant is an array of tweets which is extracted as a list
        QVariantList feed = jsonva.toList();
    
        // for each object in the array, push the variantmap in its raw form
        // into the ListView
        for (QList::iterator it = feed.begin(); it != feed.end(); it++)
        {
            QVariantMap tweet = it->toMap();
            dm->insert(tweet);
        }
    
        // set the data model to display
        list->setDataModel(dm);
        list->setVisible(true);
    }
    

    I hope that's enough to help you get started. There are many improvements that can be made, for example using multiple pages, load the ajax style tweets, even having a page where the twitter user name can be changed, and so on of error handling. Good luck!

    See you soon

    Swann

  • Convert Dialog.alert to handle the touch event

    Anyone know how I can convert my dialog.alert to handle the touch event

    Please help me = D

    You don't need - if you use the standard RIM dialogue he class shoud touch event itself.

  • Touch event works outside the buttons

    Hello

    I'm developng a touch phone application and type. Now on a single screen of the application, there are 3 buttons. Is the screenshot below:

    Here if I touch three-button, it works. But if I touch outside the buttons, we hear in the bar at the top or in the bottom bar, then touch event also works. Suppose that in the bottom, add more button is focused. So if I touch on the lower bar, then also touch button works correctly. To resolve this problem, I wrote the code below:

    try {
                int touchXPos = event.getX(1);
                int touchYPos = event.getY(1);
                int addBtnXPos = btnAddMore.getLeft();
                int saveBtnXPos = btnSave.getLeft();
                int helpBtnXpos = btnHelp.getLeft();
    
                int vfmTitleTouch = m_vfmTitle.getHeight();
    
    if ((touchXPos >= addBtnXPos + 40) && (touchXPos <= (addBtnXPos + btnAddMore.getWidth() + 40)) && (touchYPos <= screenHeight -10) && (touchYPos >= (screenHeight -10 - btnAddMore.getHeight()))  /*&& (touchYPos < (screenHeight-gmYPos)) */)
                {
                    Logger.out("touchEvent", "------------------------------1");
                    showPopUp();
                    return true;
                }
    
                else if ((touchXPos >= saveBtnXPos + 40) && (touchXPos <= (saveBtnXPos + 40 + btnSave.getWidth())) && (touchYPos <= screenHeight -10) && (touchYPos >= (screenHeight -10 - btnSave.getHeight()))/* && (touchYPos < (screenHeight-gmYPos))*/ )
                {
                    Logger.out("touchEvent", "------------------------------2");
                    saveToDb();
                    return true;
                }
    
                else if ((touchXPos >= helpBtnXpos) && (touchXPos <= (helpBtnXpos + btnHelp.getWidth())) && (touchYPos <= (btnHelp.getTop() + btnHelp.getHeight())) && (touchYPos >= btnHelp.getTop())/* && (touchYPos < (screenHeight-gmYPos))*/ )
                {
                    Logger.out("touchEvent", "------------------------------3");
                    UiApplication.getUiApplication().pushScreen(new HelpScreen());
                    return true;
                }
                else if ((touchYPos <= screenHeight - hfmBtn.getHeight()) && (touchYPos >= (vfmTitleTouch)))
                {
                    Logger.out("touchEvent", "------------------------------4");
    //              Logger.out("touchEvent", "touchY::::" +touchYPos  + "Vfm Title::::" +vfmTitleTouch  + "  "+"GM Y Pos"+  gmYPos);
                    return true;
                }
                else
                {
                    Logger.out("touchEvent", "------------------------------5");
                    return false;
                }
            }
            catch (Exception e)
            {
            }
    
            return super.touchEvent(event);
        }
    

    But it does not work... Can someone help me?

    And touch event should work in the middle of the screen as for the boxes also...

    Thank you...

    I tried this way... But it does not work. The same problem. Touch outside of the button, it works to the functionality of the button.

  • Get on touch event BB10 Simulator

    IM studying BB10 Webworks. For exl I have this:











    How can I get the event when I touch a div? It's ok when working with web by onclick but with Simulator, I do not know how to get the key events. Can someone help out me, tks so much

    Here is an example page that allows to understand how touch events:

    http://BlackBerry.github.IO/WebWorks-samples/kitchenSink/HTML/browser/touch.html

    On the BlackBerry 10 Simulator, you should expect to see the TouchStart, TouchMove events and touchstart SHOOTING when you interact with the content of the page with the mouse (Note: will also fire the click event).  Make sure that you are listening and managing events of button correctly.

  • AddEventListener Webworks Javascript PlayBook for mouse/touch events

    I am writing an app for the Playbook using Webworks BB. Inside the application, I have a few items 'div' that users can grab and move them. I implemented it and tested on the desktop browser and it works very well. But I have a few questions about the Playbook:

    For some reason I'm not able to get the mouse/touch events... Here is a small code snippet:

    ....

    ....

    OK trouvé un woraround à ce problème en utilisant : http://ross.posterous.com/2008/08/19/iphone-touch-events-in-javascript

  • Touch event of overlay question

    For our articles, we use an overlay to simulate a background image with "background-attachment: fixed" property css on mobile devices. This overlay 'pointer-events' set to none, then it does not interact with touch events.

    However scrolling is barely on the DPS Android app. It scrolls only in small steps. It works fine when loading the article Chrome (Android).

    There is also no question about the IOS version of the DPS app.

    Here is an example article reproduce the problem:

    Dropbox - Overlay_Issue.zip

    Any idea what's going on?

    Hello Sander,

    Thanks for sharing a nice, clean, the HTML file that reproduces the issue. I get the question on my camera as well. I logged a bug against the Android Viewer to investigate on what is happening.

    Neil

Maybe you are looking for