2

I want make an app/service that looks like (Nexus One touch buttons) for the navigation keys (Home, menu, Back, Search)

The buttons should always stay on top and send the command to the actually app that's running.

Someone have ideas and sample codes how to do that?

Update:

I also see and test an app which shows a "cracked display" always on top so that technique maybe should be useful to always show the buttons on top.

Those function, show the button and catch the "touch event" and send the event to the active program should be in a service module which runs in background.

Jason Aller
  • 3,391
  • 28
  • 37
  • 36
Ken
  • 21
  • 1

2 Answers2

3

You cannot do this kind of application. First, you cannot keep an app always on top, then you cannot dispatch key events to other apps.

Romain Guy
  • 95,351
  • 17
  • 214
  • 199
  • Actually, that first half is untrue, as demonstrated by a small number of stay-on-top apps. Via [http://stackoverflow.com/questions/4481226/creating-a-system-overlay-always-on-top-button-in-android](http://stackoverflow.com/questions/4481226/creating-a-system-overlay-always-on-top-button-in-android), there's a link to source code for a demo: [https://docs.google.com/leaf?id=0B9OlwWEcpDrCNTc1N2Y3NTAtMWJkZi00NzhiLTg4ODgtMDNjZTAxZWIwOTM0&hl=en](https://docs.google.com/leaf?id=0B9OlwWEcpDrCNTc1N2Y3NTAtMWJkZi00NzhiLTg4ODgtMDNjZTAxZWIwOTM0&hl=en) that gives a stay-on-top-button. – Erhannis Oct 18 '12 at 08:03
0

You could do this:

            WindowManager mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    System.out.println("Accesibilty cargado correctametne");
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mTopView = (ViewGroup) inflater.inflate(R.layout.resourceshower, null);
    LayoutParams mWmlp = new WindowManager.LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    mWmlp.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
    mWmlp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
    mWmlp.width = 100; //size of window
    mWmlp.height = 50;//size of window
    mWmlp.format = PixelFormat.TRANSPARENT;
    mWmlp.x =50; //position of window
    mWmlp.y = 50; //position of window
    mWindowManager.addView(mTopView, mWmlp);

Then if you want to get button clicks inside it, in the layout you are inflating (R.layout.resourceshower) on the buttons add this: android:onClick="launch" and create a public method with the same name like: public void launch(View v){..} you must create this method in the service/activity you create the floating window.

John Conde
  • 207,509
  • 96
  • 428
  • 469
Golgorz
  • 131
  • 1
  • 2