设为首页 加入收藏

TOP

Android 实现RippleEffect水波纹效果(四)
2015-11-10 13:45:28 来源: 作者: 【 】 浏览:20
Tags:Android 实现 RippleEffect 波纹 效果
at y) {
? ? ? ? createAnimation(x, y);
? ? }
?
? ? /**
? ? * Create Ripple animation centered at x, y
? ? *
? ? * @param x Horizontal position of the ripple center
? ? * @param y Vertical position of the ripple center
? ? */
? ? private void createAnimation(final float x, final float y) {
? ? ? ? if (this.isEnabled() && !animationRunning) {
? ? ? ? ? ? if (hasToZoom)
? ? ? ? ? ? ? ? this.startAnimation(scaleAnimation);
?
? ? ? ? ? ? radiusMax = Math.max(WIDTH, HEIGHT);
?
? ? ? ? ? ? if (rippleType != 2)
? ? ? ? ? ? ? ? radiusMax /= 2;
?
? ? ? ? ? ? radiusMax -= ripplePadding;
?
? ? ? ? ? ? if (isCentered || rippleType == 1) {
? ? ? ? ? ? ? ? this.x = getMeasuredWidth() / 2;
? ? ? ? ? ? ? ? this.y = getMeasuredHeight() / 2;
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? this.x = x;
? ? ? ? ? ? ? ? this.y = y;
? ? ? ? ? ? }
?
? ? ? ? ? ? animationRunning = true;
?
? ? ? ? ? ? if (rippleType == 1 && originBitmap == null)
? ? ? ? ? ? ? ? originBitmap = getDrawingCache(true);
?
? ? ? ? ? ? invalidate();
? ? ? ? }
? ? }
?
? ? @Override
? ? public boolean onTouchEvent(MotionEvent event) {
? ? ? ? if (gestureDetector.onTouchEvent(event)) {
? ? ? ? ? ? animateRipple(event);
? ? ? ? ? ? sendClickEvent(false);
? ? ? ? }
? ? ? ? return super.onTouchEvent(event);
? ? }
?
? ? @Override
? ? public boolean onInterceptTouchEvent(MotionEvent event) {
? ? ? ? this.onTouchEvent(event);
? ? ? ? return super.onInterceptTouchEvent(event);
? ? }
?
? ? /**
? ? * Send a click event if parent view is a Listview instance
? ? *
? ? * @param isLongClick Is the event a long click ?
? ? */
? ? private void sendClickEvent(final Boolean isLongClick) {
? ? ? ? if (getParent() instanceof AdapterView) {
? ? ? ? ? ? final AdapterView adapterView = (AdapterView) getParent();
? ? ? ? ? ? final int position = adapterView.getPositionForView(this);
? ? ? ? ? ? final long id = adapterView.getItemIdAtPosition(position);
? ? ? ? ? ? if (isLongClick) {
? ? ? ? ? ? ? ? if (adapterView.getOnItemLongClickListener() != null)
? ? ? ? ? ? ? ? ? ? adapterView.getOnItemLongClickListener().onItemLongClick(adapterView, this, position, id);
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? if (adapterView.getOnItemClickListener() != null)
? ? ? ? ? ? ? ? ? ? adapterView.getOnItemClickListener().onItemClick(adapterView, this, position, id);
? ? ? ? ? ? }
? ? ? ? }
? ? }
?
? ? private Bitmap getCircleBitmap(final int radius) {
? ? ? ? final Bitmap output = Bitmap.createBitmap(originBitmap.getWidth(), originBitmap.getHeight(), Bitmap.Config.ARGB_8888);
? ? ? ? final Canvas canvas = new Canvas(output);
? ? ? ? final Paint paint = new Paint();
? ? ? ? final Rect rect = new Rect((int)(x - radius), (int)(y - radius), (int)(x + radius), (int)(y + radius));
?
? ? ? ? paint.setAntiAlias(true);
? ? ? ? canvas.drawARGB(0, 0, 0, 0);
? ? ? ? canvas.drawCircle(x, y, radius, paint);
?
? ? ? ? paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
? ? ? ? canvas.drawBitmap(originBitmap, rect, rect, paint);
?
? ? ? ? return output;
? ? }
?
? ? /**
? ? * Set Ripple color, default is #FFFFFF
? ? *
? ? * @param rippleColor New color resource
? ? */
? ? @ColorRes
? ? public void setRippleColor(int rippleColor) {
? ? ? ? this.rippleColor = getResources().getColor(rippleColor);
? ? }
?
? ? public int getRippleColor() {
? ? ? ? return rippleColor;
? ? }
?
? ? public RippleType getRippleType()
? ? {
? ? ? ? return RippleType.values()[rippleType];
? ? }
?
? ? /**
? ? * Set Ripple type, default is RippleType.SIMPLE
? ? *
? ? * @param rippleType New Ripple type for next animation
? ? */
? ? public void setRippleType(final RippleType rippleType)
? ? {
? ? ? ? this.rippleType = rippleType.ordinal();
? ? }
?
? ? public Boolean isCentered()
? ? {
? ? ? ? return isCentered;
? ? }
?
? ? /**
? ? * Set if ri
首页 上一页 1 2 3 4 5 6 下一页 尾页 4/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux网络编程--信号阻塞与屏蔽(.. 下一篇Android 使用shape制作drawable素..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: