//时间滚轴
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 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 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() {        }    }}

更多相关文章

  1. android 根据TextView宽度 自动缩小字体大小 以适应其宽度
  2. ch07 Android 日期与时间对话框
  3. android studio 更改背景和设置字体大小
  4. Android TimeLine 时间节点轴的实现
  5. Android时间工具类 本地转UTC,UTC转本地
  6. android:sharedUserId="android.uid.system" 使用系统签名+SNTP
  7. Android中日期和时间控件的使用

随机推荐

  1. Android setting各子页面地址
  2. Android中使用am命令实现在命令行启动程
  3. android 介绍Retrofit的简单使用
  4. android 理解Fragment生命周期
  5. android下高效率的J2ME API之Graphics.dr
  6. Android数据存储(3)SQLite简介和简单的登
  7. Android 性能优化 四 布局优化merge标签
  8. 【android】SQLite数据库之SQLiteOpenHel
  9. android中Parcel中文乱码的解决:巧用十六
  10. Android编程判断手机or平板