Главная страница

Отчет_Разработка мобильных приложений_ЛР3. РМП_лр3. Необработанные


Скачать 0.75 Mb.
НазваниеНеобработанные
АнкорОтчет_Разработка мобильных приложений_ЛР3
Дата25.05.2021
Размер0.75 Mb.
Формат файлаdocx
Имя файлаРМП_лр3.docx
ТипДокументы
#209662
страница2 из 3
1   2   3

package com.example.lab3;

import androidx.appcompat.app.AppCompatActivity;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.Toast;
import com.jjoe64.graphview.GraphView;
import com.jjoe64.graphview.helper.StaticLabelsFormatter;
import com.jjoe64.graphview.series.DataPoint;
import com.jjoe64.graphview.series.LineGraphSeries;

public class MainActivity extends AppCompatActivity {
final String LOG_TAG = "myLogs";
String FILENAME = "seg";
String DIR_SD = "patient001";
String FILENAME_D = "seg01.dat";
TextView tvOut,tvHeader,tvSignal;
File rootFolder;
File[] filesArray;
Spinner patient_spinner;
Spinner signal_spinner;
Spinner interval_spinner;
ArrayList patients =new ArrayList();
String[] sigNames={"Three limb leads I Raw","Three limb leads II Raw","Three limb leads III Raw","Six precordial leads V1 Raw",
"Six precordial leads V2 Raw","Six precordial leads V3 Raw","Six precordial leads V4 Raw","Six precordial leads V5 Raw",
"Six precordial leads V6 Raw","Three limb potentials LA Raw","Three limb potentials RA Raw","Three limb potentials LL Raw",
"Six true unipolar chest leads UV1 Raw","Six true unipolar chest leads UV2 Raw","Six true unipolar chest leads UV3 Raw",
"Six true unipolar chest leads UV4 Raw","Six true unipolar chest leads UV5 Raw","Six true unipolar chest leads UV6 Raw",
"Three limb leads I","Three limb leads II","Three limb leads III","Six precordial leads V1","Six precordial leads V2",
"Six precordial leads V3","Six precordial leads V4","Six precordial leads V5","Six precordial leads V6",
"Three limb potentials LA","Three limb potentials RA","Three limb potentials LL","Six true unipolar chest leads UV1"
,"Six true unipolar chest leads UV2","Six true unipolar chest leads UV3","Six true unipolar chest leads UV4"
,"Six true unipolar chest leads UV5","Six true unipolar chest leads UV6","WCT"};
//Intervals[] - длительностьотображаемогоинтервала (1,2,5,10 секунд))
String[] Intervals={"1","2","5","10"};
int Nint=1;//порядковыйномеротображаемогоинтервала. Сбрасыватьв 1 приизменениимасштаба.
class Segment {
String name;
int number_of_segments=1;
int number_of_signals;
float sampling_frequency=250;
float counter_frequency=0;
float base_counter_value=0;
int number_of_samples_per_signal;
String base_time ="0:0:0";
String base_date="";
}
Segment seg = new Segment();

class SignHeader {
String file_name;
int format= 0;
int samples_per_frame=1;
int skew=0;
int byte_offset=0;
float adc_gain=200;
int baseline;
String units="mV";
int adc_resolution=12;
int adc_zero= 0;
int initial_value= 200;
int checksum= 0;
int block_size= 0;
String description= "";
int index=0;
}
SignHeader[] signal=new SignHeader[37]; //описаниеформатасигналоввсегменте
// int mask=0;
int max_skew=0;
int highest_adc_resolution=0;
int total_bits_per_frame=0;
int total_bytes_per_frame=0;
int highest_samples_per_frame=0;
int curSeg=1;
float[] samples=new float[101];
int cntPoints=0;

private File getExternalPath(int i,int f,String type) {
String s=Integer.toString(f);
if (f<10) s="0"+s+type;s=FILENAME+s;
return new File(filesArray[i], s);
}
File fileH;//файлзаголовка
File fileD;//файлданных
GraphView linegraph ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
// инициализациявкладок
tabHost.setup();
TabHost.TabSpec tabSpec;
// создаемвкладкуиуказываемтег
tabSpec = tabHost.newTabSpec("tag1");
// названиевкладки
tabSpec.setIndicator("Инфо");
// указываем id компонентаиз FrameLayout, онистанетсодержимым
tabSpec.setContent(R.id.tab1);
// добавляемвкорневойэлемент
tabHost.addTab(tabSpec);

tabSpec = tabHost.newTabSpec("tag2");
tabSpec.setIndicator("Сигнал");
tabSpec.setContent(R.id.tab2);
tabHost.addTab(tabSpec);

tabSpec = tabHost.newTabSpec("tag3");
tabSpec.setIndicator("График");
tabSpec.setContent(R.id.tab3);
tabHost.addTab(tabSpec);

// перваявкладкабудетвыбранапоумолчанию
tabHost.setCurrentTabByTag("tag1");

// обработчикпереключениявкладок
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
Toast.makeText(getBaseContext(), "tabId = " + tabId, Toast.LENGTH_SHORT).show();
}
});
tvOut = (TextView) this.findViewById(R.id.tvOut);
tvHeader = (TextView) this.findViewById(R.id.tvHeader);
tvSignal = (TextView) this.findViewById(R.id.tvSignal);
linegraph = (GraphView) findViewById(R.id.line_graph);
rootFolder = getExternalFilesDir(null);
filesArray = rootFolder.listFiles();
tvOut.setText("пациентов: " + filesArray.length+"\n\r");
//заполняеммассипациентов
for (File f: filesArray) {
if (f.isDirectory()) {
Collections.addAll(patients,f.toString().substring(f.toString().lastIndexOf("/")));}
}
fileH=getExternalPath(0,curSeg,".hea");
fileD=getExternalPath(0,curSeg,".dat");
// созданиеобработчикасписков
AdapterView.OnItemSelectedListener onItSel = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView parent, View view,
int position, long id) {
int i;
File f;
switch (parent.getId()) {
case R.id.patient_spinner:
curSeg=1;
f = getExternalPath(patient_spinner.getSelectedItemPosition(),curSeg,".hea");
try {
FileInputStream inputStream = new FileInputStream(f);
fileH=f;
HeaderFile(position);
SignalFile();
}
catch (FileNotFoundException e) {
tvOut.setText("File not found:\n\r");
}
catch (IOException e) {
tvOut.setText("IOException");
e.printStackTrace();
}
break;
case R.id.signal_spinner:
i=position;
tvSignal.setText("\n\rfile_name: "+ signal[i].file_name+"\n\rformat: "+signal[i].format+"\n\rsamples_per_frame: "+signal[i].samples_per_frame+
"\n\rskew: "+signal[i].skew+"\n\rbyte_offset: "+signal[i].byte_offset+
"\n\radc_gain: "+signal[i].adc_gain+"\n\rbaseline: "+signal[i].baseline+
"\n\runits: "+signal[i].units+"\n\radc_resolution: "+signal[i].adc_resolution+"\n\radc_zero: "+signal[i].adc_zero+
"\n\rinitial_value: "+signal[i].initial_value+"\n\rchecksum: "+signal[i].checksum+"\n\rblock_size: " +signal[i].block_size+
"\n\rdescription: "+signal[i].description);
SignalFile();
break;
case R.id.interval_spinner:
Nint=1;//Integer.parseInt(Intervals[interval_spinner.getSelectedItemPosition()]);
SignalFile();
break;
}
}
@Override
public void onNothingSelected(AdapterView arg0) {
}};
patient_spinner = (Spinner) findViewById(R.id.patient_spinner);
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_spinner_item,patients);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
patient_spinner.setAdapter(adapter);
patient_spinner.setPrompt("Patient");
patient_spinner.setOnItemSelectedListener(onItSel);
patient_spinner.setSelection(0);
signal_spinner = (Spinner) findViewById(R.id.signal_spinner);
ArrayAdapter adapterS = new ArrayAdapter(this,
android.R.layout.simple_spinner_item,sigNames);
// Specify the layout to use when the list of choices appears
adapterS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
signal_spinner.setAdapter(adapterS);
signal_spinner.setPrompt("Signal");
signal_spinner.setOnItemSelectedListener(onItSel);
signal_spinner.setSelection(0);
interval_spinner = (Spinner) findViewById(R.id.interval_spinner);
ArrayAdapter adapterI = new ArrayAdapter(this,
android.R.layout.simple_spinner_item,Intervals);
// Specify the layout to use when the list of choices appears
adapterI.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
interval_spinner.setAdapter(adapterI);
interval_spinner.setPrompt("Interval");
interval_spinner.setOnItemSelectedListener(onItSel);
interval_spinner.setSelection(0);
}
//---------------------------------------------------------------------------------
public void onclick(View v) {
File f;
switch (v.getId()) {
//кнопкиперемещениямеждусегментами
case R.id.btnLeft:
if (curSeg>1){
curSeg--;
tvOut.setText("Переход к предыдущему сегменту N "+curSeg);
f = getExternalPath(patient_spinner.getSelectedItemPosition(),curSeg,".hea");
try {
FileInputStream inputStream = new FileInputStream(f);
fileH=f;
HeaderFile(patient_spinner.getSelectedItemPosition());
SignalFile();
}
catch (FileNotFoundException e) {
curSeg++;
}
catch (IOException e) {
tvOut.setText("IOException");
e.printStackTrace();
curSeg++;}}
else {
tvOut.setText("Выбран 1-й сегмент");
}
break;
case R.id.btnRight:
curSeg++;
tvOut.setText("Переход к следующему сегменту N "+curSeg);
f = getExternalPath(patient_spinner.getSelectedItemPosition(),curSeg,".hea");
try {
FileInputStream inputStream = new FileInputStream(f);
fileH=f;
HeaderFile(patient_spinner.getSelectedItemPosition());
SignalFile();
}
catch (FileNotFoundException e) {
tvOut.setText("Выбран последний сегмент");
curSeg--;}
catch (IOException e) {
tvOut.setText("IOException");
e.printStackTrace();
curSeg--;}
break;
//кнопкислед./пред. дляперемещениямеждуинтервалами.
case R.id.btnIntRight:
if (Nint<(int)10/Integer.parseInt(Intervals[interval_spinner.getSelectedItemPosition()])){
Nint++;
tvOut.setText("Переход к следующему интервалу Nint="+Nint);
SignalFile();}
else
tvOut.setText("Выбран последний интервал Nint="+Nint);
break;
case R.id.btnIntLeft:
if (Nint!=1){
Nint--;
tvOut.setText("Переход к предыдущему интервалу Nint="+Nint);
SignalFile();}
else
tvOut.setText("Выбран первый интервал Nint="+Nint);
break;
}
}
//Чтениеинформацииосегментеизфайлазаголовка
void HeaderFile(int p) {
String str,str1;
int cnt=1;
try {
FileInputStream inputStream = new FileInputStream(fileH);
// открываемпотокдлячтения
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
str1= "";
str = br.readLine();
str=str.replaceAll("\\n","");
str=str.replaceAll("\\r","");
str=str.trim();
String header[] = str.split(" "); // разбиваемстрокупопробелу
str="";
max_skew=0;
highest_adc_resolution=0;
total_bits_per_frame=0;
highest_samples_per_frame=0;
if (header[0].indexOf("/")==-1) //односегментный
{
seg.name=header[0];
seg.number_of_signals=Integer.parseInt(header[1]);
if (header.length>2) {
if (header[2].indexOf("/") == -1) {
seg.sampling_frequency = Float.parseFloat(header[2]);
seg.counter_frequency =seg.sampling_frequency;
}
else {
seg.sampling_frequency = Float.parseFloat(header[2].substring(0, header[2].indexOf("/")));
if (header[2].indexOf("(") == -1)
seg.counter_frequency = Float.parseFloat(header[2].substring(header[2].indexOf("/") + 1));
else {
seg.counter_frequency = Float.parseFloat(header[2].substring(header[2].indexOf("/") + 1, header[2].indexOf("(")));
seg.base_counter_value = Float.parseFloat(header[2].substring(header[2].indexOf("(") + 1, header[2].indexOf(")")));
}
if (seg.counter_frequency<0) seg.counter_frequency=seg.sampling_frequency;
}
if (header.length > 3){
seg.number_of_samples_per_signal=Integer.parseInt(header[3]);
if (header.length > 4){
seg.base_time=header[4];
if (header.length > 5)
seg.base_date=header[5];
}
}
}
}
1   2   3


написать администратору сайта