Android Open Source - KangarooImageSearch Utils






From Project

Back to project page KangarooImageSearch.

License

The source code is released under:

MIT License

If you think the Android project KangarooImageSearch 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.nickrasband.kangarooimagesearchv2;
/* ww w .  ja v a 2  s.  c o  m*/
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Collections;
import java.util.List;
import java.util.Locale;

import org.apache.http.conn.util.InetAddressUtils;

/**
 * I found this as an example on StackExchange. It allows me to access the client's url.
 * I really didn't want to write all of this code myself.
 * @author Nik Rasband
 *
 */
public class Utils {
  /**
     * Get IP address from first non-localhost interface
     * @param ipv4  true=return ipv4, false=return ipv6
     * @return  address or empty string
     */
  public static String getIPAddress(boolean useIPv4) {
        try {
            List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
            for (NetworkInterface intf : interfaces) {
                List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
                for (InetAddress addr : addrs) {
                    if (!addr.isLoopbackAddress()) {
                        String sAddr = addr.getHostAddress().toUpperCase(Locale.US);
                        boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr); 
                        if (useIPv4) {
                            if (isIPv4) 
                                return sAddr;
                        } else {
                            if (!isIPv4) {
                                int delim = sAddr.indexOf('%'); // drop ip6 port suffix
                                return delim<0 ? sAddr : sAddr.substring(0, delim);
                            }
                        }
                    }
                }
            }
        } catch (Exception ex) { } // for now eat exceptions
        return "";
    }
}




Java Source Code List

com.nickrasband.kangarooimagesearchv2.EndlessScrollListener.java
com.nickrasband.kangarooimagesearchv2.FullScreenImageActivity.java
com.nickrasband.kangarooimagesearchv2.ImageDataAdapter.java
com.nickrasband.kangarooimagesearchv2.ImageData.java
com.nickrasband.kangarooimagesearchv2.ImageSearchActivity.java
com.nickrasband.kangarooimagesearchv2.SettingsActivity.java
com.nickrasband.kangarooimagesearchv2.SettingsData.java
com.nickrasband.kangarooimagesearchv2.Utils.java