android.view.GestureDetector.SimpleOnGestureListener Java Examples

The following examples show how to use android.view.GestureDetector.SimpleOnGestureListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DragLayout.java    From NewFastFrame with Apache License 2.0 6 votes vote down vote up
public DragLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mGestureDetector = new GestureDetector(context, new SimpleOnGestureListener() {
            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
//                                如果水平方向的偏移量大于竖直方向的偏移量,就消化该事件,
                return Math.abs(distanceX) > Math.abs(distanceY) || super.onScroll(e1, e2, distanceX, distanceY);

            }
        });
//                永远要记得,该工具实现的拖拉是基于控件位置的改变来实现的
        mViewDragHelper = ViewDragHelper.create(this, new DragViewCallBack());
    }
 
Example #2
Source File: ImageFragment.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		context = getContext();

        image = (TouchImageView) view.findViewById(R.id.image);
        videoPlayImage = (ImageView) view.findViewById(R.id.videoPlayImage);
//		minZoom = TouchImageView.SUPER_MIN_MULTIPLIER * image.getMinZoom();
//		maxZoom = TouchImageView.SUPER_MAX_MULTIPLIER * image.getMaxZoom();
//		image.setZoom(curZoom);
        final FragmentActivity activity = getActivity();
		viewPager = (ViewPager) activity.findViewById(R.id.photoViewPager);
		
		mGestureDetector = new GestureDetector(getContext(), new SimpleOnGestureListener() {
				@Override
				public boolean onSingleTapConfirmed(MotionEvent e) {
					Log.d(TAG, "onSingleTapConfirmed " + e + photoFragment);
					if (photoFragment != null) {
						return photoFragment.onSingleTapConfirmed(e);
					}
					return false;//performClick();
				}
			});
        view.setOnTouchListener(onTouch);
		//videoPlayImage.setOnTouchListener(onTouch);
		image.setOnTouchListener(onTouch);
		//rootView.setOnDoubleTapListener(onDoubleTapListener);
		//image.setOnDoubleTapListener(onDoubleTapListener);
		centerInfo = (TextView) view.findViewById(R.id.centerInfo);
		//backgroundImage.setZoom(1.5f);
		//backgroundImage.setMinZoom(1.0f);
		//backgroundImage.setMaxZoom(3.0f);
		//backgroundImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
		//backgroundImage.setZoom(1);

        loadImageToView();
	}
 
Example #3
Source File: MainDragLayout.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
public MainDragLayout(Context context, AttributeSet attrs, int defStyleAttr) {
                super(context, attrs, defStyleAttr);
                mGestureDetector = new GestureDetector(context, new SimpleOnGestureListener() {
                        @Override
                        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
//                                如果水平方向的偏移量大于竖直方向的偏移量,就消化该事件,
                                return Math.abs(distanceX) > Math.abs(distanceY) || super.onScroll(e1, e2, distanceX, distanceY);

                        }
                });
//                永远要记得,该工具实现的拖拉是基于控件位置的改变来实现的
                mViewDragHelper = ViewDragHelper.create(this, new DragViewCallBack());
        }
 
Example #4
Source File: DragLayout.java    From TestChat with Apache License 2.0 5 votes vote down vote up
public DragLayout(Context context, AttributeSet attrs, int defStyleAttr) {
                super(context, attrs, defStyleAttr);
                mGestureDetector = new GestureDetector(context, new SimpleOnGestureListener() {
                        @Override
                        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
//                                如果水平方向的偏移量大于竖直方向的偏移量,就消化该事件,
                                return Math.abs(distanceX) > Math.abs(distanceY) || super.onScroll(e1, e2, distanceX, distanceY);

                        }
                });
//                永远要记得,该工具实现的拖拉是基于控件位置的改变来实现的
                mViewDragHelper = ViewDragHelper.create(this, new DragViewCallBack());
        }
 
Example #5
Source File: ZoomImageView.java    From TestChat with Apache License 2.0 5 votes vote down vote up
public ZoomImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        super.setScaleType(ScaleType.MATRIX);
        mGestureDetector = new GestureDetector(context,
                new SimpleOnGestureListener() {
                        @Override
                        public boolean onDoubleTap(MotionEvent e) {
                                if (isAutoScale)
                                        return true;

                                float x = e.getX();
                                float y = e.getY();
                                Log.e("DoubleTap", getScale() + " , " + initScale);
                                if (getScale() < SCALE_MID) {
                                        ZoomImageView.this.postDelayed(
                                                new AutoScaleRunnable(SCALE_MID, x, y), 16);
                                        isAutoScale = true;
                                } else if (getScale() >= SCALE_MID
                                        && getScale() < SCALE_MAX) {
                                        ZoomImageView.this.postDelayed(
                                                new AutoScaleRunnable(SCALE_MAX, x, y), 16);
                                        isAutoScale = true;
                                } else {
                                        ZoomImageView.this.postDelayed(
                                                new AutoScaleRunnable(initScale, x, y), 16);
                                        isAutoScale = true;
                                }

                                return true;
                        }
                });
        mScaleGestureDetector = new ScaleGestureDetector(context, this);
        this.setOnTouchListener(this);
}
 
Example #6
Source File: ClipZoomImageView.java    From Android with MIT License 5 votes vote down vote up
public ClipZoomImageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    setScaleType(ScaleType.MATRIX);
    mGestureDetector = new GestureDetector(context,
            new SimpleOnGestureListener() {
                @Override
                public boolean onDoubleTap(MotionEvent e) {
                    if (isAutoScale)
                        return true;

                    float x = e.getX();
                    float y = e.getY();
                    if (getScale() < SCALE_MID) {
                        ClipZoomImageView.this.postDelayed(
                                new AutoScaleRunnable(SCALE_MID, x, y), 16);
                        isAutoScale = true;
                    } else {
                        ClipZoomImageView.this.postDelayed(
                                new AutoScaleRunnable(initScale, x, y), 16);
                        isAutoScale = true;
                    }

                    return true;
                }
            });
    mScaleGestureDetector = new ScaleGestureDetector(context, this);
    this.setOnTouchListener(this);
}
 
Example #7
Source File: PZSImageView.java    From Yahala-Messenger with MIT License 5 votes vote down vote up
private void init() {
     // should use matrix scale type.
     setScaleType(ScaleType.MATRIX);
     Matrix mat = getImageMatrix();
     mat.reset();
     setImageMatrix(mat);

     gd = new GestureDetector(mContext, new SimpleOnGestureListener() {

/*@Override
         public boolean onDoubleTap(MotionEvent event) {
	int action = parseDoubleTapMotionEvent(event);
	touchAction(action, event);
	return true; // indicate event was handled
}*/

         @Override
         public boolean onSingleTapConfirmed(MotionEvent ev) {
             ((AbstractGalleryActivity) mContext).topBtn();
             return true;
         }

     });

     videoText = new TextView(getContext());
     videoText.setText(getResources().getString(R.string.NoResult));
     videoText.setTextColor(0xffffffff);
     videoText.setBackgroundColor(0x66000000);
     videoText.setGravity(Gravity.CENTER);
     videoText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24);
     videoText.setText(getResources().getString(R.string.NoChats));
     videoText.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT));
 }
 
Example #8
Source File: ClipZoomImageView.java    From umeng_community_android with MIT License 5 votes vote down vote up
public ClipZoomImageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    setScaleType(ScaleType.MATRIX);
    mGestureDetector = new GestureDetector(context,
            new SimpleOnGestureListener() {
                @Override
                public boolean onDoubleTap(MotionEvent e) {
                    if (isAutoScale == true)
                        return true;

                    float x = e.getX();
                    float y = e.getY();
                    if (getScale() < SCALE_MID) {
                        ClipZoomImageView.this.postDelayed(
                                new AutoScaleRunnable(SCALE_MID, x, y), 16);
                        isAutoScale = true;
                    } else {
                        ClipZoomImageView.this.postDelayed(
                                new AutoScaleRunnable(initScale, x, y), 16);
                        isAutoScale = true;
                    }

                    return true;
                }
            });
    mScaleGestureDetector = new ScaleGestureDetector(context, this);
    setOnTouchListener(this);
}
 
Example #9
Source File: SwipeMenuLayout.java    From SwipeMenuAndRefresh with Apache License 2.0 4 votes vote down vote up
private void init() {
	setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.WRAP_CONTENT));
	mGestureListener = new SimpleOnGestureListener() {
		@Override
		public boolean onDown(MotionEvent e) {
			isFling = false;
			return true;
		}

		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2,
							   float velocityX, float velocityY) {
			// TODO
			if (Math.abs(e1.getX() - e2.getX()) > MIN_FLING
					&& velocityX < MAX_VELOCITYX) {
				isFling = true;
			}
			// Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX);
			return super.onFling(e1, e2, velocityX, velocityY);
		}
	};
	mGestureDetector = new GestureDetectorCompat(getContext(),
			mGestureListener);

	// mScroller = ScrollerCompat.create(getContext(), new
	// BounceInterpolator());
	if (mCloseInterpolator != null) {
		mCloseScroller = ScrollerCompat.create(getContext(),
				mCloseInterpolator);
	} else {
		mCloseScroller = ScrollerCompat.create(getContext());
	}
	if (mOpenInterpolator != null) {
		mOpenScroller = ScrollerCompat.create(getContext(),
				mOpenInterpolator);
	} else {
		mOpenScroller = ScrollerCompat.create(getContext());
	}

	LayoutParams contentParams = new LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	mContentView.setLayoutParams(contentParams);
	if (mContentView.getId() < 1) {
		mContentView.setId(CONTENT_VIEW_ID);
	}

	mMenuView.setId(MENU_VIEW_ID);
	mMenuView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
			mContentView.getHeight()));

	addView(mContentView);
	addView(mMenuView);

	// if (mContentView.getBackground() == null) {
	// mContentView.setBackgroundColor(Color.WHITE);
	// }

	// in android 2.x, MenuView height is MATCH_PARENT is not work.
	// getViewTreeObserver().addOnGlobalLayoutListener(
	// new OnGlobalLayoutListener() {
	// @Override
	// public void onGlobalLayout() {
	// setMenuHeight(mContentView.getHeight());
	// // getViewTreeObserver()
	// // .removeGlobalOnLayoutListener(this);
	// }
	// });

}
 
Example #10
Source File: SwipeMenuLayout.java    From SwipeMenuListView with MIT License 4 votes vote down vote up
private void init() {
	setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.WRAP_CONTENT));
	mGestureListener = new SimpleOnGestureListener() {
		@Override
		public boolean onDown(MotionEvent e) {
			isFling = false;
			return true;
		}

		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2,
				float velocityX, float velocityY) {
			// TODO
			if (Math.abs(e1.getX() - e2.getX()) > MIN_FLING
					&& velocityX < MAX_VELOCITYX) {
				isFling = true;
			}
			// Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX);
			return super.onFling(e1, e2, velocityX, velocityY);
		}
	};
	mGestureDetector = new GestureDetectorCompat(getContext(),
			mGestureListener);

	// mScroller = ScrollerCompat.create(getContext(), new
	// BounceInterpolator());
	if (mCloseInterpolator != null) {
		mCloseScroller = ScrollerCompat.create(getContext(),
				mCloseInterpolator);
	} else {
		mCloseScroller = ScrollerCompat.create(getContext());
	}
	if (mOpenInterpolator != null) {
		mOpenScroller = ScrollerCompat.create(getContext(),
				mOpenInterpolator);
	} else {
		mOpenScroller = ScrollerCompat.create(getContext());
	}

	LayoutParams contentParams = new LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	mContentView.setLayoutParams(contentParams);
	if (mContentView.getId() < 1) {
		mContentView.setId(CONTENT_VIEW_ID);
	}

	mMenuView.setId(MENU_VIEW_ID);
	mMenuView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
			LayoutParams.WRAP_CONTENT));

	addView(mContentView);
	addView(mMenuView);

	// if (mContentView.getBackground() == null) {
	// mContentView.setBackgroundColor(Color.WHITE);
	// }

	// in android 2.x, MenuView height is MATCH_PARENT is not work.
	// getViewTreeObserver().addOnGlobalLayoutListener(
	// new OnGlobalLayoutListener() {
	// @Override
	// public void onGlobalLayout() {
	// setMenuHeight(mContentView.getHeight());
	// // getViewTreeObserver()
	// // .removeGlobalOnLayoutListener(this);
	// }
	// });

}
 
Example #11
Source File: SwipeMenuLayout.java    From Android-PullToRefresh-SwipeMenuListView-Sample with MIT License 4 votes vote down vote up
private void init() {
    setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    mGestureListener = new SimpleOnGestureListener() {
        @Override
        public boolean onDown(MotionEvent e) {
            isFling = false;
            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            // TODO
            if ((e1.getX() - e2.getX()) > MIN_FLING && velocityX < MAX_VELOCITYX) {
                isFling = true;
            }
            // Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX);
            return super.onFling(e1, e2, velocityX, velocityY);
        }
    };
    mGestureDetector = new GestureDetectorCompat(getContext(), mGestureListener);

    if (mCloseInterpolator != null) {
        mCloseScroller = ScrollerCompat.create(getContext(), mCloseInterpolator);
    } else {
        mCloseScroller = ScrollerCompat.create(getContext());
    }
    if (mOpenInterpolator != null) {
        mOpenScroller = ScrollerCompat.create(getContext(), mOpenInterpolator);
    } else {
        mOpenScroller = ScrollerCompat.create(getContext());
    }

    LayoutParams contentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    mContentView.setLayoutParams(contentParams);
    if (mContentView.getId() < 1) {
        mContentView.setId(CONTENT_VIEW_ID);
    }

    mMenuView.setId(MENU_VIEW_ID);
    mMenuView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    addView(mContentView);
    addView(mMenuView);

}
 
Example #12
Source File: SwipeMenuLayout.java    From android-common-utils with Apache License 2.0 4 votes vote down vote up
private void init() {
    setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    mGestureListener = new SimpleOnGestureListener() {
        @Override
        public boolean onDown(MotionEvent e) {
            isFling = false;
            return true;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            // TODO
            if ((e1.getX() - e2.getX()) > MIN_FLING && velocityX < MAX_VELOCITYX) {
                isFling = true;
            }
            // Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX);
            return super.onFling(e1, e2, velocityX, velocityY);
        }
    };
    mGestureDetector = new GestureDetectorCompat(getContext(), mGestureListener);

    if (mCloseInterpolator != null) {
        mCloseScroller = ScrollerCompat.create(getContext(), mCloseInterpolator);
    } else {
        mCloseScroller = ScrollerCompat.create(getContext());
    }
    if (mOpenInterpolator != null) {
        mOpenScroller = ScrollerCompat.create(getContext(), mOpenInterpolator);
    } else {
        mOpenScroller = ScrollerCompat.create(getContext());
    }

    LayoutParams contentParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    mContentView.setLayoutParams(contentParams);
    if (mContentView.getId() < 1) {
        mContentView.setId(R.id.heaven7_pulltofresh_swipe_content_view);
    }

    mMenuView.setId(R.id.heaven7_pulltofresh_swipe_menu_view);
    mMenuView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    addView(mContentView);
    addView(mMenuView);

}
 
Example #13
Source File: SwipeMenuLayout.java    From android2048 with Apache License 2.0 4 votes vote down vote up
private void init() {
	setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.WRAP_CONTENT));
	mGestureListener = new SimpleOnGestureListener() {
		@Override
		public boolean onDown(MotionEvent e) {
			isFling = false;
			return true;
		}

		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2,
				float velocityX, float velocityY) {
			// TODO
			if ((e1.getX() - e2.getX()) > MIN_FLING
					&& velocityX < MAX_VELOCITYX) {
				isFling = true;
			}
			// Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX);
			return super.onFling(e1, e2, velocityX, velocityY);
		}
	};
	mGestureDetector = new GestureDetectorCompat(getContext(),
			mGestureListener);

	// mScroller = ScrollerCompat.create(getContext(), new
	// BounceInterpolator());
	if (mCloseInterpolator != null) {
		mCloseScroller = ScrollerCompat.create(getContext(),
				mCloseInterpolator);
	} else {
		mCloseScroller = ScrollerCompat.create(getContext());
	}
	if (mOpenInterpolator != null) {
		mOpenScroller = ScrollerCompat.create(getContext(),
				mOpenInterpolator);
	} else {
		mOpenScroller = ScrollerCompat.create(getContext());
	}

	LayoutParams contentParams = new LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	mContentView.setLayoutParams(contentParams);
	if (mContentView.getId() < 1) {
		mContentView.setId(CONTENT_VIEW_ID);
	}

	mMenuView.setId(MENU_VIEW_ID);
	mMenuView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
			LayoutParams.WRAP_CONTENT));

	addView(mContentView);
	addView(mMenuView);

	// if (mContentView.getBackground() == null) {
	// mContentView.setBackgroundColor(Color.WHITE);
	// }

	// in android 2.x, MenuView height is MATCH_PARENT is not work.
	// getViewTreeObserver().addOnGlobalLayoutListener(
	// new OnGlobalLayoutListener() {
	// @Override
	// public void onGlobalLayout() {
	// setMenuHeight(mContentView.getHeight());
	// // getViewTreeObserver()
	// // .removeGlobalOnLayoutListener(this);
	// }
	// });

}
 
Example #14
Source File: ZoomImageView.java    From HHComicViewer with Apache License 2.0 4 votes vote down vote up
public ZoomImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    super.setScaleType(ScaleType.MATRIX);
    mGestureDetector = new GestureDetector(context,
            new SimpleOnGestureListener() {

                @Override
                public boolean onSingleTapConfirmed(MotionEvent event) {
                    //单击屏幕中心开启菜单功能
                    //如果没有设置listener则直接略过
                    if (onCenterTapListener == null && onLeftOrRightTapListener == null) {
                        return false;
                    }

                    float x_up, y_up;
                    x_up = event.getX();
                    y_up = event.getY();
                    if (onCenterTapListener.isOpen()) {
                        onCenterTapListener.closeMenu();
                        return true;
                    }
                    if (event.getPointerCount() == 1) {
                        if (onCenterTapListener != null &&
                                (x_up > (getWidth() / 3)) && (x_up < (getWidth() / 3 * 2))) {
                            if ((y_up > (getHeight() / 3))) {
                                //当短按屏幕中心下方时,开启menu
                                if (!onCenterTapListener.isOpen()) {
                                    onCenterTapListener.openMenu();
                                    return true;
                                }
                            }
                        } else if (onLeftOrRightTapListener != null && x_up < (getWidth() / 3)) {
                            //当短按屏幕左边时,显示前一页
                            onLeftOrRightTapListener.leftTap();
                        } else if (onLeftOrRightTapListener != null && x_up > (getWidth() / 3 * 2)) {
                            //当短按屏幕右边时,显示后一页
                            onLeftOrRightTapListener.rightTap();
                        }
                    }
                    return false;
                }

                @Override
                public boolean onDoubleTap(MotionEvent e) {
                    if (isAutoScale) {
                        return true;
                    }

                    float x = e.getX();
                    float y = e.getY();
                    Log.i("DoubleTap", getScale() + " , " + initScale);
                    if (getScale() < midScale) {
                        ZoomImageView.this.postDelayed(
                                new AutoScaleRunnable(midScale, x, y), 16);
                        isAutoScale = true;
                    }
                    //禁止其二次放大
                    /** else if (getScale() >= SCALE_MID
                     && getScale() < SCALE_MAX)
                     {
                     ZoomImageView.this.postDelayed(
                     new AutoScaleRunnable(SCALE_MAX, x, y), 16);
                     isAutoScale = true;
                     }**/
                    else {
                        ZoomImageView.this.postDelayed(
                                new AutoScaleRunnable(initScale, x, y), 16);
                        isAutoScale = true;
                    }

                    return true;
                }
            });
    mScaleGestureDetector = new ScaleGestureDetector(context, this);
    this.setOnTouchListener(this);
}
 
Example #15
Source File: SwipeMenuLayout.java    From MapForTour with MIT License 4 votes vote down vote up
private void init() {
	setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.WRAP_CONTENT));
	mGestureListener = new SimpleOnGestureListener() {
		@Override
		public boolean onDown(MotionEvent e) {
			isFling = false;
			return true;
		}

		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2,
				float velocityX, float velocityY) {
			// TODO
			if (Math.abs(e1.getX() - e2.getX()) > MIN_FLING
					&& velocityX < MAX_VELOCITYX) {
				isFling = true;
			}
			// Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX);
			return super.onFling(e1, e2, velocityX, velocityY);
		}
	};
	mGestureDetector = new GestureDetectorCompat(getContext(),
			mGestureListener);

	// mScroller = ScrollerCompat.create(getContext(), new
	// BounceInterpolator());
	if (mCloseInterpolator != null) {
		mCloseScroller = ScrollerCompat.create(getContext(),
				mCloseInterpolator);
	} else {
		mCloseScroller = ScrollerCompat.create(getContext());
	}
	if (mOpenInterpolator != null) {
		mOpenScroller = ScrollerCompat.create(getContext(),
				mOpenInterpolator);
	} else {
		mOpenScroller = ScrollerCompat.create(getContext());
	}

	LayoutParams contentParams = new LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	mContentView.setLayoutParams(contentParams);
	if (mContentView.getId() < 1) {
		mContentView.setId(CONTENT_VIEW_ID);
	}

	mMenuView.setId(MENU_VIEW_ID);
	mMenuView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
			LayoutParams.WRAP_CONTENT));

	addView(mContentView);
	addView(mMenuView);

	// if (mContentView.getBackground() == null) {
	// mContentView.setBackgroundColor(Color.WHITE);
	// }

	// in android 2.x, MenuView height is MATCH_PARENT is not work.
	// getViewTreeObserver().addOnGlobalLayoutListener(
	// new OnGlobalLayoutListener() {
	// @Override
	// public void onGlobalLayout() {
	// setMenuHeight(mContentView.getHeight());
	// // getViewTreeObserver()
	// // .removeGlobalOnLayoutListener(this);
	// }
	// });

}
 
Example #16
Source File: SwipeMenuLayout.java    From HPlayer with Apache License 2.0 4 votes vote down vote up
private void init() {
	setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT,
			LayoutParams.WRAP_CONTENT));
	mGestureListener = new SimpleOnGestureListener() {
		@Override
		public boolean onDown(MotionEvent e) {
			isFling = false;
			return true;
		}

		@Override
		public boolean onFling(MotionEvent e1, MotionEvent e2,
				float velocityX, float velocityY) {
			// TODO
			if (Math.abs(e1.getX() - e2.getX()) > MIN_FLING
					&& velocityX < MAX_VELOCITYX) {
				isFling = true;
			}
			// Log.i("byz", MAX_VELOCITYX + ", velocityX = " + velocityX);
			return super.onFling(e1, e2, velocityX, velocityY);
		}
	};
	mGestureDetector = new GestureDetectorCompat(getContext(),
			mGestureListener);

	// mScroller = ScrollerCompat.create(getContext(), new
	// BounceInterpolator());
	if (mCloseInterpolator != null) {
		mCloseScroller = ScrollerCompat.create(getContext(),
				mCloseInterpolator);
	} else {
		mCloseScroller = ScrollerCompat.create(getContext());
	}
	if (mOpenInterpolator != null) {
		mOpenScroller = ScrollerCompat.create(getContext(),
				mOpenInterpolator);
	} else {
		mOpenScroller = ScrollerCompat.create(getContext());
	}

	LayoutParams contentParams = new LayoutParams(
			LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
	mContentView.setLayoutParams(contentParams);
	if (mContentView.getId() < 1) {
		mContentView.setId(CONTENT_VIEW_ID);
	}

	mMenuView.setId(MENU_VIEW_ID);
	mMenuView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
			LayoutParams.WRAP_CONTENT));

	addView(mContentView);
	addView(mMenuView);

	// if (mContentView.getBackground() == null) {
	// mContentView.setBackgroundColor(Color.WHITE);
	// }

	// in android 2.x, MenuView height is MATCH_PARENT is not work.
	// getViewTreeObserver().addOnGlobalLayoutListener(
	// new OnGlobalLayoutListener() {
	// @Override
	// public void onGlobalLayout() {
	// setMenuHeight(mContentView.getHeight());
	// // getViewTreeObserver()
	// // .removeGlobalOnLayoutListener(this);
	// }
	// });

}
 
Example #17
Source File: ClipImageView.java    From Tok-Android with GNU General Public License v3.0 4 votes vote down vote up
public ClipImageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    setScaleType(ScaleType.MATRIX);
    mGestureDetector = new GestureDetector(context, new SimpleOnGestureListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (isAutoScale) return true;

            float x = e.getX();
            float y = e.getY();
            if (getScale() < mScaleMin) {
                ClipImageView.this.postDelayed(new AutoScaleRunnable(mScaleMin, x, y), 16);
            } else {
                ClipImageView.this.postDelayed(new AutoScaleRunnable(mInitScale, x, y), 16);
            }
            isAutoScale = true;

            return true;
        }
    });
    mScaleGestureDetector = new ScaleGestureDetector(context, this);
    this.setOnTouchListener(this);

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(Color.WHITE);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ClipImageView);
    mAspectX = ta.getInteger(R.styleable.ClipImageView_civWidth, 1);
    mAspectY = ta.getInteger(R.styleable.ClipImageView_civHeight, 1);
    mClipPadding = ta.getDimensionPixelSize(R.styleable.ClipImageView_civClipPadding, 0);
    mTipText = ta.getString(R.styleable.ClipImageView_civTipText);
    mMaskColor = ta.getColor(R.styleable.ClipImageView_civMaskColor, 0xB2000000);
    mDrawCircleFlag = ta.getBoolean(R.styleable.ClipImageView_civClipCircle, false);
    mRoundCorner = ta.getDimension(R.styleable.ClipImageView_civClipRoundCorner, 0);
    final int textSize = ta.getDimensionPixelSize(R.styleable.ClipImageView_civTipTextSize, 24);
    mPaint.setTextSize(textSize);
    ta.recycle();

    mPaint.setDither(true);
}
 
Example #18
Source File: ClipImageView.java    From clip-image with Apache License 2.0 4 votes vote down vote up
public ClipImageView(Context context, AttributeSet attrs) {
    super(context, attrs);

    setScaleType(ScaleType.MATRIX);
    mGestureDetector = new GestureDetector(context,
            new SimpleOnGestureListener() {
                @Override
                public boolean onDoubleTap(MotionEvent e) {
                    if (isAutoScale)
                        return true;

                    float x = e.getX();
                    float y = e.getY();
                    if (getScale() < mScaleMin) {
                        ClipImageView.this.postDelayed(new AutoScaleRunnable(mScaleMin, x, y), 16);
                    } else {
                        ClipImageView.this.postDelayed(new AutoScaleRunnable(mInitScale, x, y), 16);
                    }
                    isAutoScale = true;

                    return true;
                }
            });
    mScaleGestureDetector = new ScaleGestureDetector(context, this);
    this.setOnTouchListener(this);

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaint.setColor(Color.WHITE);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ClipImageView);
    mAspectX = ta.getInteger(R.styleable.ClipImageView_civWidth, 1);
    mAspectY = ta.getInteger(R.styleable.ClipImageView_civHeight, 1);
    mClipPadding = ta.getDimensionPixelSize(R.styleable.ClipImageView_civClipPadding, 0);
    mTipText = ta.getString(R.styleable.ClipImageView_civTipText);
    mMaskColor = ta.getColor(R.styleable.ClipImageView_civMaskColor, 0xB2000000);
    mDrawCircleFlag = ta.getBoolean(R.styleable.ClipImageView_civClipCircle, false);
    mRoundCorner = ta.getDimension(R.styleable.ClipImageView_civClipRoundCorner, 0);
    final int textSize = ta.getDimensionPixelSize(R.styleable.ClipImageView_civTipTextSize, 24);
    mPaint.setTextSize(textSize);
    ta.recycle();

    mPaint.setDither(true);
}
 
Example #19
Source File: GestureRouter.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
GestureRouter() {
    this((T) new SimpleOnGestureListener());
}