Dialogue which doesn't steal focus?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Dialogue which doesn't steal focus?

Postby Jorenm » Tue Jan 05, 2010 10:58 pm

For my game I want to be able to create information popupstooltipsetc but I don't want them to take focus from the GLSurfaceView. Is this possible? If so, how?
Jorenm
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Nov 28, 2009 9:16 am

Top

Postby jwei512 » Tue Jan 05, 2010 11:31 pm

Maybe consider a toast / custom toast?

http://developer.android.com/guide/topi ... oasts.html

If you scroll down, it shows you different kinds of toasts that you can create... this might be what you are looking for.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby Jorenm » Tue Jan 05, 2010 11:54 pm

No wonder I never found that. Who would search for Toast when looking for that functionality?

This is almost exactly what I want, except I want it to take events as well. Is there anything that:

1) Doesn't kill the existing activity
2) Allows touch events

Of course I only want it to take touch events that actually touch it, and to ignore ones that do not. I'd also like it to not be transparent to touch events so a touch event only fires inside of it and not beneath it as well.
Jorenm
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Nov 28, 2009 9:16 am

Postby jwei512 » Wed Jan 06, 2010 12:06 am

Hm, well do you want these game notifications to last for an indeterminate amount of time? Because a Toast is very transient... it only lasts between 2-3 seconds and then it fades away.

If this is okay with you, then what you can try to do is in the "Custom Toast" example from the link above, just try to set an onClickListener or an onTouchListener to, say, the layout supporting all your views. I've never tried this for myself so I can't guarantee that it will work, but I don't see why it wouldn't...

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.  
  4.              android:id="@+id/toast_layout_root"
  5.  
  6.              android:orientation="horizontal"
  7.  
  8.              android:layout_width="fill_parent"
  9.  
  10.              android:layout_height="fill_parent"
  11.  
  12.              android:padding="10dp"
  13.  
  14.              android:background="#DAAA"
  15.  
  16.              >
  17.  
  18.     <ImageView android:id="@+id/image"
  19.  
  20.               android:layout_width="wrap_content"
  21.  
  22.               android:layout_height="fill_parent"
  23.  
  24.               android:layout_marginRight="10dp"
  25.  
  26.               />
  27.  
  28.     <TextView android:id="@+id/text"
  29.  
  30.              android:layout_width="wrap_content"
  31.  
  32.              android:layout_height="fill_parent"
  33.  
  34.              android:textColor="#FFF"
  35.  
  36.              />
  37.  
  38. </LinearLayout>
  39.  
  40.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. LayoutInflater inflater = getLayoutInflater();
  3.  
  4. View layout = inflater.inflate(R.layout.toast_layout,
  5.  
  6.                                (ViewGroup) findViewById(R.id.toast_layout_root));
  7.  
  8.  
  9.  
  10. // try adding something like this...
  11.  
  12.  
  13.  
  14. layout.setOnClickListener(new OnClickListener() {
  15.  
  16.  
  17.  
  18.       @Override
  19.  
  20.       public void onClick(View v) {
  21.  
  22.            // whatever you want the click event to be
  23.  
  24.       }
  25.  
  26. }
  27.  
  28.  
  29.  
  30. ImageView image = (ImageView) layout.findViewById(R.id.image);
  31.  
  32. image.setImageResource(R.drawable.android);
  33.  
  34. TextView text = (TextView) layout.findViewById(R.id.text);
  35.  
  36. text.setText("Hello! This is a custom toast!");
  37.  
  38.  
  39.  
  40. Toast toast = new Toast(getApplicationContext());
  41.  
  42. toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
  43.  
  44. toast.setDuration(Toast.LENGTH_LONG);
  45.  
  46. toast.setView(layout);
  47.  
  48. toast.show();
  49.  
  50.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4


And maybe that will work? Again I've never done it myself, and again if you want these toasts to stay up indefinitely then that won't be possible without a known "toast hack" and in which case a toast might not be what you want to use for your game...
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby Jorenm » Wed Jan 06, 2010 12:11 am

Hmm. It definetely needs to stay up indefinetly. Think of the orders menu you might have if you select a unit in an rts. That's basically what I am going for. Doing this with an xml layout would be infinetly preferable to doing it in opengl as that would take WAY longer.
Jorenm
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Nov 28, 2009 9:16 am

Postby jwei512 » Wed Jan 06, 2010 12:13 am

Well a Toast is designed to disappear in a short amount of time....

I know a hack that you could use to make it appear "indefinite", but first, could you try to add the onClickListener to a custom toast and tell me if that works?

If it does, then I think I know how you could do this, and I'll be more than happy to write a code snippet for you.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Top

Postby Jorenm » Wed Jan 06, 2010 12:57 am

I'd love to try it, but I can't figure out how to create a touch listener.
Jorenm
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Nov 28, 2009 9:16 am

Postby Jorenm » Wed Jan 06, 2010 1:29 am

After about an hour and a half I can't figure out any way to create a simple test case for this. I can't seem to just add a full screen touch listener to a god damned fucking activity. Driving me insane.
Jorenm
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Nov 28, 2009 9:16 am

Postby jwei512 » Wed Jan 06, 2010 1:01 pm

What exactly are you trying? Maybe try posting the code you are trying to get to work... (XML and JAVA)
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Postby Jorenm » Fri Jan 08, 2010 6:41 am

All I'm trying to do is take the base activity from when you create a project, and the base view, and add a touch listener to that base view. I can't figure out a way to do this.
Jorenm
Junior Developer
Junior Developer
 
Posts: 22
Joined: Sat Nov 28, 2009 9:16 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 12 guests