List of usage examples for android.widget PopupWindow setTouchInterceptor
public void setTouchInterceptor(OnTouchListener l)
From source file:org.onebusaway.android.ui.ArrivalsListHeader.java
/** * Sets the popup for the status/*from w w w . j a va2s. co m*/ * * @param index 0 if this is for the top ETA row, 1 if it is for the second * @param color color resource id to use for the popup background * @param statusText text to show in the status popup * @return a new PopupWindow initialized based on the provided parameters */ private PopupWindow setupPopup(final int index, int color, String statusText) { LayoutInflater inflater = LayoutInflater.from(mContext); TextView statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_large, null); statusView.setBackgroundResource(R.drawable.round_corners_style_b_status); GradientDrawable d = (GradientDrawable) statusView.getBackground(); if (color != R.color.stop_info_ontime) { // Show early/late color d.setColor(mResources.getColor(color)); } else { // For on-time, use header default color d.setColor(mResources.getColor(R.color.theme_primary)); } d.setStroke(UIUtils.dpToPixels(mContext, 1), mResources.getColor(R.color.header_text_color)); int pSides = UIUtils.dpToPixels(mContext, 5); int pTopBottom = UIUtils.dpToPixels(mContext, 2); statusView.setPadding(pSides, pTopBottom, pSides, pTopBottom); statusView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); statusView.measure(TextView.MeasureSpec.UNSPECIFIED, TextView.MeasureSpec.UNSPECIFIED); statusView.setText(statusText); PopupWindow p = new PopupWindow(statusView, statusView.getWidth(), statusView.getHeight()); p.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); p.setBackgroundDrawable(new ColorDrawable(mResources.getColor(android.R.color.transparent))); p.setOutsideTouchable(true); p.setTouchInterceptor(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { boolean touchInView; if (index == 0) { touchInView = UIUtils.isTouchInView(mEtaAndMin1, event); } else { touchInView = UIUtils.isTouchInView(mEtaAndMin2, event); } return touchInView; } }); return p; }
From source file:com.quwu.xinwo.release.Release_Activity.java
/** * //w w w .j av a2s . c om * PopupWindow * * */ private void showPopupWindow(View view, final int i) { // View contentView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.release_pop, null); final PopupWindow popupWindow = new PopupWindow(contentView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true); popupWindow.setOnDismissListener(new OnDismissListener() { public void onDismiss() { releaseLin.setAlpha(1f); } }); popupWindow.setTouchable(true); popupWindow.setTouchInterceptor(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return false; // true?touch // ? PopupWindowonTouchEvent?dismiss } }); // ?PopupWindowBackdismiss // APIbug popupWindow.setBackgroundDrawable(getResources().getDrawable(R.drawable.ic_launcher)); // ???show int[] location = new int[2]; view.getLocationOnScreen(location); popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, location[0] + view.getWidth(), location[1] - 150); // TextView year = (TextView) contentView.findViewById(R.id.release_pop_yearText); year.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { handler.sendMessage(handler.obtainMessage(i, "/")); popupWindow.dismiss(); } }); TextView month = (TextView) contentView.findViewById(R.id.release_pop_monthText); month.setOnClickListener(new OnClickListener() { public void onClick(View v) { handler.sendMessage(handler.obtainMessage(i, "/")); popupWindow.dismiss(); } }); TextView day = (TextView) contentView.findViewById(R.id.release_pop_dayText); day.setOnClickListener(new OnClickListener() { public void onClick(View v) { handler.sendMessage(handler.obtainMessage(i, "/")); popupWindow.dismiss(); } }); }