// Path: xframe/src/main/java/com/youth/xframe/utils/http/HttpCallBack.java
// public abstract class HttpCallBack<Result> {
// 
//     public abstract void onSuccess(Result result);
// 
//     public abstract void onFailed(String error);
// 
// }
// 
// Path: xframe/src/main/java/com/youth/xframe/utils/http/IHttpEngine.java
// public interface IHttpEngine {
// 
//     void get(String url, Map<String,Object> params,HttpCallBack callBack);
// 
//     void post(String url, Map<String,Object> params,HttpCallBack callBack);
// }
// 
// Path: xframe/src/main/java/com/youth/xframe/utils/http/XHttp.java
// public class XHttp implements IHttpEngine {
// 
//     private static IHttpEngine httpEngine;
//     private static XHttp xHttp;
//     public static XHandler handler = new XHandler();
// 
//     public static void init(IHttpEngine engine){
//         httpEngine=engine;
//     }
// 
//     public static XHttp obtain(){
//         if (httpEngine==null){
//             throw new NullPointerException("Call XFrame.initXHttp(IHttpEngine httpEngine) within your Application onCreate() method." +
//                     "Or extends XApplication");
//         }
//         if (xHttp == null) {
//             xHttp = new XHttp();
//         }
//         return xHttp;
//     }
// 
//     /**
//      * 获取实体类的类型
//      * @param obj
//      * @return
//      */
//     public static Class<?> analysisClassInfo(Object obj){
//         Type genType=obj.getClass().getGenericSuperclass();
//         Type[] params=((ParameterizedType)genType).getActualTypeArguments();
//         return (Class<?>) params[0];
//     }
// 
//     @Override
//     public void get(String url, Map<String, Object> params, HttpCallBack callBack) {
//         httpEngine.get(url,params,callBack);
//     }
// 
//     @Override
//     public void post(String url, Map<String, Object> params, HttpCallBack callBack) {
//         httpEngine.post(url,params,callBack);
//     }
// }


import com.alibaba.fastjson.JSON;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.youth.xframe.utils.http.HttpCallBack;
import com.youth.xframe.utils.http.IHttpEngine;
import com.youth.xframe.utils.http.XHttp;
import java.util.Map;
import cz.msebera.android.httpclient.Header;
package com.youth.xf.http;





/**
 * AsyncHttp简单实现，你可修改，这只是案例
 */
public class AsyncHttpEngine implements IHttpEngine {
    private AsyncHttpClient client;

    public AsyncHttpEngine() {
        client = new AsyncHttpClient();
    }

    @Override
    public void get(String url, Map<String, Object> params, final HttpCallBack callBack) {
        RequestParams requestParams = new RequestParams();
        if(null!=params) {
            for (String key : params.keySet()) {
                requestParams.put(key, params.get(key));
            }
        }
        client.get(url, requestParams, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                String result=new String(responseBody);
                Class<?> cls= XHttp.analysisClassInfo(callBack);
                //我这里使用的是fastjson，你也可以用gson，jackjson等
                callBack.onSuccess(JSON.parseObject(result,cls));
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                callBack.onFailed(error.toString());
            }
// Path: xframe/src/main/java/com/youth/xframe/utils/http/HttpCallBack.java
// public abstract class HttpCallBack<Result> {
// 
//     public abstract void onSuccess(Result result);
// 
//     public abstract void onFailed(String error);
// 
// }
// 
// Path: xframe/src/main/java/com/youth/xframe/utils/http/IHttpEngine.java
// public interface IHttpEngine {
// 
//     void get(String url, Map<String,Object> params,HttpCallBack callBack);
// 
//     void post(String url, Map<String,Object> params,HttpCallBack callBack);
// }
// 
// Path: xframe/src/main/java/com/youth/xframe/utils/http/XHttp.java
// public class XHttp implements IHttpEngine {
// 
//     private static IHttpEngine httpEngine;
//     private static XHttp xHttp;
//     public static XHandler handler = new XHandler();
// 
//     public static void init(IHttpEngine engine){
//         httpEngine=engine;
//     }
// 
//     public static XHttp obtain(){
//         if (httpEngine==null){
//             throw new NullPointerException("Call XFrame.initXHttp(IHttpEngine httpEngine) within your Application onCreate() method." +
//                     "Or extends XApplication");
//         }
//         if (xHttp == null) {
//             xHttp = new XHttp();
//         }
//         return xHttp;
//     }
// 
//     /**
//      * 获取实体类的类型
//      * @param obj
//      * @return
//      */
//     public static Class<?> analysisClassInfo(Object obj){
//         Type genType=obj.getClass().getGenericSuperclass();
//         Type[] params=((ParameterizedType)genType).getActualTypeArguments();
//         return (Class<?>) params[0];
//     }
// 
//     @Override
//     public void get(String url, Map<String, Object> params, HttpCallBack callBack) {
//         httpEngine.get(url,params,callBack);
//     }
// 
//     @Override
//     public void post(String url, Map<String, Object> params, HttpCallBack callBack) {
//         httpEngine.post(url,params,callBack);
//     }
// }


// Path: app/src/main/java/com/youth/xf/http/AsyncHttpEngine.java
import com.alibaba.fastjson.JSON;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.youth.xframe.utils.http.HttpCallBack;
import com.youth.xframe.utils.http.IHttpEngine;
import com.youth.xframe.utils.http.XHttp;
import java.util.Map;
import cz.msebera.android.httpclient.Header;

package com.youth.xf.http;





/**
 * AsyncHttp简单实现，你可修改，这只是案例
 */
public class AsyncHttpEngine implements IHttpEngine {
    private AsyncHttpClient client;

    public AsyncHttpEngine() {
        client = new AsyncHttpClient();
    }

    @Override
    public void get(String url, Map<String, Object> params, final HttpCallBack callBack) {
        RequestParams requestParams = new RequestParams();
        if(null!=params) {
            for (String key : params.keySet()) {
                requestParams.put(key, params.get(key));
            }
        }
        client.get(url, requestParams, new AsyncHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                String result=new String(responseBody);
                Class<?> cls= XHttp.analysisClassInfo(callBack);
                //我这里使用的是fastjson，你也可以用gson，jackjson等
                callBack.onSuccess(JSON.parseObject(result,cls));
            }

            @Override
            public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                callBack.onFailed(error.toString());
            }
        });