|
@@ -1,11 +1,20 @@
|
|
|
package com.sheishuo.app.common.util.location;
|
|
package com.sheishuo.app.common.util.location;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
+import android.graphics.Color;
|
|
|
import android.util.Log;
|
|
import android.util.Log;
|
|
|
-
|
|
|
|
|
|
|
+import android.view.Gravity;
|
|
|
|
|
+import android.view.View;
|
|
|
|
|
+import android.view.ViewGroup;
|
|
|
|
|
+import android.widget.FrameLayout;
|
|
|
|
|
+import android.widget.LinearLayout;
|
|
|
|
|
+
|
|
|
|
|
+import com.bigkoo.pickerview.OptionsPickerView;
|
|
|
|
|
+import com.bigkoo.pickerview.lib.WheelView;
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.Gson;
|
|
|
import com.google.gson.reflect.TypeToken;
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
import com.sheishuo.app.R;
|
|
import com.sheishuo.app.R;
|
|
|
|
|
+import com.sheishuo.app.cache.AccountCache;
|
|
|
import com.sheishuo.app.common.beans.CityDataBean;
|
|
import com.sheishuo.app.common.beans.CityDataBean;
|
|
|
import com.sheishuo.app.common.util.net.INet;
|
|
import com.sheishuo.app.common.util.net.INet;
|
|
|
import com.sheishuo.app.common.util.net.NetImpl;
|
|
import com.sheishuo.app.common.util.net.NetImpl;
|
|
@@ -22,7 +31,9 @@ import java.util.List;
|
|
|
public class CityDataHelper {
|
|
public class CityDataHelper {
|
|
|
static INet net;
|
|
static INet net;
|
|
|
static List<CityDataBean> list;
|
|
static List<CityDataBean> list;
|
|
|
- static List<String> provinces;
|
|
|
|
|
|
|
+ static ArrayList<String> provinces;
|
|
|
|
|
+ static ArrayList<ArrayList<String>> citys;
|
|
|
|
|
+ static ArrayList<ArrayList<ArrayList<String>>> districts;
|
|
|
static HashMap<String,List<String>> provinceCityMap;
|
|
static HashMap<String,List<String>> provinceCityMap;
|
|
|
static HashMap<String,List<String>> cityAreaMap;
|
|
static HashMap<String,List<String>> cityAreaMap;
|
|
|
|
|
|
|
@@ -32,6 +43,9 @@ public class CityDataHelper {
|
|
|
net = new NetImpl();
|
|
net = new NetImpl();
|
|
|
list = new ArrayList<>();
|
|
list = new ArrayList<>();
|
|
|
provinces = new ArrayList<>();
|
|
provinces = new ArrayList<>();
|
|
|
|
|
+ citys = new ArrayList<ArrayList<String>>();
|
|
|
|
|
+ districts = new ArrayList<ArrayList<ArrayList<String>>>();
|
|
|
|
|
+
|
|
|
provinceCityMap = new HashMap<>();
|
|
provinceCityMap = new HashMap<>();
|
|
|
cityAreaMap = new HashMap<>();
|
|
cityAreaMap = new HashMap<>();
|
|
|
|
|
|
|
@@ -50,20 +64,27 @@ public class CityDataHelper {
|
|
|
|
|
|
|
|
|
|
|
|
|
String jsonStr = context.getString(R.string.city_data);
|
|
String jsonStr = context.getString(R.string.city_data);
|
|
|
- list.clear();
|
|
|
|
|
- List<CityDataBean> temp = new Gson().fromJson(jsonStr,new TypeToken<List<CityDataBean>>(){}.getType());
|
|
|
|
|
- list.addAll(temp);
|
|
|
|
|
|
|
+ list = new Gson().fromJson(jsonStr,new TypeToken<List<CityDataBean>>(){}.getType());
|
|
|
|
|
|
|
|
Log.e("size",list.size()+"");
|
|
Log.e("size",list.size()+"");
|
|
|
|
|
|
|
|
for (CityDataBean provinceBean : list){
|
|
for (CityDataBean provinceBean : list){
|
|
|
- List<String> tempList = new ArrayList<>();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ ArrayList<String> cityList = new ArrayList<>();
|
|
|
|
|
+ ArrayList<ArrayList<String>> districtList = new ArrayList<ArrayList<String>>();
|
|
|
|
|
+
|
|
|
for (CityDataBean.CityBean cityBean : provinceBean.getCity()){
|
|
for (CityDataBean.CityBean cityBean : provinceBean.getCity()){
|
|
|
- tempList.add(cityBean.getName());
|
|
|
|
|
|
|
+ cityList.add(cityBean.getName());
|
|
|
|
|
+ districtList.add(cityBean.getArea());
|
|
|
cityAreaMap.put(cityBean.getName(),cityBean.getArea());
|
|
cityAreaMap.put(cityBean.getName(),cityBean.getArea());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
provinces.add(provinceBean.getName());
|
|
provinces.add(provinceBean.getName());
|
|
|
- provinceCityMap.put(provinceBean.getName(),tempList);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ provinceCityMap.put(provinceBean.getName(), cityList);
|
|
|
|
|
+ citys.add(cityList);
|
|
|
|
|
+
|
|
|
|
|
+ districts.add(districtList);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for (String str : getAllProvince()){
|
|
for (String str : getAllProvince()){
|
|
@@ -87,6 +108,10 @@ public class CityDataHelper {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static ArrayList<ArrayList<String>> getAllCity()
|
|
|
|
|
+ {
|
|
|
|
|
+ return citys;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
public static List<String> getArea(String city){
|
|
public static List<String> getArea(String city){
|
|
|
if (cityAreaMap != null && cityAreaMap.containsKey(city)){
|
|
if (cityAreaMap != null && cityAreaMap.containsKey(city)){
|
|
@@ -95,4 +120,96 @@ public class CityDataHelper {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static ArrayList<ArrayList<ArrayList<String>>> getAllDistrict()
|
|
|
|
|
+ {
|
|
|
|
|
+ return districts;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public static void showPickerView(Context context, OptionsPickerView.OnOptionsSelectListener listener) {
|
|
|
|
|
+
|
|
|
|
|
+ int provinceIndex = 0;
|
|
|
|
|
+ String currentProvince = AccountCache.getAccount().getProvince();
|
|
|
|
|
+ if(currentProvince != null)
|
|
|
|
|
+ provinceIndex = CityDataHelper.getAllProvince().indexOf(currentProvince);
|
|
|
|
|
+ provinceIndex = Math.max(provinceIndex, 0);
|
|
|
|
|
+ currentProvince = CityDataHelper.getAllProvince().get(provinceIndex);
|
|
|
|
|
+
|
|
|
|
|
+ int cityIndex = 0;
|
|
|
|
|
+ String currentCity = AccountCache.getAccount().getCity();
|
|
|
|
|
+ if(currentCity != null)
|
|
|
|
|
+ cityIndex = CityDataHelper.getCity(currentProvince).indexOf(currentCity);
|
|
|
|
|
+ cityIndex = Math.max(cityIndex, 0);
|
|
|
|
|
+ currentCity = CityDataHelper.getCity(currentProvince).get(cityIndex);
|
|
|
|
|
+
|
|
|
|
|
+ int districtIndex = 0;
|
|
|
|
|
+ String currentDistrict = AccountCache.getAccount().getDistrict();
|
|
|
|
|
+ if(currentDistrict != null)
|
|
|
|
|
+ districtIndex = CityDataHelper.getArea(currentCity).indexOf(currentDistrict);
|
|
|
|
|
+ districtIndex = Math.max(districtIndex, 0);
|
|
|
|
|
+ currentDistrict = CityDataHelper.getArea(currentCity).get(districtIndex);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ OptionsPickerView pvOptions = new OptionsPickerView.Builder(context, listener)
|
|
|
|
|
+ .setTitleText("请选择城市")
|
|
|
|
|
+ .setCancelText("取消")
|
|
|
|
|
+ .setSubmitText("保存")
|
|
|
|
|
+ .setDividerColor(Color.GRAY)
|
|
|
|
|
+ .setTextColorCenter(Color.GRAY)
|
|
|
|
|
+ .setContentTextSize(13)
|
|
|
|
|
+ .setOutSideCancelable(false)
|
|
|
|
|
+ .setSelectOptions(provinceIndex, cityIndex, districtIndex)
|
|
|
|
|
+ .build();
|
|
|
|
|
+
|
|
|
|
|
+ /*pvOptions.setPicker(options1Items);//一级选择器
|
|
|
|
|
+ pvOptions.setPicker(options1Items, options2Items);//二级选择器*/
|
|
|
|
|
+ pvOptions.setPicker(CityDataHelper.getAllProvince(), CityDataHelper.getAllCity(), CityDataHelper.getAllDistrict());//三级选择器
|
|
|
|
|
+ View view = pvOptions.findViewById(com.bigkoo.pickerview.R.id.optionspicker);
|
|
|
|
|
+ while(view.getParent() != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ if(view.getParent() instanceof View)
|
|
|
|
|
+ {
|
|
|
|
|
+ view = (View) view.getParent();
|
|
|
|
|
+ if(view.getId() == com.bigkoo.pickerview.R.id.content_container)
|
|
|
|
|
+ {
|
|
|
|
|
+ view.setLayoutParams(new FrameLayout.LayoutParams(
|
|
|
|
|
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.BOTTOM
|
|
|
|
|
+ ));
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ ViewGroup.LayoutParams viewLayout = view.getLayoutParams();
|
|
|
|
|
+ viewLayout.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
|
+ view.setLayoutParams(viewLayout);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ LinearLayout optionsPicker = (LinearLayout) pvOptions.findViewById(com.bigkoo.pickerview.R.id.optionspicker);
|
|
|
|
|
+ LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)optionsPicker.getLayoutParams();
|
|
|
|
|
+ layoutParams.height = LinearLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
|
+ optionsPicker.setLayoutParams(layoutParams);
|
|
|
|
|
+
|
|
|
|
|
+ View wv_option1 = optionsPicker.findViewById(com.bigkoo.pickerview.R.id.options1);// 初始化时显示的数据
|
|
|
|
|
+ View wv_option2 = optionsPicker.findViewById(com.bigkoo.pickerview.R.id.options2);
|
|
|
|
|
+ View wv_option3 = optionsPicker.findViewById(com.bigkoo.pickerview.R.id.options3);
|
|
|
|
|
+
|
|
|
|
|
+ ViewGroup.LayoutParams optionLayout = wv_option1.getLayoutParams();
|
|
|
|
|
+ optionLayout.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
|
+ wv_option1.setLayoutParams(optionLayout);
|
|
|
|
|
+
|
|
|
|
|
+ optionLayout = wv_option2.getLayoutParams();
|
|
|
|
|
+ optionLayout.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
|
+ wv_option2.setLayoutParams(optionLayout);
|
|
|
|
|
+
|
|
|
|
|
+ optionLayout = wv_option3.getLayoutParams();
|
|
|
|
|
+ optionLayout.height = ViewGroup.LayoutParams.MATCH_PARENT;
|
|
|
|
|
+ wv_option3.setLayoutParams(optionLayout);
|
|
|
|
|
+
|
|
|
|
|
+ pvOptions.show();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|