5

I have created a service which will overlay an image on top of the whole screen.

This part is the code which will overlay an image on top of the whole screen:

@Override public void onCreate() {
    super.onCreate();

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

    img = new ImageView(this);
    img.setImageResource(R.drawable.image); // Image is .png format

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.WRAP_CONTENT,
        WindowManager.LayoutParams.TYPE_PHONE,
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
        PixelFormat.TRANSLUCENT);

        params.gravity = Gravity.CENTER | Gravity.CENTER;
        params.x = 0;
        params.y = 0;

        windowManager.addView(img, params);
}

However, any space which the image covers in untouchable. I want the image to be just overlaid, without affecting any other components on the screen, similar to what this does:

CPU usage overlay example

How can I make the area beneath the image touchable (touch-through)?

Edit
It seems that the transparent space of the image fills a square, and covers the screen (FYI). So my ultimate goal is, to make the image touch-through.

I have tried the popupWindow class, recommended by a few SO users, but its purpose does not fulfill my needs and does not work.

jyoonPro
  • 1,661
  • 1
  • 16
  • 41
  • You can use a RelativeLayout below ImageView with background color like that #99000000, important part "#99" to Alpha color or use transparent color and add onClick events to RelativeLayout – Aspicas Jun 13 '14 at 09:26
  • Does it work if you add `return false` in onTouchListener of an imageview, so touch event can be passed to relative layout instead? – MysticMagicϡ Jun 13 '14 at 09:27
  • Setting `return false`on onTouchListener didn't work. It seems that the image is causing the problem: the blank space. Is there a way to remove the blank space? – jyoonPro Jun 13 '14 at 09:50
  • NO. The "blank" space... just **isn't blank**. Instead, it is **transparent** (that is, it is filled with "see-through" pixels, which arent "touch-through" - they are a solid barrier covering the screen, like a **glass sheet**). – Phantômaxx Jun 13 '14 at 09:54
  • So how to make every pixel touch through? – jyoonPro Jun 13 '14 at 09:56
  • 2
    I wouldn't use the word "Service", in Android that has a special meaning. – PearsonArtPhoto Jun 15 '14 at 14:16
  • As a caution, you've made a lot of seemingly trivial edits to "bump" this question. Please stick to making more substantial edits, as frequent edits like this can be seen as exploiting the system. – Brad Larson Jun 20 '14 at 20:40
  • Actually service is correct since it will be used to display above the entire screen, even when the app is closed. – jyoonPro Aug 20 '14 at 19:05
  • 1
    You could add a touch listener to the overlay, manually intercept touch events, examine the coordinates that were touched, and re-route the touch event to the underlying views accordingly. – EricaCooksey Aug 20 '14 at 19:21
  • http://stackoverflow.com/questions/11635934/touch-through-translucent-app – Shirish Herwade Jul 14 '16 at 07:20

3 Answers3

1

I found that WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY solves the issue.

jyoonPro
  • 1,661
  • 1
  • 16
  • 41
0

Try

img.setClickable(false);

http://developer.android.com/reference/android/view/View.html#setClickable(boolean)

Michele
  • 6,126
  • 2
  • 41
  • 45
0

Try setting the param flags to:

WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | 
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | 
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH

I've tried this with success before. The last two will help send touch events to the views behind it.

telkins
  • 10,440
  • 8
  • 52
  • 79