| | |
| | |
|
| | | import com.bsk.zhangbo.demoforbsk.R;
|
| | | import com.bsk.zhangbo.demoforbsk.adapter.MyWheelAdapter;
|
| | | import com.bsk.zhangbo.demoforbsk.listeners.OkButtonClickedListener;
|
| | | import com.wx.wheelview.widget.WheelView;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
|
| | | import cn.com.basic.face.discern.entity.Dictionary;
|
| | |
|
| | | /**
|
| | | * Created by Sinoe on 2017/2/27.
|
| | |
| | | public class SingleSelectionPopup extends PopupWindow implements View.OnClickListener,WheelView.OnWheelItemSelectedListener{
|
| | | private View view;
|
| | | private TextView mTvConfirm,mTvCancel,mTvTitle;
|
| | | private List<String> mList;
|
| | | private List mList;
|
| | | private WheelView mWheelView;
|
| | | private Context mContext;
|
| | | public SingleSelectionPopup(Context context, List<String> mList,String mTitle) {
|
| | | public SingleSelectionPopup(Context context, List mList,String mTitle) {
|
| | | this.mContext = context;
|
| | | view = LayoutInflater.from(context).inflate(R.layout.pop_single_selection,null);
|
| | | this.mList = mList;
|
| | |
| | | mTvConfirm.setOnClickListener(this);
|
| | | mWheelView.setWheelAdapter(new MyWheelAdapter(context));
|
| | | mWheelView.setSkin(WheelView.Skin.Holo);
|
| | | mWheelView.setWheelData(mList);
|
| | | if (mList != null && mList.size() > 0) {
|
| | | mWheelView.setWheelData(mList);
|
| | | }
|
| | | mWheelView.setWheelSize(5);
|
| | | mWheelView.setBackgroundResource(R.color.colorBackground);
|
| | | WheelView.WheelViewStyle style = new WheelView.WheelViewStyle();
|
| | |
| | | view.setOnTouchListener(new View.OnTouchListener() {
|
| | | @Override
|
| | | public boolean onTouch(View view, MotionEvent motionEvent) {
|
| | | View popLayout = view.findViewById(R.id.pop_single_ll);
|
| | | int top = popLayout.getTop();
|
| | | int bottom = popLayout.getBottom();
|
| | | int left = popLayout.getLeft();
|
| | | int right = popLayout.getRight();
|
| | | int y = (int) motionEvent.getY();
|
| | | int x = (int) motionEvent.getX();
|
| | | if (motionEvent.getAction() == MotionEvent.ACTION_UP){
|
| | | if (y<top || y> bottom){
|
| | | dismiss();
|
| | | }
|
| | | if (x < left || x > right){
|
| | | dismiss();
|
| | | }
|
| | |
|
| | | View popLayout = view.findViewById(R.id.pop_single_ll);
|
| | | int top = popLayout.getTop();
|
| | | int bottom = popLayout.getBottom();
|
| | | int left = popLayout.getLeft();
|
| | | int right = popLayout.getRight();
|
| | | int y = (int) motionEvent.getY();
|
| | | int x = (int) motionEvent.getX();
|
| | | if (motionEvent.getAction() == MotionEvent.ACTION_UP){
|
| | | if (y<top || y> bottom){
|
| | | dismiss();
|
| | | }
|
| | | return true;
|
| | | if (x < left || x > right){
|
| | | dismiss();
|
| | | }
|
| | |
|
| | | }
|
| | | return true;
|
| | | }
|
| | | });
|
| | |
|
| | |
| | | dismiss();
|
| | | break;
|
| | | case R.id.pop_single_confirm:
|
| | | for (OkButtonClickedListener okButtonClickedListener : okButtonClickedListeners) {
|
| | | if (mWheelView.getCurrentPosition() >= 0) {
|
| | | Object o = mList.get(mWheelView.getCurrentPosition());
|
| | | String item = "";
|
| | | if (o instanceof Dictionary) {
|
| | | item = ((Dictionary) o).getName();
|
| | | } else {
|
| | | item = o+"";
|
| | | }
|
| | | okButtonClickedListener.onItemSelected(mWheelView.getCurrentPosition(), o, item);
|
| | | }
|
| | | }
|
| | | dismiss();
|
| | | break;
|
| | | }
|
| | |
| | |
|
| | | @Override
|
| | | public void onItemSelected(int position, Object o) {
|
| | | Toast.makeText(mContext,mList.get(position),Toast.LENGTH_SHORT).show();
|
| | | //Toast.makeText(mContext,mList.get(position),Toast.LENGTH_SHORT).show();
|
| | | }
|
| | |
|
| | | private List<OkButtonClickedListener> okButtonClickedListeners = new ArrayList<OkButtonClickedListener>();
|
| | |
|
| | | public void addOkButtonClickedListener(OkButtonClickedListener okButtonClickedListener) {
|
| | | this.okButtonClickedListeners.add(okButtonClickedListener);
|
| | | }
|
| | |
|
| | | }
|