Android Open Source - gm-httpengine-studio G M Http Loader






From Project

Back to project page gm-httpengine-studio.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project gm-httpengine-studio listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.gemini.httpengine.library;
/*w ww. j ava 2 s . c om*/
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Loader;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;

import java.lang.ref.WeakReference;

/**
 * Created by geminiwen on 14-7-28.
 */
@TargetApi(11)
public class GMHttpLoader extends Loader<GMHttpResult> implements OnResponseListener{
    private GMHttpService httpService;
    private GMHttpRequest httpRequest;

    private Handler handler;

    private class UIHandler extends Handler {

        private WeakReference<GMHttpLoader> loaderWeakReference;

        public UIHandler(Looper looper, GMHttpLoader loader) {
            super(looper);
            this.loaderWeakReference = new WeakReference<GMHttpLoader>(loader);
        }

        @Override
        public void handleMessage(Message msg) {
            GMHttpLoader loader = this.loaderWeakReference.get();
            if (loader != null) {
                GMHttpResult result = (GMHttpResult) msg.obj;
                loader.deliverResult(result);
            }
        }
    }

    public GMHttpLoader(Context context, GMHttpRequest httpRequest) {
        super(context);
        this.httpService = GMHttpService.getInstance();
        this.httpRequest = httpRequest;
        this.handler = new UIHandler(Looper.getMainLooper(), this);
    }

    @Override
    protected void onStartLoading() {
        this.httpRequest.setOnResponseListener(this);
        this.httpService.executeHttpMethod(this.httpRequest);
    }

    @Override
    public void onResponse(GMHttpResponse response, GMHttpRequest request) {
        GMHttpResult result = new GMHttpResult();
        result.httpRequest = request;
        result.httpResponse = response;
        handler.obtainMessage(0, result)
               .sendToTarget();
    }
}




Java Source Code List

org.gemini.httpengine.examples.LoginAPI.java
org.gemini.httpengine.examples.MainActivity.java
org.gemini.httpengine.library.Config.java
org.gemini.httpengine.library.FormUrlEncodedParser.java
org.gemini.httpengine.library.GMHttpEngine.java
org.gemini.httpengine.library.GMHttpException.java
org.gemini.httpengine.library.GMHttpLoader.java
org.gemini.httpengine.library.GMHttpMethodExecutor.java
org.gemini.httpengine.library.GMHttpParameters.java
org.gemini.httpengine.library.GMHttpRequest.java
org.gemini.httpengine.library.GMHttpResponse.java
org.gemini.httpengine.library.GMHttpResult.java
org.gemini.httpengine.library.GMHttpService.java
org.gemini.httpengine.library.GMModelParser.java
org.gemini.httpengine.library.GMTrustManager.java
org.gemini.httpengine.library.HttpMethod.java
org.gemini.httpengine.library.HttpParameter.java
org.gemini.httpengine.library.HttpRequestParser.java
org.gemini.httpengine.library.HttpResponseParser.java
org.gemini.httpengine.library.LOG.java
org.gemini.httpengine.library.MultiPartParser.java
org.gemini.httpengine.library.MultipartEntity.java
org.gemini.httpengine.library.OnProgressUpdateListener.java
org.gemini.httpengine.library.OnResponseListener.java