|
1 | 1 | package com.allen.androidcustomview.widget; |
2 | 2 |
|
3 | 3 |
|
4 | | -import android.animation.AnimatorSet; |
5 | | -import android.animation.FloatEvaluator; |
6 | 4 | import android.animation.ValueAnimator; |
7 | 5 | import android.annotation.SuppressLint; |
8 | 6 | import android.content.Context; |
|
19 | 17 | import android.util.Log; |
20 | 18 | import android.view.MotionEvent; |
21 | 19 | import android.view.View; |
22 | | -import android.view.animation.AccelerateInterpolator; |
23 | | -import android.view.animation.DecelerateInterpolator; |
24 | 20 | import android.view.animation.LinearInterpolator; |
25 | 21 |
|
26 | 22 | import com.allen.androidcustomview.R; |
@@ -140,7 +136,7 @@ private void initTextPaint() { |
140 | 136 | private boolean isSmall; |
141 | 137 | public void setSmall() { |
142 | 138 | initBaseSize(); |
143 | | - isSmall = true; |
| 139 | + isSmall = false; |
144 | 140 |
|
145 | 141 | BitmapFactory.Options options = new BitmapFactory.Options(); |
146 | 142 | options.inPreferredConfig = Bitmap.Config.RGB_565; |
@@ -170,10 +166,14 @@ public void setSmall() { |
170 | 166 | angle = random.nextInt(57) - 28; |
171 | 167 | awardNum = random.nextInt(6); |
172 | 168 | angle = 360 + awardNum * 60 + angle; |
173 | | - float spend = new BigDecimal(angle).divide(new BigDecimal(360), 2, BigDecimal.ROUND_UP).floatValue(); |
| 169 | + float spend = new BigDecimal(angle) |
| 170 | + .divide(new BigDecimal(360), 2, RoundingMode.UP).floatValue(); |
174 | 171 | float time = spend + 1 + 2.5f; |
175 | | - a = new BigDecimal(360).divide(new BigDecimal(spend), 2, BigDecimal.ROUND_UP).floatValue(); |
176 | | - Log.d("xijingLog", "time="+time+" "+awardNum); |
| 172 | + bigWheelAccent = new BigDecimal(360) |
| 173 | + .divide(new BigDecimal(spend), 2, RoundingMode.UP).floatValue(); |
| 174 | + Log.d("xijingLog", "time="+time+" awardNum="+awardNum+" angle="+angle+" t="+spend); |
| 175 | + smallWheelSpeed = new BigDecimal(3*360) |
| 176 | + .divide(new BigDecimal(time - 1), 2, RoundingMode.UP).floatValue(); |
177 | 177 | anim.setFloatValues(0, time); |
178 | 178 | anim.setDuration((long) (time * 1000)); |
179 | 179 |
|
@@ -351,30 +351,29 @@ private void initAnim() { |
351 | 351 | @Override |
352 | 352 | public void onAnimationUpdate(ValueAnimator animation) { |
353 | 353 | float t = (float) animation.getAnimatedValue(); |
| 354 | + if(t >= 1){ |
| 355 | + angleIn = (int) (smallWheelSpeed * (t - 1)) % 360; |
| 356 | + } |
| 357 | +// Log.e("xijingLog", "angleIn="+angleIn+" t="+t); |
| 358 | + |
354 | 359 | if(t <= 1) { |
355 | 360 | t = (float)Math.pow(t, 2); |
356 | 361 | angleOut = (int) (t * 360)/2; |
357 | | -// Log.d("xijingLog", "111 angleOut ="+angleOut +" t="+t +" In="+angleIn); |
358 | | - } else if(t <= 3.5f) { |
359 | | - //360 / 1 * t |
| 362 | + } else if(t < 3.5f) { |
360 | 363 | angleOut = (int) ((t - 1) * 360 + 180); |
361 | | -// Log.d("xijingLog", "222 angleOut ="+angleOut +" t="+t +" In="+angleIn); |
362 | 364 | } else { |
363 | 365 | t = (t - 3.5f); |
364 | | -// float v = (float) (1.0f - Math.pow((1.0f - t), 2 * 2)); |
365 | | -// float v = 360 - 360*t; |
366 | | - angleOut = (int) (360 * t - (a * Math.pow(t, 2))/2); |
367 | | -// Log.e("xijingLog", "t="+t+" v="+v); |
368 | | -// angleOut = (int) (v * 360 * t); |
369 | | -// Log.d("xijingLog", "333 angleOut ="+angleOut +" t="+t +" In="+angleIn); |
| 366 | + angleOut = (int) (360 * t - bigWheelAccent * Math.sqrt(t)/2); |
| 367 | + Log.e("xijingLog", "angleOut="+angleOut+" t="+t); |
370 | 368 | } |
371 | 369 |
|
372 | 370 | angleOut %= 360; |
373 | 371 | invalidate(); |
374 | 372 | } |
375 | 373 | }); |
376 | 374 | } |
377 | | - float a; |
| 375 | + float bigWheelAccent;//加速度 |
| 376 | + float smallWheelSpeed;//小圆的速度 |
378 | 377 |
|
379 | 378 | private RectF rectFTouch; |
380 | 379 | private short downIndex; |
|