package com.example.miraclewong.customview;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;

/**
 * Created by miraclewong on 2016/1/26.
 * 该自定义的View——360加速球的动画效果，参照To_be_Designer的博客：http://blog.csdn.net/To_be_Designer/article/details/48554469
 */
public class AnimationActivity extends Activity {
    private Button mButton;
    private MyProgressAnimation myprogressanomation;
    private static final int PROGRESS= 0X0003;
    //定义一个进度
    private int progress;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case PROGRESS:
                    progress++;
                    if (progress <= 100) {
                        myprogressanomation.setCurrentProgress(progress);
                        sendEmptyMessageDelayed(PROGRESS, 100);
                    }
                    break;
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation);
        mButton = (Button) findViewById(R.id.button_start);
        myprogressanomation= (MyProgressAnimation) findViewById(R.id.myprogress);
        mButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                handler.sendEmptyMessageDelayed(PROGRESS, 1000);
            }
        });
    }
}
