package com.example.http;

import java.util.ArrayList;
import java.util.List;

import com.example.kechengbiao.Fir_MainActivity;
import com.example.kechengbiao.MainActivity;
import com.example.utils.ParseHtml;
import com.example.utils.Student;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ShareActionProvider;

public class KVAsyncTask extends AsyncTask<Void, Void, String> {

	HttpUtils httpUtils;
	String id,pwd;
	Fir_MainActivity activity;
	Student student;
	ArrayList<String[]> kc_list;
	public KVAsyncTask(Context context, String id,String pwd){
		this.id= id;
		this.pwd = pwd;
		activity = (Fir_MainActivity) context;
	}
	protected void onPreExecute() {
		// TODO Auto-generated method stub
		httpUtils = new HttpUtils();		
	}
	
	protected String doInBackground(Void... params) {
		String result = httpUtils.set(id, pwd);
		
		return result;
	}
	/**
	 * 解析网页内容，并把解析出的数据，保存起来
	 */
	protected void onPostExecute(String result) {
		
		
		SharedPreferences preferences = activity.getSharedPreferences("STU_DATA", Activity.MODE_PRIVATE);
		
		//System.out.println("result->"+result);
		ParseHtml paseHtml = new ParseHtml(result);
		paseHtml.parseHtml();
		student = paseHtml.getStu();
		kc_list = paseHtml.getKc_Strs();
		//保存数据
		Editor editor =preferences.edit();//YX,ZY,XH,XM
		editor.putString("YX", student.getYX())
		.putString("ZY", student.getZY())
		.putString("XH", student.getXH())
		.putString("XM", student.getXM())
		.commit();
		Intent intent = new Intent();
		intent.putExtra("KC_List", paseHtml.kc_List2);
		intent.setClass(activity, MainActivity.class);
		activity.startActivity(intent);
	}

	protected void onProgressUpdate(Void... values) {
		// TODO Auto-generated method stub
		super.onProgressUpdate(values);
	}
 
}
