From 8ce7cb3e54852a7ee0b03ee339f4ce05d7e3107c Mon Sep 17 00:00:00 2001 From: "JungWon, Kim" Date: Wed, 20 Jan 2021 23:33:05 +0900 Subject: [PATCH 1/6] Update README.md --- README.md | 100 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 79 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 35b87ee..d3c933c 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,89 @@ # PhillipsHue Android Library -Feature +How to use it ====== -1. connect bridge -2. get list of lights -3. turn on or off the lights -4. change hue & color of lights - -Requirement -====== -1. you should add this properties to application manifests - -```xml - - +## 1. get bridge list in your network +```kotlin +private fun initBridgeList() { + CoroutineScope(Dispatchers.Main).launch { + // you can get bridge list in your network + val bridgeList = BridgeManager().getBridgeList() + } +} ``` -2. if you want to use remote hue api, you should set this at Android WebView - +## 2. get token for controlling philips hue bulbs ```kotlin -// HueLoginActivity.kt -hue_login_web_view.settings.userAgentString = System.getProperty("http.agent") -hue_login_web_view.webViewClient = HueWebViewClient { - //something to do after philips hue login - finish() +private fun fetchLightList() { + val bridgeIp = Bridge.internalIpAddress + val lightController = BridgeController(bridgeIp) + + CoroutineScope(Dispatchers.Main).launch { + try { + // if you click the link button, you can get a token! + token: String = lightController.getToken() + ... + } catch (exception: Exception) { + // it will throw UnClickBridgeLinkButtonException + // if you have not clicked the bridge link button + // so if the exception is thrown, you should deliver the message like "click the bridge button" } + } +} + +``` +## 3. get light list +```kotlin +CoroutineScope(Dispatchers.Main).launch { + val lightList:List = lightController.getLights(token) +} +``` +## 4. turn on the light +```kotlin +CoroutineScope(Dispatchers.Main).launch { + //you can get light id from Light.kt + lightController.turnOn(token, lightId, turnOn) +} +``` +## 5. change hue & color of lights +```kotlin +// use ColorInt +CoroutineScope(Dispatchers.Main).launch { + lightController.changeColor( + token, + lightId, + //ColorInt + selectColor + ) +} +// use RGB +CoroutineScope(Dispatchers.Main).launch { + lightController.changeRGBColor( + token, + lightId, + red = Color.red(colorInt) + green = Color.green(colorInt) + blue = Color.blue(colorInt) + ) +} +// use HSV +CoroutineScope(Dispatchers.Main).launch { + val hsv = FloatArray(3) + + Color.colorToHSV(Color.rgb(red, green, blue), hsv) + val brightness = (hsv[2] * 255).toInt() + val saturation = (hsv[1] * 255).toInt() + val hue = ((hsv[0] * 65535) / 360).toInt() + + lightController.changeHSVColor( + token, + lightId, + hue = hue, + saturation = saturation, + brightness = brightness + ) +} + ``` License From e85a8d63447d118513566146c5b5306acb7cf1a5 Mon Sep 17 00:00:00 2001 From: "JungWon, Kim" Date: Wed, 20 Jan 2021 23:33:54 +0900 Subject: [PATCH 2/6] Update README.md --- README.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d3c933c..a37bb48 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # PhillipsHue Android Library - -How to use it ====== -## 1. get bridge list in your network + +## How to use it + +### 1. get bridge list in your network ```kotlin private fun initBridgeList() { CoroutineScope(Dispatchers.Main).launch { @@ -12,7 +13,7 @@ private fun initBridgeList() { } ``` -## 2. get token for controlling philips hue bulbs +### 2. get token for controlling philips hue bulbs ```kotlin private fun fetchLightList() { val bridgeIp = Bridge.internalIpAddress @@ -32,20 +33,20 @@ private fun fetchLightList() { } ``` -## 3. get light list +### 3. get light list ```kotlin CoroutineScope(Dispatchers.Main).launch { val lightList:List = lightController.getLights(token) } ``` -## 4. turn on the light +### 4. turn on the light ```kotlin CoroutineScope(Dispatchers.Main).launch { //you can get light id from Light.kt lightController.turnOn(token, lightId, turnOn) } ``` -## 5. change hue & color of lights +### 5. change hue & color of lights ```kotlin // use ColorInt CoroutineScope(Dispatchers.Main).launch { @@ -86,7 +87,7 @@ CoroutineScope(Dispatchers.Main).launch { ``` -License +# License ======= Copyright 2019 Reno. From 0896dd6aecc487a47b5e66dac893019aa8e2357c Mon Sep 17 00:00:00 2001 From: "JungWon, Kim" Date: Wed, 20 Jan 2021 23:34:09 +0900 Subject: [PATCH 3/6] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index a37bb48..68a3a4f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ # PhillipsHue Android Library -====== ## How to use it From 5a0a10a17c94c317db4f3813a711e2fbcd177bd8 Mon Sep 17 00:00:00 2001 From: "JungWon, Kim" Date: Wed, 20 Jan 2021 23:34:23 +0900 Subject: [PATCH 4/6] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 68a3a4f..80b9e4f 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,6 @@ CoroutineScope(Dispatchers.Main).launch { ``` # License -======= Copyright 2019 Reno. From e9d2786d16d45e340b9f46d6a5a325667b662b7e Mon Sep 17 00:00:00 2001 From: "JungWon, Kim" Date: Wed, 20 Jan 2021 23:38:06 +0900 Subject: [PATCH 5/6] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 80b9e4f..d64a834 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## How to use it -### 1. get bridge list in your network +### 1. get bridge list in your network ([MainActivity.kt line: 38](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/MainActivity.kt)) ```kotlin private fun initBridgeList() { CoroutineScope(Dispatchers.Main).launch { @@ -12,7 +12,7 @@ private fun initBridgeList() { } ``` -### 2. get token for controlling philips hue bulbs +### 2. get token for controlling philips hue bulbs ([BridgeControlActivity.kr line: 93](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) ```kotlin private fun fetchLightList() { val bridgeIp = Bridge.internalIpAddress @@ -32,20 +32,20 @@ private fun fetchLightList() { } ``` -### 3. get light list +### 3. get light list ([BridgeControlActivity.kr line: 100](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) ```kotlin CoroutineScope(Dispatchers.Main).launch { val lightList:List = lightController.getLights(token) } ``` -### 4. turn on the light +### 4. turn on the light ([BridgeControlActivity.kr line: 46](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) ```kotlin CoroutineScope(Dispatchers.Main).launch { //you can get light id from Light.kt lightController.turnOn(token, lightId, turnOn) } ``` -### 5. change hue & color of lights +### 5. change hue & color of lights ([BridgeControlActivity.kr line: 64](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) ```kotlin // use ColorInt CoroutineScope(Dispatchers.Main).launch { From b6836d814745cf9254dea2c79a50407cd329928f Mon Sep 17 00:00:00 2001 From: "JungWon, Kim" Date: Wed, 20 Jan 2021 23:38:34 +0900 Subject: [PATCH 6/6] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d64a834..b501795 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ private fun initBridgeList() { } ``` -### 2. get token for controlling philips hue bulbs ([BridgeControlActivity.kr line: 93](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) +### 2. get token for controlling philips hue bulbs ([BridgeControlActivity.kt line: 93](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) ```kotlin private fun fetchLightList() { val bridgeIp = Bridge.internalIpAddress @@ -32,20 +32,20 @@ private fun fetchLightList() { } ``` -### 3. get light list ([BridgeControlActivity.kr line: 100](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) +### 3. get light list ([BridgeControlActivity.kt line: 100](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) ```kotlin CoroutineScope(Dispatchers.Main).launch { val lightList:List = lightController.getLights(token) } ``` -### 4. turn on the light ([BridgeControlActivity.kr line: 46](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) +### 4. turn on the light ([BridgeControlActivity.kt line: 46](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) ```kotlin CoroutineScope(Dispatchers.Main).launch { //you can get light id from Light.kt lightController.turnOn(token, lightId, turnOn) } ``` -### 5. change hue & color of lights ([BridgeControlActivity.kr line: 64](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) +### 5. change hue & color of lights ([BridgeControlActivity.kt line: 64](https://github.com/renovatio0424/PhilipsHueSampleApp/blob/master/app/src/main/java/com/reno/philipshuesampleapp/BridgeControlActivity.kt)) ```kotlin // use ColorInt CoroutineScope(Dispatchers.Main).launch {