package cn.ccy.test_weather.utils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import android.content.Context;

public class GetProvinceOrCity {
	public static Properties prop;
	public static List<String> ProvinceList;
	public static List<String> CityList;
	public static FileInputStream fis;

	public static List<String> getProvinceMsg(Context context)
			throws IOException {
		prop = new Properties();
		try {
			fis = context.openFileInput("ProvinceOrCityMsg");
			prop.load(fis);

		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			e.printStackTrace();
		}
		fis.close();
		// 读取文件，将省份添加入选择列表
		String s = prop.getProperty("Provinces").toString();
		s = s.substring(1, s.length() - 1);
		String[] str = s.split(", ");
		ProvinceList = new ArrayList<String>();
		for (int i = 0; i < str.length; i++) {
			ProvinceList.add(str[i]);
		}

		return ProvinceList;

	}

	public static List<String> getCityMsg(String province)
			throws IOException {
//		System.out.println("prop.isEmpty()??????????????" + prop.isEmpty()
//				+ province);
		String s = prop.getProperty(province).toString();
		s = s.substring(1, s.length() - 1);
		String[] str = s.split(", ");
		CityList = new ArrayList<String>();
		for (int i = 0; i < str.length; i++) {
			CityList.add(str[i]);
		}
		return CityList;

	}

}
