Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 1,657
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

SystemToast and predefined timeout (my solution)

I know many of us would like to be able to set the timeout on SystemToast instead of an invisible default timeout.

 

also it's problematic, if you use a button on your Toast - then timeout is counting down from first user UI activity - and I found some cases where it seems that not all UI activity counts as a count-down-starter ;-)

 

if clicking on the button will trigger a specific action, then this is not a way to go if the user doesn't want to do the button action.

here's my use-case:

 

Toast as UNDO: SystemToast has a button labeled "undo" and if user clicks it, last action will be undone.  So far so good, but if the user gets the Toast and then does another action (hitting back or an ActionItem or....) I would like to cancel the SystemToast.

 

problem: cancel() closes the SystemToast without any signal, which means, my delete-logic doesn't run.

 

my UNDO usecase is described here.

(Run into this because DeleteAction is automatically mapped with DEL key on Q10 - and per accident a user can tip the wrong key.)

 

now my solution:

SystemToast gets a

property bool killed: false

 

and in situations, where I cancel() the SystemToast, I also set deleteToast.killed = true.

 

now the onKilledChanged() signal was emitted and I can test at my SystemToast if killed == true and do the same logic as on timeout.

 

this is only the half part of the story:

if deleting a record (only on Q10) I don't execute the delete logic, but a preparedToDelete() logic, where in this case I change the Icon of the row and show() the toast. Toast gets also the recordId as parameter.

 

so the simplified process is like this:

 

ActionItem

id: deleteAction

if triggered

   if Q10

      doPrepareDelete(recordId)

   else

     deleteRecord(recordId)

 

------

function doPrepareDelete(recordId)

    // do some stuff

    deleteToast.recordId = recordId

    deleteToast.show()

 

-----

SystemToast

    id: deleteToast

    property int recordId : -1

    property bool killed : false

    onFinished()

        if undoButtonClicked

            // reverse UI changes or so

            recordId = -1

        if timeOut

            deleteRecord(recordId)

            recordId = -1

    onKilledChanged

        if (killed && recordId > 0)

            deleteRecord(recordId)

            recordId = -1

 

----

in all cases where I expect the user doesn't want to Undo (Back Action, other Actions) I execute

 

deleteToast.cancel()

deleteToast.killed = true

 

Now I can rely on the default timeout or force it in special situations

----------------------------

 

perhaps this gives you an idea

 

I will put a sample project on github later, not enough time yet, because had so much work preparing my sessions for BlackBerry Live / BBJam next week and to do some customer project work and blogging and ....

 

If you're at BBJam I recommend JAM56 on InvocationFramework and JAM69 Maps in your apps ;-)

 

I'm in orlando the whole week send me a tweet to meet @ekkescorner

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner