设为首页 加入收藏

TOP

Android 实现RippleEffect水波纹效果(二)
2015-11-10 13:45:28 来源: 作者: 【 】 浏览:8
Tags:Android 实现 RippleEffect 波纹 效果
cale, 1.03f);
? ? ? ? zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200);
? ? ? ? typedArray.recycle();
? ? ? ? paint = new Paint();
? ? ? ? paint.setAntiAlias(true);
? ? ? ? paint.setStyle(Paint.Style.FILL);
? ? ? ? paint.setColor(rippleColor);
? ? ? ? paint.setAlpha(rippleAlpha);
? ? ? ? this.setWillNotDraw(false);
?
? ? ? ? gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
? ? ? ? ? ? @Override
? ? ? ? ? ? public void onLongPress(MotionEvent event) {
? ? ? ? ? ? ? ? super.onLongPress(event);
? ? ? ? ? ? ? ? animateRipple(event);
? ? ? ? ? ? ? ? sendClickEvent(true);
? ? ? ? ? ? }
?
? ? ? ? ? ? @Override
? ? ? ? ? ? public boolean onSingleTapConfirmed(MotionEvent e) {
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
?
? ? ? ? ? ? @Override
? ? ? ? ? ? public boolean onSingleTapUp(MotionEvent e) {
? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? }
? ? ? ? });
?
? ? ? ? this.setDrawingCacheEnabled(true);
? ? ? ? this.setClickable(true);
? ? }
?
? ? @Override
? ? public void draw(Canvas canvas) {
? ? ? ? super.draw(canvas);
? ? ? ? if (animationRunning) {
? ? ? ? ? ? if (rippleDuration <= timer * frameRate) {
? ? ? ? ? ? ? ? animationRunning = false;
? ? ? ? ? ? ? ? timer = 0;
? ? ? ? ? ? ? ? durationEmpty = -1;
? ? ? ? ? ? ? ? timerEmpty = 0;
? ? ? ? ? ? ? ? canvas.restore();
? ? ? ? ? ? ? ? invalidate();
? ? ? ? ? ? ? ? if (onCompletionListener != null) onCompletionListener.onComplete(this);
? ? ? ? ? ? ? ? return;
? ? ? ? ? ? } else
? ? ? ? ? ? ? ? canvasHandler.postDelayed(runnable, frameRate);
?
? ? ? ? ? ? if (timer == 0)
? ? ? ? ? ? ? ? canvas.save();
?
?
? ? ? ? ? ? canvas.drawCircle(x, y, (radiusMax * (((float) timer * frameRate) / rippleDuration)), paint);
?
? ? ? ? ? ? paint.setColor(Color.parseColor("#ffff4444"));
?
? ? ? ? ? ? if (rippleType == 1 && originBitmap != null && (((float) timer * frameRate) / rippleDuration) > 0.4f) {
? ? ? ? ? ? ? ? if (durationEmpty == -1)
? ? ? ? ? ? ? ? ? ? durationEmpty = rippleDuration - timer * frameRate;
?
? ? ? ? ? ? ? ? timerEmpty++;
? ? ? ? ? ? ? ? final Bitmap tmpBitmap = getCircleBitmap((int) ((radiusMax) * (((float) timerEmpty * frameRate) / (durationEmpty))));
? ? ? ? ? ? ? ? canvas.drawBitmap(tmpBitmap, 0, 0, paint);
? ? ? ? ? ? ? ? tmpBitmap.recycle();
? ? ? ? ? ? }
?
? ? ? ? ? ? paint.setColor(rippleColor);
?
? ? ? ? ? ? if (rippleType == 1) {
? ? ? ? ? ? ? ? if ((((float) timer * frameRate) / rippleDuration) > 0.6f)
? ? ? ? ? ? ? ? ? ? paint.setAlpha((int) (rippleAlpha - ((rippleAlpha) * (((float) timerEmpty * frameRate) / (durationEmpty)))));
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? paint.setAlpha(rippleAlpha);
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? ? ? paint.setAlpha((int) (rippleAlpha - ((rippleAlpha) * (((float) timer * frameRate) / rippleDuration))));
?
? ? ? ? ? ? timer++;
? ? ? ? }
? ? }
?
? ? @Override
? ? protected void onSizeChanged(int w, int h, int oldw, int oldh) {
? ? ? ? super.onSizeChanged(w, h, oldw, oldh);
? ? ? ? WIDTH = w;
? ? ? ? HEIGHT = h;
?
? ? ? ? scaleAnimation = new ScaleAnimation(1.0f, zoomScale, 1.0f, zoomScale, w / 2, h / 2);
? ? ? ? scaleAnimation.setDuration(zoomDuration);
? ? ? ? scaleAnimation.setRepeatMode(Animation.REVERSE);
? ? ? ? scaleAnimation.setRepeatCount(1);
? ? }
?
? ? /**
? ? * Launch Ripple animation for the current view with a MotionEvent
? ? *
? ? * @param event MotionEvent registered by the Ripple gesture listener
? ? */
? ? public void animateRipple(MotionEvent event) {
? ? ? ? createAnimation(event.getX(), event.getY());
? ? }
?
? ? /**
? ? * Launch Ripple animation for the current view centered at x and y position
? ? *
? ? * @param x Horizontal position of the ripple center
? ? * @param y Vertical position of the ripple center
? ? */
? ? public void animateRipple(final float x, final flo
首页 上一页 1 2 3 4 5 6 下一页 尾页 2/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Linux网络编程--信号阻塞与屏蔽(.. 下一篇Android 使用shape制作drawable素..

评论

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