-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
193 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,90 @@ | ||
package com.example.rehabapp | ||
|
||
import android.database.Cursor | ||
import android.os.Build | ||
|
||
import android.graphics.Color | ||
import android.graphics.Paint | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.RequiresApi | ||
import androidx.core.content.ContextCompat | ||
import androidx.fragment.app.Fragment | ||
import com.androidplot.xy.XYPlot | ||
|
||
import com.androidplot.Plot | ||
import com.androidplot.xy.* | ||
import java.text.DecimalFormat | ||
import java.util.* | ||
|
||
|
||
class EmgFragment : Fragment() { | ||
class EmgFragment(private val queueHandOuter: QueueHandOuter) : Fragment() { | ||
|
||
lateinit var emgChart: XYPlot | ||
lateinit var data: RealTimeXYDatasource | ||
lateinit var myThread: Thread | ||
|
||
@RequiresApi(Build.VERSION_CODES.P) | ||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
val view: View = inflater.inflate(R.layout.emg_layout, container, false) | ||
|
||
var color1 = ContextCompat.getColor((activity as MainActivity).applicationContext, R.color.colorblue) | ||
var color2 = ContextCompat.getColor((activity as MainActivity).applicationContext, R.color.colorpink) | ||
|
||
emgChart=view.findViewById(R.id.emgChart) | ||
|
||
val plotUpdater=MyPlotUpdater(emgChart) | ||
emgChart.graph.getLineLabelStyle(XYGraphWidget.Edge.BOTTOM).format = DecimalFormat("0") | ||
emgChart.domainStepMode = StepMode.INCREMENT_BY_VAL | ||
emgChart.domainStepValue = 400.0 | ||
emgChart.rangeStepMode = StepMode.INCREMENT_BY_VAL | ||
emgChart.rangeStepValue = 10000.0 | ||
emgChart.graph.getLineLabelStyle(XYGraphWidget.Edge.LEFT).format = DecimalFormat("0") | ||
|
||
emgChart.setRangeBoundaries(0,4095, BoundaryMode.FIXED) | ||
|
||
data= RealTimeXYDatasource(this.queueHandOuter, 0) | ||
|
||
val rawSeries = RealTimeSeries(data, 0, "Raw") | ||
val filteredSeries = RealTimeSeries(data, 1, "Filtered") | ||
|
||
val formatter1 = LineAndPointFormatter(Color.rgb(0, 200, 0), null, null, null) | ||
formatter1.linePaint.strokeJoin = Paint.Join.ROUND | ||
formatter1.linePaint.strokeWidth = 2f | ||
emgChart.addSeries(rawSeries, formatter1) | ||
|
||
val formatter2 = LineAndPointFormatter(Color.rgb(0, 0, 200), null, null, null) | ||
formatter2.linePaint.strokeJoin = Paint.Join.ROUND | ||
formatter2.linePaint.strokeWidth = 2f | ||
emgChart.addSeries(filteredSeries, formatter2) | ||
|
||
data.addObserver(plotUpdater) | ||
|
||
return view | ||
} | ||
|
||
override fun setUserVisibleHint(isVisibleToUser: Boolean) { | ||
super.setUserVisibleHint(isVisibleToUser) | ||
if(isVisibleToUser&&isResumed){ | ||
onResume() | ||
} else if(!isVisibleToUser&&isResumed){ | ||
onPause() | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
if((!userVisibleHint)) return | ||
myThread = Thread(data) | ||
myThread.start() | ||
} | ||
|
||
override fun onPause() { | ||
data.stopThread() | ||
super.onPause() | ||
} | ||
|
||
inner class MyPlotUpdater(private var emgplot: Plot<*, *, *, *, *>) : Observer { | ||
|
||
override fun update(o: Observable?, arg: Any?) { | ||
emgplot.redraw() | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.