|
| 1 | +package sample.kingja.loadsir.callback; |
| 2 | + |
| 3 | +import android.content.Context; |
| 4 | +import android.util.Log; |
| 5 | +import android.view.View; |
| 6 | +import android.view.animation.Animation; |
| 7 | +import android.view.animation.LinearInterpolator; |
| 8 | +import android.view.animation.RotateAnimation; |
| 9 | +import android.widget.Toast; |
| 10 | + |
| 11 | +import com.kingja.loadsir.callback.Callback; |
| 12 | + |
| 13 | +import sample.kingja.loadsir.R; |
| 14 | + |
| 15 | +import static android.content.ContentValues.TAG; |
| 16 | + |
| 17 | +/** |
| 18 | + * Description:TODO |
| 19 | + * Create Time:2017/9/3 10:22 |
| 20 | + * Author:KingJA |
| 21 | + * Email:kingjavip@gmail.com |
| 22 | + */ |
| 23 | +public class AnimateCallback extends Callback { |
| 24 | + |
| 25 | + private Context context; |
| 26 | + private View animateView; |
| 27 | + |
| 28 | + @Override |
| 29 | + protected int onCreateView() { |
| 30 | + return R.layout.layout_animate; |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + protected void onViewCreate(Context context, View view) { |
| 35 | + super.onViewCreate(context, view); |
| 36 | + Log.e(TAG, "onViewCreate: "); |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public void onAttach(Context context, View view) { |
| 41 | + super.onAttach(context, view); |
| 42 | + this.context = context; |
| 43 | + animateView = view.findViewById(R.id.view_animate); |
| 44 | + Animation animation = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, |
| 45 | + 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); |
| 46 | + animation.setDuration(1000); |
| 47 | + animation.setRepeatCount(Integer.MAX_VALUE); |
| 48 | + animation.setFillAfter(true); |
| 49 | + animation.setInterpolator(new LinearInterpolator()); |
| 50 | + animateView.startAnimation(animation); |
| 51 | + Toast.makeText(context.getApplicationContext(), "start animation", Toast.LENGTH_SHORT).show(); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public void onDetach() { |
| 56 | + super.onDetach(); |
| 57 | + if (animateView != null) { |
| 58 | + animateView.clearAnimation(); |
| 59 | + } |
| 60 | + Toast.makeText(context.getApplicationContext(), "stop animation", Toast.LENGTH_SHORT).show(); |
| 61 | + } |
| 62 | +} |
0 commit comments