Best way to introduce repeated action to a Button descendant - codenameone

I'd like derive a class from Button to add an initial delay and interval which shall be used as long as the button is touched for repeated action.
At first thought this seems to be simple enough but the method com.codename1.ui.Button.setState(int) cannot be overridden because it has package access only. Is that for a good reason?
I noticed, that Button calls actionPerformed on pointerReleased. My Button descendant should call actionPerformed repeatedly but not wen the parent container of the Button is beeing scrolled. This would hopefully just correspond with the Button state STATE_PRESSED, right?

If I understand correctly what you mean then I'd just start a timer on the pressed method and then repeatedly call super.pressed & super.released whenever the timer elapses.

Related

FullCalendar Current Event Change callback

I'm using react FullCalendar component and I need to change the background color of an event as it becomes the "CurrentEvent" (when the now indicator is over it).
I'm able to do that when I load the screen, but I also need to do it when the screen is open and the "current event" changes as the time passes.
The way I was thinking about doing that is by using any callback indicating this situation and then changing the style, but I'm not finding any callback that points out this situation.
Any ideas? Thank you.

Codename One Focus and Removing Components

I have implemented code in focusGained that in some cases may cause the component (a container I have set to be focusable) which just received that focus to be removed from the screen, and replaced in the container by another component. This will also cause a redraw of the screen to show the changed component.
This does work but I have a bit of a problem, in that the next component in the container also gains focus and so my code removes/replaces it also. I assume this is because on the redraw, that component now occupies the same space where the tap originally occurred.
If the last component in the container was originally selected, then the replacement component is itself given focus and so it is removed and replaced.
Any ideas on what I may have miscoded or anything I can do to avoid the second focusGained call?
I doubt you did something wrong. If we remove the component with the focus we'll find the next available one. The replace method doesn't take focus into consideration but can't grant focus to a component that isn't physically here yet so it's granted to the next component. Not much to do here.
You can requstFocus() after the transition completes to fix the order manually.

With a Component derivative pointerReleased may never be called after pointerPressed

When a Component derivative is in a scrollable Container after pointerPressed and some scrolling the pointerReleased is never called.
Is this a bug or a feature - and why do You think that way?
There is a special case for buttons which you can leverage by deriving buttons. Events are delivered to the component where they occur. If a release occurs outside of the component it's sent to the component where it occurred as we don't track the original component.
For buttons there is a special pressed and not released case. This will detect such a button in the pointer release code and deliver the event to it.

Drag finger from one button to another - want to un-trigger old button and trigger new button - Windows Store

I am working on a windows store application and I want to be able to drag between buttons so that the originally pressed button becomes deactivated and the newly "dragged onto" button becomes activated but I can't seem to get this to work.
I have 2 Buttons inside a StackPanel and the events I have on them are:
PointerPressed
PointerEntered
PointerReleased
PointerExited
PointerCanceled
PointerCaptureLost
PointerPressed and PointerEntered share the same event handler and the rest (the "deactivation" events) share the same event handler.
If I press one button my "activated" event handler is triggered and if I drag off it my "deactivated" event handler is triggered but if I then drag onto the second button the "activated" event handler isn't triggered again.
Strangely, if I start by dragging from off the StackPanel onto one of the buttons the "activated" event handler is triggered. I assume that it is something to do with the internal pointer management stuff but can't seem to find a workaround.
Does anyone know why this is happening and how I can get it to work how I want?
Thanks for your time.
Edit
Okay I've been researching some stuff and I've come across CapturePointer() and ReleasePointerCapture() but this seems to be broken - If I capture the pointer, when I take my finger off the screen, PointerReleased doesn't even get hit.
I've also realized why the "dragging from off the SP onto one of the buttons causes it to 'activate'" - this is because when a button is pressed it doesn't route its event but fires a Click event - meaning the same pointer cannot fire a PointerEntered event of another button, but if it starts outside a Button it will trigger PointerEntered.
This doesn't get me much further but it is a little extra info :)
The concept of Button is a bit unique in regard to mouse capture and how dragging away from it happens. In your scenario I'm not sure if the event model around Button will work correctly for you. On Button, when a pointer is depressed (mouse) it has capture until it is released. This is not the same for touch where a press and drag away is different because in touch there isn't any explicit capture unless you create it.
So what you are hitting is going to be a slight conflict between mouse/touch interactions anyway using Button -- using some other UI element (not sure if you have a styled button) should get you what you want.

Silverlight click event registered a second time before first event completed

I have a button which launches a "modal dialog" - it just creates a transparent grid covering everything, with the "dialog" created on top of that.
However I have a strange issue - if I double/triple click the button really fast (or add some delay in the event code), the button click event is executed multiple times, creating multiple overlapping modal dialogs. If the first action in my event is to disable the button (IsEnabled=false) it seems to prevent this.
My guess is that Silverlight is being multithreaded with input - it is not only recording the second click in another thread (while the button's click event is running), but it is jumping the gun by evaluating which control should be the target before the previous event has finished executing. Even though that event alters what control is at those mouse coordinates, it doesn't matter.
Does anyone know anything about this behavoir, or a way around it? If I have something like a save window, where the user clicks a save button, a blocking grid ("Saving...") is placed up while it saves, and then the whole "window" is closed, I'd like to avoid the user being able to queue up multiple save event clicks (this could lead to unpredictable program behavoir).
If you've ever worked with WinForms or WPF, this is expected behavior. Your button is broadcasting its Click event until your modal dialog covers it up. Unfortunately, there is some amount of time between your first click and when the modal dialog covers the button which allows multiple clicks to the original button.
You have two solution choices:
Disable the button after the first click and then re-enable after the modal dialog returns. You've already mentioned that this works.
Write code in the Event Handler of the button to determine if a modal dialog is already being displayed. This way, you're putting the responsibility in one location rather than splitting it up (disabling and re-enabling the button). This would be my preferred solution.
I think what you're seeing is the behaviour of Silverlight's routed events.
You can set the Handled property of the event arguments to true to prevent the event from bubbling.

Resources