Android Open Source - Android-Fast-ImageLoader Proxy Util






From Project

Back to project page Android-Fast-ImageLoader.

License

The source code is released under:

Apache License

If you think the Android project Android-Fast-ImageLoader 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 com.sunny.net;
// w w  w. j  a va  2s  . co  m
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
import org.apache.http.HttpHost;
import org.apache.http.client.HttpClient;
import org.apache.http.conn.params.ConnRoutePNames;

import java.net.InetSocketAddress;


public class ProxyUtil {

    /* 2014-04-03 Kang, Leo ???????????? */
    private static final String HTTP_PROXY_HOST = "http.proxyHost";
    private static final String HTTP_PROXY_PORT = "http.proxyPort";

    /**
     * Set APN for HTTP Client. Use old way to get host and port.
     *
     * @param httpClient
     * @param context
     */
    public static void setProxyHttpHost(HttpClient httpClient, Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        HttpHost proxyhost = null;
        if (networkInfo != null
                && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {

            if (proxyhost == null) {
                final String port = System.getProperty(HTTP_PROXY_PORT);
                int p = -1;
                String host;
                if ((!TextUtils.isEmpty(port)) && TextUtils.isDigitsOnly(port)) {
                    p = Integer.valueOf(port);
                }
                // GPRS: APN http proxy
                host = System.getProperty(HTTP_PROXY_HOST);
                if (!TextUtils.isEmpty(host) && p > 0) {
                    proxyhost = new HttpHost(host, p);
                }
            }
            if (proxyhost != null) {
                httpClient.getParams().setParameter(
                        ConnRoutePNames.DEFAULT_PROXY, proxyhost);
            }
        }
    }

    public static java.net.Proxy getProxy(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        java.net.Proxy result = null;
        if (networkInfo != null
                && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {

            if (result == null) {
                final String port = System.getProperty(HTTP_PROXY_PORT);
                int p = -1;
                String host;
                if ((!TextUtils.isEmpty(port)) && TextUtils.isDigitsOnly(port)) {
                    p = Integer.valueOf(port);
                }
                // GPRS: APN http proxy
                host = System.getProperty(HTTP_PROXY_HOST);
                if (!TextUtils.isEmpty(host) && p > 0) {
                    result = new java.net.Proxy(java.net.Proxy.Type.HTTP,
                            new InetSocketAddress(host, p));
                }
            }
        }
        return result;
    }

}




Java Source Code List

com.sunny.cache.BaseLoadListener.java
com.sunny.cache.CacheWorker.java
com.sunny.cache.DiskLruCache.java
com.sunny.cache.FileLastModifSort.java
com.sunny.cache.GIFDecoder.java
com.sunny.cache.IDownloadHandler.java
com.sunny.cache.MemoryCache.java
com.sunny.cache.OnSetImageListener.java
com.sunny.cache.RecyclingBitmapDrawable.java
com.sunny.cache.ThumbnailLoader.java
com.sunny.net.DHttpClient.java
com.sunny.net.ProxyUtil.java
com.sunny.threadpool.AbstractCommand.java
com.sunny.threadpool.CommandFactory.java
com.sunny.threadpool.DThreadPool.java
com.sunny.threadpool.IDThreadPool.java
com.sunny.threadpool.IPriorityTask.java
com.sunny.threadpool.ITaskHandler.java
com.sunny.threadpool.PriorityTask.java
com.sunny.threadpool.PriorityThreadFactory.java
com.sunny.threadpool.TaskPriority.java
com.sunny.util.ImageUtil.java
com.sunny.util.MD5Util.java
com.sunny.util.Utils.java