-1

i would like to create a secret event gesture that will be hardcoded to my app to activate a function.

a secret hidden admin menu, that will ask for admin password and do admin staff, and i would like it to show up after the user do:

5 fingers anywere on screen for 5 seconds

this is to avoid adding a visible admenistrator button to the app since the user does not need to see it and has no use for it.

can anyone provide me with a part of code to achieve this? i searched but not found an example for the kind of gesture i need...

p.s: the code can be for rooted devices.. since it for specific rooted device..

thanks alot for the help :-)

itai
  • 302
  • 5
  • 15
  • If you get here looking for a solution for having a secret menu or administration section, just be aware that this is not a safe solution. – MRodrigues Dec 23 '16 at 16:52

2 Answers2

1

You can set an OnTouchListener on your root View, then check the MotionEvent's getPointerCount() method along with a timer to check this.

Here's a brief example:

import android.view.View.OnTouchListener;

private static final int FIVE_SECONDS = 5 * 1000; // 5s * 1000 ms/s
private long fiveFingerDownTime = -1;


getWindow().getDecorView().findViewById(android.R.id.content).setOnTouchListener(new OnTouchListener() {        

@Override
public boolean onTouch(View v, MotionEvent ev) {
    final int action = ev.getAction();
    switch (action & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_POINTER_DOWN:
            if (ev.getPointerCount() == 5) {
                // We have five fingers touching, so start the timer
                fiveFingerDownTime = System.currentTimeMillis();
            }
            break;

        case MotionEvent.ACTION_POINTER_UP:
            if (ev.getPointerCount() < 5) {
                // Fewer than five fingers, so reset the timer
                fiveFingerDownTime = -1;
            }
            final long now = System.currentTimeMillis();
            if (now - fiveFingerDownTime > FIVE_SECONDS && fiveFingerDownTime != -1) {
                // Five fingers have been down for 5 seconds!
                // TODO Do something
            }

            break;
    }

    return true;
}
});
itai
  • 302
  • 5
  • 15
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120
0

Here is a relevant android dev blog post about multi touch gestures. http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html

Rohan
  • 1,312
  • 3
  • 17
  • 43
  • thanks, but how can i implement that specific gesture? 5 points fingers(no matter location of them) for 5 seconds? i guess it's got somting to do with 'long press', thanks – itai Jan 10 '14 at 17:52