@@ -76,7 +76,7 @@ public ChessBoard(Context context, AttributeSet attrs) {
76
76
blackPiecePaint = new Paint ();
77
77
blackPiecePaint .setAntiAlias (true );
78
78
79
- moveMarkPaint = new ArrayList <Paint >();
79
+ moveMarkPaint = new ArrayList <>();
80
80
for (int i = 0 ; i < 6 ; i ++) {
81
81
Paint p = new Paint ();
82
82
p .setStyle (Paint .Style .FILL );
@@ -120,25 +120,23 @@ final class AnimInfo {
120
120
int piece1 , from1 , to1 , hide1 ;
121
121
int piece2 , from2 , to2 , hide2 ;
122
122
123
- public final boolean updateState () {
123
+ final boolean updateState () {
124
124
now = System .currentTimeMillis ();
125
125
return animActive ();
126
126
}
127
127
128
- private final boolean animActive () {
129
- if (paused || (startTime < 0 ) || (now >= stopTime )
130
- || (posHash != pos .zobristHash ()))
131
- return false ;
132
- return true ;
128
+ private boolean animActive () {
129
+ return !paused && (startTime >= 0 ) && (now < stopTime )
130
+ && (posHash == pos .zobristHash ());
133
131
}
134
132
135
- public final boolean squareHidden (int sq ) {
133
+ final boolean squareHidden (int sq ) {
136
134
if (!animActive ())
137
135
return false ;
138
136
return (sq == hide1 ) || (sq == hide2 );
139
137
}
140
138
141
- public final void draw (Canvas canvas ) {
139
+ final void draw (Canvas canvas ) {
142
140
if (!animActive ())
143
141
return ;
144
142
double animState = (now - startTime )
@@ -162,13 +160,13 @@ private void drawAnimPiece(Canvas canvas, int piece, int from, int to,
162
160
double animState ) {
163
161
if (piece == Piece .EMPTY )
164
162
return ;
165
- final int xCrd1 = getXCrd (Position .getX (from ));
166
- final int yCrd1 = getYCrd (Position .getY (from ));
167
- final int xCrd2 = getXCrd (Position .getX (to ));
168
- final int yCrd2 = getYCrd (Position .getY (to ));
169
- final int xCrd = xCrd1
163
+ int xCrd1 = getXCrd (Position .getX (from ));
164
+ int yCrd1 = getYCrd (Position .getY (from ));
165
+ int xCrd2 = getXCrd (Position .getX (to ));
166
+ int yCrd2 = getYCrd (Position .getY (to ));
167
+ int xCrd = xCrd1
170
168
+ (int ) Math .round ((xCrd2 - xCrd1 ) * animState );
171
- final int yCrd = yCrd1
169
+ int yCrd = yCrd1
172
170
+ (int ) Math .round ((yCrd2 - yCrd1 ) * animState );
173
171
drawPiece (canvas , xCrd , yCrd , piece );
174
172
}
@@ -269,21 +267,16 @@ public void setAnimMove(Position sourcePos, Move move, boolean forward, double s
269
267
/**
270
268
* Set the board to a given state.
271
269
*
272
- * @param pos
270
+ * @param pos the position to set
273
271
*/
274
272
final public void setPosition (Position pos ) {
275
- boolean doInvalidate = false ;
276
273
if (anim .paused = true ) {
277
274
anim .paused = false ;
278
- doInvalidate = true ;
279
275
}
280
276
if (!this .pos .equals (pos )) {
281
277
this .pos = new Position (pos );
282
- doInvalidate = true ;
283
- }
284
- if (doInvalidate ) {
285
- invalidate ();
286
278
}
279
+ invalidate ();
287
280
}
288
281
289
282
/**
@@ -370,16 +363,16 @@ protected void onDraw(Canvas canvas) {
370
363
if (isInEditMode ())
371
364
return ;
372
365
boolean animActive = anim .updateState ();
373
- final int width = getWidth ();
374
- final int height = getHeight ();
366
+ int width = getWidth ();
367
+ int height = getHeight ();
375
368
sqSize = Math .min (getSqSizeW (width ), getSqSizeH (height ));
376
369
blackPiecePaint .setTextSize (sqSize );
377
370
whitePiecePaint .setTextSize (sqSize );
378
371
computeOrigin (width , height );
379
372
for (int x = 0 ; x < 8 ; x ++) {
380
373
for (int y = 0 ; y < 8 ; y ++) {
381
- final int xCrd = getXCrd (x );
382
- final int yCrd = getYCrd (y );
374
+ int xCrd = getXCrd (x );
375
+ int yCrd = getYCrd (y );
383
376
Paint paint = Position .darkSquare (x , y ) ? darkPaint
384
377
: brightPaint ;
385
378
canvas
@@ -428,7 +421,7 @@ protected void onDraw(Canvas canvas) {
428
421
anim .draw (canvas );
429
422
}
430
423
431
- private final void drawMoveHints (Canvas canvas ) {
424
+ private void drawMoveHints (Canvas canvas ) {
432
425
if (moveHints == null )
433
426
return ;
434
427
float h = (float ) (sqSize / 2.0 );
@@ -553,7 +546,7 @@ public int eventToSquare(MotionEvent evt) {
553
546
return sq ;
554
547
}
555
548
556
- final private boolean myColor (int piece ) {
549
+ private boolean myColor (int piece ) {
557
550
return (piece != Piece .EMPTY ) && (Piece .isWhite (piece ) == pos .whiteMove );
558
551
}
559
552
@@ -632,8 +625,7 @@ public boolean onTrackballEvent(MotionEvent event) {
632
625
protected int getSquare (int x , int y ) { return Position .getSquare (x , y ); }
633
626
634
627
public final Move handleTrackballEvent (MotionEvent event ) {
635
- switch (event .getAction ()) {
636
- case MotionEvent .ACTION_DOWN :
628
+ if (event .getAction () == MotionEvent .ACTION_DOWN ) {
637
629
invalidate ();
638
630
if (cursorVisible ) {
639
631
int x = Math .round (cursorX );
@@ -658,7 +650,7 @@ public final Move handleTrackballEvent(MotionEvent event) {
658
650
}
659
651
660
652
public final void setMoveHints (List <Move > moveHints ) {
661
- boolean equal = false ;
653
+ boolean equal ;
662
654
if ((this .moveHints == null ) || (moveHints == null )) {
663
655
equal = this .moveHints == moveHints ;
664
656
} else {
0 commit comments