watch integration ui #183

Closed
taha.alam wants to merge 2 commits from watch_integration into master

@ -1 +1,110 @@
{"agcgw":{"url":"connect-drcn.dbankcloud.cn","backurl":"connect-drcn.hispace.hicloud.com","websocketurl":"connect-ws-drcn.hispace.dbankcloud.cn","websocketbackurl":"connect-ws-drcn.hispace.dbankcloud.com"},"agcgw_all":{"SG":"connect-dra.dbankcloud.cn","SG_back":"connect-dra.hispace.hicloud.com","CN":"connect-drcn.dbankcloud.cn","CN_back":"connect-drcn.hispace.hicloud.com","RU":"connect-drru.hispace.dbankcloud.ru","RU_back":"connect-drru.hispace.dbankcloud.cn","DE":"connect-dre.dbankcloud.cn","DE_back":"connect-dre.hispace.hicloud.com"},"websocketgw_all":{"SG":"connect-ws-dra.hispace.dbankcloud.cn","SG_back":"connect-ws-dra.hispace.dbankcloud.com","CN":"connect-ws-drcn.hispace.dbankcloud.cn","CN_back":"connect-ws-drcn.hispace.dbankcloud.com","RU":"connect-ws-drru.hispace.dbankcloud.ru","RU_back":"connect-ws-drru.hispace.dbankcloud.cn","DE":"connect-ws-dre.hispace.dbankcloud.cn","DE_back":"connect-ws-dre.hispace.dbankcloud.com"},"client":{"cp_id":"2640966000002322881","product_id":"736430079244816567","client_id":"563735388191982656","client_secret":"650C7C799812AFFD53A10C7756CF05FB9F215A7E49032ABA8EBF3E14B77535CF","project_id":"736430079244816567","app_id":"116912301","api_key":"CgB6e3x9DJzMgRCmnT6dyUEkp6UsIfddb6l3w0ZEXzeiRMHEFi3400Z5fJ5qaHneU0OrAI/JRpk+DMGVs3QpUxlI","package_name":"com.cloudsolutions.HMGPatientApp"},"oauth_client":{"client_id":"116912301","client_type":1},"app_info":{"app_id":"116912301","package_name":"com.cloudsolutions.HMGPatientApp"},"service":{"analytics":{"collector_url":"datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn","collector_url_cn":"datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn","collector_url_de":"datacollector-dre.dt.hicloud.com,datacollector-dre.dt.dbankcloud.cn","collector_url_ru":"datacollector-drru.dt.dbankcloud.ru,datacollector-drru.dt.hicloud.com","collector_url_sg":"datacollector-dra.dt.hicloud.com,datacollector-dra.dt.dbankcloud.cn","resource_id":"p1","channel_id":""},"ml":{"mlservice_url":"ml-api-drcn.ai.dbankcloud.com,ml-api-drcn.ai.dbankcloud.cn"},"cloudstorage":{"storage_url":"https://agc-storage-drcn.platform.dbankcloud.cn","storage_url_ru":"https://agc-storage-drru.cloud.huawei.ru","storage_url_sg":"https://ops-dra.agcstorage.link","storage_url_de":"https://ops-dre.agcstorage.link","storage_url_cn":"https://agc-storage-drcn.platform.dbankcloud.cn","storage_url_ru_back":"https://agc-storage-drru.cloud.huawei.ru","storage_url_sg_back":"https://agc-storage-dra.cloud.huawei.asia","storage_url_de_back":"https://agc-storage-dre.cloud.huawei.eu","storage_url_cn_back":"https://agc-storage-drcn.cloud.huawei.com.cn"},"search":{"url":"https://search-drcn.cloud.huawei.com"},"edukit":{"edu_url":"edukit.cloud.huawei.com.cn","dh_url":"edukit.cloud.huawei.com.cn"}},"region":"CN","configuration_version":"3.0","appInfos":[{"package_name":"com.cloudsolutions.HMGPatientApp","client":{"app_id":"116912301"},"app_info":{"package_name":"com.cloudsolutions.HMGPatientApp","app_id":"116912301"},"oauth_client":{"client_type":1,"client_id":"116912301"}},{"package_name":"com.ejada.hmg","client":{"app_id":"102857389"},"app_info":{"package_name":"com.ejada.hmg","app_id":"102857389"},"oauth_client":{"client_type":1,"client_id":"102857389"}}]} {
"agcgw": {
"url": "connect-drcn.dbankcloud.cn",
"backurl": "connect-drcn.hispace.hicloud.com",
"websocketurl": "connect-ws-drcn.hispace.dbankcloud.cn",
"websocketbackurl": "connect-ws-drcn.hispace.dbankcloud.com"
},
"agcgw_all": {
"SG": "connect-dra.dbankcloud.cn",
"SG_back": "connect-dra.hispace.hicloud.com",
"CN": "connect-drcn.dbankcloud.cn",
"CN_back": "connect-drcn.hispace.hicloud.com",
"RU": "connect-drru.hispace.dbankcloud.ru",
"RU_back": "connect-drru.hispace.dbankcloud.cn",
"DE": "connect-dre.dbankcloud.cn",
"DE_back": "connect-dre.hispace.hicloud.com"
},
"websocketgw_all": {
"SG": "connect-ws-dra.hispace.dbankcloud.cn",
"SG_back": "connect-ws-dra.hispace.dbankcloud.com",
"CN": "connect-ws-drcn.hispace.dbankcloud.cn",
"CN_back": "connect-ws-drcn.hispace.dbankcloud.com",
"RU": "connect-ws-drru.hispace.dbankcloud.ru",
"RU_back": "connect-ws-drru.hispace.dbankcloud.cn",
"DE": "connect-ws-dre.hispace.dbankcloud.cn",
"DE_back": "connect-ws-dre.hispace.dbankcloud.com"
},
"client": {
"cp_id": "2640966000002322881",
"product_id": "736430079244816567",
"client_id": "563735388191982656",
"client_secret": "650C7C799812AFFD53A10C7756CF05FB9F215A7E49032ABA8EBF3E14B77535CF",
"project_id": "736430079244816567",
"app_id": "116912301",
"api_key": "CgB6e3x9DJzMgRCmnT6dyUEkp6UsIfddb6l3w0ZEXzeiRMHEFi3400Z5fJ5qaHneU0OrAI/JRpk+DMGVs3QpUxlI",
"package_name": "com.cloudsolutions.HMGPatientApp"
},
"oauth_client": {
"client_id": "116912301",
"client_type": 1
},
"app_info": {
"app_id": "116912301",
"package_name": "com.cloudsolutions.HMGPatientApp"
},
"service": {
"analytics": {
"collector_url": "datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn",
"collector_url_cn": "datacollector-drcn.dt.hicloud.com,datacollector-drcn.dt.dbankcloud.cn",
"collector_url_de": "datacollector-dre.dt.hicloud.com,datacollector-dre.dt.dbankcloud.cn",
"collector_url_ru": "datacollector-drru.dt.dbankcloud.ru,datacollector-drru.dt.hicloud.com",
"collector_url_sg": "datacollector-dra.dt.hicloud.com,datacollector-dra.dt.dbankcloud.cn",
"resource_id": "p1",
"channel_id": ""
},
"ml": {
"mlservice_url": "ml-api-drcn.ai.dbankcloud.com,ml-api-drcn.ai.dbankcloud.cn"
},
"cloudstorage": {
"storage_url": "https://agc-storage-drcn.platform.dbankcloud.cn",
"storage_url_ru": "https://agc-storage-drru.cloud.huawei.ru",
"storage_url_sg": "https://ops-dra.agcstorage.link",
"storage_url_de": "https://ops-dre.agcstorage.link",
"storage_url_cn": "https://agc-storage-drcn.platform.dbankcloud.cn",
"storage_url_ru_back": "https://agc-storage-drru.cloud.huawei.ru",
"storage_url_sg_back": "https://agc-storage-dra.cloud.huawei.asia",
"storage_url_de_back": "https://agc-storage-dre.cloud.huawei.eu",
"storage_url_cn_back": "https://agc-storage-drcn.cloud.huawei.com.cn"
},
"search": {
"url": "https://search-drcn.cloud.huawei.com"
},
"edukit": {
"edu_url": "edukit.cloud.huawei.com.cn",
"dh_url": "edukit.cloud.huawei.com.cn"
}
},
"region": "CN",
"configuration_version": "3.0",
"appInfos": [
{
"package_name": "com.cloudsolutions.HMGPatientApp",
"client": {
"app_id": "116912301"
},
"app_info": {
"package_name": "com.cloudsolutions.HMGPatientApp",
"app_id": "116912301"
},
"oauth_client": {
"client_type": 1,
"client_id": "116912301"
}
},
{
"package_name": "com.ejada.hmg",
"client": {
"app_id": "102857389"
},
"app_info": {
"package_name": "com.ejada.hmg",
"app_id": "102857389"
},
"oauth_client": {
"client_type": 1,
"client_id": "102857389"
}
}
]
}

@ -71,22 +71,22 @@ android {
signingConfigs { signingConfigs {
create("release") { create("release") {
keyAlias = keystoreProperties.getProperty("keyAlias") keyAlias = "hmg"//keystoreProperties.getProperty("keyAlias")"
keyPassword = keystoreProperties.getProperty("keyPassword") keyPassword = "HmGsa123"//keystoreProperties.getProperty("keyPassword")
storeFile = keystoreProperties.getProperty("storeFile")?.let { file(it) } storeFile = rootProject.file("./key")//keystoreProperties.getProperty("storeFile")?.let { file(it) }
storePassword = keystoreProperties.getProperty("storePassword") storePassword = "HmGsa123"//keystoreProperties.getProperty("storePassword")
} }
} }
buildTypes { buildTypes {
getByName("debug") { getByName("debug") {
isDebuggable = true isDebuggable = true
signingConfig = signingConfigs.getByName("debug") signingConfig = signingConfigs.getByName("release")
isMinifyEnabled = false isMinifyEnabled = false
isShrinkResources = false isShrinkResources = false
} }
getByName("release") { getByName("release") {
isDebuggable = false isDebuggable = true
signingConfig = signingConfigs.getByName("release") signingConfig = signingConfigs.getByName("release")
isMinifyEnabled = true isMinifyEnabled = true
isShrinkResources = true isShrinkResources = true
@ -197,7 +197,7 @@ dependencies {
implementation(files("libs/Penguin.aar")) implementation(files("libs/Penguin.aar"))
implementation(files("libs/PenguinRenderer.aar")) implementation(files("libs/PenguinRenderer.aar"))
api(files("libs/samsung-health-data-api.aar")) api(files("libs/samsung-health-data-api.aar"))
implementation("com.huawei.hms:health:6.11.0.300") implementation("com.huawei.hms:health:6.15.0.300")
implementation("com.huawei.hms:hmscoreinstaller:6.6.0.300") implementation("com.huawei.hms:hmscoreinstaller:6.6.0.300")
implementation("com.github.kittinunf.fuel:fuel:2.3.1") implementation("com.github.kittinunf.fuel:fuel:2.3.1")

@ -139,6 +139,10 @@
android:usesCleartextTraffic="true" android:usesCleartextTraffic="true"
android:extractNativeLibs="true" android:extractNativeLibs="true"
tools:replace="android:label"> tools:replace="android:label">
<meta-data
android:name="com.huawei.hms.client.appid"
android:value="116912301" />
<!-- <activity--> <!-- <activity-->
<!-- android:name="com.cloud.hmg_patient_app.whatsapp.WhatsAppCodeActivity"--> <!-- android:name="com.cloud.hmg_patient_app.whatsapp.WhatsAppCodeActivity"-->
<!-- android:exported="true"--> <!-- android:exported="true"-->

@ -7,6 +7,7 @@ import android.util.Log
import android.view.WindowManager import android.view.WindowManager
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
import com.cloudsolutions.HMGPatientApp.watch.huawei.HuaweiWatch
import com.cloudsolutions.HMGPatientApp.watch.samsung_watch.SamsungWatch import com.cloudsolutions.HMGPatientApp.watch.samsung_watch.SamsungWatch
import io.flutter.embedding.engine.FlutterEngine import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant import io.flutter.plugins.GeneratedPluginRegistrant
@ -24,6 +25,7 @@ class MainActivity: FlutterFragmentActivity() {
PenguinInPlatformBridge(flutterEngine, this).create() PenguinInPlatformBridge(flutterEngine, this).create()
SamsungWatch(flutterEngine, this) SamsungWatch(flutterEngine, this)
HuaweiWatch(flutterEngine, this)
} }
override fun onRequestPermissionsResult( override fun onRequestPermissionsResult(

@ -0,0 +1,83 @@
package com.cloudsolutions.HMGPatientApp.watch.huawei
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import com.cloudsolutions.HMGPatientApp.MainActivity
import com.cloudsolutions.HMGPatientApp.watch.samsung_watch.model.Vitals
import com.huawei.hms.adapter.AvailableAdapter
import com.huawei.hms.adapter.internal.AvailableCode
import com.samsung.android.sdk.health.data.HealthDataStore
import com.samsung.android.sdk.health.data.permission.AccessType
import com.samsung.android.sdk.health.data.permission.Permission
import com.samsung.android.sdk.health.data.request.DataType
import com.samsung.android.sdk.health.data.request.DataTypes
import com.samsung.android.sdk.health.data.request.LocalTimeFilter
import com.samsung.android.sdk.health.data.request.LocalTimeGroup
import com.samsung.android.sdk.health.data.request.LocalTimeGroupUnit
import com.samsung.android.sdk.health.data.request.Ordering
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import java.time.LocalDateTime
import java.time.LocalTime
class HuaweiWatch(
private var flutterEngine: FlutterEngine,
private var mainActivity: MainActivity
) {
private lateinit var channel: MethodChannel
private lateinit var dataStore: HealthDataStore
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
private val TAG = "HuaweiWatch"
private lateinit var vitals: MutableMap<String, List<Vitals>>
companion object {
private const val CHANNEL = "huawei_watch"
}
init{
create()
}
@RequiresApi(Build.VERSION_CODES.O)
fun create() {
Log.d(TAG, "create: is called")
// openTok = OpenTok(mainActivity, flutterEngine)
channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
channel.setMethodCallHandler { call: MethodCall, result: MethodChannel.Result ->
when (call.method) {
"init" -> {
init(result)
}
else -> {
result.notImplemented()
}
}
}
}
fun init(methodResult: MethodChannel.Result) {
val availableAdapter = AvailableAdapter(60400312)
val result = availableAdapter.isHuaweiMobileServicesAvailable(mainActivity) // context indicates a context object.
if (result != AvailableCode.SUCCESS) {
availableAdapter.startResolution(mainActivity, object : AvailableAdapter.AvailableCallBack {
override fun onComplete(result: Int) {
Log.d(TAG, "onComplete result: " + result)
}
})
}else {
methodResult.error("failure", "Unable to install hms" , null )
}
}
}

@ -0,0 +1,333 @@
package com.ejada.hmg.watch.huawei
import android.content.Intent
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
import com.ejada.hmg.MainActivity
import com.ejada.hmg.watch.huawei.samsung_watch.model.Vitals
import com.huawei.hms.adapter.AvailableAdapter
import com.huawei.hms.adapter.internal.AvailableCode
import com.huawei.hms.hihealth.HuaweiHiHealth
import com.huawei.hms.hihealth.SettingController
import com.huawei.hms.hihealth.data.Scopes
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import java.time.Instant
import java.time.temporal.ChronoUnit
import java.util.Date
class HuaweiWatch(
private var flutterEngine: FlutterEngine,
private var mainActivity: MainActivity
) {
private lateinit var channel: MethodChannel
lateinit var mSettingController: SettingController
val REQUEST_AUTH: Int = 1002
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
val TAG = "HuaweiWatch"
var result : MethodChannel.Result? = null
var startDate: Date? = null
var endDate: Date? = null
private lateinit var vitals: MutableMap<String, List<Vitals>>
companion object {
private const val CHANNEL = "huawei_watch"
}
init{
create()
val now = Instant.now()
endDate = Date.from(now)
startDate = Date.from(now.minus(365, ChronoUnit.DAYS))
}
@RequiresApi(Build.VERSION_CODES.O)
fun create() {
Log.d(TAG, "create: is called")
// openTok = OpenTok(mainActivity, flutterEngine)
channel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL)
channel.setMethodCallHandler { call: MethodCall, result: MethodChannel.Result ->
when (call.method) {
"init" -> {
this.result = result
Log.d(TAG, "onMethodCall: init called")
mSettingController = HuaweiHiHealth.getSettingController(mainActivity);
val availableAdapter = AvailableAdapter(60400312)
val results= availableAdapter.isHuaweiMobileServicesAvailable(mainActivity) // context indicates a context object.
if (results != AvailableCode.SUCCESS) {
availableAdapter.startResolution(mainActivity, object : AvailableAdapter.AvailableCallBack {
override fun onComplete(result: Int) {
Log.d(TAG, "onComplete result: " + result)
}
})
}
result.success("init success")
}
"getPermission"->{
if(!this::mSettingController.isInitialized)
result.error("DataStoreNotInitialized", "Please call init before requesting permissions", null)
// Add scopes to apply for. The following only shows an example. You need to add scopes according to your specific needs.
val scopes = arrayOf<String?>( // View and store step count data in Health Service Kit.
Scopes.HEALTHKIT_STEP_READ, Scopes.HEALTHKIT_OXYGEN_SATURATION_READ, // View and store height and weight data in Health Service Kit.
Scopes.HEALTHKIT_HEARTRATE_READ, Scopes.HEALTHKIT_SLEEP_READ,
Scopes.HEALTHKIT_BODYTEMPERATURE_READ, Scopes.HEALTHKIT_CALORIES_READ
)
// Obtain the intent of the authorization process. Value true indicates that the authorization process of the Huawei Health app is enabled, and false indicates that the authorization process is disabled.
val intent: Intent? = mSettingController.requestAuthorizationIntent(scopes, true)
// Open the authorization process screen.
Log.i(TAG, "start authorization activity")
intent?.let{
mainActivity.startActivityForResult(intent, REQUEST_AUTH)
}
}
"getHeartRate"->{
val dateTime = LocalDateTime.now().with(LocalTime.MIDNIGHT).minusDays(365)
val localTimeFilter = LocalTimeFilter.of(dateTime, LocalDateTime.now())
val readRequest = DataTypes.HEART_RATE.readDataRequestBuilder
.setLocalTimeFilter(localTimeFilter)
.setOrdering(Ordering.DESC)
.build()
scope.launch {
val heartRateList = dataStore.readData(readRequest).dataList
processHeartVital(heartRateList)
Log.d("TAG"," the data is ${vitals}")
print("the data is ${vitals}")
result.success("Data is obtained")
}
}
//
//
// "getSleepData" -> {
// val dateTime = LocalDateTime.now().with(LocalTime.MIDNIGHT).minusDays(365)
// val localTimeFilter = LocalTimeFilter.of(dateTime, LocalDateTime.now())
// val readRequest = DataTypes.SLEEP.readDataRequestBuilder
// .setLocalTimeFilter(localTimeFilter)
// .setOrdering(Ordering.ASC)
// .build()
// scope.launch {
// val sleepData = dataStore.readData(readRequest).dataList
// processSleepVital(sleepData)
// print("the data is $vitals")
// Log.d(TAG, "the data is $vitals")
// result.success("Data is obtained")
// }
//
// }
//
// "steps"->{
// val dateTime = LocalDateTime.now().with(LocalTime.MIDNIGHT).minusDays(365)
// val localTimeFilter = LocalTimeFilter.of(dateTime, LocalDateTime.now())
// val localTimeGroup = LocalTimeGroup.of(LocalTimeGroupUnit.HOURLY, 1)
// val aggregateRequest = DataType.StepsType.TOTAL.requestBuilder
// .setLocalTimeFilterWithGroup(localTimeFilter, localTimeGroup)
// .setOrdering(Ordering.ASC)
// .build()
//
// scope.launch {
// val steps = dataStore.aggregateData(aggregateRequest)
// processStepsCount(steps)
// print("the data is $vitals")
// Log.d(TAG, "the data is $vitals")
// result.success("Data is obtained")
// }
// }
//
// "activitySummary"->{
// val dateTime = LocalDateTime.now().with(LocalTime.MIDNIGHT).minusDays(365)
// val localTimeFilter = LocalTimeFilter.of(dateTime, LocalDateTime.now())
// val localTimeGroup = LocalTimeGroup.of(LocalTimeGroupUnit.HOURLY, 1)
// val readRequest = DataType.ActivitySummaryType.TOTAL_CALORIES_BURNED.requestBuilder
// .setLocalTimeFilterWithGroup(localTimeFilter, localTimeGroup)
// .setOrdering(Ordering.DESC)
// .build()
//
// scope.launch {
// val activityResult = dataStore.aggregateData(readRequest).dataList
// processActivity(activityResult)
// Log.d("TAG"," the data is ${vitals}")
// print("the data is ${vitals}")
// result.success("Data is obtained")
// }
// }
//
// "bloodOxygen"->{
// val dateTime = LocalDateTime.now().with(LocalTime.MIDNIGHT).minusDays(365)
// val localTimeFilter = LocalTimeFilter.of(dateTime, LocalDateTime.now())
// val readRequest = DataTypes.BLOOD_OXYGEN.readDataRequestBuilder
// .setLocalTimeFilter(localTimeFilter)
// .setOrdering(Ordering.DESC)
// .build()
//
// scope.launch {
// val bloodOxygenList = dataStore.readData(readRequest).dataList
// processBloodOxygen(bloodOxygenList)
// Log.d("TAG"," the data is ${vitals}")
// print("the data is ${vitals["bloodOxygen"]}")
// result.success("Data is obtained")
// }
// }
//
//
// "bodyTemperature"->{
// val dateTime = LocalDateTime.now().with(LocalTime.MIDNIGHT).minusDays(365)
// val localTimeFilter = LocalTimeFilter.of(dateTime, LocalDateTime.now())
// val readRequest = DataTypes.BODY_TEMPERATURE.readDataRequestBuilder
// .setLocalTimeFilter(localTimeFilter)
// .setOrdering(Ordering.DESC)
// .build()
//
// scope.launch {
// val bodyTemperatureList = dataStore.readData(readRequest).dataList
// processBodyTemperature(bodyTemperatureList)
// Log.d("TAG"," the data is ${vitals}")
// print("the data is ${vitals["bodyTemperature"]}")
// result.success("Data is obtained")
// }
// }
//
// "retrieveData"->{
// if(vitals.isEmpty()){
// result.error("NoDataFound", "No Data was obtained", null)
// return@setMethodCallHandler
// }
// result.success("""
// {
// "heartRate": ${vitals["heartRate"]},
// "steps": ${vitals["steps"]},
// "sleep": ${vitals["sleep"]},
// "activity": ${vitals["activity"]},
// "bloodOxygen": ${vitals["bloodOxygen"]},
// "bodyTemperature": ${vitals["bodyTemperature"]}
// }
// """.trimIndent())
// }
"closeCoroutineScope"->{
destroy()
result.success("Coroutine Scope Cancelled")
}
else -> {
result.notImplemented()
}
}
}
}
/**
* Check whether users have enabled Health Service Kit.
*/
fun getHealthAppAuthorization() {
mSettingController.healthAppAuthorization
.addOnFailureListener { result?.error("UnAuthorized", "User denied the permission", null) }
.addOnSuccessListener { result?.success("permission granted"); }
}
private fun CoroutineScope.processBodyTemperature( bodyTemperatureList :List<HealthDataPoint>) {
vitals["bodyTemperature"] = mutableListOf()
bodyTemperatureList.forEach { stepData ->
val vitalData = Vitals().apply {
value = stepData.getValue(DataType.BodyTemperatureType.BODY_TEMPERATURE).toString()
timeStamp = stepData.endTime.toString()
}
(vitals["bodyTemperature"] as MutableList).add(vitalData)
}
}
private fun CoroutineScope.processBloodOxygen( bloodOxygenList :List<HealthDataPoint>) {
vitals["bloodOxygen"] = mutableListOf()
bloodOxygenList.forEach { stepData ->
val vitalData = Vitals().apply {
value = stepData.getValue(DataType.BloodOxygenType.OXYGEN_SATURATION).toString()
timeStamp = stepData.endTime.toString()
}
(vitals["bloodOxygen"] as MutableList).add(vitalData)
}
}
private fun CoroutineScope.processActivity(activityResult: List<AggregatedData<Float>>) {
vitals["activity"] = mutableListOf()
activityResult.forEach { stepData ->
val vitalData = Vitals().apply {
value = stepData.value.toString()
timeStamp = stepData.endTime.toString()
}
(vitals["activity"] as MutableList).add(vitalData)
}
}
private fun CoroutineScope.processStepsCount(result: DataResponse<AggregatedData<Long>>) {
val stepCount = ArrayList<AggregatedData<Long>>()
var totalSteps: Long = 0
vitals["steps"] = mutableListOf()
result.dataList.forEach { stepData ->
val vitalData = Vitals().apply {
value = (stepData.value as Long).toString()
timeStamp = stepData.startTime.toString()
}
(vitals["steps"] as MutableList).add(vitalData)
}
}
private fun CoroutineScope.processSleepVital(sleepData: List<HealthDataPoint>) {
vitals["sleep"] = mutableListOf()
sleepData.forEach {
(vitals["sleep"] as MutableList).add(
Vitals().apply {
timeStamp = it.startTime.toString()
value = (it.getValue(DataType.SleepType.DURATION)?.toString().toString())
}
)
}
}
private suspend fun CoroutineScope.processHeartVital(
heartRateList: List<HealthDataPoint>,
) {
vitals["heartRate"] = mutableListOf()
heartRateList.forEach {
(vitals["heartRate"] as MutableList).add(processHeartRateData(it))
}
}
private fun processHeartRateData(heartRateData: HealthDataPoint) =
Vitals().apply {
heartRateData.getValue(DataType.HeartRateType.MAX_HEART_RATE)?.let {
value = it.toString()
}
timeStamp = heartRateData.startTime.toString()
}
fun destroy() {
scope.cancel()
}
}

@ -1,4 +1,4 @@
storePassword=HmGsa123 storePassword=HmGsa123
keyPassword=HmGsa123 keyPassword=HmGsa123
keyAlias=hmg keyAlias=hmg
storeFile=key storeFile=./key

@ -189,13 +189,13 @@ class HealthService {
return null; return null;
} }
try { try {
await watchHelper!.getHeartRate(); // await watchHelper!.getHeartRate();
await watchHelper!.getSleep(); // await watchHelper!.getSleep();
await watchHelper!.getSteps(); await watchHelper!.getSteps();
await watchHelper!.getActivity(); // await watchHelper!.getActivity();
await watchHelper!.getBodyTemperature(); // await watchHelper!.getBodyTemperature();
await watchHelper!.getDistance(); // await watchHelper!.getDistance();
await watchHelper!.getBloodOxygen(); // await watchHelper!.getBloodOxygen();
Result<dynamic> data = await watchHelper!.retrieveData(); Result<dynamic> data = await watchHelper!.retrieveData();
if (data.isError) { if (data.isError) {
print('Unable to get the data'); print('Unable to get the data');

@ -29,7 +29,6 @@ class HealthConnectHelper extends WatchHelper {
try { try {
final types = HealthDataType.HEART_RATE; final types = HealthDataType.HEART_RATE;
final endDate = DateTime.now(); final endDate = DateTime.now();
// final startDate = endDate.subtract(Duration(days: 365));
final startDate = endDate.subtract(Duration(days: 365)); final startDate = endDate.subtract(Duration(days: 365));
final data = await getHeartData(startDate, endDate, types); final data = await getHeartData(startDate, endDate, types);
addDataToMap("heartRate",data ); addDataToMap("heartRate",data );

@ -1,13 +1,22 @@
import 'dart:async'; import 'dart:async';
import 'dart:developer';
import 'package:async/src/result/result.dart'; import 'package:async/src/result/result.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:hmg_patient_app_new/features/smartwatch_health_data/model/Vitals.dart';
import 'package:hmg_patient_app_new/features/smartwatch_health_data/watch_connectors/watch_helper.dart'; import 'package:hmg_patient_app_new/features/smartwatch_health_data/watch_connectors/watch_helper.dart';
import 'package:http/http.dart';
import 'package:huawei_health/huawei_health.dart'; import 'package:huawei_health/huawei_health.dart';
import '../../../presentation/smartwatches/huawei_health_example.dart';
class HuaweiHealthDataConnector extends WatchHelper{ class HuaweiHealthDataConnector extends WatchHelper{
final MethodChannel _channel = MethodChannel('huawei_watch'); final MethodChannel _channel = MethodChannel('huawei_watch');
DataController? _dataController;
Map<String , List<Vitals>> mappedData = {};
@override @override
Future<Result<bool>> initDevice() async{ Future<Result<bool>> initDevice() async{
try{ try{
@ -18,19 +27,76 @@ class HuaweiHealthDataConnector extends WatchHelper{
} }
// List of scopes to ask for authorization. // List of scopes to ask for authorization.
// Note: These scopes should also be authorized on the Huawei Developer Console. // Note: These scopes should also be authorized on the Huawei Developer Console.
List<Scope> scopes = [ // List<Scope> scopes = [
Scope.HEALTHKIT_STEP_READ, Scope.HEALTHKIT_OXYGEN_SATURATION_READ, // View and store height and weight data in Health Service Kit. // Scope.HEALTHKIT_STEP_READ, Scope.HEALTHKIT_OXYGEN_SATURATION_READ, // View and store height and weight data in Health Service Kit.
Scope.HEALTHKIT_HEARTRATE_READ, Scope.HEALTHKIT_SLEEP_READ, // Scope.HEALTHKIT_HEARTRATE_READ, Scope.HEALTHKIT_SLEEP_READ,
Scope.HEALTHKIT_BODYTEMPERATURE_READ, Scope.HEALTHKIT_CALORIES_READ // Scope.HEALTHKIT_BODYTEMPERATURE_READ, Scope.HEALTHKIT_CALORIES_READ,
// Scope.HEALTHKIT_STEP_READ,
// ];
final List<Scope> scopes = <Scope>[
Scope.HEALTHKIT_ACTIVITY_READ,
Scope.HEALTHKIT_ACTIVITY_WRITE,
Scope.HEALTHKIT_BLOODGLUCOSE_READ,
Scope.HEALTHKIT_BLOODGLUCOSE_WRITE,
Scope.HEALTHKIT_CALORIES_READ,
Scope.HEALTHKIT_CALORIES_WRITE,
Scope.HEALTHKIT_DISTANCE_READ,
Scope.HEALTHKIT_DISTANCE_WRITE,
Scope.HEALTHKIT_HEARTRATE_READ,
Scope.HEALTHKIT_HEARTRATE_WRITE,
Scope.HEALTHKIT_HEIGHTWEIGHT_READ,
Scope.HEALTHKIT_HEIGHTWEIGHT_WRITE,
Scope.HEALTHKIT_LOCATION_READ,
Scope.HEALTHKIT_LOCATION_WRITE,
Scope.HEALTHKIT_PULMONARY_READ,
Scope.HEALTHKIT_PULMONARY_WRITE,
Scope.HEALTHKIT_SLEEP_READ,
Scope.HEALTHKIT_SLEEP_WRITE,
Scope.HEALTHKIT_SPEED_READ,
Scope.HEALTHKIT_SPEED_WRITE,
Scope.HEALTHKIT_STEP_READ,
Scope.HEALTHKIT_STEP_WRITE,
Scope.HEALTHKIT_STRENGTH_READ,
Scope.HEALTHKIT_STRENGTH_WRITE,
Scope.HEALTHKIT_BODYFAT_READ,
Scope.HEALTHKIT_BODYFAT_WRITE,
Scope.HEALTHKIT_NUTRITION_READ,
Scope.HEALTHKIT_NUTRITION_WRITE,
Scope.HEALTHKIT_BLOODPRESSURE_READ,
Scope.HEALTHKIT_BLOODPRESSURE_WRITE,
Scope.HEALTHKIT_BODYTEMPERATURE_READ,
Scope.HEALTHKIT_BODYTEMPERATURE_WRITE,
Scope.HEALTHKIT_OXYGENSTATURATION_READ,
Scope.HEALTHKIT_OXYGENSTATURATION_WRITE,
Scope.HEALTHKIT_REPRODUCTIVE_READ,
Scope.HEALTHKIT_REPRODUCTIVE_WRITE,
Scope.HEALTHKIT_ACTIVITY_RECORD_READ,
Scope.HEALTHKIT_ACTIVITY_RECORD_WRITE,
Scope.HEALTHKIT_HEARTRATE_REALTIME,
Scope.HEALTHKIT_STEP_REALTIME,
Scope.HEALTHKIT_HEARTHEALTH_WRITE,
Scope.HEALTHKIT_HEARTHEALTH_READ,
Scope.HEALTHKIT_STRESS_WRITE,
Scope.HEALTHKIT_STRESS_READ,
Scope.HEALTHKIT_OXYGEN_SATURATION_WRITE,
Scope.HEALTHKIT_OXYGEN_SATURATION_READ,
Scope.HEALTHKIT_HISTORYDATA_OPEN_WEEK,
Scope.HEALTHKIT_HISTORYDATA_OPEN_MONTH,
Scope.HEALTHKIT_HISTORYDATA_OPEN_YEAR,
]; ];
try { try {
bool? result = await SettingController.getHealthAppAuthorization(); var healthResult = await HealthAuth.signIn(scopes,);
debugPrint( // var result = await SettingController.requestAuthorizationIntent(scopes,true);
'Granted Scopes for result == is $result}', // AuthHuaweiId? id = await HealthAuth.signIn(scopes);
); _dataController = await DataController.init();
// debugPrint(
// 'Granted Scopes for result == is ${result.status?.statusCode}',
// );
return Result.value(true); return Result.value(true);
} catch (e) { } on PlatformException catch (e) {
debugPrint('Error on authorization, Error:${e.toString()}');
print('Error on authorization, Error:${e.toString()}');
return Result.error(false); return Result.error(false);
} }
} }
@ -67,8 +133,20 @@ class HuaweiHealthDataConnector extends WatchHelper{
} }
@override @override
FutureOr<void> getSteps() { FutureOr<void> getSteps() async{
throw UnimplementedError(); try {
final types = DataType.DT_INSTANTANEOUS_STEPS_RATE;
final endDate = DateTime.now();
final startDate = endDate.subtract(Duration(days: 20));
final data = await readDataType(types,startDate, endDate);
if(data == null){
mappedData["heartRate"] = [];
return;
}
addDataToMap("heartRate",data);
} catch (e) {
print('Error getting Steps rate: $e');
}
} }
@ -83,4 +161,92 @@ class HuaweiHealthDataConnector extends WatchHelper{
throw UnimplementedError(); throw UnimplementedError();
} }
Future<ReadReply?> readDataType(
DataType dataType,
DateTime startTime,
DateTime endTime,
) async {
DataCollector dataCollector = DataCollector(
dataType: dataType,
dataGenerateType: DataGenerateType.DATA_TYPE_RAW,
);
// Build the time range for the query: start time and end time.
ReadOptions readOptions = ReadOptions(
dataCollectors: <DataCollector>[
dataCollector,
],
startTime: startTime,
endTime: endTime,
allowRemoteInquiry: true,
)..groupByTime(1, timeUnit: TimeUnit.HOURS);
// Call the api with the constructed ReadOptions instance.
try {
ReadReply? readReply = await _dataController?.read(readOptions);
log(
'read',
LogOptions.success,
result: readReply.toString(),
);
return readReply;
} on PlatformException catch (e) {
log(
'read',
LogOptions.error,
error: e.message,
);
return null;
}
}
/// Prints the specified text on both the console and the specified text controller.
void log(
String methodName,
LogOptions logOption, {
String? result = '',
String? error = '',
}) {
final now = DateTime.now();
final timestamp = '${now.hour.toString().padLeft(2, '0')}:'
'${now.minute.toString().padLeft(2, '0')}:'
'${now.second.toString().padLeft(2, '0')}';
String log = '';
switch (logOption) {
case LogOptions.call:
log = '[$timestamp] $methodName called';
break;
case LogOptions.success:
log = '[$timestamp] $methodName [Success: $result]';
break;
case LogOptions.error:
log =
'[$timestamp] $methodName [Error: $error] [Error Description: ${HiHealthStatusCodes.getStatusCodeMessage(error ?? '')}]';
break;
case LogOptions.custom:
log = '[$timestamp] $methodName';
break;
}
print(log);
}
void addDataToMap(String s, ReadReply data) {
mappedData[s] = [];
for (var point in data.groups) {
if(point.sampleSets == null){
continue;
}
for (var points in point.sampleSets!) {
debugPrint("the stART AND END TIME ARE ${point.startTime} ${point.endTime}");
print("the pair is ${points.pairs}");
for (var value in points.samplePoints) {
debugPrint("the value is ${value.fieldValues}");
// mappedData[s]?.add(Vitals(value: value, time: DateTime.fromMillisecondsSinceEpoch(point.startTime)));
}
}
}
}
} }

@ -121,7 +121,7 @@ class AppRoutes {
register: (context) => RegisterNew(), register: (context) => RegisterNew(),
registerStepTwo: (context) => RegisterNewStep2(), registerStepTwo: (context) => RegisterNewStep2(),
medicalFilePage: (context) => MedicalFilePage(), medicalFilePage: (context) => MedicalFilePage(),
zoomCallPage: (context) => CallScreen(), zoomCallPage: (context) => MedicalFilePage(),
eReferralPage: (context) => NewReferralPage(), eReferralPage: (context) => NewReferralPage(),
comprehensiveCheckupPage: (context) => ComprehensiveCheckupPage(), comprehensiveCheckupPage: (context) => ComprehensiveCheckupPage(),
homeHealthCarePage: (context) => HhcProceduresPage(), homeHealthCarePage: (context) => HhcProceduresPage(),

@ -1,25 +1,25 @@
// lib/services/zoom_service.dart // lib/services/zoom_service.dart
import 'package:flutter_zoom_videosdk/native/zoom_videosdk.dart'; // import 'package:flutter_zoom_videosdk/native/zoom_videosdk.dart';
class ZoomService { class ZoomService {
static final ZoomService _instance = ZoomService._internal(); static final ZoomService _instance = ZoomService._internal();
factory ZoomService() => _instance; factory ZoomService() => _instance;
ZoomService._internal(); ZoomService._internal();
ZoomVideoSdk? _zoom; // ZoomVideoSdk? _zoom;
bool _isInitialized = false; bool _isInitialized = false;
Future<void> initializeZoomSDK() async { Future<void> initializeZoomSDK() async {
if (_isInitialized) return; if (_isInitialized) return;
try { try {
_zoom = ZoomVideoSdk(); // _zoom = ZoomVideoSdk();
InitConfig initConfig = InitConfig( // InitConfig initConfig = InitConfig(
domain: "zoom.us", // domain: "zoom.us",
enableLog: true, // Enable for debugging // enableLog: true, // Enable for debugging
); // );
await _zoom!.initSdk(initConfig); // await _zoom!.initSdk(initConfig);
_isInitialized = true; _isInitialized = true;
print("Zoom SDK initialized successfully"); print("Zoom SDK initialized successfully");
} catch (e) { } catch (e) {
@ -28,6 +28,6 @@ class ZoomService {
} }
} }
ZoomVideoSdk? get zoom => _zoom; // ZoomVideoSdk? get zoom => _zoom;
bool get isInitialized => _isInitialized; bool get isInitialized => _isInitialized;
} }

@ -63,7 +63,7 @@ dependencies:
geolocator: ^14.0.2 geolocator: ^14.0.2
dropdown_search: ^6.0.2 dropdown_search: ^6.0.2
google_maps_flutter: ^2.13.1 google_maps_flutter: ^2.13.1
flutter_zoom_videosdk: 2.1.10 # flutter_zoom_videosdk: 2.1.10
dart_jsonwebtoken: ^3.2.0 dart_jsonwebtoken: ^3.2.0
dartz: ^0.10.1 dartz: ^0.10.1
equatable: ^2.0.7 equatable: ^2.0.7
@ -96,7 +96,7 @@ dependencies:
location: ^8.0.1 location: ^8.0.1
gms_check: ^1.0.4 gms_check: ^1.0.4
huawei_location: ^6.14.2+301 huawei_location: ^6.14.2+301
huawei_health: ^6.15.0+300 huawei_health: ^6.17.0+300
intl: ^0.20.2 intl: ^0.20.2
flutter_widget_from_html: ^0.17.1 flutter_widget_from_html: ^0.17.1
huawei_map: ^6.12.0+301 huawei_map: ^6.12.0+301

Loading…
Cancel
Save