Skip to content

Commit

Permalink
Merge pull request #11 from aditydcp/9-reduce-power-consumption-and-heat
Browse files Browse the repository at this point in the history
reduce power consumption and heat
  • Loading branch information
aditydcp committed Jun 17, 2023
2 parents 55b3904 + 0a2c01c commit ac5434d
Show file tree
Hide file tree
Showing 67 changed files with 328 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
plugins {
id 'com.android.application' version '7.3.0' apply false
id 'com.android.library' version '7.3.0' apply false
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
id 'org.jetbrains.kotlin.android' version '1.8.21' apply false
// id 'org.jetbrains.kotlin.jvm' version '1.7.10' apply false
}
2 changes: 2 additions & 0 deletions mobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

<uses-feature android:name="android.hardware.bluetooth" android:required="true"/>

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
Expand Down
Binary file added mobile/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ object Constants {
var PREF_DEVICE_ID = "deviceId"
var PREF_TREE_URI = "treeUri"
var PREF_PATIENT_NAME = "patientName"
var PREF_PPG_GREEN_VISIBILITY = "ppgGreenVisibility"
var PREF_PPG_IR_VISIBILITY = "ppgIrVisibility"
var PREF_PPG_RED_VISIBILITY = "ppgRedVisibility"
var PREF_ECG_VISIBILITY = "ecgVisibility"
var PREF_ANALYSIS_VISIBILITY = "analysisVisibility"

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ import com.example.samplewearmobileapp.Constants.PPG_GREEN_SAMPLE_RATE
import com.example.samplewearmobileapp.Constants.PPG_IR_RED_SAMPLE_RATE
import com.example.samplewearmobileapp.Constants.PREF_ANALYSIS_VISIBILITY
import com.example.samplewearmobileapp.Constants.PREF_DEVICE_ID
import com.example.samplewearmobileapp.Constants.PREF_ECG_VISIBILITY
import com.example.samplewearmobileapp.Constants.PREF_PATIENT_NAME
import com.example.samplewearmobileapp.Constants.PREF_PPG_GREEN_VISIBILITY
import com.example.samplewearmobileapp.Constants.PREF_PPG_IR_VISIBILITY
import com.example.samplewearmobileapp.Constants.PREF_PPG_RED_VISIBILITY
import com.example.samplewearmobileapp.Constants.PREF_TREE_URI
import com.example.samplewearmobileapp.EcgImager.createImage
import com.example.samplewearmobileapp.constants.Entity.PHONE_APP
Expand Down Expand Up @@ -92,7 +96,6 @@ class MainActivity : AppCompatActivity(), GoogleApiClient.ConnectionCallbacks,
private var wearMessage: Message? = null
private var appState = 0
private var bluetoothState = STATE_OFF
private var isUsingAnalysis = false

private var ppgGreenValueNumber = 0
private var ppgIrValueNumber = 0
Expand All @@ -114,6 +117,12 @@ class MainActivity : AppCompatActivity(), GoogleApiClient.ConnectionCallbacks,
private var isPpgIrRunning = false
private var isPpgRedRunning = false

private var isPpgGreenVisible = true
private var isPpgIrVisible = true
private var isPpgRedVisible = true
private var isEcgVisible = true
private var isUsingAnalysis = false

private var sharedPreferences: SharedPreferences? = null

private var deviceId = ""
Expand Down Expand Up @@ -277,6 +286,21 @@ class MainActivity : AppCompatActivity(), GoogleApiClient.ConnectionCallbacks,
if (oldDeviceId != deviceId) {
resetDeviceId(oldDeviceId)
}
// setup plot visibility preferences
isPpgGreenVisible = sharedPreferences!!.getBoolean(
PREF_PPG_GREEN_VISIBILITY, true
)
isPpgIrVisible = sharedPreferences!!.getBoolean(
PREF_PPG_IR_VISIBILITY, true
)
isPpgRedVisible = sharedPreferences!!.getBoolean(
PREF_PPG_RED_VISIBILITY, true
)
isEcgVisible = sharedPreferences!!.getBoolean(
PREF_ECG_VISIBILITY, true
)
setPlotVisibility()

// PREF_ANALYSIS_VISIBILITY
isUsingAnalysis = sharedPreferences!!.getBoolean(
PREF_ANALYSIS_VISIBILITY, true
Expand Down Expand Up @@ -367,14 +391,26 @@ class MainActivity : AppCompatActivity(), GoogleApiClient.ConnectionCallbacks,
getString(R.string.status_default))
}

if (!isUsingAnalysis) {
analysisContainer.visibility = View.GONE
}

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
// register preference listener
sharedPreferences!!.registerOnSharedPreferenceChangeListener(this)

// get visibility preferences
isPpgGreenVisible = sharedPreferences!!.getBoolean(
PREF_PPG_GREEN_VISIBILITY, true)
isPpgIrVisible = sharedPreferences!!.getBoolean(
PREF_PPG_IR_VISIBILITY, true)
isPpgRedVisible = sharedPreferences!!.getBoolean(
PREF_PPG_RED_VISIBILITY, true)
isEcgVisible = sharedPreferences!!.getBoolean(
PREF_ECG_VISIBILITY, true)
setPlotVisibility()
isUsingAnalysis = sharedPreferences!!.getBoolean(
PREF_ANALYSIS_VISIBILITY, false)
if (!isUsingAnalysis) {
analysisContainer.visibility = View.GONE
}

setLastHr()
// stopTime = Date()

Expand Down Expand Up @@ -444,6 +480,8 @@ class MainActivity : AppCompatActivity(), GoogleApiClient.ConnectionCallbacks,
}
if (isRecording) {
// Turn recording off
// stop foreground service
MobileService.stopService(this)
setLastHr()
stopTime = Date()
isRecording = false
Expand All @@ -463,6 +501,8 @@ class MainActivity : AppCompatActivity(), GoogleApiClient.ConnectionCallbacks,
menu.findItem(R.id.save).isVisible = true
} else {
// Turn recording on
// start foreground service
MobileService.startService(this,"Start recording...")
setLastHr()
startTime = Date()
stopTime = Date()
Expand Down Expand Up @@ -1141,6 +1181,27 @@ class MainActivity : AppCompatActivity(), GoogleApiClient.ConnectionCallbacks,
hrPlotter?.setupPlot()
}

private fun setPlotVisibility() {
runOnUiThread {
ppgGreenPlot.visibility = when (isPpgGreenVisible) {
true -> View.VISIBLE
false -> View.GONE
}
ppgIrPlot.visibility = when (isPpgIrVisible) {
true -> View.VISIBLE
false -> View.GONE
}
ppgRedPlot.visibility = when (isPpgRedVisible) {
true -> View.VISIBLE
false -> View.GONE
}
ecgPlot.visibility = when (isEcgVisible) {
true -> View.VISIBLE
false -> View.GONE
}
}
}

// /**
// * Setup a new device into the shared preferences.
// * This will remove the earliest device added to the list
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.example.samplewearmobileapp

import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.os.IBinder
import androidx.core.app.NotificationCompat
import androidx.core.content.ContextCompat

class MobileService : Service() {
private val CHANNEL_ID = "MobileService"
private var isServiceRunning = false

companion object {
fun startService(context: Context, message: String) {
val intent = Intent(context, MobileService::class.java)
intent.putExtra("message", message)
ContextCompat.startForegroundService(context, intent)

val service = ContextCompat.getSystemService(context, MobileService::class.java)
service?.isServiceRunning = true
}

fun stopService(context: Context) {
val service = ContextCompat.getSystemService(context, MobileService::class.java)
service?.isServiceRunning = false

val intent = Intent(context, MobileService::class.java)
context.stopService(intent)
}

fun isServiceRunning(context: Context) : Boolean {
val service = ContextCompat.getSystemService(context, MobileService::class.java)
return service?.isServiceRunning() ?: false
}
}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val message = intent?.getStringExtra("message")
createNotificationChannel()

val pendingIntent: PendingIntent =
Intent(this, MainActivity::class.java).let { notificationIntent ->
PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_IMMUTABLE)
}

val notification = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle("Main Foreground Service Sample App")
.setContentText("Recording...")
.setContentIntent(pendingIntent)
.setOngoing(true)
.build()

startForeground(1, notification)
isServiceRunning = true
return START_STICKY
}

override fun onBind(intent: Intent?): IBinder? {
return null
}

private fun createNotificationChannel() {
val serviceChannel = NotificationChannel(
CHANNEL_ID, "Mobile Foreground Service Channel",
NotificationManager.IMPORTANCE_HIGH
)
serviceChannel.description = "Description"
serviceChannel.enableLights(true)
serviceChannel.lightColor = Color.BLUE

val manager = getSystemService(NotificationManager::class.java)
manager?.createNotificationChannel(serviceChannel)
}

private fun isServiceRunning() : Boolean {
return isServiceRunning
}
}
21 changes: 21 additions & 0 deletions mobile/src/main/res/drawable-anydpi/ic_notification.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="212"
android:viewportHeight="161.64844"
android:tint="#FFFFFF">
<group android:scaleX="0.92"
android:scaleY="0.7014932"
android:translateX="8.48"
android:translateY="24.126577">
<group android:translateY="132.82031">
<path android:pathData="M51.6875,-7.8125Q51.6875,-4.359375,49.53125,-2.171875Q47.390625,-0,43.953125,-0L16.25,-0Q12.796875,-0,10.578125,-2.171875Q8.375,-4.359375,8.375,-7.8125L8.375,-35.71875L18.140625,-35.71875L18.140625,-8.65625L41.90625,-8.65625L41.90625,-34.875L11.53125,-71.578125Q8.375,-75.375,8.375,-79.953125L8.375,-102.234375Q8.375,-105.6875,10.578125,-107.859375Q12.796875,-110.046875,16.25,-110.046875L43.953125,-110.046875Q47.390625,-110.046875,49.53125,-107.859375Q51.6875,-105.6875,51.6875,-102.234375L51.6875,-76.640625L41.90625,-76.640625L41.90625,-101.390625L18.140625,-101.390625L18.140625,-78.1875L48.65625,-41.484375Q51.6875,-37.828125,51.6875,-33.265625L51.6875,-7.8125Z"
android:fillColor="#000000"/>
<path android:pathData="M124.21875,0L115,0L115,-69.6875Q115,-71.15625,115.984375,-78.328125L97.984375,-10.34375L96.015625,-10.34375L78.015625,-78.328125Q79,-71.09375,79,-69.6875L79,0L69.796875,0L69.796875,-110.046875L78.859375,-110.046875L96.71875,-38.46875Q96.859375,-37.90625,97,-35.296875Q97,-36.359375,97.28125,-38.46875L115.140625,-110.046875L124.21875,-110.046875L124.21875,0Z"
android:fillColor="#000000"/>
<path android:pathData="M208.60938,-110.046875L193.625,0.28125L185.6875,0.28125L173.73438,-82.6875Q173.65625,-84.875,173.45312,-89.15625Q173.45312,-86.90625,173.17188,-82.6875L161.21875,0.28125L153.26562,0.28125L138.29688,-110.046875L148,-110.046875L157.34375,-30.65625Q157.42188,-27.984375,157.625,-22.78125Q157.5625,-25.453125,157.90625,-30.65625L169.29688,-110.046875L177.67188,-110.046875L188.98438,-30.65625Q189.125,-27.984375,189.26562,-22.78125Q189.26562,-25.453125,189.625,-30.65625L198.96875,-110.046875L208.60938,-110.046875Z"
android:fillColor="#000000"/>
</group>
</group>
</vector>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 0 additions & 30 deletions mobile/src/main/res/drawable-v24/ic_launcher_foreground.xml

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions mobile/src/main/res/drawable/ic_launcher_foreground.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="108dp"
android:height="108dp"
android:viewportWidth="212"
android:viewportHeight="161.64844">
<group android:scaleX="0.46"
android:scaleY="0.3507466"
android:translateX="57.24"
android:translateY="52.4754">
<group android:translateY="132.82031">
<path android:pathData="M51.6875,-7.8125Q51.6875,-4.359375,49.53125,-2.171875Q47.390625,-0,43.953125,-0L16.25,-0Q12.796875,-0,10.578125,-2.171875Q8.375,-4.359375,8.375,-7.8125L8.375,-35.71875L18.140625,-35.71875L18.140625,-8.65625L41.90625,-8.65625L41.90625,-34.875L11.53125,-71.578125Q8.375,-75.375,8.375,-79.953125L8.375,-102.234375Q8.375,-105.6875,10.578125,-107.859375Q12.796875,-110.046875,16.25,-110.046875L43.953125,-110.046875Q47.390625,-110.046875,49.53125,-107.859375Q51.6875,-105.6875,51.6875,-102.234375L51.6875,-76.640625L41.90625,-76.640625L41.90625,-101.390625L18.140625,-101.390625L18.140625,-78.1875L48.65625,-41.484375Q51.6875,-37.828125,51.6875,-33.265625L51.6875,-7.8125Z"
android:fillColor="#FFFFFF"/>
<path android:pathData="M124.21875,0L115,0L115,-69.6875Q115,-71.15625,115.984375,-78.328125L97.984375,-10.34375L96.015625,-10.34375L78.015625,-78.328125Q79,-71.09375,79,-69.6875L79,0L69.796875,0L69.796875,-110.046875L78.859375,-110.046875L96.71875,-38.46875Q96.859375,-37.90625,97,-35.296875Q97,-36.359375,97.28125,-38.46875L115.140625,-110.046875L124.21875,-110.046875L124.21875,0Z"
android:fillColor="#FFFFFF"/>
<path android:pathData="M208.60938,-110.046875L193.625,0.28125L185.6875,0.28125L173.73438,-82.6875Q173.65625,-84.875,173.45312,-89.15625Q173.45312,-86.90625,173.17188,-82.6875L161.21875,0.28125L153.26562,0.28125L138.29688,-110.046875L148,-110.046875L157.34375,-30.65625Q157.42188,-27.984375,157.625,-22.78125Q157.5625,-25.453125,157.90625,-30.65625L169.29688,-110.046875L177.67188,-110.046875L188.98438,-30.65625Q189.125,-27.984375,189.26562,-22.78125Q189.26562,-25.453125,189.625,-30.65625L198.96875,-110.046875L208.60938,-110.046875Z"
android:fillColor="#FFFFFF"/>
</group>
</group>
</vector>
4 changes: 2 additions & 2 deletions mobile/src/main/res/mipmap-anydpi-v26/ic_launcher.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
4 changes: 2 additions & 2 deletions mobile/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
<background android:drawable="@color/ic_launcher_background"/>
<foreground android:drawable="@drawable/ic_launcher_foreground"/>
</adaptive-icon>
Binary file added mobile/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed mobile/src/main/res/mipmap-hdpi/ic_launcher.webp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added mobile/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed mobile/src/main/res/mipmap-mdpi/ic_launcher.webp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added mobile/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed mobile/src/main/res/mipmap-xhdpi/ic_launcher.webp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added mobile/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed mobile/src/main/res/mipmap-xxhdpi/ic_launcher.webp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed mobile/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
4 changes: 4 additions & 0 deletions mobile/src/main/res/values/ic_launcher_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">#5B0992</color>
</resources>
12 changes: 12 additions & 0 deletions mobile/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@
<string name="device_id_summary">Polar device ID or MAC address</string>
<string name="patient_name_title">Patient Name</string>
<string name="patient_name_summary">Patient name for ECG image file</string>
<string name="ppg_green_visibility_title">PPG Green Plot Visibility</string>
<string name="ppg_green_visibility_summary_on">PPG Green plot will be shown</string>
<string name="ppg_green_visibility_summary_off">PPG Green plot will not be shown</string>
<string name="ppg_ir_visibility_title">PPG IR Plot Visibility</string>
<string name="ppg_ir_visibility_summary_on">PPG IR plot will be shown</string>
<string name="ppg_ir_visibility_summary_off">PPG IR plot will not be shown</string>
<string name="ppg_red_visibility_title">PPG Red Plot Visibility</string>
<string name="ppg_red_visibility_summary_on">PPG Red plot will be shown</string>
<string name="ppg_red_visibility_summary_off">PPG Red plot will not be shown</string>
<string name="ecg_visibility_title">ECG Plot Visibility</string>
<string name="ecg_visibility_summary_on">ECG plot will be shown</string>
<string name="ecg_visibility_summary_off">ECG plot will not be shown</string>
<string name="analysis_visibility_title">Analysis Visibility</string>
<string name="analysis_visibility_summary_on">Analysis plots will be shown</string>
<string name="analysis_visibility_summary_off">Analysis plots will not be shown</string>
Expand Down
Loading

0 comments on commit ac5434d

Please sign in to comment.