Displaying the ProgressDialog from the OpenGL thread.

by Dmitriy Shilonosov » Wed, 12 May 2010 15:13:07 GMT


Sponsored Links
 Hi!

Does anyone have expirience with opengl-ui-opengl threading
interraction?

I'am developing a small opengl application. I'am a little bit confused
with separate opengl thread...
Currently, my application is logically separated in two parts - the
controlling one and the rendering one.
The controlling part interracts with user - accepting user input,
changing activities, dealing with files and so on.
The rendering part - just render everything it should.

Ok, so when I need to load new texture to opengl (unfortunatelly its
large and I cant reduce its size), I'd like to show a ProgerssDialog
dialog.
Trying to show it from the open gl thread brings me an exception:
"Can't create handler inside thread that has not called
Looper.prepare()".
Because the initiator of loading is in the ui thread (for example -
user selected a menu option), I'am opening the dialog, adding the load
Runnable to stack on Runnables that will be called in
Render.onDrawFrame and passing there a callback that will be executed
after texture is loaded.

Like this:

//ui

public class Controller extends Activity {

  ...

  protected void loadTexture(InputStream aStream) {
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setTitle("Please wait...");
    dialog.setMessage("Loading texture");
    dialog.show();
    _renderer.loadTexture(_stream, new Runnable() {
      @Override
      public void run() {
        dialog.dismiss();
      }});
  }

  ...
}

//gl

public class SceneRenderer implements Renderer {
  @Override
  public void onDrawFrame(GL10 aGL) {
    this.runGLRunnables(aGL);
  }

  public void loadTexture(final InputStream aStream, final Runnable
aCallback) {
    _glRunnablesStack.push(new GLRunnable() {
    @Override
    public void run(GL10 aGL) {
      SceneRenderer.this.doLoadTexture(aStream);
      aCallback.run();
    };});
  }
}

So the question is: Is there any way to show ProgressDialog from the
opengl thread?
I need exactly the ProgressDialog. There is a way to show some
picture, previously loaded, like a splashscreen using opengl renderer,
but I'd like to avoid it.

Thanks!

--



Other Threads

1. How to display List in homescreen app widget ?

Hi,

I can't find how to display a list in the app widget.

I have created one app-widget which fetches the database table
information and I want to display all the icon:text into app-widget.
Remoteviews doesn't have any list functionality.

How can I do it, please help

Thanks
Harshit
--~--~---------~--~----~------------~-------~--~----~

2. ListView - duplicate onScroll events

In my app I have a ListView backed by ArrayAdapter. In it I'm
detecting events in OnScrollListener#onScroll method to find end of
the list. I noticed that on the phone (MyTouch) both track-ball and
gesture/touch scrolling will trigger the event twice. On the emulator
I get the same behavior with a scrolling wheel and click-and-drug
scrolling. However in emulator if I use down-arrow button to scroll
the event is fired only once.

Here's the code:

    this.view.setOnScrollListener(new OnScrollListener() {
        @Override
        public void onScroll(final AbsListView view, final int first,
                                    final int visible, final int
total) {
            // detect if last item is visible
            if (visible < total && (first + visible == total)) {
                Log.d("OnScrollListener - end of list", "fvi: " +
                   first + ", vic: " + visible + ", tic: " + total);
                // this line gets called twice
                onLastListItemDisplayed(total, visible);
            }
        }
    }

How do I suppress or handle this behavior? I need just a single event
and trying not to revert to silly hacks such as boolean field.

As far as I can tell - both events have identical stacktrace

    Thread [<3> main] (Suspended (breakpoint at line 116 in
SearchResultsView$4))
     SearchResultsView$4.onScroll(AbsListView, int, int, int) line:
116
     ListView(AbsListView).invokeOnItemScrollListener() line: 655
     ListView.arrowScrollImpl(int) line: 2256
     ListView.arrowScroll(int) line: 2172
     ListView.commonKey(int, int, KeyEvent) line: 1977
     ListView.onKeyMultiple(int, int, KeyEvent) line: 1929
     KeyEvent.dispatch(KeyEvent$Callback) line: 899
     ListView(View).dispatchKeyEvent(KeyEvent) line: 3647
     ListView(ViewGroup).dispatchKeyEvent(KeyEvent) line: 744
     ListView.dispatchKeyEvent(KeyEvent) line: 1909
     FrameLayout(ViewGroup).dispatchKeyEvent(KeyEvent) line: 746
     LinearLayout(ViewGroup).dispatchKeyEvent(KeyEvent) line: 746
     PhoneWindow$DecorView(ViewGroup).dispatchKeyEvent(KeyEvent) line:
746
     PhoneWindow$DecorView.superDispatchKeyEvent(KeyEvent) line: 1708
     PhoneWindow.superDispatchKeyEvent(KeyEvent) line: 1197
     SearchResultsView(Activity).dispatchKeyEvent(KeyEvent) line:
1967
     PhoneWindow$DecorView.dispatchKeyEvent(KeyEvent) line: 1684
     ViewRoot.deliverKeyEventToViewHierarchy(KeyEvent, boolean) line:
2329
     ViewRoot.handleFinishedEvent(int, boolean) line: 2299
     ViewRoot.handleMessage(Message) line: 1621
     ViewRoot(Handler).dispatchMessage(Message) line: 99
     Looper.loop() line: 123
     ActivityThread.main(String[]) line: 4203
     Method.invokeNative(Object, Object[], Class, Class[], Class, int,
boolean) line: not available [native method]
     Method.invoke(Object, Object...) line: 521
     ZygoteInit$MethodAndArgsCaller.run() line: 791
     ZygoteInit.main(String[]) line: 549
     NativeStart.main(String[]) line: not available [native method]
--~--~---------~--~----~------------~-------~--~----~

3. donuts supports screens issue

4. How to hide views within a layout

5. Custom Object Serialization in Android?

6. scheme compiler for android

7. My application has died when I started to use Browser