@@ -222,63 +222,69 @@ public void onDrawOver ( Canvas c, RecyclerView parent, RecyclerView.State state
222222 int dX ;
223223 int dY = 0 ;
224224
225- int firstVisiblePos = parent .getChildLayoutPosition ( parent . getChildAt (0 ) );
226- int lastVisiblePos = parent .getChildLayoutPosition ( parent . getChildAt (parent .getChildCount () - 1 ) );
225+ View firstChild = parent .getChildAt (0 );
226+ View lastChild = parent .getChildAt (parent .getChildCount () - 1 );
227227
228- boolean drawStripUnderHeaderAndFooter = dewey . getFocusedPosition () != 0 && dewey . getFocusedPosition () != footerPos ;
228+ if ( firstChild != null && lastChild != null ) {
229229
230- if (drawStripUnderHeaderAndFooter ) {
231- drawStrip (parent , c , firstVisiblePos , lastVisiblePos );
232- }
230+ int firstVisiblePos = parent .getChildLayoutPosition (firstChild );
231+ int lastVisiblePos = parent .getChildLayoutPosition (lastChild );
233232
234- // Draw sticky header.
235- if (headerView != null ) {
236- float headerPercentageHidden = getPercentageOfViewHidden (parent .getChildAt (0 ), parent );
233+ boolean drawStripUnderHeaderAndFooter = dewey .getFocusedPosition () != 0 && dewey .getFocusedPosition () != footerPos ;
237234
238- if (firstVisiblePos == 0 ) {
239- cloakPaint .setAlpha (getMixedCloakAlpha (headerPercentageHidden ));
240- } else {
241- cloakPaint .setAlpha (Color .alpha (dewey .getCloakColor ()));
235+ if (drawStripUnderHeaderAndFooter ) {
236+ drawStrip (parent , c , firstVisiblePos , lastVisiblePos );
242237 }
243238
244- c . drawRect ( 0 , 0 , headerView . getMeasuredWidth (), headerView . getMeasuredHeight () - dewey . getStripOffset (), cloakPaint );
245- headerView . draw ( c );
246- }
239+ // Draw sticky header.
240+ if ( headerView != null ) {
241+ float headerPercentageHidden = getPercentageOfViewHidden ( firstChild , parent );
247242
248- // Draw sticky footer.
249- if ( footerView != null ) {
250- float footerPercentageHidden = getPercentageOfViewHidden (parent .getChildAt (parent .getChildCount () - 1 ), parent );
243+ if (firstVisiblePos == 0 ) {
244+ cloakPaint .setAlpha (getMixedCloakAlpha (headerPercentageHidden ));
245+ } else {
246+ cloakPaint .setAlpha (Color .alpha (dewey .getCloakColor ()));
247+ }
251248
252- if (lastVisiblePos == footerPos ) {
253- cloakPaint .setAlpha (getMixedCloakAlpha (footerPercentageHidden ));
254- } else {
255- cloakPaint .setAlpha (Color .alpha (dewey .getCloakColor ()));
249+ c .drawRect (0 , 0 , headerView .getMeasuredWidth (), headerView .getMeasuredHeight () - dewey .getStripOffset (), cloakPaint );
250+ headerView .draw (c );
256251 }
257252
258- dX = parent .getMeasuredWidth () - footerView .getMeasuredWidth ();
259- c .translate (dX , dY );
253+ // Draw sticky footer.
254+ if (footerView != null ) {
255+ float footerPercentageHidden = getPercentageOfViewHidden (lastChild , parent );
260256
261- c .drawRect (0 , 0 , footerView .getMeasuredWidth (), footerView .getMeasuredHeight () - dewey .getStripOffset (), cloakPaint );
262- footerView .draw (c );
257+ if (lastVisiblePos == footerPos ) {
258+ cloakPaint .setAlpha (getMixedCloakAlpha (footerPercentageHidden ));
259+ } else {
260+ cloakPaint .setAlpha (Color .alpha (dewey .getCloakColor ()));
261+ }
263262
264- c . translate (- 1 * dX , - 1 * dY );
265- }
263+ dX = parent . getMeasuredWidth () - footerView . getMeasuredWidth ( );
264+ c . translate ( dX , dY );
266265
267- if (!drawStripUnderHeaderAndFooter ) {
268- drawStrip (parent , c , firstVisiblePos , lastVisiblePos );
269- }
266+ c .drawRect (0 , 0 , footerView .getMeasuredWidth (), footerView .getMeasuredHeight () - dewey .getStripOffset (), cloakPaint );
267+ footerView .draw (c );
268+
269+ c .translate (-1 * dX , -1 * dY );
270+ }
270271
271- c .restore ();
272+ if (!drawStripUnderHeaderAndFooter ) {
273+ drawStrip (parent , c , firstVisiblePos , lastVisiblePos );
274+ }
272275
273- if (framesRemaining > 0 ) {
274- framesRemaining --;
276+ c .restore ();
275277
276- animatingStripXOffset = animatingStripXOffset + animatingStripXOffsetPerFrame ;
277- animatingStripWidthOffset = animatingStripWidthOffset + animatingStripWidthOffsetPerFrame ;
278+ if ( framesRemaining > 0 ) {
279+ framesRemaining -- ;
278280
279- dewey .postInvalidateDelayed ((long ) (1000f / ((float ) framesPerMs / 1000f )));
280- } else {
281- resetAnimationProperties ();
281+ animatingStripXOffset = animatingStripXOffset + animatingStripXOffsetPerFrame ;
282+ animatingStripWidthOffset = animatingStripWidthOffset + animatingStripWidthOffsetPerFrame ;
283+
284+ dewey .postInvalidateDelayed ((long ) (1000f / ((float ) framesPerMs / 1000f )));
285+ } else {
286+ resetAnimationProperties ();
287+ }
282288 }
283289 }
284290
0 commit comments