Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable All Touch Screen Interactions While Animation

I wish to disable all the touch screen interactions while an animation is being displayed. I don't wish to use the setClickable() method on the buttons at the start or end of the animation because there are a large number of buttons. Any suggestions?

like image 894
gursahib.singh.sahni Avatar asked Jun 11 '12 21:06

gursahib.singh.sahni


People also ask

How do I turn off screen animation?

Open Settings . Scroll down and select Accessibility. Scroll down to Display and tap Text and display. Tap the toggle switch for Remove animations to turn it on.

What is remove animations in accessibility?

It's called "Remove animations," and it does exactly what you'd think: It disables all animations throughout the Android interface (and doesn't require you to activate and poke around in Android's developer settings, either, as the more common method of animation disabling does).

What are animations on Android?

Animation is the process of adding a motion effect to any view, image, or text. With the help of an animation, you can add motion or can change the shape of a specific view. Animation in Android is generally used to give your UI a rich look and feel.

How do I turn off touch events on Android?

Search for Enable resampling input events. Click on Enable touch events > Disabled.


1 Answers

In your Activity, you can override onTouchEvent and always return true; to indicate you are handling the touch events.

You can find the documentation for that function there.

Edit Here is one way you can disable touch over the whole screen instead of handling every view one by one... First change your current layout like this:

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    < .... put your current layout here ... />

    <TouchBlackHoleView
        android:id="@+id/black_hole"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
</FrameLayout>

And then define your custom view with something like this:

public class TouchBlackHoleView extends View {
    private boolean touch_disabled=true;
    @Override
    public boolean onTouchEvent(MotionEvent e) {
        return touch_disabled;
    }
    public disable_touch(boolean b) {
        touch_disabled=b;
    }
}

Then, in the activity, you can disable the touch with

(TouchBlackHoleView) black_hole = findViewById(R.id.black_hole);
black_hole.disable_touch(true);

And enable it back with

black_hole.disable_touch(false);
like image 81
Matthieu Avatar answered Sep 21 '22 12:09

Matthieu