Skip to content

Commit de6cb2b

Browse files
author
yangjian
committed
refactor Particle to ParticleModel
1 parent 0f2b7e9 commit de6cb2b

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

app/src/main/java/com/jian/explosion/animation/ExplosionAnimator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
class ExplosionAnimator extends ValueAnimator {
3434
private static final int DEFAULT_DURATION = 1500;
35-
private Particle[][] mParticles;
35+
private ParticleModel[][] mParticles;
3636
private Paint mPaint;
3737
private View mContainer;
3838

@@ -47,17 +47,17 @@ public ExplosionAnimator(View view, Bitmap bitmap, Rect bound) {
4747
mParticles = generateParticles(bitmap, bound);
4848
}
4949

50-
private Particle[][] generateParticles(Bitmap bitmap, Rect bound) {
50+
private ParticleModel[][] generateParticles(Bitmap bitmap, Rect bound) {
5151
int w = bound.width();
5252
int h = bound.height();
5353

54-
int partW_Count = w / Particle.PART_WH; //横向个数
55-
int partH_Count = h / Particle.PART_WH; //竖向个数
54+
int partW_Count = w / ParticleModel.PART_WH; //横向个数
55+
int partH_Count = h / ParticleModel.PART_WH; //竖向个数
5656

5757
int bitmap_part_w = bitmap.getWidth() / partW_Count;
5858
int bitmap_part_h = bitmap.getHeight() / partH_Count;
5959

60-
Particle[][] particles = new Particle[partH_Count][partW_Count];
60+
ParticleModel[][] particles = new ParticleModel[partH_Count][partW_Count];
6161
Point point = null;
6262
for (int row = 0; row < partH_Count; row++) { //行
6363
for (int column = 0; column < partW_Count; column++) { //列
@@ -66,7 +66,7 @@ private Particle[][] generateParticles(Bitmap bitmap, Rect bound) {
6666

6767
point = new Point(column, row); //x是列,y是行
6868

69-
particles[row][column] = Particle.generateParticle(color, bound, point);
69+
particles[row][column] = ParticleModel.generateParticle(color, bound, point);
7070
}
7171
}
7272

@@ -77,8 +77,8 @@ void draw(Canvas canvas) {
7777
if (!isStarted()) { //动画结束时停止
7878
return;
7979
}
80-
for (Particle[] particle : mParticles) {
81-
for (Particle p : particle) {
80+
for (ParticleModel[] particle : mParticles) {
81+
for (ParticleModel p : particle) {
8282
p.advance((Float) getAnimatedValue());
8383
mPaint.setColor(p.color);
8484
// mPaint.setAlpha((int) (255 * p.alpha)); //只是这样设置,透明色会显示为黑色

app/src/main/java/com/jian/explosion/animation/Particle.java renamed to app/src/main/java/com/jian/explosion/animation/ParticleModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* 作者:Jian
2727
* 时间:2017/12/26.
2828
*/
29-
class Particle {
29+
class ParticleModel {
3030
static final int PART_WH = 8; //默认小球宽高
3131

3232
//原本的值(不可变)
@@ -46,11 +46,11 @@ class Particle {
4646

4747
Rect mBound;
4848

49-
static Particle generateParticle(int color, Rect bound, Point point) {
49+
static ParticleModel generateParticle(int color, Rect bound, Point point) {
5050
int row = point.y; //行是高
5151
int column = point.x; //列是宽
5252

53-
Particle particle = new Particle();
53+
ParticleModel particle = new ParticleModel();
5454
particle.mBound = bound;
5555
particle.color = color;
5656
particle.alpha = 1f;

0 commit comments

Comments
 (0)