Skip to content

Commit

Permalink
Working logging and comminication between tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
tainfante committed Aug 7, 2019
1 parent 00bd121 commit 567034a
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 55 deletions.
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.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ android {
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
Expand All @@ -39,4 +40,5 @@ dependencies {
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
implementation 'com.android.support:multidex:1.0.3'
}
30 changes: 29 additions & 1 deletion app/src/main/java/com/example/rehabapp/AccFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,43 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.rehabapp.ValuesToLoad.Companion.accEntries
import com.example.rehabapp.ValuesToLoad.Companion.gyrEntries
import com.github.mikephil.charting.charts.LineChart
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.data.LineData
import com.github.mikephil.charting.data.LineDataSet


class AccFragment : Fragment() {

lateinit var accChart: LineChart
lateinit var gyrChart: LineChart

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View = inflater.inflate(R.layout.acc_layout, container, false)
): View {
var view: View =inflater.inflate(R.layout.acc_layout, container, false)

accChart=view.findViewById(R.id.accChart)

val accDataSet= LineDataSet(accEntries, "Random")

val accLineData= LineData(accDataSet)
accChart.data = accLineData
accChart.invalidate()

gyrChart=view.findViewById(R.id.gyrChart)

val gyrDataSet= LineDataSet(gyrEntries, "Random")

val gyrLineData= LineData(gyrDataSet)
gyrChart.data = gyrLineData
gyrChart.invalidate()

return view
}

}
6 changes: 1 addition & 5 deletions app/src/main/java/com/example/rehabapp/ComFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import android.view.View
import android.view.ViewGroup
import android.widget.Button
import androidx.fragment.app.Fragment
import android.widget.Toast
import android.graphics.Bitmap
import java.text.SimpleDateFormat
import java.util.*

import android.app.Activity

class ComFragment : Fragment() {

Expand Down
30 changes: 17 additions & 13 deletions app/src/main/java/com/example/rehabapp/EmgFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.example.rehabapp.ValuesToLoad.Companion.emgEntries
import com.example.rehabapp.ValuesToLoad.Companion.fftEntries
import com.github.mikephil.charting.charts.LineChart
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.data.LineData
Expand All @@ -13,7 +15,8 @@ import com.github.mikephil.charting.data.LineDataSet

class EmgFragment : Fragment() {

lateinit var chart: LineChart
lateinit var emgChart: LineChart
lateinit var fftChart: LineChart

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -22,20 +25,21 @@ class EmgFragment : Fragment() {
): View {
val view: View = inflater.inflate(R.layout.emg_layout, container, false)

chart=view.findViewById(R.id.emgChart)
val entries = ArrayList<Entry>()
entries.add(Entry(1.0F, 2.0F))
entries.add(Entry(2.0F, 8.0F))
entries.add(Entry(3.0F, 13.0F))
entries.add(Entry(4.0F, 15.0F))
entries.add(Entry(5.0F, 7.0F))
entries.add(Entry(6.0F, 3.0F))
emgChart=view.findViewById(R.id.emgChart)

val dataSet=LineDataSet(entries, "Random")
val emgDataSet=LineDataSet(emgEntries, "Random")

val lineData= LineData(dataSet)
chart.data = lineData
chart.invalidate()
val emgLineData= LineData(emgDataSet)
emgChart.data = emgLineData
emgChart.invalidate()

fftChart=view.findViewById(R.id.fftChart)

val fftDataSet=LineDataSet(fftEntries, "Random")

val fftLineData= LineData(fftDataSet)
fftChart.data = fftLineData
fftChart.invalidate()


return view
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/example/rehabapp/HistFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class HistFragment : Fragment() {
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View = inflater.inflate(R.layout.hist_layout, container, false)
):View {
var view : View = inflater.inflate(R.layout.hist_layout, container, false)

return view
}
}
10 changes: 9 additions & 1 deletion app/src/main/java/com/example/rehabapp/LogFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.fragment.app.Fragment
import com.example.rehabapp.ValuesToLoad.Companion.logText


class LogFragment : Fragment() {

lateinit var log:TextView

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View = inflater.inflate(R.layout.log_layout, container, false)
): View {
val view: View = inflater.inflate(R.layout.log_layout, container, false)
log=view.findViewById(R.id.log)
log.append(logText)

return view
}
}
19 changes: 15 additions & 4 deletions app/src/main/java/com/example/rehabapp/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import androidx.viewpager.widget.ViewPager
import com.google.android.material.appbar.AppBarLayout
import com.google.android.material.tabs.TabLayout
import android.R.attr.start
import android.os.Build
import android.os.SystemClock
import android.widget.Chronometer
import android.widget.Toast


import androidx.annotation.RequiresApi
import com.example.rehabapp.ValuesToLoad.Companion.logText
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*


class MainActivity : AppCompatActivity() {
Expand Down Expand Up @@ -40,6 +44,13 @@ class MainActivity : AppCompatActivity() {
}


fun addLog(log: String) {
val calendar = Calendar.getInstance()
val h = calendar.get(Calendar.HOUR_OF_DAY)
val m = calendar.get(Calendar.MINUTE)
val result = "$h:$m"
logText=("$logText$result $log")
}

private fun setupViewPager(viewPager: ViewPager) {
val adapter = SectionsPageAdapter(super.getSupportFragmentManager())
Expand All @@ -51,18 +62,18 @@ class MainActivity : AppCompatActivity() {
viewPager.adapter = adapter
}


fun startChronometer() {
if (!running) {
chronometer.base = SystemClock.elapsedRealtime()
chronometer.start()
addLog("Started measurement\n")
running = true
}
}
fun stopChronometer() {
if (running) {
chronometer.stop()
chronometer.base = SystemClock.elapsedRealtime()
addLog("Stopped measurement\n")
running = false
}
}
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/java/com/example/rehabapp/ValuesToLoad.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.rehabapp

import com.github.mikephil.charting.data.Entry

class ValuesToLoad {

companion object{
var logText: String = ""
val emgEntries = ArrayList<Entry>()
val fftEntries = ArrayList<Entry>()
val accEntries = ArrayList<Entry>()
val gyrEntries = ArrayList<Entry>()
}

}
25 changes: 15 additions & 10 deletions app/src/main/res/layout/acc_layout.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="25sp"
android:text="Tab3"
android:layout_marginTop="40dp"
android:id="@+id/textTab1"/>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/accChart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="top"/>

</RelativeLayout>
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/gyrChart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="bottom"/>

</LinearLayout>
7 changes: 6 additions & 1 deletion app/src/main/res/layout/com_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
android:id="@+id/textTab1"/>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/spinner"/>
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:layout_marginTop="40dp"
android:layout_marginBottom="100dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
Expand All @@ -25,12 +28,14 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/startButton"
android:layout_weight="1"
android:layout_margin="30dp" android:gravity="center|top"/>
<Button
android:text="STOP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:layout_weight="1"
android:id="@+id/stopButton" android:gravity="center|center_horizontal|top"/>
</LinearLayout>

Expand Down
25 changes: 17 additions & 8 deletions app/src/main/res/layout/emg_layout.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.github.mikephil.charting.charts.LineChart
android:id="@+id/emgChart"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="top"/>

<com.github.mikephil.charting.charts.LineChart
android:id="@+id/emgChart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/fftChart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_gravity="bottom"/>

</RelativeLayout>
</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/hist_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="25sp"
android:text="Tab4"
android:text="Nothing interesting here"
android:layout_marginTop="40dp"
android:id="@+id/textTab1"/>

Expand Down
17 changes: 8 additions & 9 deletions app/src/main/res/layout/log_layout.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textSize="25sp"
android:text="Tab5"
android:layout_marginTop="40dp"
android:id="@+id/textTab1"/>

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:textSize="15sp"
android:id="@+id/log"/>

</RelativeLayout>

0 comments on commit 567034a

Please sign in to comment.