From 13837feb8b9fde43ed481200fca0db2a8b8cb698 Mon Sep 17 00:00:00 2001
From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期六, 01 四月 2017 10:05:20 +0800
Subject: [PATCH] 

---
 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/CountrySelectionDialog.java |  148 ++++++++++++++++++++++--------------------------
 1 files changed, 68 insertions(+), 80 deletions(-)

diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/CountrySelectionDialog.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/CountrySelectionDialog.java
index 7993c4d..50ce1e8 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/CountrySelectionDialog.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/dialog/CountrySelectionDialog.java
@@ -3,7 +3,6 @@
 import android.content.Context;
 import android.graphics.Color;
 import android.graphics.drawable.ColorDrawable;
-import android.support.v7.widget.AppCompatTextView;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
@@ -14,73 +13,85 @@
 import com.bsk.zhangbo.demoforbsk.R;
 import cn.com.basic.face.adapter.MyWheelAdapter;
 
-import cn.com.basic.face.listeners.OkButtonClickedListener;
-import cn.com.basic.face.util.CountryPresenter;
+import cn.com.basic.face.util.OkButtonClickedListener;
 
+import com.lidroid.xutils.ViewUtils;
+import com.lidroid.xutils.view.annotation.ViewInject;
+import com.lidroid.xutils.view.annotation.event.OnClick;
 import com.wx.wheelview.widget.WheelView;
 
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 
-/**
- * Created by Sinoe on 2017/2/28.
- */
+public class CountrySelectionDialog extends PopupWindow implements WheelView.OnWheelItemSelectedListener {
 
-public class CountrySelectionDialog extends PopupWindow implements View.OnClickListener, WheelView.OnWheelItemSelectedListener {
-    private Context mContext;
+    @ViewInject(R.id.dialog_country_ok)
+    private TextView dialog_country_ok;
+    @ViewInject(R.id.dialog_country_cancel)
+    private TextView dialog_country_cancel;
+    @ViewInject(R.id.dialog_country_name_first_letter)
+    private WheelView dialog_country_name_first_letter;
+    @ViewInject(R.id.dialog_country_name)
+    private WheelView dialog_country_name;
+
     private View view;
-    private TextView mTvConfirm, mTvCancel;
-    private WheelView mWheelViewTitle, mWheelViewName;
-    private HashMap<String, List<String>> countryData;
-    private List<String> countryWordList;
-    private List<String> countryList;
-    private CountryPresenter countryPresenter;
+    private static HashMap<String, List<String>> countriesGroupByFirstLetter = new HashMap<>();
+    private static List<String> uniqueFirstLetterList = new ArrayList<>();
+    private List<String> countriesWithSameFirstLetter = new ArrayList<>();
 
-    public CountrySelectionDialog(Context context, String[] countryWordData, List<String> countryWordList, HashMap<String, List<String>> countryData) {
+    public static void setCountries(List<String> _uniqueFirstLetterList, HashMap<String, List<String>> _countriesGroupByFirstLetter) {
+        uniqueFirstLetterList = _uniqueFirstLetterList;
+        countriesGroupByFirstLetter = _countriesGroupByFirstLetter;
+    }
 
-        this.mContext = context;
-        countryPresenter = new CountryPresenter(context);
+    @OnClick(R.id.dialog_country_ok)
+    public void dialog_country_ok_click(View view) {
+        for (OkButtonClickedListener okButtonClickedListener : okButtonClickedListeners) {
+            if (dialog_country_name_first_letter.getCurrentPosition() >= 0) {
+                countriesWithSameFirstLetter = countriesGroupByFirstLetter.get(uniqueFirstLetterList.get(dialog_country_name_first_letter.getCurrentPosition()));
+                okButtonClickedListener.onItemSelected(0, null, countriesWithSameFirstLetter.get(dialog_country_name.getCurrentPosition()));
+            }
+        }
+        dismiss();
+    }
+
+    @OnClick(R.id.dialog_country_cancel)
+    public void dialog_country_cancel_click(View view) {
+        dismiss();
+    }
+
+    public CountrySelectionDialog(Context context, OkButtonClickedListener okButtonClickedListener) {
         view = LayoutInflater.from(context).inflate(R.layout.dialog_country, null);
-        mWheelViewTitle = (WheelView) view.findViewById(R.id.pop_country_title);
-        mWheelViewTitle.setOnWheelItemSelectedListener(this);
-        mWheelViewName = (WheelView) view.findViewById(R.id.pop_country_name);
-        mWheelViewName.setOnWheelItemSelectedListener(this);
-        mTvCancel = (TextView) view.findViewById(R.id.pop_country_cancel);
-        mTvConfirm = (TextView) view.findViewById(R.id.pop_country_confirm);
-        mTvCancel.setOnClickListener(this);
-        mTvConfirm.setOnClickListener(this);
+        ViewUtils.inject(this, view);
 
-        //String[] countryWordData = DictionaryMng.countryWordData;
-        this.countryWordList = countryWordList;//DictionaryMng.countryWordList;
-        this.countryData = countryData;//DictionaryMng.countryData;
+        this.countriesWithSameFirstLetter = countriesGroupByFirstLetter.get(uniqueFirstLetterList.get(dialog_country_name_first_letter.getSelection()));
 
-        countryList = countryData.get(countryWordList.get(mWheelViewTitle.getSelection()));
+        WheelView.WheelViewStyle wheelViewStyle = new WheelView.WheelViewStyle();
+        wheelViewStyle.selectedTextColor = Color.parseColor("#11c3e3");
+        wheelViewStyle.textColor = Color.parseColor("#bcc6cf");
+        wheelViewStyle.selectedTextSize = 22;
+        wheelViewStyle.textSize = 16;
+        wheelViewStyle.holoBorderColor = Color.parseColor("#11c3e3");
 
-        mWheelViewTitle.setWheelAdapter(new MyWheelAdapter(context));
-        mWheelViewTitle.setSkin(WheelView.Skin.Holo);
-        mWheelViewTitle.setWheelSize(5);
-        mWheelViewTitle.setBackgroundResource(R.color.colorBackground);
-        mWheelViewName.setWheelAdapter(new MyWheelAdapter(context));
-        mWheelViewName.setSkin(WheelView.Skin.Holo);
-        mWheelViewName.setWheelSize(5);
-        mWheelViewName.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");
-        mWheelViewTitle.setStyle(style);
-        mWheelViewName.setStyle(style);
+        dialog_country_name_first_letter.setWheelAdapter(new MyWheelAdapter(context));
+        dialog_country_name_first_letter.setSkin(WheelView.Skin.Holo);
+        dialog_country_name_first_letter.setWheelSize(5);
+        dialog_country_name_first_letter.setBackgroundResource(R.color.colorBackground);
+        dialog_country_name_first_letter.setStyle(wheelViewStyle);
+
+        dialog_country_name.setWheelAdapter(new MyWheelAdapter(context));
+        dialog_country_name.setSkin(WheelView.Skin.Holo);
+        dialog_country_name.setWheelSize(5);
+        dialog_country_name.setBackgroundResource(R.color.colorBackground);
+        dialog_country_name.setStyle(wheelViewStyle);
+
         initData();
-        //澶栭儴鍙偣鍑�
-        setOutsideTouchable(true);
 
         view.setOnTouchListener(new View.OnTouchListener() {
             @Override
             public boolean onTouch(View view, MotionEvent motionEvent) {
-                View popLayout = view.findViewById(R.id.pop_single_ll);
+                View popLayout = view.findViewById(R.id.dialog_country_linear_layout);
                 int top = popLayout.getTop();
                 int bottom = popLayout.getBottom();
                 int left = popLayout.getLeft();
@@ -100,50 +111,27 @@
             }
         });
 
-        /*
-             璁剧疆绐楀彛鐗瑰緛
-         */
-        //璁剧疆瑙嗗浘
+        this.setOutsideTouchable(true);
+        this.setFocusable(true);
         this.setContentView(this.view);
-        //璁剧疆绐楀彛瀹介珮
         this.setHeight(RelativeLayout.LayoutParams.MATCH_PARENT);
         this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
-        //璁剧疆寮瑰嚭绐楀彛鍙偣鍑�
-        this.setFocusable(true);
-        //瀹炰緥鍖朇olor
-        ColorDrawable colorDrawable = new ColorDrawable(0x7f000000);
-        this.setBackgroundDrawable(colorDrawable);
+        this.setBackgroundDrawable(new ColorDrawable(0x7f000000));
         this.setAnimationStyle(R.style.PopupAnimation);
-    }
 
-    @Override
-    public void onClick(View view) {
-        if (view instanceof AppCompatTextView) {
-            if (((AppCompatTextView) view).getText().equals("纭")) {
-                for (OkButtonClickedListener okButtonClickedListener : okButtonClickedListeners) {
-                    if (mWheelViewTitle.getCurrentPosition() >= 0) {
-                        countryList = countryData.get(countryWordList.get(mWheelViewTitle.getCurrentPosition()));
-                        okButtonClickedListener.onItemSelected(0, null, countryList.get(mWheelViewName.getCurrentPosition()));
-                    }
-                }
-                dismiss();
-            }
-            if (((AppCompatTextView) view).getText().equals("鍙栨秷")) {
-                dismiss();
-            }
-        }
+        okButtonClickedListeners.add(okButtonClickedListener);
     }
 
     @Override
     public void onItemSelected(int position, Object o) {
-        countryList = countryData.get(countryWordList.get(mWheelViewTitle.getCurrentPosition()));
+        countriesWithSameFirstLetter = countriesGroupByFirstLetter.get(uniqueFirstLetterList.get(dialog_country_name_first_letter.getCurrentPosition()));
     }
 
     private void initData() {
-        mWheelViewTitle.setWheelData(countryWordList);
-        mWheelViewTitle.join(mWheelViewName);
-        mWheelViewTitle.joinDatas(countryData);
-        mWheelViewName.setWheelData(countryList);
+        dialog_country_name_first_letter.setWheelData(uniqueFirstLetterList);
+        dialog_country_name_first_letter.join(dialog_country_name);
+        dialog_country_name_first_letter.joinDatas(countriesGroupByFirstLetter);
+        dialog_country_name.setWheelData(countriesWithSameFirstLetter);
     }
 
     private List<OkButtonClickedListener> okButtonClickedListeners = new ArrayList<OkButtonClickedListener>();

--
Gitblit v1.8.0