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