0

As seen in this app, I want to create an app which dims the screen by creating a shaded overlay.

The window is created, and it's partially transparent, however, I cannot get the applications below it to launch. I can click them, and see the button presses, but other apps cannot launch while mine is running.

Suggestions?

I enclosed my code below, and an example of an app which is already doing this.

final WindowManager.LayoutParams params = new WindowManager.LayoutParams( 
    WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
    WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
    WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | 
    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | 
    WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
    WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
    PixelFormat.TRANSLUCENT);   

    WindowManager wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);    

    LayoutInflater inflater = (LayoutInflater)   getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    ViewGroup mTopView = (ViewGroup) inflater.inflate(R.layout.activity_black, null);
    getWindow().setAttributes(params);
    wm.addView(mTopView, params);

https://play.google.com/store/apps/details?id=com.haxor

mcollard
  • 161
  • 1
  • 12
  • 2
    Fortunately, what you are trying to do no longer works as of Android 4.0, for privacy and security reasons. You can either intercept touch events (which are not passed through to the underlying activity) or not intercept touch events (which are passed through to the underlying activity). – CommonsWare Jan 08 '13 at 18:46
  • Tested the above product, com.haxor, works fine on Android 4.0. – mcollard Jan 08 '13 at 21:53
  • Ah, I misunderstood your requirement. The app in question does not intercept touch events. – CommonsWare Jan 08 '13 at 22:07

2 Answers2

0

This is an easy way:

Dialog dialog = new Dialog(this,android.R.style.Theme_DeviceDefault_Dialog_NoActionBar_MinWidth);
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY);

dialog.getWindow().setFormat(PixelFormat.TRANSLUCENT);
dialog.getWindow().setDimAmount(0);
dialog.setContentView(new EditText(this));
dialog.show();
user812786
  • 4,302
  • 5
  • 38
  • 50
ben
  • 71
  • 2
-2

Modified the Activity to be settings, and moved the blacking component to a service, which worked fine.

mcollard
  • 161
  • 1
  • 12
  • i am sorry but i couldnt get your answer, could you help me out here. My problem is the same as yours but i was able to get touch response from the previous layer but i am getting a completely black screen. – Mayank Oct 19 '13 at 19:05