Toast with Focus and Touchable

446 views
Skip to first unread message

bizack

unread,
Oct 28, 2009, 7:57:41 PM10/28/09
to android-platform
I'm attempting to create a Toast-like class, which responds to user
input (but unlike a Dialog, does not have a full-screen window). I've
pretty much copied Toast.java, but changed TN() to:

TN() {
// XXX This should be changed to use a Dialog, with a
Theme.Toast
// defined that sets up the layout params appropriately.
final WindowManager.LayoutParams params = mParams;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.width = WindowManager.LayoutParams.WRAP_CONTENT;
params.flags =
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
params.format = PixelFormat.TRANSLUCENT;
params.windowAnimations =
com.android.internal.R.style.Animation_Toast;
params.type = WindowManager.LayoutParams.TYPE_TOAST;
params.setTitle("MyToast");
}

I thought by removing the flags that specified no focus and not
touchable, this would be a quick fix. However, that's not the case.
Why am I not receiving focus or touches with these modifications? Is
there some technical limitation that makes this impossible? I've gone
through the source, and I can see that a Toast is basically a view
that's added via the WindowManager, and then removed when the duration
time is met. However, I still don't quite understand how a Toast
behaves as if it has its own (non full-screen) Window (i.e. you can
still interact with anything outside the bounds of a Toast).

Thanks.

Dianne Hackborn

unread,
Oct 28, 2009, 11:52:46 PM10/28/09
to android-...@googlegroups.com
What you are creating is, by definition, not a toast, so you can't specify its type to be toast etc.  (Actually you can't do what you are doing here anyway -- the toast type is a special window type that you can not use unless you get an appropriate token from the system to display it.)

You'll need to just use a standard Dialog but with a theme that has whatever toast-like behavior you want.
--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

bizack

unread,
Oct 29, 2009, 12:33:03 PM10/29/09
to android-platform
The problem is, a Dialog, although appearing to not be full-screen,
has a full-screen window that blocks input to any window below it.
I'm trying to have a Dialog-like Window that is the exact size of the
Dialog (not full-screen), thus allowing input to the Window below
(i.e. around the borders of the Dialog). I can't decide if this was
an engineering problem on the Android side, or a design decision (not
having an explicit multi-window OS).
I've seen different param fields that indicate the use of the token
you mention, but I have no idea how one goes about finding/retrieving
that token. I certainly don't expect, and am not asking for you to
solve this problem for me. I'm just wondering if it's not worth my
time trying to implement because of reasons you're already aware of.

Thanks.
> hack...@android.com

bizack

unread,
Oct 29, 2009, 2:24:23 PM10/29/09
to android-platform
Answered by you in another post:

http://osdir.com/ml/handhelds.android.devel/2008-03/msg00766.html

This is exactly what I'm trying to do (I thought this would be a
platform question, but the getWindow() API exposes this at the
Developer layer...).

Thanks.
Reply all
Reply to author
Forward
0 new messages