Доброго времени суток))
Помогите пожалуйста вытащить полученные данные из метода Sun
Нужно вывести значение переменной proiz на экран.
Заранее спасибо)))
Помогите пожалуйста вытащить полученные данные из метода Sun
Код:
package ru.myscanner.scannerth;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
@SuppressLint("SdCardPath")
private String FILENAME = "/mnt/sdcard/cnc.txt";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView text = (TextView)findViewById(R.id.text1);
ArrayList<String> listWithCommands = null;
try {
listWithCommands = getCommandsToDB(FILENAME);
} catch (IOException e) {
// TODO Автоматически созданный блок catch
e.printStackTrace();
}
for (String s : listWithCommands) {
text.append(s+"\n");
}
}
public static ArrayList<String> getCommandsToDB(String fileName) throws IOException {
ArrayList<String> forReturnList = new ArrayList<String>();
String stringWithText = null;
BufferedReader bufferedReader = new BufferedReader(new FileReader(new File(fileName)));
StringBuilder stringBuilder = new StringBuilder();
while((stringWithText = bufferedReader.readLine()) != null) {
stringBuilder.append(stringWithText + "\n");
}
Pattern pattern = Pattern.compile("((PART)\\s?(((\\w*\\.?))*)?)|(((G|M)[0-9]{1,3})?\\s(X|Y|A|B)(-?[0-9]+\\.?[0-9]+)\\s?((X|Y)(-?[0-9]+\\.?[0-9]+))?\\s?(((I)([0-9]+\\.?[0-9]+))?\\s((J)([0-9]+\\.?[0-9]+)))?)");
Matcher matcher = pattern.matcher(stringBuilder.toString());
String mainGroup = null;
double x = 0;
double y = 0;
String part = null;
while (matcher.find()) {
double a = 0;
double b = 0;
double i = 0;
double j = 0;
mainGroup = matcher.group(7);
part = matcher.group(3);
x = (matcher.group(9) != null && matcher.group(9).equals("X")) ? Double.parseDouble(matcher.group(10)) : 0;
y = (matcher.group(9) != null && matcher.group(9).equals("Y")) ? Double.parseDouble(matcher.group(10)) : 0;
a = (matcher.group(9) != null && matcher.group(9).equals("A")) ? Double.parseDouble(matcher.group(10)) : a;
b = (matcher.group(9) != null && matcher.group(9).equals("B")) ? Double.parseDouble(matcher.group(10)) : b;
x = (matcher.group(12) != null && matcher.group(12).equals("X")) ? Double.parseDouble(matcher.group(13)) : x;
y = (matcher.group(12) != null && matcher.group(12).equals("Y")) ? Double.parseDouble(matcher.group(13)) : y;
i = (matcher.group(16) != null && matcher.group(16).equals("I")) ? Double.parseDouble(matcher.group(17)) : i;
j = (matcher.group(19) != null && matcher.group(19).equals("J")) ? Double.parseDouble(matcher.group(20)) : j;
forReturnList.add(mainGroup + " " + x +" " + y + " " + i + " " + j + " " + a + " " + b + " " + part);
Sun(mainGroup, x, y, i, j, a, b, part);
}
return forReturnList;
}
public static void Sun(String mg, double x, double y, double i, double j, double a, double b, String part){
double x1 = 0;
double x2 = 0;
double y1 = 0;
double y2 = 0;
double i1 = 0;
double j1 = 0;
double u = 0;
double u0 = 15;
double u1 = 20;
String pt = null;
double proiz = 0;
if(part!=null){
pt=part;
}
if(mg=="G0"){
proiz=x+y;
}
return;
}
}
Нужно вывести значение переменной proiz на экран.
Заранее спасибо)))