2

I've run into some difficulties with implementing a custom progress dialog. Even though an overlay intercepts touch events the user can still operate the trackball and click elements that are supposed to be disabled.

Is there any way around this?

Edit: here's a solution

//=====================================================================================
protected void showProgressIndicator()
{
    progressIndicator_.show();
}

//=====================================================================================
@Override
public boolean onTrackballEvent(MotionEvent event)
{
    return progressIndicator_.getVisibility() == View.VISIBLE;
}

//=====================================================================================
protected void hideProgressIndicator()
{
    progressIndicator_.hide();
}

An then in show method

//=====================================================================================
public void show()
{
    setVisibility(VISIBLE);
    if (animationHandler_ != null)
        return;

    animationHandler_ = new Handler();
    animationHandler_.post(animateTask_);
    requestFocus();
}
Kostia Dombrovsky
  • 1,647
  • 2
  • 18
  • 29

3 Answers3

1

In order to prevent your trackball doing anything while your activity is on screen, add the following code to your Activity subclass.

@Override 
public boolean dispatchTrackballEvent(android.view.MotionEvent ev) {
  return true;
};

I've tested this on a Google Nexus One phone and it works fine.

Ben Clayton
  • 80,996
  • 26
  • 120
  • 129
  • can i turn off trackball in emulator using this technique? – Manoj Kumar Sep 27 '12 at 07:15
  • 1
    @MoJo it does work since it overrides the even and does not call the base class. Returning true is important too since it will tell Android that you ate the event. – ForceMagic May 21 '14 at 17:37
0

Check the onTrackballEvent() method. Then try to directly returning true in the method without doing anything in it. This should kill the event right away.

Sephy
  • 50,022
  • 30
  • 123
  • 131
  • Your solution isn't precisely correct because the user can't navigate with the trackball that way but he can click it. So if a button is focused he can still click it. The solution was just to request foucs from the progress dialog and implemento nTrackballEvent(). Thanks for your advice :) – Kostia Dombrovsky Aug 06 '10 at 16:17
  • can u please post the solution? – Pria Aug 27 '10 at 06:14
0

Override onTrackballEvent() does not work. Try overriding dispatchTrackballEvent(), do nothing in it just return true;.

ethangao
  • 223
  • 4
  • 11