Skip to content

Commit 5689e18

Browse files
authored
Merge pull request #15 from vens8/native-neural-networks
question 2 progress
2 parents 9f0414d + d1017f1 commit 5689e18

File tree

65 files changed

+1381
-637
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1381
-637
lines changed

Assignment2/.idea/deploymentTargetDropDown.xml

-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assignment3/Axelero/.idea/inspectionProfiles/Project_Default.xml

+41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assignment3/Axelero/app/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ android {
5252

5353
dependencies {
5454
implementation(libs.androidx.lifecycle.viewmodel.compose)
55+
implementation(libs.androidx.navigation.runtime.ktx)
5556
val room_version = "2.6.1"
5657
kapt("androidx.room:room-compiler:$room_version")
5758
implementation(libs.androidx.core.ktx)
@@ -74,6 +75,7 @@ dependencies {
7475
androidTestImplementation(libs.androidx.junit)
7576
androidTestImplementation(libs.androidx.espresso.core)
7677
androidTestImplementation(platform(libs.androidx.compose.bom))
78+
implementation(libs.androidx.core.splashscreen)
7779
androidTestImplementation(libs.androidx.ui.test.junit4)
7880
debugImplementation(libs.androidx.ui.tooling)
7981
debugImplementation(libs.androidx.ui.test.manifest)

Assignment3/Axelero/app/src/main/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
android:label="@string/app_name"
1313
android:roundIcon="@mipmap/ic_launcher_round"
1414
android:supportsRtl="true"
15-
android:theme="@style/Theme.Axelero"
15+
android:theme="@style/Theme.MySplashScreen"
1616
tools:targetApi="31">
1717
<activity
1818
android:name=".HistoryActivity"
@@ -23,7 +23,7 @@
2323
android:name=".MainActivity"
2424
android:exported="true"
2525
android:label="@string/app_name"
26-
android:theme="@style/Theme.Axelero">
26+
android:theme="@style/Theme.MySplashScreen">
2727
<intent-filter>
2828
<action android:name="android.intent.action.MAIN" />
2929

Assignment3/Axelero/app/src/main/java/com/example/axelero/HistoryActivity.kt

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@ import androidx.activity.result.contract.ActivityResultContracts
99
import androidx.compose.foundation.layout.fillMaxSize
1010
import androidx.compose.material3.MaterialTheme
1111
import androidx.compose.material3.Surface
12-
import androidx.compose.material3.Text
13-
import androidx.compose.runtime.Composable
1412
import androidx.compose.ui.Modifier
15-
import androidx.compose.ui.tooling.preview.Preview
16-
import androidx.lifecycle.ViewModelProvider
1713
import androidx.lifecycle.lifecycleScope
18-
import androidx.lifecycle.viewmodel.compose.viewModel
19-
import com.example.axelero.db.AppDatabase
2014
import com.example.axelero.repository.OrientationDataRepository
2115
import com.example.axelero.ui.HistoryContent
2216
import com.example.axelero.ui.theme.AxeleroTheme
@@ -43,7 +37,15 @@ class HistoryActivity : ComponentActivity() {
4337
super.onCreate(savedInstanceState)
4438
Log.d("HistoryActivity: orientationDataRepository", orientationDataRepository.toString())
4539
setContent {
46-
HistoryContent(orientationDataRepository, createDocumentResult)
40+
AxeleroTheme {
41+
// A surface container using the 'background' color from the theme
42+
Surface(
43+
modifier = Modifier.fillMaxSize(),
44+
color = MaterialTheme.colorScheme.background
45+
) {
46+
HistoryContent(orientationDataRepository, createDocumentResult)
47+
}
48+
}
4749
}
4850
}
4951

Assignment3/Axelero/app/src/main/java/com/example/axelero/MainActivity.kt

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package com.example.axelero
22

3+
import android.os.Build
34
import android.os.Bundle
45
import android.util.Log
56
import androidx.activity.ComponentActivity
67
import androidx.activity.compose.setContent
8+
import androidx.annotation.RequiresApi
9+
import androidx.compose.foundation.layout.fillMaxSize
10+
import androidx.compose.material3.MaterialTheme
11+
import androidx.compose.material3.Surface
712
import androidx.compose.runtime.getValue
813
import androidx.compose.runtime.mutableFloatStateOf
914
import androidx.compose.runtime.setValue
15+
import androidx.compose.ui.Modifier
1016
import com.example.axelero.repository.OrientationDataRepository
1117
import com.example.axelero.ui.MainContent
18+
import com.example.axelero.ui.theme.AxeleroTheme
1219

1320
class MainActivity : ComponentActivity() {
1421
private val orientationDataRepository by lazy {
@@ -17,10 +24,19 @@ class MainActivity : ComponentActivity() {
1724
private var xAngle by mutableFloatStateOf(0f)
1825
private var yAngle by mutableFloatStateOf(0f)
1926
private var zAngle by mutableFloatStateOf(0f)
27+
@RequiresApi(Build.VERSION_CODES.O)
2028
override fun onCreate(savedInstanceState: Bundle?) {
2129
super.onCreate(savedInstanceState)
2230
setContent {
23-
MainContent(xAngle, yAngle, zAngle, orientationDataRepository)
31+
AxeleroTheme {
32+
// A surface container using the 'background' color from the theme
33+
Surface(
34+
modifier = Modifier.fillMaxSize(),
35+
color = MaterialTheme.colorScheme.background
36+
) {
37+
MainContent(xAngle, yAngle, zAngle, orientationDataRepository)
38+
}
39+
}
2440
}
2541
}
2642

Assignment3/Axelero/app/src/main/java/com/example/axelero/repository/OrientationDataRepository.kt

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import android.hardware.SensorEvent
66
import android.hardware.SensorEventListener
77
import android.hardware.SensorManager
88
import android.util.Log
9-
import androidx.core.content.getSystemService
109
import com.example.axelero.db.AppDatabase
1110
import com.example.axelero.db.OrientationData
1211
import com.example.axelero.db.OrientationDataDao

Assignment3/Axelero/app/src/main/java/com/example/axelero/ui/HistoryContent.kt

+95-63
Original file line numberDiff line numberDiff line change
@@ -2,103 +2,135 @@ package com.example.axelero.ui
22

33
import android.app.Activity
44
import android.content.Intent
5-
import android.hardware.SensorManager
6-
import android.os.Bundle
7-
import android.os.Environment
85
import androidx.activity.result.ActivityResultLauncher
96
import androidx.compose.foundation.layout.Arrangement
107
import androidx.compose.foundation.layout.Column
118
import androidx.compose.foundation.layout.Spacer
129
import androidx.compose.foundation.layout.fillMaxSize
10+
import androidx.compose.foundation.layout.fillMaxWidth
1311
import androidx.compose.foundation.layout.height
14-
import androidx.compose.material3.Button
12+
import androidx.compose.foundation.layout.padding
13+
import androidx.compose.foundation.rememberScrollState
14+
import androidx.compose.foundation.shape.RoundedCornerShape
15+
import androidx.compose.foundation.verticalScroll
16+
import androidx.compose.material.icons.Icons
17+
import androidx.compose.material.icons.automirrored.filled.ArrowBack
18+
import androidx.compose.material3.CardDefaults
19+
import androidx.compose.material3.ExperimentalMaterial3Api
20+
import androidx.compose.material3.Icon
21+
import androidx.compose.material3.IconButton
22+
import androidx.compose.material3.MaterialTheme
23+
import androidx.compose.material3.OutlinedButton
24+
import androidx.compose.material3.OutlinedCard
25+
import androidx.compose.material3.Scaffold
1526
import androidx.compose.material3.Text
27+
import androidx.compose.material3.TopAppBar
1628
import androidx.compose.runtime.Composable
17-
import androidx.compose.runtime.State
18-
import androidx.compose.runtime.getValue
19-
import androidx.compose.runtime.mutableIntStateOf
20-
import androidx.compose.runtime.mutableStateOf
2129
import androidx.compose.runtime.produceState
2230
import androidx.compose.runtime.remember
23-
import androidx.compose.runtime.setValue
31+
import androidx.compose.runtime.rememberCoroutineScope
2432
import androidx.compose.ui.Alignment
2533
import androidx.compose.ui.Modifier
34+
import androidx.compose.ui.platform.LocalContext
2635
import androidx.compose.ui.unit.dp
27-
import androidx.core.app.ActivityCompat.startActivityForResult
2836
import com.example.axelero.db.OrientationData
2937
import com.example.axelero.repository.OrientationDataRepository
3038
import com.example.axelero.ui.components.LineChart
31-
import com.example.axelero.ui.components.SensorDelayDropdownMenu
3239
import com.patrykandpatrick.vico.core.model.CartesianChartModelProducer
33-
import kotlinx.coroutines.CoroutineScope
34-
import kotlinx.coroutines.Dispatchers
3540
import kotlinx.coroutines.launch
36-
import java.io.File
3741

42+
@OptIn(ExperimentalMaterial3Api::class)
3843
@Composable
39-
fun HistoryContent(orientationDataRepository: OrientationDataRepository, createDocumentResult: ActivityResultLauncher<Intent>) {
44+
fun HistoryContent(
45+
orientationDataRepository: OrientationDataRepository,
46+
createDocumentResult: ActivityResultLauncher<Intent>
47+
) {
48+
val context = LocalContext.current
4049
val orientationData = produceState<List<OrientationData>>(initialValue = emptyList()) {
4150
value = orientationDataRepository.getOrientationData()
4251
}
43-
4452
val modelProducer1 = remember { CartesianChartModelProducer.build() }
4553
val modelProducer2 = remember { CartesianChartModelProducer.build() }
4654
val modelProducer3 = remember { CartesianChartModelProducer.build() }
55+
val coroutineScope = rememberCoroutineScope()
56+
val scrollState = rememberScrollState()
4757

48-
Column(
49-
modifier = Modifier.fillMaxSize(),
50-
verticalArrangement = Arrangement.Center,
51-
horizontalAlignment = Alignment.CenterHorizontally
52-
) {
53-
Text("Orientation Data History")
54-
Spacer(modifier = Modifier.height(16.dp))
55-
56-
// Display the three line charts for the actual orientation angles
57-
LineChart(
58-
"X Angle",
59-
orientationData.value.map { it.xAngle },
60-
modelProducer1
61-
)
62-
Spacer(modifier = Modifier.height(16.dp))
63-
LineChart(
64-
"Y Angle",
65-
orientationData.value.map { it.yAngle },
66-
modelProducer2
67-
)
68-
Spacer(modifier = Modifier.height(16.dp))
69-
LineChart(
70-
"Z Angle",
71-
orientationData.value.map { it.zAngle },
72-
modelProducer3
73-
)
58+
Scaffold(
59+
topBar = {
60+
TopAppBar(title = { Text("Orientation Data History") },
61+
navigationIcon = {
62+
IconButton(onClick = {(context as? Activity)?.onBackPressed() }) {
63+
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
64+
}
65+
}
66+
)
67+
}
68+
) { padding ->
69+
Column(
70+
modifier = Modifier
71+
.fillMaxSize()
72+
.padding(padding)
73+
.padding(horizontal = 16.dp)
74+
.verticalScroll(scrollState),
75+
verticalArrangement = Arrangement.Center,
76+
horizontalAlignment = Alignment.CenterHorizontally
77+
) {
78+
Spacer(Modifier.height(16.dp))
79+
OutlinedCard(modifier = Modifier.fillMaxWidth(), elevation = CardDefaults.outlinedCardElevation(defaultElevation = 4.dp)) {
80+
Column(modifier = Modifier.padding(16.dp)) {
81+
Text("X Angle", style = MaterialTheme.typography.titleMedium)
82+
Spacer(Modifier.height(8.dp))
83+
LineChart("X Angle", orientationData.value.map { it.xAngle }, modelProducer1)
84+
}
85+
}
7486

75-
Spacer(modifier = Modifier.height(16.dp))
76-
Button(
77-
onClick = {
78-
// Save the orientation data to a text file on the device
79-
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
80-
addCategory(Intent.CATEGORY_OPENABLE)
81-
type = "text/plain"
82-
putExtra(Intent.EXTRA_TITLE, "orientation_data_" + {orientationDataRepository.sensingInterval.toString()} + ".txt")
87+
Spacer(Modifier.height(16.dp))
88+
OutlinedCard(modifier = Modifier.fillMaxWidth(), elevation = CardDefaults.outlinedCardElevation(defaultElevation = 4.dp)) {
89+
Column(modifier = Modifier.padding(16.dp)) {
90+
Text("Y Angle", style = MaterialTheme.typography.titleMedium)
91+
Spacer(Modifier.height(8.dp))
92+
LineChart("Y Angle", orientationData.value.map { it.yAngle }, modelProducer2)
8393
}
84-
createDocumentResult.launch(intent)
8594
}
86-
) {
87-
Text("Export Data")
88-
}
89-
Spacer(modifier = Modifier.height(16.dp))
90-
Button(
91-
onClick = {
92-
// Reset the orientation data in the database
93-
CoroutineScope(Dispatchers.IO).launch {
94-
orientationDataRepository.clearOrientationData()
95+
96+
Spacer(Modifier.height(16.dp))
97+
OutlinedCard(modifier = Modifier.fillMaxWidth(), elevation = CardDefaults.outlinedCardElevation(defaultElevation = 4.dp)) {
98+
Column(modifier = Modifier.padding(16.dp)) {
99+
Text("Z Angle", style = MaterialTheme.typography.titleMedium)
100+
Spacer(Modifier.height(8.dp))
101+
LineChart("Z Angle", orientationData.value.map { it.zAngle }, modelProducer3)
95102
}
96103
}
97-
) {
98-
Text("Reset Data")
104+
105+
Spacer(Modifier.height(24.dp))
106+
OutlinedButton(
107+
onClick = {
108+
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT).apply {
109+
addCategory(Intent.CATEGORY_OPENABLE)
110+
type = "text/plain"
111+
putExtra(Intent.EXTRA_TITLE, "orientation_data_" + orientationDataRepository.sensingInterval.toString() + ".txt")
112+
}
113+
createDocumentResult.launch(intent)
114+
},
115+
modifier = Modifier.fillMaxWidth(0.6f),
116+
shape = RoundedCornerShape(8.dp)
117+
) {
118+
Text("Export Data")
119+
}
120+
Spacer(Modifier.height(16.dp))
121+
OutlinedButton(
122+
onClick = {
123+
coroutineScope.launch {
124+
orientationDataRepository.clearOrientationData()
125+
}
126+
},
127+
modifier = Modifier.fillMaxWidth(0.6f),
128+
shape = RoundedCornerShape(8.dp)
129+
) {
130+
Text("Reset Data")
131+
}
99132
}
100133
}
101134
}
102135

103136

104-

0 commit comments

Comments
 (0)