New file |
| | |
| | | package cn.com.basic.face.dialog;
|
| | |
|
| | | import android.content.Context;
|
| | | import android.graphics.Color;
|
| | | import android.graphics.drawable.ColorDrawable;
|
| | | import android.view.Gravity;
|
| | | import android.view.LayoutInflater;
|
| | | import android.view.MotionEvent;
|
| | | import android.view.View;
|
| | | import android.view.ViewGroup;
|
| | | import android.widget.EditText;
|
| | | import android.widget.PopupWindow;
|
| | | import android.widget.RelativeLayout;
|
| | | import android.widget.TextView;
|
| | | import android.widget.Toast;
|
| | |
|
| | | import com.bsk.zhangbo.demoforbsk.R;
|
| | | import com.lidroid.xutils.ViewUtils;
|
| | | import com.lidroid.xutils.view.annotation.ViewInject;
|
| | | import com.lidroid.xutils.view.annotation.event.OnClick;
|
| | | import com.wx.wheelview.adapter.BaseWheelAdapter;
|
| | | import com.wx.wheelview.widget.WheelView;
|
| | |
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
|
| | | import cn.com.basic.face.base.MainActivity;
|
| | | import cn.com.basic.face.discern.entity.Dictionary;
|
| | | import cn.com.basic.face.util.Constant;
|
| | | import cn.com.basic.face.util.OkClickedListener;
|
| | |
|
| | | public class AddDialog extends PopupWindow {
|
| | | private final View parentView;
|
| | | @ViewInject(R.id.dialog_add_title)
|
| | | private TextView dialog_add_title;
|
| | | @ViewInject(R.id.dialog_add_list_view)
|
| | | private WheelView dialog_add_list_view;
|
| | | @ViewInject(R.id.dialog_add_content)
|
| | | private EditText dialog_add_content;
|
| | |
|
| | | private List list = new ArrayList();
|
| | |
|
| | | public static List visitorTypeList = new ArrayList();
|
| | | public static List genderList = new ArrayList();
|
| | | public static List idTypeList = new ArrayList();
|
| | | public static List visitReasonList = new ArrayList();
|
| | |
|
| | | public static void setVisitorTypeList(List visitorTypeList) {
|
| | | AddDialog.visitorTypeList = visitorTypeList;
|
| | | }
|
| | |
|
| | | public static void setGenderList(List genderList) {
|
| | | AddDialog.genderList = genderList;
|
| | | }
|
| | |
|
| | | public static void setIdTypeList(List idTypeList) {
|
| | | AddDialog.idTypeList = idTypeList;
|
| | | }
|
| | |
|
| | | public AddDialog(View parentView, int type, OkClickedListener okButtonClickedListener) {
|
| | | this.parentView = parentView;
|
| | | View view = LayoutInflater.from(MainActivity.getInstance()).inflate(R.layout.dialog_add,null);
|
| | | ViewUtils.inject(this, view);
|
| | | setTitleAndList(type);
|
| | | 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");
|
| | |
|
| | | dialog_add_list_view.setWheelAdapter(new WheelAdapter(MainActivity.getInstance()));
|
| | | dialog_add_list_view.setSkin(WheelView.Skin.Holo);
|
| | | if (list != null && list.size() > 0) {
|
| | | dialog_add_list_view.setWheelData(list);
|
| | | }
|
| | | dialog_add_list_view.setWheelSize(5);
|
| | | dialog_add_list_view.setBackgroundResource(R.color.colorBackground);
|
| | | dialog_add_list_view.setStyle(style);
|
| | |
|
| | | view.setOnTouchListener(new View.OnTouchListener() {
|
| | | @Override
|
| | | public boolean onTouch(View view, MotionEvent motionEvent) {
|
| | | View popLayout = view.findViewById(R.id.dialog_add_linear_layout);
|
| | | 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;
|
| | | }
|
| | | });
|
| | |
|
| | | setOutsideTouchable(true);
|
| | | this.setContentView(view);
|
| | | this.setHeight(RelativeLayout.LayoutParams.MATCH_PARENT);
|
| | | this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
|
| | | this.setFocusable(true);
|
| | | this.setBackgroundDrawable(new ColorDrawable(0x7f000000));
|
| | | this.setAnimationStyle(R.style.PopupAnimation);
|
| | | okButtonClickedListeners.add(okButtonClickedListener);
|
| | | this.showAtLocation(parentView, Gravity.CENTER,0,0);
|
| | | }
|
| | |
|
| | | @OnClick(R.id.dialog_add_ok)
|
| | | public void dialog_add_ok_click(View view) {
|
| | | for (OkClickedListener okButtonClickedListener : okButtonClickedListeners) {
|
| | | okButtonClickedListener.onSelected(dialog_add_content.getText().toString());
|
| | | }
|
| | | dismiss();
|
| | | }
|
| | |
|
| | | @OnClick(R.id.dialog_add_cancel)
|
| | | public void dialog_add_cancel_click(View view) {
|
| | | dismiss();
|
| | | }
|
| | |
|
| | | private List<OkClickedListener> okButtonClickedListeners = new ArrayList<OkClickedListener>();
|
| | |
|
| | | public void addOkButtonClickedListener(OkClickedListener okButtonClickedListener) {
|
| | | this.okButtonClickedListeners.add(okButtonClickedListener);
|
| | | }
|
| | |
|
| | | private void setTitleAndList(int type) {
|
| | | String tile = "";
|
| | | switch (type) {
|
| | | case Constant.DialogSelectType.VISIT_REASON_ADD:
|
| | | tile = "添加访问事由";
|
| | | break;
|
| | | }
|
| | | dialog_add_title.setText(tile);
|
| | | }
|
| | |
|
| | | public static void setVisitReasonList(List visitReasonList) {
|
| | | AddDialog.visitReasonList = visitReasonList;
|
| | | }
|
| | |
|
| | |
|
| | | public static class WheelAdapter extends BaseWheelAdapter<String> {
|
| | | private Context mContext;
|
| | |
|
| | | public WheelAdapter(Context context) {
|
| | | mContext = context;
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected View bindView(int position, View convertView, ViewGroup parent) {
|
| | | ViewHolder viewHolder;
|
| | | if (convertView == null) {
|
| | | viewHolder = new ViewHolder();
|
| | | convertView = LayoutInflater.from(mContext).inflate(R.layout.dialog_row, null);
|
| | | viewHolder.textView = (TextView) convertView.findViewById(R.id.item_wheel_name);
|
| | | convertView.setTag(viewHolder);
|
| | | } else {
|
| | | viewHolder = (ViewHolder) convertView.getTag();
|
| | | }
|
| | | viewHolder.textView.setText(mList.get(position)+"");
|
| | | return convertView;
|
| | | }
|
| | |
|
| | | static class ViewHolder {
|
| | | TextView textView;
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | |
|
| | | }
|