This commit is contained in:
2026-05-14 16:54:32 +00:00
parent 5b2a2e7ddb
commit 15fcbcc9eb
212 changed files with 18586 additions and 10360 deletions
+3 -3
View File
@@ -1,3 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml
# Default ignored files
/shelf/
/workspace.xml
+5 -5
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidProjectSystem">
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AndroidProjectSystem">
<option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
</component>
</project>
+5 -5
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="21" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="21" />
</component>
</project>
+17 -17
View File
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetSelector">
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-04-21T21:27:34.624668600Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=d76a0274" />
</handle>
</Target>
</DropdownSelection>
<DialogSelection />
</SelectionState>
</selectionStates>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="deploymentTargetSelector">
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-04-21T21:27:34.624668600Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="PhysicalDevice" identifier="serial=d76a0274" />
</handle>
</Target>
</DropdownSelection>
<DialogSelection />
</SelectionState>
</selectionStates>
</component>
</project>
+17 -17
View File
@@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="CHOOSE_PER_TEST" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="testRunner" value="CHOOSE_PER_TEST" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/app" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>
+50
View File
@@ -0,0 +1,50 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ComposePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="ComposePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="ComposePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="ComposePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="GlancePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewDeviceShouldUseNewSpec" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
<inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
<option name="composableFile" value="true" />
</inspection_tool>
</profile>
</component>
+16 -16
View File
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
<option value="com.intellij.execution.junit.PatternConfigurationProducer" />
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
<option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
<option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
<option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
</set>
</option>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
<option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
<option value="com.intellij.execution.junit.PatternConfigurationProducer" />
<option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
<option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
<option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
<option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
<option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
</set>
</option>
</component>
</project>
+5 -5
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
+49 -49
View File
@@ -1,50 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:name="android.hardware.type.watch" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault">
<uses-library
android:name="com.google.android.wearable"
android:required="true" />
<uses-library
android:name="wear-sdk"
android:required="false" />
<!--
Set to true if your app is Standalone, that is, it does not require the handheld
app to run.
-->
<meta-data
android:name="com.google.android.gms.wearable.standalone"
android:value="true" />
<meta-data
android:name="com.google.android.gms.wearable.capabilities"
android:resource="@xml/wearable_app_values" />
<activity
android:name="com.cesizen.app.MainActivity"
android:exported="true"
android:taskAffinity=""
android:theme="@style/MainActivityTheme.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature android:name="android.hardware.type.watch" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@android:style/Theme.DeviceDefault">
<uses-library
android:name="com.google.android.wearable"
android:required="true" />
<uses-library
android:name="wear-sdk"
android:required="false" />
<!--
Set to true if your app is Standalone, that is, it does not require the handheld
app to run.
-->
<meta-data
android:name="com.google.android.gms.wearable.standalone"
android:value="true" />
<meta-data
android:name="com.google.android.gms.wearable.capabilities"
android:resource="@xml/wearable_app_values" />
<activity
android:name="com.cesizen.app.MainActivity"
android:exported="true"
android:taskAffinity=""
android:theme="@style/MainActivityTheme.Starting">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
@@ -1,282 +1,282 @@
package com.cesizen.app
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
import androidx.wear.compose.material3.*
import com.cesizen.app.presentation.theme.MyApplicationTheme
import com.google.android.gms.tasks.Tasks
import com.google.android.gms.wearable.*
import org.json.JSONObject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
class MainActivity : ComponentActivity(), DataClient.OnDataChangedListener {
private var userName by mutableStateOf<String?>(null)
private var currentMood by mutableStateOf<String?>(null)
private var isRefreshing by mutableStateOf(false)
private val TAG = "CESIZen_Watch"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Wearable.getDataClient(this).addListener(this)
refreshData()
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val request = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI) // Priorité Wi-Fi
.addTransportType(NetworkCapabilities.TRANSPORT_BLUETOOTH) // Secours Bluetooth
.build()
connectivityManager.requestNetwork(request, object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
// Le système a trouvé soit du Wi-Fi, soit le pont Bluetooth du téléphone
connectivityManager.bindProcessToNetwork(network)
}
})
setContent {
WearApp(
userName = userName,
currentMood = currentMood,
isRefreshing = isRefreshing,
onRefresh = { refreshData() },
onMoodSelected = { mood -> sendMoodToPhone(mood) }
)
}
}
private fun refreshData() {
if (isRefreshing) return
isRefreshing = true
val today = java.text.SimpleDateFormat("yyyy-MM-dd", java.util.Locale.getDefault()).format(java.util.Date())
Wearable.getDataClient(this).dataItems.addOnSuccessListener { items ->
for (item in items) {
if (item.uri.path == "/auth_status") {
val dataMap = DataMapItem.fromDataItem(item).dataMap
userName = if (dataMap.getString("status") == "authenticated") dataMap.getString("userName") else null
} else if (item.uri.path == "/daily_mood") {
val dataMap = DataMapItem.fromDataItem(item).dataMap
val moodDate = dataMap.getString("date")
if (moodDate == today) {
currentMood = dataMap.getString("mood")
} else {
currentMood = null
}
}
}
isRefreshing = false
}
CoroutineScope(Dispatchers.IO).launch {
try {
val nodes = Tasks.await(Wearable.getNodeClient(this@MainActivity).connectedNodes)
for (node in nodes) {
val payload = JSONObject().apply { put("command", "get_sync_data") }.toString().toByteArray()
Wearable.getMessageClient(this@MainActivity).sendMessage(node.id, "/wearable_communication", payload)
}
} catch (e: Exception) {
Log.e(TAG, "Error sync nodes", e)
}
}
}
private fun sendMoodToPhone(mood: String) {
currentMood = mood
if (mood.isEmpty()) {
// Reset mood locally to show the selection again
currentMood = null
}
CoroutineScope(Dispatchers.IO).launch {
try {
val nodes = Tasks.await(Wearable.getNodeClient(this@MainActivity).connectedNodes)
for (node in nodes) {
val payload = JSONObject().apply {
put("command", "save_mood")
put("mood", mood)
}.toString().toByteArray()
Wearable.getMessageClient(this@MainActivity).sendMessage(node.id, "/wearable_communication", payload)
}
} catch (e: Exception) {
Log.e(TAG, "Error sending mood", e)
}
}
}
override fun onDataChanged(dataEvents: DataEventBuffer) {
val today = java.text.SimpleDateFormat("yyyy-MM-dd", java.util.Locale.getDefault()).format(java.util.Date())
for (event in dataEvents) {
val dataMap = DataMapItem.fromDataItem(event.dataItem).dataMap
if (event.dataItem.uri.path == "/auth_status") {
userName = if (dataMap.getString("status") == "authenticated") dataMap.getString("userName") else null
} else if (event.dataItem.uri.path == "/daily_mood") {
val moodDate = dataMap.getString("date")
if (moodDate == today) {
currentMood = dataMap.getString("mood")
} else {
currentMood = null
}
}
}
}
}
@Composable
fun WearApp(userName: String?, currentMood: String?, isRefreshing: Boolean, onRefresh: () -> Unit, onMoodSelected: (String) -> Unit) {
val cesiBlue = Color(0xFF000091)
MyApplicationTheme {
AppScaffold {
val listState = rememberTransformingLazyColumnState()
ScreenScaffold(scrollState = listState) { contentPadding ->
TransformingLazyColumn(
modifier = Modifier
.fillMaxSize()
.background(Brush.verticalGradient(listOf(Color.Black, Color(0xFF000022)))),
contentPadding = contentPadding,
state = listState,
horizontalAlignment = Alignment.CenterHorizontally
) {
// Header
item {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(bottom = 12.dp)
) {
Text(
"CESIZen",
color = cesiBlue,
style = MaterialTheme.typography.labelMedium,
fontWeight = FontWeight.Bold
)
Spacer(modifier = Modifier.height(4.dp))
}
}
if (userName == null) {
item {
TitleCard(
onClick = onRefresh,
title = { Text("Connexion requise", textAlign = TextAlign.Center) },
subtitle = { Text("Ouvrez l'app sur votre téléphone", textAlign = TextAlign.Center, fontSize = 12.sp) },
modifier = Modifier.padding(horizontal = 8.dp)
)
}
} else {
// User Status
item {
val displayName = userName.split(" ").firstOrNull() ?: "Zen"
Text(
"Bonjour $displayName",
style = MaterialTheme.typography.titleMedium,
textAlign = TextAlign.Center
)
}
if (currentMood.isNullOrEmpty()) {
item {
Text(
"Comment allez-vous ?",
style = MaterialTheme.typography.bodySmall,
color = Color.LightGray,
modifier = Modifier.padding(vertical = 8.dp)
)
}
val moods = listOf(
MoodItem("Très bien", "😊", Color(0xFF4CAF50)),
MoodItem("Bien", "🙂", Color(0xFF8BC34A)),
MoodItem("Neutre", "😐", Color(0xFFFFC107)),
MoodItem("Pas top", "🙁", Color(0xFFFF9800)),
MoodItem("Stressé", "😫", Color(0xFFF44336))
)
moods.forEach { mood ->
item {
FilledTonalButton(
onClick = { onMoodSelected(mood.label) },
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 2.dp, horizontal = 16.dp),
colors = ButtonDefaults.filledTonalButtonColors(
containerColor = mood.color.copy(alpha = 0.2f),
contentColor = Color.White
)
) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Text(mood.emoji, fontSize = 20.sp)
Spacer(modifier = Modifier.width(12.dp))
Text(mood.label, style = MaterialTheme.typography.labelLarge)
}
}
}
}
} else {
item {
Card(
onClick = { onMoodSelected("") },
modifier = Modifier.padding(16.dp),
colors = CardDefaults.cardColors(containerColor = cesiBlue.copy(alpha = 0.3f))
) {
Column(
modifier = Modifier.fillMaxWidth().padding(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text("Humeur enregistrée", style = MaterialTheme.typography.labelSmall)
Spacer(modifier = Modifier.height(8.dp))
Text(currentMood, style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold)
Spacer(modifier = Modifier.height(8.dp))
Text("Tapoter pour changer", fontSize = 10.sp, color = Color.LightGray)
}
}
}
}
}
// Bottom Spacer
item {
Spacer(modifier = Modifier.height(20.dp))
}
}
}
}
}
}
data class MoodItem(val label: String, val emoji: String, val color: Color)
package com.cesizen.app
import android.content.Context
import android.os.Bundle
import android.util.Log
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
import androidx.wear.compose.material3.*
import com.cesizen.app.presentation.theme.MyApplicationTheme
import com.google.android.gms.tasks.Tasks
import com.google.android.gms.wearable.*
import org.json.JSONObject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
class MainActivity : ComponentActivity(), DataClient.OnDataChangedListener {
private var userName by mutableStateOf<String?>(null)
private var currentMood by mutableStateOf<String?>(null)
private var isRefreshing by mutableStateOf(false)
private val TAG = "CESIZen_Watch"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Wearable.getDataClient(this).addListener(this)
refreshData()
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val request = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI) // Priorité Wi-Fi
.addTransportType(NetworkCapabilities.TRANSPORT_BLUETOOTH) // Secours Bluetooth
.build()
connectivityManager.requestNetwork(request, object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
// Le système a trouvé soit du Wi-Fi, soit le pont Bluetooth du téléphone
connectivityManager.bindProcessToNetwork(network)
}
})
setContent {
WearApp(
userName = userName,
currentMood = currentMood,
isRefreshing = isRefreshing,
onRefresh = { refreshData() },
onMoodSelected = { mood -> sendMoodToPhone(mood) }
)
}
}
private fun refreshData() {
if (isRefreshing) return
isRefreshing = true
val today = java.text.SimpleDateFormat("yyyy-MM-dd", java.util.Locale.getDefault()).format(java.util.Date())
Wearable.getDataClient(this).dataItems.addOnSuccessListener { items ->
for (item in items) {
if (item.uri.path == "/auth_status") {
val dataMap = DataMapItem.fromDataItem(item).dataMap
userName = if (dataMap.getString("status") == "authenticated") dataMap.getString("userName") else null
} else if (item.uri.path == "/daily_mood") {
val dataMap = DataMapItem.fromDataItem(item).dataMap
val moodDate = dataMap.getString("date")
if (moodDate == today) {
currentMood = dataMap.getString("mood")
} else {
currentMood = null
}
}
}
isRefreshing = false
}
CoroutineScope(Dispatchers.IO).launch {
try {
val nodes = Tasks.await(Wearable.getNodeClient(this@MainActivity).connectedNodes)
for (node in nodes) {
val payload = JSONObject().apply { put("command", "get_sync_data") }.toString().toByteArray()
Wearable.getMessageClient(this@MainActivity).sendMessage(node.id, "/wearable_communication", payload)
}
} catch (e: Exception) {
Log.e(TAG, "Error sync nodes", e)
}
}
}
private fun sendMoodToPhone(mood: String) {
currentMood = mood
if (mood.isEmpty()) {
// Reset mood locally to show the selection again
currentMood = null
}
CoroutineScope(Dispatchers.IO).launch {
try {
val nodes = Tasks.await(Wearable.getNodeClient(this@MainActivity).connectedNodes)
for (node in nodes) {
val payload = JSONObject().apply {
put("command", "save_mood")
put("mood", mood)
}.toString().toByteArray()
Wearable.getMessageClient(this@MainActivity).sendMessage(node.id, "/wearable_communication", payload)
}
} catch (e: Exception) {
Log.e(TAG, "Error sending mood", e)
}
}
}
override fun onDataChanged(dataEvents: DataEventBuffer) {
val today = java.text.SimpleDateFormat("yyyy-MM-dd", java.util.Locale.getDefault()).format(java.util.Date())
for (event in dataEvents) {
val dataMap = DataMapItem.fromDataItem(event.dataItem).dataMap
if (event.dataItem.uri.path == "/auth_status") {
userName = if (dataMap.getString("status") == "authenticated") dataMap.getString("userName") else null
} else if (event.dataItem.uri.path == "/daily_mood") {
val moodDate = dataMap.getString("date")
if (moodDate == today) {
currentMood = dataMap.getString("mood")
} else {
currentMood = null
}
}
}
}
}
@Composable
fun WearApp(userName: String?, currentMood: String?, isRefreshing: Boolean, onRefresh: () -> Unit, onMoodSelected: (String) -> Unit) {
val cesiBlue = Color(0xFF000091)
MyApplicationTheme {
AppScaffold {
val listState = rememberTransformingLazyColumnState()
ScreenScaffold(scrollState = listState) { contentPadding ->
TransformingLazyColumn(
modifier = Modifier
.fillMaxSize()
.background(Brush.verticalGradient(listOf(Color.Black, Color(0xFF000022)))),
contentPadding = contentPadding,
state = listState,
horizontalAlignment = Alignment.CenterHorizontally
) {
// Header
item {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(bottom = 12.dp)
) {
Text(
"CESIZen",
color = cesiBlue,
style = MaterialTheme.typography.labelMedium,
fontWeight = FontWeight.Bold
)
Spacer(modifier = Modifier.height(4.dp))
}
}
if (userName == null) {
item {
TitleCard(
onClick = onRefresh,
title = { Text("Connexion requise", textAlign = TextAlign.Center) },
subtitle = { Text("Ouvrez l'app sur votre téléphone", textAlign = TextAlign.Center, fontSize = 12.sp) },
modifier = Modifier.padding(horizontal = 8.dp)
)
}
} else {
// User Status
item {
val displayName = userName.split(" ").firstOrNull() ?: "Zen"
Text(
"Bonjour $displayName",
style = MaterialTheme.typography.titleMedium,
textAlign = TextAlign.Center
)
}
if (currentMood.isNullOrEmpty()) {
item {
Text(
"Comment allez-vous ?",
style = MaterialTheme.typography.bodySmall,
color = Color.LightGray,
modifier = Modifier.padding(vertical = 8.dp)
)
}
val moods = listOf(
MoodItem("Très bien", "😊", Color(0xFF4CAF50)),
MoodItem("Bien", "🙂", Color(0xFF8BC34A)),
MoodItem("Neutre", "😐", Color(0xFFFFC107)),
MoodItem("Pas top", "🙁", Color(0xFFFF9800)),
MoodItem("Stressé", "😫", Color(0xFFF44336))
)
moods.forEach { mood ->
item {
FilledTonalButton(
onClick = { onMoodSelected(mood.label) },
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 2.dp, horizontal = 16.dp),
colors = ButtonDefaults.filledTonalButtonColors(
containerColor = mood.color.copy(alpha = 0.2f),
contentColor = Color.White
)
) {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Text(mood.emoji, fontSize = 20.sp)
Spacer(modifier = Modifier.width(12.dp))
Text(mood.label, style = MaterialTheme.typography.labelLarge)
}
}
}
}
} else {
item {
Card(
onClick = { onMoodSelected("") },
modifier = Modifier.padding(16.dp),
colors = CardDefaults.cardColors(containerColor = cesiBlue.copy(alpha = 0.3f))
) {
Column(
modifier = Modifier.fillMaxWidth().padding(8.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text("Humeur enregistrée", style = MaterialTheme.typography.labelSmall)
Spacer(modifier = Modifier.height(8.dp))
Text(currentMood, style = MaterialTheme.typography.titleLarge, fontWeight = FontWeight.Bold)
Spacer(modifier = Modifier.height(8.dp))
Text("Tapoter pour changer", fontSize = 10.sp, color = Color.LightGray)
}
}
}
}
}
// Bottom Spacer
item {
Spacer(modifier = Modifier.height(20.dp))
}
}
}
}
}
}
data class MoodItem(val label: String, val emoji: String, val color: Color)
@@ -1,13 +1,13 @@
package com.cesizen.app.presentation.theme
import androidx.compose.runtime.Composable
import androidx.wear.compose.material3.MaterialTheme
@Composable
fun MyApplicationTheme(
content: @Composable () -> Unit
) {
MaterialTheme(
content = content
)
}
package com.cesizen.app.presentation.theme
import androidx.compose.runtime.Composable
import androidx.wear.compose.material3.MaterialTheme
@Composable
fun MyApplicationTheme(
content: @Composable () -> Unit
) {
MaterialTheme(
content = content
)
}
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<capability name="cesizen_wear_app" />
</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<capability name="cesizen_wear_app" />
</resources>
+9 -9
View File
@@ -1,9 +1,9 @@
#Tue Apr 21 22:42:57 CEST 2026
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=b266d5ff6b90eada6dc3b20cb090e3731302e553a27c5d3e4df1f0d76beaff06
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#Tue Apr 21 22:42:57 CEST 2026
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=b266d5ff6b90eada6dc3b20cb090e3731302e553a27c5d3e4df1f0d76beaff06
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
+94 -94
View File
@@ -1,94 +1,94 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
:execute
@rem Setup the command line
set CLASSPATH=
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega