package cn.ccy.test_weather.ui;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.ccy.test_weather.R;
import cn.ccy.test_weather.ShowWeatherView;
import cn.ccy.test_weather_model.WeatherDetail;

public class TodayFragment extends Fragment {

	public static TextView ShowWeatherCurrent;
	public static TextView ShowWeatherToday;
	public static TextView ShowupdateTime;
	private static String weatherToday = "";
	private static String weatherCurrent = "";
	private static String updateTime = "";
	private static String[] str;
	WeatherDetail info;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		info = ShowWeatherView.wd;

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {

		View parentView = inflater.inflate(R.layout.today_fragment, container,
				false);
		LinearLayout weatherView = (LinearLayout) parentView
				.findViewById(R.id.weatherView1);
		ShowupdateTime = (TextView) parentView.findViewById(R.id.updateTime);
		ShowWeatherCurrent = (TextView) parentView
				.findViewById(R.id.weatherCurrent);
		ShowWeatherToday = (TextView) parentView
				.findViewById(R.id.weatherToday);
		Resources resources = this.getResources();
		if (info != null) {
			if (info.getAll().indexOf("有雨") != -1) {
				Drawable drawable = resources.getDrawable(R.drawable.rain);
				weatherView.setBackground(drawable);
				ShowupdateTime.setTextColor(this.getResources().getColor(
						R.color.white));
				ShowWeatherCurrent.setTextColor(this.getResources().getColor(
						R.color.white));
			} else if (info.getAll().indexOf("无雨") != -1) {
				Drawable drawable = resources.getDrawable(R.drawable.sunny);
				weatherView.setBackground(drawable);
				ShowupdateTime.setTextColor(this.getResources().getColor(
						R.color.sunny));
			}

			updateTime = "更新时间： " + info.getUpdateTime();
			str = info.getWeatherCurrent().split("；");
			weatherCurrent = str[0].substring(0,6)+"\n\n"+str[0].substring(7,str[0].length())+"\n\n"+str[1]+"\n\n"+str[2];
			// 解析今天的天气情况
	
			ShowupdateTime.setText(updateTime);
			ShowWeatherCurrent.setText(weatherCurrent);
		}
		return parentView;
	}

}
