传递onTouch事件窗口管理器

时间:2015-01-22 13:30:37

标签: android android-event

我只需要在按钮上获取onclick事件,但是当用户点击视图(windowManager)时,我想将触摸传递给后面的片段。我的问题是我得到按钮的onclick但我不知道如何将事件传递给后面的视图。有什么建议吗?

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);
    }
}

0 个答案:

没有答案