New file |
| | |
| | | package com.bsk.zhangbo.demoforbsk.widget;
|
| | |
|
| | | import android.content.Context;
|
| | | import android.graphics.Color;
|
| | | import android.graphics.drawable.ColorDrawable;
|
| | | import android.view.LayoutInflater;
|
| | | import android.view.MotionEvent;
|
| | | import android.view.View;
|
| | | import android.widget.PopupWindow;
|
| | | import android.widget.RelativeLayout;
|
| | | import android.widget.TextView;
|
| | |
|
| | | 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 VisitPurposePopup extends PopupWindow implements View.OnClickListener,WheelView.OnWheelItemSelectedListener{
|
| | | private View view;
|
| | | private TextView mTvConfirm,mTvCancel,mTvTitle;
|
| | | private List mList;
|
| | | private WheelView mWheelView;
|
| | | private Context mContext;
|
| | | public VisitPurposePopup(Context context, List mList, String mTitle) {
|
| | | this.mContext = context;
|
| | | view = LayoutInflater.from(context).inflate(R.layout.visit_purpose_popup,null);
|
| | | this.mList = mList;
|
| | | mTvTitle = (TextView) view.findViewById(R.id.pop_single_title);
|
| | | if (mTitle !=null && mTitle.length() > 0){
|
| | | mTvTitle.setText(mTitle);
|
| | | }else {
|
| | | mTvTitle.setText("标题");
|
| | | }
|
| | | mWheelView = (WheelView) view.findViewById(R.id. pop_single_wheel);
|
| | | mWheelView.setOnWheelItemSelectedListener(this);
|
| | | mTvCancel = (TextView) view.findViewById(R.id.pop_single_cancel);
|
| | | mTvConfirm = (TextView) view.findViewById(R.id.pop_single_confirm);
|
| | | mTvCancel.setOnClickListener(this);
|
| | | mTvConfirm.setOnClickListener(this);
|
| | | mWheelView.setWheelAdapter(new MyWheelAdapter(context));
|
| | | mWheelView.setSkin(WheelView.Skin.Holo);
|
| | | if (mList != null && mList.size() > 0) {
|
| | | mWheelView.setWheelData(mList);
|
| | | }
|
| | | mWheelView.setWheelSize(5);
|
| | | mWheelView.setBackgroundResource(R.color.colorBackground);
|
| | | WheelView.WheelViewStyle style = new WheelView.WheelViewStyle();
|
| | | style.selectedTextColor = Color.parseColor("#11c3e3");
|
| | | style.textColor = Color.parseColor("#bcc6cf");
|
| | | style.selectedTextSize = 22;
|
| | | style.textSize = 16;
|
| | | style.holoBorderColor = Color.parseColor("#11c3e3");
|
| | | mWheelView.setStyle(style);
|
| | |
|
| | | //外部可点击
|
| | | setOutsideTouchable(true);
|
| | |
|
| | | 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();
|
| | | }
|
| | |
|
| | | }
|
| | | return true;
|
| | | }
|
| | | });
|
| | |
|
| | | /*
|
| | | 设置窗口特征
|
| | | */
|
| | | //设置视图
|
| | | this.setContentView(this.view);
|
| | | //设置窗口宽高
|
| | | this.setHeight(RelativeLayout.LayoutParams.MATCH_PARENT);
|
| | | this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
|
| | | //设置弹出窗口可点击
|
| | | this.setFocusable(true);
|
| | | //实例化Color
|
| | | ColorDrawable colorDrawable = new ColorDrawable(0x7f000000);
|
| | | this.setBackgroundDrawable(colorDrawable);
|
| | | this.setAnimationStyle(R.style.PopupAnimation);
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void onClick(View view) {
|
| | | switch (view.getId()){
|
| | | case R.id.pop_single_cancel:
|
| | | dismiss();
|
| | | break;
|
| | | case R.id.pop_single_add:
|
| | | 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();
|
| | | }
|
| | |
|
| | | private List<OkButtonClickedListener> okButtonClickedListeners = new ArrayList<OkButtonClickedListener>();
|
| | |
|
| | | public void addOkButtonClickedListener(OkButtonClickedListener okButtonClickedListener) {
|
| | | this.okButtonClickedListeners.add(okButtonClickedListener);
|
| | | }
|
| | |
|
| | | }
|