下面列出了android.widget.PopupWindow#setTouchInterceptor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void apply(PopupWindow mPopupWindow) {
mPopupWindow.setClippingEnabled(this.mClippEnable);
if(this.mIgnoreCheekPress) {
mPopupWindow.setIgnoreCheekPress();
}
if(this.mInputMode != -1) {
mPopupWindow.setInputMethodMode(this.mInputMode);
}
if(this.mSoftInputMode != -1) {
mPopupWindow.setSoftInputMode(this.mSoftInputMode);
}
if(this.mOnDismissListener != null) {
mPopupWindow.setOnDismissListener(this.mOnDismissListener);
}
if(this.mOnTouchListener != null) {
mPopupWindow.setTouchInterceptor(this.mOnTouchListener);
}
mPopupWindow.setTouchable(this.mTouchable);
}
/**
* 添加一些属性设置
* @param popupWindow
*/
private void apply(PopupWindow popupWindow){
popupWindow.setClippingEnabled(mClippEnable);
if(mIgnoreCheekPress){
popupWindow.setIgnoreCheekPress();
}
if(mInputMode!=-1){
popupWindow.setInputMethodMode(mInputMode);
}
if(mSoftInputMode!=-1){
popupWindow.setSoftInputMode(mSoftInputMode);
}
if(mOnDismissListener!=null){
popupWindow.setOnDismissListener(mOnDismissListener);
}
if(mOnTouchListener!=null){
popupWindow.setTouchInterceptor(mOnTouchListener);
}
popupWindow.setTouchable(mTouchable);
}
/**
* Constructs a {@link TextBubble} instance.
* @param context Context to draw resources from.
* @param rootView The {@link View} to use for size calculations and for display.
* @param stringId The id of the string resource for the text that should be shown.
* @param accessibilityStringId The id of the string resource of the accessibility text.
*/
public TextBubble(Context context, View rootView, @StringRes int stringId,
@StringRes int accessibilityStringId) {
mContext = context;
mRootView = rootView.getRootView();
mStringId = stringId;
mAccessibilityStringId = accessibilityStringId;
mPopupWindow = new PopupWindow(mContext);
mDrawable = new ArrowBubbleDrawable(context);
mHandler = new Handler();
mPopupWindow.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
mPopupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
mPopupWindow.setBackgroundDrawable(mDrawable);
mPopupWindow.setAnimationStyle(R.style.TextBubbleAnimation);
mPopupWindow.setTouchInterceptor(this);
mPopupWindow.setOnDismissListener(mDismissListener);
mMarginPx = context.getResources().getDimensionPixelSize(R.dimen.text_bubble_margin);
// Set predefined styles for the TextBubble.
mDrawable.setBubbleColor(
ApiCompatibilityUtils.getColor(mContext.getResources(), R.color.google_blue_500));
}
/**
* Constructor.
*
* @param context
* Context
*/
public PopupWindows(final Context context) {
mContext = context;
mWindow = new PopupWindow(context);
mWindow.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(final View v, final MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
mWindow.dismiss();
return true;
}
return false;
}
});
mWindowManager = (WindowManager) context
.getSystemService(Context.WINDOW_SERVICE);
}
public static PopupWindow getPopupWindow(View contentView, int width, int height, final View
dimView, final onCloseListener listener)
{
final PopupWindow mPopupWindow = new PopupWindow(contentView, width, height, true);
mPopupWindow.setTouchable(true);
mPopupWindow.setAnimationStyle(R.style.selectPopupWindowAnim);
mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
mPopupWindow.setTouchInterceptor(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_OUTSIDE)
{
mPopupWindow.dismiss();
return true;
}
return false;
}
});
mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener()
{
@Override
public void onDismiss()
{
if (dimView != null)
toggleLight(false, dimView);
if (listener != null)
listener.onClose();
}
});
return mPopupWindow;
}
private void initPop()
{
mPopupWindow = new PopupWindow(mContext);
mPopupWindow.setFocusable(setFocusable());
boolean outsideTouchacle = setOutsideTouchable();
mPopupWindow.setOutsideTouchable(outsideTouchacle);
mPopupWindow.setBackgroundDrawable(new ShapeDrawable());
mPopupWindow.setWidth(setLayoutWidthParams());
mPopupWindow.setHeight(setLayoutHeightParams());
int animStyle = setAnimStyle();
if (animStyle != 0)
mPopupWindow.setAnimationStyle(animStyle);
//设置内容布局
mContentView = mContext.getLayoutInflater().inflate(setContentViewId()
, (ViewGroup) mContext.findViewById(android.R.id.content), false);
mContentView.measure(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
mPopupWindow.setContentView(mContentView);
//设置点击外部关闭pop
if (outsideTouchacle)
mPopupWindow.setTouchInterceptor(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_OUTSIDE)
{
mPopupWindow.dismiss();
return true;
}
return false;
}
});
}
private static void initPopupShow() {
introViewer = new IntroViewer(activity, activity.getResources()
.getString(R.string.intro_start_title), activity.getResources()
.getString(R.string.intro_start_desc));
graph = new TaskGraph();
popup = new PopupWindow(introViewer, LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
popup.setTouchable(false);
popup.setFocusable(true);
popup.setOutsideTouchable(true);
popup.setTouchInterceptor(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
});
activity.getWindow().getDecorView().post(new Runnable() {
@Override
public void run() {
if(popup!=null)
popup.showAtLocation(activity.getWindow().getDecorView()
.getRootView(), Gravity.TOP, 0, 0);
}
});
}