diff --git a/README.md b/README.md index 3415860..8a4e4bd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # FoscamAPI -Easily connect to Foscam IP camera's with this lightweight Java library. One command is all it takes. -FoscamAPI is suitable for all the HD cameras, including FI9821W, FI9818W, FI9801W, FI9802W and FI9805W. +Easily connect to Foscam IP cameras with this lightweight Java library. One command is all it takes. +FoscamAPI is suitable for all the IP cameras, including FI9821W, FI9818W, FI9801W, FI9802W, FI9805W and FosBaby P1. It is tested on the FI9900P. ## Example @@ -28,6 +28,20 @@ camera.setSharpness(90); ``` +## Gradle dependency +```gradle +repositories { + maven { + url "https://raw.github.com/hypothermic/foscamapi/mvn-repo/" + } +} + +dependencies { + // Note: use 'api' instead of 'compile' if you're using Android Studio. + compile group: 'nl.hypothermic', name: 'foscamlib', version: '1.07-RELEASE' +} +``` + ## Features Here is a full list of commands: @@ -193,6 +207,36 @@ Here is a full list of commands: - getPTZPrePointForSelfTest(); - setPTZPrePointForSelfTest(name); +// Cloud & push controls (not supported by 3518A based cameras) +- getCloudConfig(); +- setCloudConfig(...); +- getCloudServer(); +- setCloudServer(...); +- testCloudServer(); +- refreshCloudToken(); +- refreshCloudQuota(); +- getCloudStreamLevel(); +- setCloudStreamLevel(0-100); +- getCloudAuthcode(); +- isCloudEnabled(); + +- getPushConfig(); +- setPushConfig(...); +- getPushServer(); +- setPushServer(...); +- testPushServer(); +- sendPush(...); +- isPushEnabled(); + +// Miscellaneous controls (not supported by all platforms, see javadoc!) +- getHumidity(); +- getNightlightState(); +- setNightlightState(true/false); +- getLedState(); +- setLedState(true/false); +- getHDRState(); +- setHDRState(true/false); + // Deprecated, kept for backwards compatibility - doesCameraSupportOnvif(); - doesCameraSupportRtsp(); @@ -201,6 +245,13 @@ Here is a full list of commands: See [javadoc](https://hypothermic.nl/foscamlib/javadoc/) for more information and details about these features. ## Changelog +v1.08 +- Added cloud controls +- Added push controls +- Added night light controls +- Added humidity getter +- Added HDR controls + v1.07 - Added storage controls - Added audio volume controls @@ -264,6 +315,8 @@ If you are having issues with FoscamAPI or any component: ## Mentions FoscamAPI (previously named FoscamLib) is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Shenzhen Foscam Intelligent Technology Limited, or any of its subsidiaries or its affiliates. The official Foscam website can be found at https://www.foscam.com. The name “Foscam” as well as related names, marks, emblems and images are registered trademarks of Shenzhen Foscam Intelligent Technology Limited. +If there are any legal issues, please contact me via GitHub or email (admin@hypothermic.nl) + ## License The license can be found [here](./LICENSE.txt) or in the root folder of the project. diff --git a/pom.xml b/pom.xml index 9825e6b..2988906 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 nl.hypothermic foscamlib - 1.07-RELEASE + 1.08-RELEASE FoscamAPI https://github.com/hypothermic/foscamapi Java Library for Foscam IP camera's. diff --git a/src/main/java/nl/hypothermic/foscamlib/Foscam.java b/src/main/java/nl/hypothermic/foscamlib/Foscam.java index e44e59e..576be4a 100644 --- a/src/main/java/nl/hypothermic/foscamlib/Foscam.java +++ b/src/main/java/nl/hypothermic/foscamlib/Foscam.java @@ -9,6 +9,8 @@ import nl.hypothermic.foscamlib.containers.AccessPoint; import nl.hypothermic.foscamlib.containers.Account; +import nl.hypothermic.foscamlib.containers.CloudConfig; +import nl.hypothermic.foscamlib.containers.CloudConfig.CloudServer; import nl.hypothermic.foscamlib.containers.Credentials; import nl.hypothermic.foscamlib.containers.DeviceInfo; import nl.hypothermic.foscamlib.containers.FTPConfig; @@ -18,6 +20,10 @@ import nl.hypothermic.foscamlib.containers.PTZSelfTestMode; import nl.hypothermic.foscamlib.containers.PTZSpeed; import nl.hypothermic.foscamlib.containers.PortInfo; +import nl.hypothermic.foscamlib.containers.PushCommand; +import nl.hypothermic.foscamlib.containers.PushConfig; +import nl.hypothermic.foscamlib.containers.PushConfig.PushServer; +import nl.hypothermic.foscamlib.containers.PushDevice; import nl.hypothermic.foscamlib.containers.SnapConfig; import nl.hypothermic.foscamlib.containers.SnapConfig.PicQuality; import nl.hypothermic.foscamlib.containers.SnapConfig.SaveLocation; @@ -2391,4 +2397,366 @@ public Double getTemperatureFahrenheit() { } return 32 + (Double.parseDouble(p.getTagValue(out.xml, "degree")) * 9 / 5); } + + /** + * Get cloud config + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @return CloudConfig instance + */ + public CloudConfig getCloudConfig() { + RxData out = nm.exec("getCloudConfig", null); + if (out.result != Result.SUCCESS) { + return null; + } + return new CloudConfig(p.getTagValue(out.xml, "isEnable"), CloudServer.match(p.getTagValue(out.xml, "cloudServer")), + p.getTagValue(out.xml, "code"), p.getTagValue(out.xml, "authAddr"), p.getTagValue(out.xml, "accessToken"), + p.getTagValue(out.xml, "quota"), p.getTagValue(out.xml, "userd"), p.getTagValue(out.xml, "statusMsg")); + } + + /** + * Set cloud config + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @param CloudConfig instance, only the final members (isEnabled, server, authCode) need to be assigned with values. + * @return boolean if change succeeded or not + */ + public boolean setCloudConfig(final CloudConfig config) { + RxData out = nm.exec("setCloudConfig", new HashMap() {{ + put("isEnable", config.isEnabled); + put("cloudServer", config.server.getValue() + ""); + put("code", config.authCode); + }}); + return out.result == Result.SUCCESS; + } + + /** + * Test if cloud is enabled + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @return True or false. Can return null if error occurred. + */ + public Boolean isCloudEnabled() { + RxData out = nm.exec("getCloudConfig", null); + if (out.result != Result.SUCCESS) { + return null; + } + return p.getTagValue(out.xml, "isEnable").equals("1"); + } + + /** + * Get current Cloud Server + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @return CloudServer instance + */ + public CloudServer getCloudServer() { + RxData out = nm.exec("getCloudConfig", null); + if (out.result != Result.SUCCESS) { + return null; + } + return CloudServer.match(p.getTagValue(out.xml, "cloudServer")); + } + + /** + * Set Cloud Server + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @param CloudServer instance + * @return boolean if change succeeded or not + */ + public boolean setCloudServer(final CloudServer server) { + RxData out = nm.exec("selectCloudServer", new HashMap() {{ + //put("isEnable", 1 & Boolean.hashCode(isCloudEnabled()) >> 1 + ""); + put("isEnable", (isCloudEnabled() ? 1 : 0) + ""); + put("cloudServer", server.getValue() + ""); + }}); + return out.result == Result.SUCCESS; + } + + /** + * Get authentication code from cloud server + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @return Authentication code from server + */ + public String getCloudAuthcode() { + RxData out = nm.exec("getCloudConfig", null); + if (out.result != Result.SUCCESS) { + return null; + } + return p.getTagValue(out.xml, "code"); + } + + /** + * Refresh cloud token + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + *
NOTE: Call this function, then call getCloudConfig 10s later to find accessToken + * @return True if refresh succeeded, false if not succeeded + */ + public boolean refreshCloudToken() { + final String authcode = this.getCloudAuthcode(); + if (authcode.equals("")) { + return false; // cloud not set up correctly + } + RxData out = nm.exec("getCloudToken", new HashMap() {{ + put("isEnable", (isCloudEnabled() ? 1 : 0) + ""); + put("cloudServer", getCloudServer().getValue() + ""); + put("code", authcode); + }}); + if (out.result != Result.SUCCESS) { + return false; + } + return true; + } + + /** + * Refresh cloud quota and userd + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + *
NOTE: Call this function, then call getCloudConfig 10s later to find quota and userd + * @return True if refresh succeeded, false if not succeeded + */ + public boolean refreshCloudQuota() { + RxData out = nm.exec("getCloudQuota", new HashMap() {{ + put("isEnable", (isCloudEnabled() ? 1 : 0) + ""); + put("cloudServer", getCloudServer().getValue() + ""); + }}); + if (out.result != Result.SUCCESS) { + return false; + } + return true; + } + + /** + * Refresh cloud quota and userd + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + *
NOTE: Call this function, then call getCloudConfig 10s later to find statusMsg + * @return True if refresh succeeded, false if not succeeded + */ + public boolean testCloudServer() { + RxData out = nm.exec("testCloudServer", new HashMap() {{ + put("isEnable", (isCloudEnabled() ? 1 : 0) + ""); + put("cloudServer", getCloudServer().getValue() + ""); + }}); + if (out.result != Result.SUCCESS) { + return false; + } + return true; + } + + /** + * Get cloud stream level + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @return Integer between 0-100 + */ + public Integer getCloudStreamLevel() { + RxData out = nm.exec("getCloudStreamLevel", null); + if (out.result != Result.SUCCESS) { + return null; + } + return Integer.parseInt(p.getTagValue(out.xml, "level")); + } + + /** + * Set cloud stream level + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @param value cloud stream level (0-100) + * @return boolean if change succeeded or not + */ + public boolean setCloudStreamLevel(final int value) { + if (value < 0 || value > 100) { + return false; + } + RxData out = nm.exec("setCloudStreamLevel", new HashMap() {{ put("level", value + ""); }}); + return out.result == Result.SUCCESS; + } + + /** + * Get push config + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @return PushConfig instance + */ + public PushConfig getPushConfig() { + RxData out = nm.exec("getPushConfig", null); + if (out.result != Result.SUCCESS) { + return null; + } + return new PushConfig(p.getTagValue(out.xml, "isEnable"), PushServer.match(p.getTagValue(out.xml, "pushServer")), p.getTagValue(out.xml, "statusMsg")); + } + + /** + * Set push config + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @param PushConfig instance, only the final members (isEnabled and server) need to be assigned with values. + * @return boolean if change succeeded or not + */ + public boolean setPushConfig(final PushConfig config) { + RxData out = nm.exec("setPushConfig", new HashMap() {{ + put("isEnable", config.isEnabled); + put("pushServer", config.server.getValue() + ""); + }}); + return out.result == Result.SUCCESS; + } + + /** + * Test if push is enabled + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @return True if enabled, false if disabled, null if error occurred + */ + public Boolean isPushEnabled() { + RxData out = nm.exec("getPushConfig", null); + if (out.result != Result.SUCCESS) { + return null; + } + return p.getTagValue(out.xml, "isEnable").equals("1"); + } + + /** + * Get push server + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @return PushServer instance, can return null if it's not set properly! + */ + public PushServer getPushServer() { + RxData out = nm.exec("getPushConfig", null); + if (out.result != Result.SUCCESS) { + return null; + } + System.out.println("DEBUG: " + p.getTagValue(out.xml, "pushServer")); + return PushServer.match(p.getTagValue(out.xml, "pushServer")); + } + + /** + * Set push server + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @param server PushServer instance + * @return boolean if change succeeded or not + */ + public boolean setPushServer(final PushServer server) { + RxData out = nm.exec("setPushConfig", new HashMap() {{ + //put("isEnable", 1 & Boolean.hashCode(isPushEnabled()) >> 1 + ""); + put("isEnable", (isPushEnabled() ? 1 : 0) + ""); + put("pushServer", server.getValue() + ""); + }}); + return out.result == Result.SUCCESS; + } + + /** + * Test push server + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + *
NOTE: Call this function, then call getPushConfig 10s later to find statusMsg + * @return True if refresh succeeded, false if not succeeded + */ + public boolean testPushServer() { + final PushServer ps = getPushServer(); + if (ps == null) { + return false; // user did not setup push correctly + } + RxData out = nm.exec("testPushServer", new HashMap() {{ + put("isEnable", (isCloudEnabled() ? 1 : 0) + ""); + put("pushServer", ps.getValue() + ""); + }}); + if (out.result != Result.SUCCESS) { + return false; + } + return true; + } + + /** + * Send push (equivalent to pushOperate) + *

NOTE: Platform dependent, does not work on camera's with the 3518A chipset! + * @param command PushCommand instance + * @return boolean if change succeeded or not + */ + public boolean sendPush(final PushCommand command, final PushDevice device, final int channelId, final int userId) { + RxData out = nm.exec("pushOperate", new HashMap() {{ + put("cmd_oper", command.getValue() + ""); + put("device_type", device.getValue() + ""); + put("channel_id", channelId + ""); + put("user_id", userId + ""); + }}); + return out.result == Result.SUCCESS; + } + + /** + * Get humidity in % + *

NOTE: Platform dependent, check if your camera has a humidity sensor. It is only confirmed working on FosBaby_P1 and FI9900P! + * @return Integer between 0-100, null if error occurred + */ + public Integer getHumidity() { + RxData out = nm.exec("getHumidityState", null); + if (out.result != Result.SUCCESS) { + return null; + } + return Integer.parseInt(p.getTagValue(out.xml, "humidity")); + } + + /** + * Get Night Light state + *

NOTE: Platform dependent, it is only confirmed working on FosBaby_P1! + *
NOTE: Untested + * @return True if night light is enabled, false if disabled, null if error occured + */ + public Boolean getNightlightState() { + RxData out = nm.exec("getNightLightState", null); + if (out.result != Result.SUCCESS) { + return null; + } + return p.getTagValue(out.xml, "state").contains("1"); + } + + /** + * Set Night Light state + *

NOTE: Platform dependent, it is only confirmed working on FosBaby_P1! + *
NOTE: Untested + * @param state New state to assign to the Night Light + * @return True if succeeded, false if not succeeded or error occured. + */ + public Boolean setNightlightState(final boolean state) { + RxData out = nm.exec("setNightLightState", new HashMap() {{ put("state", (state ? 1 : 0) + ""); }}); + return out.result == Result.SUCCESS; + } + + /** + * Get state of System and Net LED's + *

NOTE: Platform dependent, it is only confirmed working on FosBaby_P1 and FI9900P! + *
NOTE: Untested + * @return True if LED's are enabled, false if disabled, null if error occured + */ + public Boolean getLedState() { + RxData out = nm.exec("getLedEnableState", null); + if (out.result != Result.SUCCESS) { + return null; + } + return p.getTagValue(out.xml, "isEnable").contains("1"); + } + + /** + * Set state of System and Net LED's + *

NOTE: Platform dependent, it is only confirmed working on FosBaby_P1 and FI9900P! + *
NOTE: Untested + * @param state New state to assign to the LED's + * @return True if succeeded, false if not succeeded or error occured. + */ + public Boolean setLedState(final boolean state) { + RxData out = nm.exec("setLedEnableState", new HashMap() {{ put("mode", (state ? 1 : 0) + ""); }}); + return out.result == Result.SUCCESS; + } + + /** + * Get state of HDR + *

NOTE: Platform dependent, it is only confirmed working on FosBaby_P1 and FI9900P! + * @return True if HDR is enabled, false if disabled, null if error occured + */ + public Boolean getHDRState() { + RxData out = nm.exec("getHdrMode", null); + if (out.result != Result.SUCCESS) { + return null; + } + return p.getTagValue(out.xml, "mode").contains("1"); + } + + /** + * Set state of HDR + *

NOTE: Platform dependent, it is only confirmed working on FosBaby_P1 and FI9900P! + * @param state New state to assign to the HDR + * @return True if succeeded, false if not succeeded or error occured. + */ + public Boolean setHDRState(final boolean state) { + RxData out = nm.exec("setHdrMode", new HashMap() {{ put("mode", (state ? 1 : 0) + ""); }}); + return out.result == Result.SUCCESS; + } } diff --git a/src/main/java/nl/hypothermic/foscamlib/containers/CloudConfig.java b/src/main/java/nl/hypothermic/foscamlib/containers/CloudConfig.java new file mode 100644 index 0000000..0049775 --- /dev/null +++ b/src/main/java/nl/hypothermic/foscamlib/containers/CloudConfig.java @@ -0,0 +1,82 @@ +package nl.hypothermic.foscamlib.containers; + +/******************************\ + * > CloudConfig.java < * + * FoscamAPI by hypothermic * + * www.github.com/hypothermic * +\******************************/ + +public class CloudConfig { + + // Javadoc comments are directly from the user guide + + /** Is cloud enabled (0-1) */ + public final String isEnabled; + /** Status message from cloud server
NOTE: Call testCloudServer() to find this */ + public String statusMsg; + /** Current cloud server */ + public final CloudServer server; + /** Authorization addr to server */ + public String authAddr; + /** Authorization code from server */ + public final String authCode; + /** Access Token from authorization code
NOTE: Call refreshCloudToken() to find this */ + public String accessToken; + /** Cloud storage total size
NOTE: Call refreshCloudQuota() to find this */ + public String quota; + /** Cloud storage userd size
NOTE: Call refreshCloudQuota() to find this */ + public String userd; + + public CloudConfig(final String isEnabled, final CloudServer server, final String authCode) { + this.isEnabled = isEnabled; + this.server = server; + this.authCode = authCode; + } + + public CloudConfig(final String isEnabled, final CloudServer server, final String authCode, final String authAddr, + final String accessToken, final String quota, final String userd, final String statusMsg) { + this.isEnabled = isEnabled; + this.server = server; + this.authCode = authCode; + this.authAddr = authAddr; + this.accessToken = accessToken; + this.quota = quota; + this.userd = userd; + this.statusMsg = statusMsg; + } + + /** + * CloudServer enum + */ + public static enum CloudServer { + DROPBOX(1), + BAIDU(2); + + private final int value; + + private CloudServer(final int value) { + this.value = value; + } + + /** + * Returns int value of CloudServer instance + * @return int value of CloudServer instance + */ + public int getValue() { + return this.value; + } + + public static CloudServer fromInt(int value) { + for (CloudServer l : CloudServer.values()) { + if (l.value == value) return l; + } + throw new IllegalArgumentException("Not found."); + } + + public static CloudServer match(String value) { + if (value.contains("1")) return DROPBOX; + if (value.contains("2")) return BAIDU; + return null; + } + } +} diff --git a/src/main/java/nl/hypothermic/foscamlib/containers/PushCommand.java b/src/main/java/nl/hypothermic/foscamlib/containers/PushCommand.java new file mode 100644 index 0000000..0bc5e3c --- /dev/null +++ b/src/main/java/nl/hypothermic/foscamlib/containers/PushCommand.java @@ -0,0 +1,81 @@ +package nl.hypothermic.foscamlib.containers; + +import nl.hypothermic.foscamlib.containers.PushConfig.PushServer; + +/******************************\ + * > PushCommand.java < * + * FoscamAPI by hypothermic * + * www.github.com/hypothermic * +\******************************/ + +/** + * Enum of Push Commands with their respective integers attached. + */ +public enum PushCommand { + + // Javadoc comments are directly from the user guide + + /** Register App device */ + REGISTER_APP_DEVICE(1), + /** Unregister App device */ + UNREGISTER_APP_DEVICE(2), + /** Test device */ + TEST_DEVICE(3), + /** Register tag */ + REGISTER_TAG(4), + /** Push msg to single app device */ + PUSH_TO_APP_DEVICE(5), + /** Push msg to tag */ + PUSH_TO_TAG(6); + + private final int value; + + private PushCommand(final int value) { + this.value = value; + } + + /** + * Returns int value of PushCommand instance + */ + public int getValue() { + return this.value; + } + + /** + * Get PushCommand instance from int + * @param x int to get PushCommand instance from + * @return PushCommand instance or null if error + */ + public static PushCommand match(int x) { + switch(x) { + case 1: + return REGISTER_APP_DEVICE; + case 2: + return UNREGISTER_APP_DEVICE; + case 3: + return TEST_DEVICE; + case 4: + return REGISTER_TAG; + case 5: + return PUSH_TO_APP_DEVICE; + case 6: + return PUSH_TO_TAG; + } + return null; + } + + /** + * Get PushCommand instance from String + * @param value String to get PushCommand instance from + * @return PushCommand instance or null if error + */ + public static PushCommand match(String value) { + if (value.contains("1")) return REGISTER_APP_DEVICE; + if (value.contains("2")) return UNREGISTER_APP_DEVICE; + if (value.contains("3")) return TEST_DEVICE; + if (value.contains("4")) return REGISTER_TAG; + if (value.contains("5")) return PUSH_TO_APP_DEVICE; + if (value.contains("6")) return PUSH_TO_TAG; + return null; + } +} \ No newline at end of file diff --git a/src/main/java/nl/hypothermic/foscamlib/containers/PushConfig.java b/src/main/java/nl/hypothermic/foscamlib/containers/PushConfig.java new file mode 100644 index 0000000..14160d4 --- /dev/null +++ b/src/main/java/nl/hypothermic/foscamlib/containers/PushConfig.java @@ -0,0 +1,63 @@ +package nl.hypothermic.foscamlib.containers; + +/******************************\ + * > PushConfig.java < * + * FoscamAPI by hypothermic * + * www.github.com/hypothermic * +\******************************/ + +public class PushConfig { + + /** Is push enabled (0-1) */ + public final String isEnabled; + /** Current push server */ + public final PushServer server; + /** Status message from cloud server
NOTE: Call testPushServer() to find this */ + public String statusMsg; + + public PushConfig(final String isEnabled, final PushServer server) { + this.isEnabled = isEnabled; + this.server = server; + } + + public PushConfig(final String isEnabled, final PushServer server, final String statusMsg) { + this.isEnabled = isEnabled; + this.server = server; + this.statusMsg = statusMsg; + } + + /** + * PushServer enum + */ + public static enum PushServer { + + // Why is there only one PushServer lol? Hello Foscam? + BAIDU(1); + + private final int value; + + private PushServer(final int value) { + this.value = value; + } + + /** + * Returns int value of PushServer instance + * @return int value of PushServer instance + */ + public int getValue() { + return this.value; + } + + public static PushServer fromInt(int value) { + for (PushServer l : PushServer.values()) { + if (l.value == value) return l; + } + throw new IllegalArgumentException("Not found."); + } + + public static PushServer match(String value) { + if (value.contains("1")) return BAIDU; + return null; + } + } +} diff --git a/src/main/java/nl/hypothermic/foscamlib/containers/PushDevice.java b/src/main/java/nl/hypothermic/foscamlib/containers/PushDevice.java new file mode 100644 index 0000000..09cc3b1 --- /dev/null +++ b/src/main/java/nl/hypothermic/foscamlib/containers/PushDevice.java @@ -0,0 +1,74 @@ +package nl.hypothermic.foscamlib.containers; + +/******************************\ + * > PushDevice.java < * + * FoscamAPI by hypothermic * + * www.github.com/hypothermic * +\******************************/ + +/** + * Enum of Push Device Types with their respective integers attached. + */ +public enum PushDevice { + + // Javadoc comments are directly from the user guide + + /** Web browsers */ + WEB_BROWSER(1), + /** PC */ + PC(2), + /** Android */ + ANDROID(3), + /** iOS */ + IOS(4), + /** Windows Phone */ + WINDOWS_PHONE(5); + + private final int value; + + private PushDevice(final int value) { + this.value = value; + } + + /** + * Returns int value of PushDevice instance + */ + public int getValue() { + return this.value; + } + + /** + * Get PushDevice instance from int + * @param x int to get PushDevice instance from + * @return PushDevice instance or null if error + */ + public static PushDevice match(int x) { + switch(x) { + case 1: + return WEB_BROWSER; + case 2: + return PC; + case 3: + return ANDROID; + case 4: + return IOS; + case 5: + return WINDOWS_PHONE; + } + return null; + } + + /** + * Get PushDevice instance from String + * @param value String to get PushDevice instance from + * @return PushDevice instance or null if error + */ + public static PushDevice match(String value) { + if (value.contains("1")) return WEB_BROWSER; + if (value.contains("2")) return PC; + if (value.contains("3")) return ANDROID; + if (value.contains("4")) return IOS; + if (value.contains("5")) return WINDOWS_PHONE; + return null; + } +} \ No newline at end of file