Android 时间滚轴

//时间滚轴
public class OptionsPopupWindow extends PopupWindow implements OnClickListener {

    private View rootView; // 总的布局
    private View btnSubmit, btnCancel;
    private static final String TAG_SUBMIT = "submit";
    private static final String TAG_CANCEL = "cancel";
    private OnoptionsSelectListener onoptionsSelectListener;
    private LoopView options;
    private ArrayList<String> list;
    private int optionSelect;
    private  SweetView sweetView;

    public OptionsPopupWindow(Context context) {
        super(context);
        this.setWidth(LayoutParams.FILL_PARENT);
        this.setHeight(LayoutParams.WRAP_CONTENT);
        this.setBackgroundDrawable(new BitmapDrawable());// 这样设置才能点击屏幕外dismiss窗口
        this.setOutsideTouchable(true);
        this.setAnimationStyle(R.style.timepopwindow_anim_style);

        LayoutInflater mLayoutInflater = LayoutInflater.from(context);
        rootView = mLayoutInflater.inflate(R.layout.pw_options, null);
        // -----确定和取消按钮
        btnSubmit = rootView.findViewById(R.id.btnSubmit);
        btnSubmit.setTag(TAG_SUBMIT);
        btnCancel = rootView.findViewById(R.id.btnCancel);
        btnCancel.setTag(TAG_CANCEL);
        btnSubmit.setOnClickListener(this);
        btnCancel.setOnClickListener(this);
        sweetView = (SweetView) rootView.findViewById(R.id.sweetView);
        sweetView.setAnimationListener(new MyAnimationListener());
        // ----时间转轮
        options = (LoopView) rootView.findViewById(R.id.options);

        setContentView(rootView);
        setLoopView();
    }

    /**
     * 设置LoopView
     */
    private void setLoopView() {
        //滚动监听
        options.setListener(new LoopListener() {
            @Override
            public void onItemSelect(int item) {
                optionSelect = item;
            }
        });

        //设置初始位置
        options.setPosition(0);
        //设置字体大小
        options.setTextSize(18);
    }

    public void setList(ArrayList<String> list) {
        this.list = list;
        //设置原始数据
        options.setArrayList(list);
    }

    /**
     * 设置是否循环播放
     */
    public void setNotLoop() {

        options.setNotLoop();
    }

    /**
     * 检验是否超过当前时间
     *
     * @param date
     * @return
     */
    public boolean checkStime(Date date) {
        long userTime = date.getTime();
        long currentTime = new Date().getTime();
        if (currentTime > userTime) {
            return true;
        }
        return false;
    }

    /**
     * 指定选中的时间,显示选择器
     *
     * @param parent
     * @param gravity
     * @param x
     * @param y
     * @param date
     */
    public void showAtLocation(View parent, int gravity, int x, int y, Date date) {
        super.showAtLocation(parent, gravity, x, y);
        sweetView.show();
    }

    @Override
    public void onClick(View v) {
        String tag = (String) v.getTag();
        if (tag.equals(TAG_CANCEL)) {
            dismiss();
            return;
        } else {
            if (onoptionsSelectListener != null) {
                try {
                    onoptionsSelectListener.onInfoSelect(optionSelect);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            dismiss();
            return;
        }
    }

    private boolean isFirst = true;


    public interface OnoptionsSelectListener {
        public void onInfoSelect(int option);
    }

    public void setOnoptionsSelectListener(OnoptionsSelectListener onoptionsSelectListener) {
        this.onoptionsSelectListener = onoptionsSelectListener;
    }

    class MyAnimationListener implements SweetView.AnimationListener {

        @Override
        public void onStart() {
            btnSubmit.setVisibility(View.GONE);
            btnCancel.setVisibility(View.GONE);
        }

        @Override
        public void onEnd() {
            btnSubmit.setVisibility(View.VISIBLE);
            btnCancel.setVisibility(View.VISIBLE);
        }

        @Override
        public void onContentShow() {

        }
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值