title: Android Click Through PopupWindow
body: <p>I have created a class that extends popupwindow. its constructor looks something like the following</p>
  
  <pre><code>super(builder.context.get());
  
  this.setWindowLayoutMode(ViewGroup.LayoutParams.MATCH_PARENT,
          ViewGroup.LayoutParams.MATCH_PARENT);
  setFocusable(true);
  setBackgroundDrawable(new BitmapDrawable());
  setTouchInterceptor(onTouchListener);
  FrameLayout frameLayout = new FrameLayout(builder.context.get());
  LayoutInflater inflater = (LayoutInflater) builder.context.get().getSystemService(
          Context.LAYOUT_INFLATER_SERVICE);
  View overlayBase = inflater.inflate(R.layout.tutorial_view_items, null, false);
  frameLayout.addView(builder.backgroundView);
  frameLayout.addView(overlayBase);
  setContentView(frameLayout);
  </code></pre>
  
  <p>the onTouchListener looks like the following:</p>
  
  <pre><code>private OnTouchListener onTouchListener = new OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
          float x = event.getX();
          float y = event.getY();
          Log.d(TAG, "Received");
  
          if (Math.pow(x - coordinates[0], 2) + Math.pow((y - coordinates[1]), 2) &lt; Math.pow(radius, 2)) {
              Log.d(TAG, "bubbled through");
              return false;
          }
          return true;
      }
  };
  </code></pre>
  
  <p>to actually display the popupwindow, I call <code>SomePopupWindow.showAtLocation(SomeActivity.getWindow().getDecorView().getRootView(), Gravity.CENTER, 0, 0);</code></p>
  
  <p>Visually represented, here is the product in question</p>
  
  <p><img src="https://i.stack.imgur.com/Z7j3M.png" alt="blah"></p>
  
  <p>The touchListener is responding, but the input does not get sent to the underlying activity OR the popupwindow? (the button is unresponsive, where as if i were to remove the ontouchlistener, the button works fine).</p>
  
  <p><strong>update</strong>
  setting the touch listener to the frameLayout (i.e. content view of popupwindow in this case) instead of the popupwindow itself allows me to click on the buttons defined in the popup.  still looking for way to delegate the touch event to the underlying activity/view</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <p>Register a touch interceptor for the Popupwindow.  If you want the activity to handle it, assuming you have a reference to the activity, call <code>someActivity.dispatchTouchEvent(someMotionEventPassedIntoTheTouchIntercepter);</code>, if you want the popupwindow to handle the touch even, call <code>someView.dispatchTouchEvent(theMotionEventPassedToTouchInterceptor)</code> to the popupwindow's <strong>content view</strong>, as set in the popupwindows <code>setContentView(someView)</code> method.</p>
  
  <p>My method specifically looked like the following</p>
  
  <pre><code>private OnTouchListener onTouchListener = new OnTouchListener() {
  @Override
      public boolean onTouch(View v, MotionEvent event) {
          float x = event.getX();
          float y = event.getY();
  
          if (Math.pow(x - coordinates[0], 2) + Math.pow((y - coordinates[1]), 2) &lt; Math.pow(
                  radius, 2)) {
              activity.get().dispatchTouchEvent(event);
              return false;
          }
          frameLayout.dispatchTouchEvent(event);
          return true;
      }
  };
  </code></pre>