content: package com.freecoders.photobook.network;
  
  import android.content.Context;
  
  import com.android.volley.DefaultRetryPolicy;
  import com.android.volley.Request;
  import com.android.volley.RequestQueue;
  import com.android.volley.RetryPolicy;
  import com.android.volley.toolbox.HurlStack;
  import com.android.volley.toolbox.Volley;
  
  import java.io.IOException;
  import java.net.HttpURLConnection;
  import java.net.InetSocketAddress;
  import java.net.Proxy;
  import java.net.URL;
  
  import test.ServerInterfaceTest;
  
  public class VolleySingleton {
  	private static VolleySingleton mInstance;
      private RequestQueue mRequestQueue;
      private static Context mCtx;
  
      private VolleySingleton(Context context) {
          mCtx = context;
          mRequestQueue = getRequestQueue();
      }
  
      public static synchronized VolleySingleton getInstance(Context context) {
          if (mInstance == null) {
              mInstance = new VolleySingleton(context);
          }
          return mInstance;
      }
  
      public RequestQueue getRequestQueue() {
          if (mRequestQueue == null) {
              // getApplicationContext() is key, it keeps you from leaking the
              // Activity or BroadcastReceiver if someone passes one in.
              mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
          }
          return mRequestQueue;
      }
  
      public <T> void addToRequestQueue(Request<T> req) {
          int socketTimeout = 90000;
          RetryPolicy policy = new DefaultRetryPolicy(socketTimeout,
                  DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                  DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
          req.setRetryPolicy(policy);
          getRequestQueue().add(req);
      }
  
      public class ProxiedHurlStack extends HurlStack {
          @Override
          protected HttpURLConnection createConnection(URL url) throws IOException {
              Proxy proxy = new Proxy(Proxy.Type.HTTP,
                      InetSocketAddress.createUnresolved(ServerInterfaceTest.strProxyHost,
                              ServerInterfaceTest.intProxyPort));
              HttpURLConnection returnThis = (HttpURLConnection) url
                      .openConnection(proxy);
              return returnThis;
          }
      }
  }
  