|
|
@ -1,9 +1,11 @@ |
|
|
|
package com.unionmed.unionmedtv.utils; |
|
|
|
package com.unionmed.unionmedtv.utils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.animation.ValueAnimator; |
|
|
|
import android.content.Context; |
|
|
|
import android.content.Context; |
|
|
|
import android.util.AttributeSet; |
|
|
|
import android.util.AttributeSet; |
|
|
|
import android.util.Log; |
|
|
|
import android.util.Log; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
|
|
|
|
import android.view.animation.CycleInterpolator; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager; |
|
|
|
import androidx.recyclerview.widget.GridLayoutManager; |
|
|
|
|
|
|
|
|
|
|
@ -57,6 +59,7 @@ public class MyGridLayoutManager extends GridLayoutManager { |
|
|
|
switch (direction) { |
|
|
|
switch (direction) { |
|
|
|
case View.FOCUS_DOWN: |
|
|
|
case View.FOCUS_DOWN: |
|
|
|
if(currentPosition /getSpanCount() ==rowCount){ |
|
|
|
if(currentPosition /getSpanCount() ==rowCount){ |
|
|
|
|
|
|
|
jitter(getFocusedChild()); |
|
|
|
scrollToPosition(currentPosition); |
|
|
|
scrollToPosition(currentPosition); |
|
|
|
return findViewByPosition(currentPosition); |
|
|
|
return findViewByPosition(currentPosition); |
|
|
|
}else if (currentPosition + getSpanCount() < count) { |
|
|
|
}else if (currentPosition + getSpanCount() < count) { |
|
|
@ -69,7 +72,7 @@ public class MyGridLayoutManager extends GridLayoutManager { |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case View.FOCUS_UP: |
|
|
|
case View.FOCUS_UP: |
|
|
|
if (currentPosition % getSpanCount() == 0 && upView != null) { |
|
|
|
if (currentPosition / getSpanCount() == 0 && upView != null) { |
|
|
|
upView.requestFocus(); |
|
|
|
upView.requestFocus(); |
|
|
|
}else if (currentPosition - getSpanCount() < count) { |
|
|
|
}else if (currentPosition - getSpanCount() < count) { |
|
|
|
int nextRowFirstPosition1 = currentPosition - getSpanCount(); |
|
|
|
int nextRowFirstPosition1 = currentPosition - getSpanCount(); |
|
|
@ -83,11 +86,13 @@ public class MyGridLayoutManager extends GridLayoutManager { |
|
|
|
scrollToPosition(nextRowFirstPosition); |
|
|
|
scrollToPosition(nextRowFirstPosition); |
|
|
|
return findViewByPosition(nextRowFirstPosition); |
|
|
|
return findViewByPosition(nextRowFirstPosition); |
|
|
|
} else if (currentPosition == count) { |
|
|
|
} else if (currentPosition == count) { |
|
|
|
|
|
|
|
jitter(getFocusedChild()); |
|
|
|
return findViewByPosition(currentPosition); |
|
|
|
return findViewByPosition(currentPosition); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case View.FOCUS_LEFT: |
|
|
|
case View.FOCUS_LEFT: |
|
|
|
if (currentPosition == 0) { |
|
|
|
if (currentPosition == 0) { |
|
|
|
|
|
|
|
jitter(getFocusedChild()); |
|
|
|
return findViewByPosition(currentPosition); |
|
|
|
return findViewByPosition(currentPosition); |
|
|
|
} else if (currentPosition <=count) { |
|
|
|
} else if (currentPosition <=count) { |
|
|
|
int nextRowFirstPosition = currentPosition - 1; |
|
|
|
int nextRowFirstPosition = currentPosition - 1; |
|
|
@ -98,4 +103,18 @@ public class MyGridLayoutManager extends GridLayoutManager { |
|
|
|
} |
|
|
|
} |
|
|
|
return super.onInterceptFocusSearch(focused, direction); |
|
|
|
return super.onInterceptFocusSearch(focused, direction); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//左右抖动效果
|
|
|
|
|
|
|
|
public void jitter(View view){ |
|
|
|
|
|
|
|
ValueAnimator shakeAnimator = ValueAnimator.ofFloat(0, 5); |
|
|
|
|
|
|
|
shakeAnimator.setDuration(300); |
|
|
|
|
|
|
|
shakeAnimator.setInterpolator(new CycleInterpolator(5)); |
|
|
|
|
|
|
|
shakeAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onAnimationUpdate(ValueAnimator animation) { |
|
|
|
|
|
|
|
float currentValue = (float) animation.getAnimatedValue(); |
|
|
|
|
|
|
|
view.setTranslationX(currentValue); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
shakeAnimator.start(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|