1

I need to get the onclick event only on the button, but when the user clicks on the view (windowManager), I want to pass the touch to the fragment behind. My problem is that I get the onclick of the button but I don't know how to pass the event to the view behind. Any suggestions?

public class ReconnectionLinkedInOverlayView extends View {

private final Context mContext;
private final ViewGroup mPopupLayout;
private Button refresh;
private WindowManager mWinManager;

public ReconnectionLinkedInOverlayView(Activity activity) {
    super(activity.getApplicationContext());

    mContext = activity.getApplicationContext();

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

    mWinManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);

    LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mPopupLayout = (RelativeLayout) inflater.inflate(R.layout.notification_linkedin_reconnection_card, null);
    mPopupLayout.setVisibility(GONE);

    refresh = (Button) mPopupLayout.findViewById(R.id.notification_linked_in_reconnection_button);
    Typeface face = Typeface.createFromAsset(activity.getAssets(),
            "fonts/OpenSans-Regular.ttf");
    refresh.setTypeface(face);
    refresh.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            hide();
        }
    });

    mPopupLayout.setTouchInterceptor(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.i(TAG, "PopupWindow :: onTouch()");
            return false;
        }
    });


    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;

    mWinManager.addView(mPopupLayout, params);
    mPopupLayout.setVisibility(GONE);


}

/**
 * Shows view
 */
public void show() {
    final Animation in = AnimationUtils.loadAnimation(this.mContext, android.R.anim.fade_in);
    in.setDuration(1000);
    mPopupLayout.setVisibility(VISIBLE);
    mPopupLayout.startAnimation(in);
}

/**
 * Hides view
 */
public void hide() {
    final Animation in = AnimationUtils.loadAnimation(this.mContext, android.R.anim.fade_out);
    in.setDuration(1000);
    if(mPopupLayout != null)
        mWinManager.removeView(mPopupLayout);
    mPopupLayout.setVisibility(GONE);
    }
}
Steve Vinoski
  • 19,847
  • 3
  • 31
  • 46
gadosa
  • 71
  • 2
  • Can you clarify you question by specifing which view and which listener and showing you layout ? Also, to pass a MotioNEvent from one view to other, you can use `View..onTouchEvent()` or return false which will not consume the event – Hugo Gresse Jan 22 '15 at 13:41

0 Answers0