Search in sources :

Example 1 with ProvinceEntity

use of com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity in project AndroidPicker by gzu-liyujiang.

the class TextAddressParser method parseData.

@NonNull
@Override
public List<ProvinceEntity> parseData(@NonNull String text) {
    provinces.clear();
    String[] fullCodeAndNames = text.split(";");
    for (String fullCodeAndName : fullCodeAndNames) {
        String[] codeAndName = fullCodeAndName.split(",");
        if (codeAndName.length != 2) {
            continue;
        }
        String code = codeAndName[0];
        String name = codeAndName[1];
        if (code.startsWith("0000", 2)) {
            // 省份
            ProvinceEntity province = new ProvinceEntity();
            province.setCode(code);
            province.setName(name);
            province.setCityList(new ArrayList<>());
            provinces.add(province);
        } else if (code.startsWith("00", 4)) {
            // 地市
            ProvinceEntity province = findProvinceByCode(code.substring(0, 2));
            if (province != null) {
                CityEntity city = new CityEntity();
                city.setCode(code);
                city.setName(name);
                city.setCountyList(new ArrayList<>());
                province.getCityList().add(city);
            }
        } else {
            // 区县
            CityEntity city = findCityByCode(code.substring(0, 2), code.substring(2, 4));
            if (city != null) {
                CountyEntity county = new CountyEntity();
                county.setCode(code);
                county.setName(name);
                city.getCountyList().add(county);
            }
        }
    }
    return provinces;
}
Also used : CountyEntity(com.github.gzuliyujiang.wheelpicker.entity.CountyEntity) ArrayList(java.util.ArrayList) CityEntity(com.github.gzuliyujiang.wheelpicker.entity.CityEntity) ProvinceEntity(com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity) NonNull(androidx.annotation.NonNull)

Example 2 with ProvinceEntity

use of com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity in project AndroidPicker by gzu-liyujiang.

the class AddressPicker method onOk.

@Override
protected void onOk() {
    if (onAddressPickedListener != null) {
        ProvinceEntity province = wheelLayout.getFirstWheelView().getCurrentItem();
        CityEntity city = wheelLayout.getSecondWheelView().getCurrentItem();
        CountyEntity county = wheelLayout.getThirdWheelView().getCurrentItem();
        onAddressPickedListener.onAddressPicked(province, city, county);
    }
}
Also used : CountyEntity(com.github.gzuliyujiang.wheelpicker.entity.CountyEntity) CityEntity(com.github.gzuliyujiang.wheelpicker.entity.CityEntity) ProvinceEntity(com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity)

Example 3 with ProvinceEntity

use of com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity in project AndroidPicker by gzu-liyujiang.

the class AddressJsonParser method parseProvince.

private List<ProvinceEntity> parseProvince(JSONArray provinceArray) {
    List<ProvinceEntity> data = new ArrayList<>();
    for (int i = 0, x = provinceArray.length(); i < x; i++) {
        ProvinceEntity provinceEntity = new ProvinceEntity();
        JSONObject provinceObject = provinceArray.optJSONObject(i);
        provinceEntity.setCode(provinceObject.optString(builder.provinceCodeField));
        provinceEntity.setName(provinceObject.optString(builder.provinceNameField));
        provinceEntity.setCityList(new ArrayList<>());
        JSONArray cityArray = provinceObject.optJSONArray(builder.provinceChildField);
        parseCity(provinceEntity, cityArray);
        data.add(provinceEntity);
    }
    return data;
}
Also used : JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ProvinceEntity(com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity)

Example 4 with ProvinceEntity

use of com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity in project AndroidPicker by gzu-liyujiang.

the class CustomAddressPicker method onClick.

@Override
public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.wheel_picker_address_cancel) {
        dismiss();
        return;
    }
    if (id == R.id.wheel_picker_address_confirm) {
        if (onAddressPickedListener != null) {
            ProvinceEntity province = wheelLayout.getFirstWheelView().getCurrentItem();
            CityEntity city = wheelLayout.getSecondWheelView().getCurrentItem();
            CountyEntity county = wheelLayout.getThirdWheelView().getCurrentItem();
            onAddressPickedListener.onAddressPicked(province, city, county);
        }
        dismiss();
    }
}
Also used : CountyEntity(com.github.gzuliyujiang.wheelpicker.entity.CountyEntity) CityEntity(com.github.gzuliyujiang.wheelpicker.entity.CityEntity) ProvinceEntity(com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity)

Aggregations

ProvinceEntity (com.github.gzuliyujiang.wheelpicker.entity.ProvinceEntity)4 CityEntity (com.github.gzuliyujiang.wheelpicker.entity.CityEntity)3 CountyEntity (com.github.gzuliyujiang.wheelpicker.entity.CountyEntity)3 ArrayList (java.util.ArrayList)2 NonNull (androidx.annotation.NonNull)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1