Compare commits

...

2 Commits

Author SHA1 Message Date
vsuryakumar
9b609f4de2 minor updates in graph. 2023-02-15 18:56:42 +05:30
vsuryakumar
cc11e057d4 Added graph view to the result page. 2023-02-13 17:01:02 +05:30
9 changed files with 169 additions and 4 deletions

1
.idea/misc.xml generated
View File

@@ -19,6 +19,7 @@
<entry key="app/src/main/res/layout/activity_main.xml" value="0.165" />
<entry key="app/src/main/res/layout/activity_splash.xml" value="0.24375" />
<entry key="app/src/main/res/layout/activity_test_right.xml" value="0.24375" />
<entry key="app/src/main/res/layout/fragment_graph.xml" value="0.19791666666666666" />
<entry key="app/src/main/res/layout/fragment_test_right_exp_reference.xml" value="0.25" />
<entry key="app/src/main/res/layout/fragment_test_right_exp_sample.xml" value="0.25" />
<entry key="app/src/main/res/layout/fragment_test_right_process.xml" value="0.24375" />

View File

@@ -56,6 +56,8 @@ dependencies {
implementation 'com.opencsv:opencsv:4.6'
// For the Graph
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0'
// implementation 'androidx.appcompat:appcompat:1.1.0'
// implementation "androidx.core:core-ktx:+"
// implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

View File

@@ -0,0 +1,102 @@
package com.example.hpos.presentation.testRight
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.fragment.app.activityViewModels
import com.example.hpos.R
import com.example.hpos.databinding.FragmentGraphBinding
import com.github.mikephil.charting.animation.Easing
import com.github.mikephil.charting.data.Entry
import com.github.mikephil.charting.data.LineData
import com.github.mikephil.charting.data.LineDataSet
class GraphFragment : Fragment() {
private lateinit var binding: FragmentGraphBinding
private val viewModel: TestRightViewModel by activityViewModels()
private val TAG = "GraphFragment"
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
// Inflate the layout for this fragment
binding = FragmentGraphBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
setLineChartData()
// setLineChartDataTest()
activity?.onBackPressedDispatcher?.addCallback(viewLifecycleOwner, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
parentFragmentManager.beginTransaction().replace(R.id.fl_main, TestRightResults()).commit()
}
})
}
private fun setLineChartData() {
val linevalues = ArrayList<Entry>()
Log.d(TAG, "SIZE = ${viewModel.wavelengthToAbsorbance.size}")
for (each in viewModel.wavelengthToAbsorbance) {
Log.d(TAG, each[0].toString())
// if (each[0] in 350.0..751.0) {
linevalues.add(Entry(each[0].toFloat(), each[1].toFloat()))
// }
}
val lineDataSet = LineDataSet(linevalues, "Wavelength -> Absorbance")
//We add features to our chart
lineDataSet.color = resources.getColor(R.color.blue_app)
lineDataSet.fillColor = resources.getColor(R.color.blue_app)
lineDataSet.setDrawFilled(true)
lineDataSet.mode = LineDataSet.Mode.CUBIC_BEZIER
lineDataSet.setDrawCircles(false)
//We connect our data to the UI Screen
val data = LineData(lineDataSet)
binding.getTheGraph.setBackgroundColor(resources.getColor(R.color.white))
binding.getTheGraph.animateXY(1000, 1000, Easing.EaseInCubic)
binding.getTheGraph.data = data
binding.getTheGraph.notifyDataSetChanged()
binding.getTheGraph.invalidate()
}
// private fun setLineChartDataTest() {
// val linevalues = ArrayList<Entry>()
// var y = 0.1f
// for (each in 350..555) {
// linevalues.add(Entry(each.toFloat(), y))
// y += 0.1f
// }
// for (each in 556..800) {
// linevalues.add(Entry(each.toFloat(), y))
// y -= 0.1f
// }
//
// val lineDataSet = LineDataSet(linevalues, "HPOS")
//
// lineDataSet.mode = LineDataSet.Mode.LINEAR;
//// lineDataSet.mode = LineDataSet.Mode.CUBIC_BEZIER
//
// lineDataSet.setDrawFilled(true)
// lineDataSet.fillColor = resources.getColor(R.color.blue_app)
//
// val data = LineData(lineDataSet)
// binding.getTheGraph.data = data
// binding.getTheGraph.invalidate()
// }
}

View File

@@ -110,7 +110,13 @@ class TestRightActivity : AppCompatActivity() {
val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(manager)
if (availableDrivers.isEmpty()) {
// Todo: To Add
onErrorReported("No Device is Connected")
// Todo: To remove
// supportFragmentManager.beginTransaction()
// .replace(binding.flMain.id, GraphFragment()).commit()
} else {
mDriver = availableDrivers[0]

View File

@@ -53,6 +53,11 @@ class TestRightResults : Fragment() {
binding.ivNext.setOnClickListener {
moveToSamplePage()
}
binding.ivGraph.setOnClickListener {
parentFragmentManager.beginTransaction()
.replace(R.id.fl_main, GraphFragment())
.commit()
}
}
fun moveToSamplePage() {

View File

@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="48dp"
android:tint="#219AD6" android:viewportHeight="24"
android:viewportWidth="24" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M14.06,9.94L12,9l2.06,-0.94L15,6l0.94,2.06L18,9l-2.06,0.94L15,12L14.06,9.94zM4,14l0.94,-2.06L7,11l-2.06,-0.94L4,8l-0.94,2.06L1,11l2.06,0.94L4,14zM8.5,9l1.09,-2.41L12,5.5L9.59,4.41L8.5,2L7.41,4.41L5,5.5l2.41,1.09L8.5,9zM4.5,20.5l6,-6.01l4,4L23,8.93l-1.41,-1.41l-7.09,7.97l-4,-4L3,19L4.5,20.5z"/>
</vector>

View File

@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.testRight.GraphFragment">
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/getTheGraph"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="52dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View File

@@ -190,7 +190,7 @@
android:layout_marginEnd="16dp"
android:src="@drawable/ic_baseline_home_24"
app:layout_constraintStart_toStartOf="@id/cv_sample_details"
app:layout_constraintEnd_toStartOf="@id/iv_next"
app:layout_constraintEnd_toStartOf="@id/iv_graph"
app:layout_constraintTop_toBottomOf="@id/cv_sample_details" />
<TextView
@@ -206,14 +206,37 @@
app:layout_constraintTop_toBottomOf="@id/iv_home" />
<ImageView
android:id="@+id/iv_next"
android:id="@+id/iv_graph"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:src="@drawable/ic_baseline_auto_graph_24"
app:layout_constraintStart_toEndOf="@id/iv_home"
app:layout_constraintEnd_toStartOf="@id/iv_next"
app:layout_constraintTop_toBottomOf="@id/cv_sample_details" />
<TextView
style="@style/title3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View\nSpectrum"
android:textAlignment="center"
android:textColor="@color/gray"
app:layout_constraintEnd_toEndOf="@id/iv_graph"
app:layout_constraintStart_toStartOf="@id/iv_graph"
app:layout_constraintTop_toBottomOf="@id/iv_graph" />
<ImageView
android:id="@+id/iv_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_baseline_new_label_24"
app:layout_constraintStart_toEndOf="@id/iv_home"
app:layout_constraintStart_toEndOf="@id/iv_graph"
app:layout_constraintEnd_toEndOf="@id/cv_sample_details"
app:layout_constraintTop_toBottomOf="@id/cv_sample_details" />

View File

@@ -33,7 +33,6 @@
<string name="yes_and_run">Yes, Run</string>
<!-- Instructions Text -->
<string name="Instructions">Instructions</string>
<string name="step1"><b><u>Step 1</u> : </b> Place the cuvette containing reference/baseline sample for referencing.</string>