package com.game.webgame.network;



import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.util.prefs.Preferences;

import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.HttpParams;


import android.annotation.SuppressLint;
import android.content.Context;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.HttpClientStack;
import com.android.volley.toolbox.HttpStack;
import com.android.volley.toolbox.Volley;
import com.tsgame.tsgame_niuniu.system.Myapplication;

import okhttp3.OkHttpClient;

public class volleymanager {
	private static volleymanager mInstance = null;

	private static RequestQueue mRequestQueue;

	@SuppressLint("NewApi") @SuppressWarnings("deprecation")
	private volleymanager(Context context) {


		 
//		 DefaultHttpClient httpclient = new DefaultHttpClient();
		 OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
    	 //�ǳ־û��洢(�ڴ�洢) BasicCookieStore | �־û��洢 PreferencesCookieStore
//    	 CookieStore cookieStore = new BasicCookieStore();
//    	 httpclient.setCookieStore(cookieStore);
//    	 HttpStack httpStack = new HttpClientStack(httpclient);
//         mRequestQueue = Volley.newRequestQueue(context.getApplicationContext(),httpStack);
         
		 
		 CookieManager manager= new CookieManager(new volleypreferencesCookie(context), CookiePolicy.ACCEPT_ALL);
	     CookieHandler.setDefault(manager);
	     
		
		 
//		 DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
//		 ClientConnectionManager mClientConnectionManager = defaultHttpClient.getConnectionManager();
//		 HttpParams mHttpParams = defaultHttpClient.getParams();
//		 ThreadSafeClientConnManager mThreadSafeClientConnManager = new ThreadSafeClientConnManager( mHttpParams,       
//		 mClientConnectionManager.getSchemeRegistry() );
//		 defaultHttpClient = new DefaultHttpClient( mThreadSafeClientConnManager, mHttpParams );
//		 CookieStore cookieStore = new PreferencesCookieStore( context );
//		 defaultHttpClient.setCookieStore( cookieStore );
//		 HttpStack httpStack = new HttpClientStack( defaultHttpClient );
		 
		 mRequestQueue =
		 Volley.newRequestQueue(context.getApplicationContext());
	}

	public static synchronized volleymanager getInstance() {
		if (mInstance == null) {
			mInstance = new volleymanager(Myapplication.application);
		}
		return mInstance;
	}

	public RequestQueue getmRequestQueue() {
		if (mRequestQueue == null) {
			mRequestQueue = Volley.newRequestQueue(Myapplication.application
					.getApplicationContext());
		}

		return mRequestQueue;
	}

}
