Android Open Source - LibGeppa Device Info






From Project

Back to project page LibGeppa.

License

The source code is released under:

Apache License

If you think the Android project LibGeppa 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 net.cattaka.libgeppa.data;
//from   ww  w .j a  v  a2s . c o m
import net.cattaka.libgeppa.Constants;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

public class DeviceInfo implements Parcelable {
    private static final String KEY_DEVICE_TYPE = "deviceType";

    private static final String KEY_USB_DEVICE_KEY = "usbDeviceKey";

    private static final String KEY_TCP_HOSTNAME = "tcpHostname";

    private static final String KEY_TCP_PORT = "tcpPort";

    private static final String KEY_SUPPORT_CAMERA = "supportCamera";

    public enum DeviceType {
        DUMMY, SERVICE, USB, TCP;
        public static DeviceType valueOfOrdinal(int ordinal) {
            for (DeviceType t : values()) {
                if (t.ordinal() == ordinal) {
                    return t;
                }
            }
            return DUMMY;
        }
    }

    private DeviceType mDeviceType;

    private String mUsbDeviceKey;

    private String mTcpHostName;

    private int mTcpPort;

    private boolean mSupportCamera;

    public static DeviceInfo createDummy(boolean supportCamera) {
        DeviceInfo info = new DeviceInfo();
        info.mDeviceType = DeviceType.DUMMY;
        info.mSupportCamera = supportCamera;
        return info;
    }

    public static DeviceInfo createUsb(String devicekey, boolean supportCamera) {
        DeviceInfo info = new DeviceInfo();
        info.mDeviceType = DeviceType.USB;
        info.mUsbDeviceKey = devicekey;
        info.mSupportCamera = supportCamera;
        return info;
    }

    public static DeviceInfo createTcp(String hostname, int port, boolean supportCamera) {
        DeviceInfo info = new DeviceInfo();
        info.mDeviceType = DeviceType.TCP;
        info.mTcpHostName = hostname;
        info.mTcpPort = port;
        info.mSupportCamera = supportCamera;
        return info;
    }

    private DeviceInfo() {
        super();
    }

    public String getLabel() {
        switch (mDeviceType) {
            case DUMMY:
                return "DUMMY";
            case SERVICE:
                return "SERVICE";
            case USB:
                return "USB:" + mUsbDeviceKey;
            case TCP:
                return "TCP:" + mTcpHostName + ":" + mTcpPort;
            default:
                return "Unknown";
        }
    }

    public DeviceType getDeviceType() {
        return mDeviceType;
    }

    public String getUsbDeviceKey() {
        return mUsbDeviceKey;
    }

    public String getTcpHostName() {
        return mTcpHostName;
    }

    public int getTcpPort() {
        return mTcpPort;
    }

    public boolean isSupportCamera() {
        return mSupportCamera;
    }

    private <T> boolean equalsValue(T s1, T s2) {
        if (s1 == null) {
            return s2 == null;
        } else {
            return s1.equals(s2);
        }
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof DeviceInfo) {
            DeviceInfo d = (DeviceInfo)o;
            return mDeviceType == o && equalsValue(mUsbDeviceKey, d.mUsbDeviceKey)
                    && equalsValue(mTcpHostName, d.mTcpHostName) && mTcpPort == d.mTcpPort;
        } else {
            return false;
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        Bundle bundle = new Bundle();
        bundle.putInt(KEY_DEVICE_TYPE, mDeviceType.ordinal());
        bundle.putString(KEY_USB_DEVICE_KEY, mUsbDeviceKey);
        bundle.putString(KEY_TCP_HOSTNAME, mTcpHostName);
        bundle.putInt(KEY_TCP_PORT, mTcpPort);
        bundle.putBoolean(KEY_SUPPORT_CAMERA, mSupportCamera);
        dest.writeBundle(bundle);
    }

    public static final Parcelable.Creator<DeviceInfo> CREATOR = new Parcelable.Creator<DeviceInfo>() {
        @Override
        public DeviceInfo[] newArray(int size) {
            return new DeviceInfo[size];
        }

        @Override
        public DeviceInfo createFromParcel(Parcel source) {
            DeviceInfo info = new DeviceInfo();
            Bundle bundle = source.readBundle();
            info.mDeviceType = DeviceType.valueOfOrdinal(bundle.getInt(KEY_DEVICE_TYPE, -1));
            info.mUsbDeviceKey = bundle.getString(KEY_USB_DEVICE_KEY);
            info.mTcpHostName = bundle.getString(KEY_TCP_HOSTNAME);
            info.mTcpPort = bundle.getInt(KEY_TCP_PORT, Constants.DEFAULT_SERVER_PORT);
            info.mSupportCamera = bundle.getBoolean(KEY_SUPPORT_CAMERA);
            return info;
        }
    };

}




Java Source Code List

net.cattaka.libgeppa.ActiveGeppaService.java
net.cattaka.libgeppa.AdkPassiveGeppaService.java
net.cattaka.libgeppa.BluetoothPassiveGeppaService.java
net.cattaka.libgeppa.Constants.java
net.cattaka.libgeppa.GeppaService.java
net.cattaka.libgeppa.IRawSocket.java
net.cattaka.libgeppa.PassiveGeppaService.java
net.cattaka.libgeppa.adapter.AbsConnectionAdapter.java
net.cattaka.libgeppa.adapter.DummyDeviceAdapter.java
net.cattaka.libgeppa.adapter.IDeviceAdapterListener.java
net.cattaka.libgeppa.adapter.IDeviceAdapter.java
net.cattaka.libgeppa.adapter.IDeviceCommandAdapter.java
net.cattaka.libgeppa.adapter.LocalDeviceAdapter.java
net.cattaka.libgeppa.adapter.RemoteDeviceAdapter.java
net.cattaka.libgeppa.binder.ActiveGeppaServiceFuncs.java
net.cattaka.libgeppa.binder.PassiveGeppaServiceFuncs.java
net.cattaka.libgeppa.binder.async.ActiveGeppaServiceFuncsAsync.java
net.cattaka.libgeppa.binder.async.AsyncInterfaceException.java
net.cattaka.libgeppa.binder.async.PassiveGeppaServiceFuncsAsync.java
net.cattaka.libgeppa.bluetooth.BluetoothAdapterFactory.java
net.cattaka.libgeppa.bluetooth.BluetoothAdapterWrapper.java
net.cattaka.libgeppa.bluetooth.BluetoothDeviceWrapper.java
net.cattaka.libgeppa.bluetooth.BluetoothSocketWrapper.java
net.cattaka.libgeppa.bluetooth.IBluetoothAdapter.java
net.cattaka.libgeppa.bluetooth.IBluetoothDevice.java
net.cattaka.libgeppa.bluetooth.IBluetoothSocket.java
net.cattaka.libgeppa.data.BaudRate.java
net.cattaka.libgeppa.data.ConnectionCode.java
net.cattaka.libgeppa.data.ConnectionState.java
net.cattaka.libgeppa.data.DeviceEventCode.java
net.cattaka.libgeppa.data.DeviceInfo.java
net.cattaka.libgeppa.data.DeviceState.java
net.cattaka.libgeppa.data.IPacketFactory.java
net.cattaka.libgeppa.data.IPacket.java
net.cattaka.libgeppa.data.PacketWrapper.java
net.cattaka.libgeppa.data.SocketState.java
net.cattaka.libgeppa.exception.NotImplementedException.java
net.cattaka.libgeppa.net.DummySocketPrepareTask.java
net.cattaka.libgeppa.net.DummySocket.java
net.cattaka.libgeppa.net.PhysicaloidSocketPrepareTask.java
net.cattaka.libgeppa.net.PhysicaloidSocket.java
net.cattaka.libgeppa.net.RemoteSocketPrepareTask.java
net.cattaka.libgeppa.net.RemoteSocket.java
net.cattaka.libgeppa.net.UsbClass.java
net.cattaka.libgeppa.passive.AdkPassiveReceiver.java
net.cattaka.libgeppa.passive.BluetoothPassiveReceiver.java
net.cattaka.libgeppa.passive.IPassiveReceiverListener.java
net.cattaka.libgeppa.passive.IPassiveReceiver.java
net.cattaka.libgeppa.socket.AdkRawSocket.java
net.cattaka.libgeppa.socket.BtRawSocket.java
net.cattaka.libgeppa.thread.ClientThread.java
net.cattaka.libgeppa.thread.ConnectionThread.java
net.cattaka.libgeppa.thread.IConnectionThreadListener.java
net.cattaka.libgeppa.thread.ReceiveThread.java
net.cattaka.libgeppa.thread.ServerThread.java
net.cattaka.libgeppa.util.AidlUtil.java
net.cattaka.libgeppa.util.DeviceUtil.java