android 自定义View之SubmitView

转载请注明出处:王亟亟的大牛之路

最近看了一大堆的自定义View多数都可以充当耗时操作的交互界面,再接再厉再传一个SubmitView,一个和可用于模仿提交等待与用户交互用的一个自定义View
效果图:
这里写图片描述

项目结构:
这里写图片描述
一个Android Studio项目。也可以转成Eclipse,因为没有涉及到打包啊lib的一些操作,连资源文件都没用,所以可以直接Copy过去。

自定义View

public class SubmitView extends View {
   

    private static final int COLOR_BACK = 0xff00cd97;
    private static final int COLOR_GREY = 0xffb9b9b9;

    private int mColor = COLOR_BACK;

    //
    private Paint mBorderPaint;
    private Paint mTextPaint;
    private Paint mBackPaint;

    private int mWidth;
    private int mHeight;
    private int mRadius;
    private static final int PADDING = 5;

    private Rect mTextBounds;

    private boolean mShowText = true;
    private static final String TEXT_SUBMIT = "提交";
    private String mText = TEXT_SUBMIT;
    private int mStrokeWidth;

    // indicate if view can click
    private boolean mCanClick = true;

    // indicate the animator state
    private AniState mAniState = AniState.INIT;

    private boolean mIfReset = false;

    enum AniState {
        INIT,
        FIRST_START, // start animation which change backcolor and text color
        FIRST_STOP,
        SECOND_START,  // second animation which change "submit" size for a while
        SECOND_STOP,
        THIRD_START,  // third animation which convert to circle and change back color
        THIRD_STOP,
        FOURTH_START,  // fourth animation which show the progress
        FOURTH_STOP,
        FIFTH_START,   // fifth animation which can narrow the back and border and show "correct" sign
        FIFTH_STOP;


        public boolean isPlaying() {
            return this==FIRST_START
                    || this==SECOND_START
                    || this == THIRD_START
                    || this == FOURTH_START
                    || this == FIFTH_START;
        }

        @Override
        public String toString() {
            switch (this) {
                case INIT:
                    return "***init***";
                case FIRST_START:
                    return "***first start***";
                case FIRST_STOP:
                    return "***first stop***";
                case SECOND_START:
                    return "***second start***";
                case SECOND_STOP:
                    return "***second stop***";
                case THIRD_START:
                    return "***third start***";
                case THIRD_STOP:
                    return "****third stop**";
                case FOURTH_START:
                    return "***fourth start***";
                case FOURTH_STOP:
                    return "***fourth stop***";
                case FIFTH_START:
                    return "***fifth start***";
                case FIFTH_STOP:
                    return "***fifth stop";
                default:
                    return "unknown state";
            }
        }
    }




    public SubmitView(Context context) {
        this(context, null, 0);
    }

    public SubmitView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public SubmitView(Context context, Attribute
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值