Toast and duration : LENGTH_LONG and LENGTH_SHORT are FLAGS!

How many times I've seen this code:
Surely I wrote it myself.
Toast.makeText (context, "My Text", 5000).show();
Pay attention!! Here you can see the doc:

This is the source:

LENGTH_LONG and LENGTH_SHORT ARE FLAGS!
Then duration is not expressed in milliseconds!
If you debug this code you can see:

And this is the central point,the NotificationManagerService:

This is the main row:
long delay = immediate ? 0 : (r.duration == Toast.LENGTH_LONG ? LONG_DELAY : SHORT_DELAY);
where:
    private static final int LONG_DELAY = 3500; // 3.5 seconds
    private static final int SHORT_DELAY = 2000; // 2 seconds
Then, the code written in the beginning IS WRONG
Toast.makeText (context, "My Text", 5000).show();< // IT IS WRONG!
Toast.makeText expects duration Toast.LENGTH_SHORT or Toast.LENGTH_LONG, a custom duration value is not supported.
However I have a little doubt: in the source we can find:
This time could be user-definable.
Honestly I can't find way to do this.Any suggestion is welcome.

Popular posts from this blog

Expand and collapse animation

How to centralize the support libraries dependencies in gradle

A Material styled AlertDialog