@@ -202,17 +202,22 @@ public void onLayoutChange(View v, int left, int top, int right, int bottom, int
202202 };
203203
204204 protected List <Animator > getScaleAnimator (View view , boolean isScale ) {
205+
205206 List <Animator > animatorList = new ArrayList <Animator >(2 );
206- float scaleBefore = 1.0f ;
207- float scaleAfter = mScale ;
208- if (!isScale ) {
209- scaleBefore = mScale ;
210- scaleAfter = 1.0f ;
207+ try {
208+ float scaleBefore = 1.0f ;
209+ float scaleAfter = mScale ;
210+ if (!isScale ) {
211+ scaleBefore = mScale ;
212+ scaleAfter = 1.0f ;
213+ }
214+ ObjectAnimator scaleX = new ObjectAnimator ().ofFloat (view , "scaleX" , scaleBefore , scaleAfter );
215+ ObjectAnimator scaleY = new ObjectAnimator ().ofFloat (view , "scaleY" , scaleBefore , scaleAfter );
216+ animatorList .add (scaleX );
217+ animatorList .add (scaleY );
218+ }catch (Exception ex ){
219+ ex .printStackTrace ();
211220 }
212- ObjectAnimator scaleX = new ObjectAnimator ().ofFloat (view , "scaleX" , scaleBefore , scaleAfter );
213- ObjectAnimator scaleY = new ObjectAnimator ().ofFloat (view , "scaleY" , scaleBefore , scaleAfter );
214- animatorList .add (scaleX );
215- animatorList .add (scaleY );
216221 return animatorList ;
217222 }
218223
@@ -485,41 +490,45 @@ public void onAttach(View target, View attachView) {
485490 recyclerViewOnScrollListener = new RecyclerView .OnScrollListener () {
486491 @ Override
487492 public void onScrollStateChanged (RecyclerView recyclerView , int newState ) {
488- super .onScrollStateChanged (recyclerView , newState );
489- //Log.d(TAG, "========>onScrollStateChanged");
490-
491- if (newState == RecyclerView .SCROLL_STATE_IDLE ) {
492- //Log.d(TAG, "========>SCROLL_STATE_IDLE");
493- isScrolling = false ;
494- View oldFocus = oldLastFocus ;
495- View newFocus = lastFocus ;
496- VisibleScope scope = checkVisibleScope (oldFocus , newFocus );
497- if (!scope .isVisible ) {
498- return ;
499- } else {
500- oldFocus = scope .oldFocus ;
501- newFocus = scope .newFocus ;
502- }
503- AnimatorSet animatorSet = new AnimatorSet ();
504- List <Animator > list = new ArrayList <>();
505- // list.addAll(getScaleAnimator(oldLastFocus, false));
506- list .addAll (getScaleAnimator (newFocus , true ));
507- list .addAll (getMoveAnimator (newFocus , 0 , 0 ));
508- animatorSet .setDuration (mDurationTraslate );
509- animatorSet .playTogether (list );
510- animatorSet .start ();
511-
512-
513- } else if (newState == RecyclerView .SCROLL_STATE_SETTLING ) {
514- //Log.d(TAG, "========>SCROLL_STATE_SETTLING=" + mAnimatorSet.isRunning());
515- isScrolling = true ;
516- if (lastFocus != null ) {
517- List <Animator > list = getScaleAnimator (lastFocus , false );
493+ try {
494+ super .onScrollStateChanged (recyclerView , newState );
495+ //Log.d(TAG, "========>onScrollStateChanged");
496+
497+ if (newState == RecyclerView .SCROLL_STATE_IDLE ) {
498+ //Log.d(TAG, "========>SCROLL_STATE_IDLE");
499+ isScrolling = false ;
500+ View oldFocus = oldLastFocus ;
501+ View newFocus = lastFocus ;
502+ VisibleScope scope = checkVisibleScope (oldFocus , newFocus );
503+ if (!scope .isVisible ) {
504+ return ;
505+ } else {
506+ oldFocus = scope .oldFocus ;
507+ newFocus = scope .newFocus ;
508+ }
518509 AnimatorSet animatorSet = new AnimatorSet ();
519- animatorSet .setDuration (150 );
510+ List <Animator > list = new ArrayList <>();
511+ // list.addAll(getScaleAnimator(oldLastFocus, false));
512+ list .addAll (getScaleAnimator (newFocus , true ));
513+ list .addAll (getMoveAnimator (newFocus , 0 , 0 ));
514+ animatorSet .setDuration (mDurationTraslate );
520515 animatorSet .playTogether (list );
521516 animatorSet .start ();
517+
518+
519+ } else if (newState == RecyclerView .SCROLL_STATE_SETTLING ) {
520+ //Log.d(TAG, "========>SCROLL_STATE_SETTLING=" + mAnimatorSet.isRunning());
521+ isScrolling = true ;
522+ if (lastFocus != null ) {
523+ List <Animator > list = getScaleAnimator (lastFocus , false );
524+ AnimatorSet animatorSet = new AnimatorSet ();
525+ animatorSet .setDuration (150 );
526+ animatorSet .playTogether (list );
527+ animatorSet .start ();
528+ }
522529 }
530+ } catch (Exception ex ) {
531+
523532 }
524533 }
525534 };
@@ -557,44 +566,48 @@ protected class MyOnItemSelectedListener implements AdapterView.OnItemSelectedLi
557566
558567 @ Override
559568 public void onItemSelected (AdapterView <?> parent , View view , int position , long id ) {
560- if (onItemSelectedListener != null && parent != null ) {
561- onItemSelectedListener .onItemSelected (parent , view , position , id );
562- }
563- if (newFocus == null )
564- return ;
565- newFocus = view ;
566- Log .d (TAG , "onItemSelected" );
569+ try {
570+ if (onItemSelectedListener != null && parent != null ) {
571+ onItemSelectedListener .onItemSelected (parent , view , position , id );
572+ }
573+ if (newFocus == null )
574+ return ;
575+ newFocus = view ;
576+ Log .d (TAG , "onItemSelected" );
567577
568- Rect rect = new Rect ();
569- view .getLocalVisibleRect (rect );
578+ Rect rect = new Rect ();
579+ view .getLocalVisibleRect (rect );
570580
571- ViewGroup vg = (ViewGroup ) newFocus .getParent ();
581+ ViewGroup vg = (ViewGroup ) newFocus .getParent ();
572582// Log.d(TAG, "onItemSelected:" + vg.getWidth() + " " + newFocus.getMeasuredWidth() + " w=" + (rect.left - rect.right));
573583
574- int factorX = 0 , factorY = 0 ;
575- if (Math .abs (rect .left - rect .right ) > newFocus .getMeasuredWidth ()) {
576- factorX = (Math .abs (rect .left - rect .right ) - newFocus .getMeasuredWidth ()) / 2 - 1 ;
577- factorY = (Math .abs (rect .top - rect .bottom ) - newFocus .getMeasuredHeight ()) / 2 ;
584+ int factorX = 0 , factorY = 0 ;
585+ if (Math .abs (rect .left - rect .right ) > newFocus .getMeasuredWidth ()) {
586+ factorX = (Math .abs (rect .left - rect .right ) - newFocus .getMeasuredWidth ()) / 2 - 1 ;
587+ factorY = (Math .abs (rect .top - rect .bottom ) - newFocus .getMeasuredHeight ()) / 2 ;
578588
579- }
589+ }
580590
581591
582- List <Animator > animatorList = new ArrayList <Animator >(3 );
583- animatorList .addAll (getScaleAnimator (newFocus , true ));
584- if (oldFocus != null )
585- animatorList .addAll (getScaleAnimator (oldFocus , false ));
586- animatorList .addAll (getMoveAnimator (newFocus , factorX , factorY ));
587- mTarget .setVisibility (View .VISIBLE );
592+ List <Animator > animatorList = new ArrayList <Animator >(3 );
593+ animatorList .addAll (getScaleAnimator (newFocus , true ));
594+ if (oldFocus != null )
595+ animatorList .addAll (getScaleAnimator (oldFocus , false ));
596+ animatorList .addAll (getMoveAnimator (newFocus , factorX , factorY ));
597+ mTarget .setVisibility (View .VISIBLE );
588598
589- if (animatorSet != null && animatorSet .isRunning ())
590- animatorSet .end ();
591- animatorSet = new AnimatorSet ();
592- animatorSet .setDuration (mDurationTraslate );
593- animatorSet .playTogether (animatorList );
594- animatorSet .start ();
599+ if (animatorSet != null && animatorSet .isRunning ())
600+ animatorSet .end ();
601+ animatorSet = new AnimatorSet ();
602+ animatorSet .setDuration (mDurationTraslate );
603+ animatorSet .playTogether (animatorList );
604+ animatorSet .start ();
595605
596606
597- oldFocus = newFocus ;
607+ oldFocus = newFocus ;
608+ }catch (Exception ex ){
609+ ex .printStackTrace ();
610+ }
598611
599612 }
600613
0 commit comments