OverRiding a Function

I'm not much of an object oriented programmer, but I've developed some pretty cool/complex data fields even so.

Quick question. I have a InputDelegate class that traps an onTap event, in order to switch between screen views. tap upper left/right of screen to change views, or tap center of the screen to return to the main screen. works great.

But I just created a "service" to display a pop-up (along with a beep tone) to alert the athlete of certain conditions. That pop-up automatically expires after about 8 seconds.

I'd like to enable a screen tap to dismiss the alert immediately. So in my "procedural" mindset, I could set a global variable when a pop-up is active, and in my InputDelegate function, just change the behavoir of the onTap() logic when popUp == true.

But I think there is probably a more elegant OO approach in which I override the function when a pop up is active so the pop up tap handler takes over during that time.

Thoughts? I know this is basic stuff for OO programmers. Just trying to learn how to do this right.

Thanks in advance!

-- Dave



  • It sounds like your app is a data field and not a full device app or widget, in which case it is restricted to a single view.

    If you were talking about a full device app, then your popup could've been a separate view which could've had its own InputDelegate. In this case I think you have to have the same InputDelegate class at all times.

    However, I would not use a global variable unless you are down to your last handful of free bytes and you really need to save memory. (In other words, don't do it.)

    I wouldn't even have the input delegate know anything about what happens when you tap. That should be the responsibility of the view, not delegate, if it depends on state/logic that belongs to the view. Pass the datafield view to the delegate and provide a public function that handles taps.

    class MyInputDelegate extends InputDelegate {
    var datafieldView;
    function initialize(_datafieldView)
    {
    InputDelegate.initialize();
    datafieldView = _datafieldView;
    }
    function onTap() {
    datafieldView.onTap(); // the delegate does not want or need to know anything about what the view does here
    }
    }

    class MyDataFieldView ... {
    function onTap() {
    if (displayingPopup) {
    dismissPopup();
    } else {
    cycleView();
    }
    }
    }


    To extend this concept further, if this were a full app or widget that could handle both button presses and taps, then you could even make this more generic and provide an onButtonPressOrTap() function in the view, depending on your needs. The input delegate could handle receiving the specific button presses/taps that the view would be interested in, and just call an appropriate function provided by the view. (For example, you might wish to only treat UP/DOWN/START and taps equivalently, while allowing BACK to do something else.)

    But you get the idea.
  • My DataField has 5 different screens.... easy to do. Just handle an onTap() and call a different screen paint function from onUpdate(). Works flawlessly and I get to display different views from a single full screen data field. It is amazingly useful. That works for touch screens. So I had to implement a kludge so that a double tap on the START/STOP button switches screens for the Edge 520plus, a great device but no touch screen.

    My InputDelgate grabs the coordinates of the onTap() event and determines which quadrant of the screen was tapped. Since that determines if we move left or right among the screen views, or back home to the main screen.

    Yes, I get the idea. Thank you!!! That really helps!
  • FlowState , I wonder the the Forum algorithms are going to upgrade you from "Junior Member"? I was unexpectedly, and quite undeservedly upgraded to Master after only a couple of months!