Parser.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package de.tu_darmstadt.informatik.tk.olir;
  2. import android.widget.TextView;
  3. /**
  4. * Parses an objectSpecs.txt file
  5. * Created by Martin Herbers on 17.03.2017.
  6. */
  7. public class Parser {
  8. public static void parseFile(String[] content, ReadingActivity activity) {
  9. //First line: Object title
  10. TextView textView = activity.findViewById(R.id.textView);
  11. String title = content[0].substring(content[0].indexOf(':')+1);
  12. textView.setText(title);
  13. activity.name = title;
  14. //Set the two status strings
  15. activity.stringTrue = content[3].substring(content[3].indexOf(':')+1);
  16. activity.stringFalse = content[4].substring(content[4].indexOf(':')+1);
  17. DrawView background = activity.findViewById(R.id.drawView);
  18. //Outer shapes
  19. String shapes = content[1].substring(content[1].indexOf(':')+1);
  20. background.clearShapes();
  21. int idx = shapes.indexOf(']')+1;
  22. while (idx > 0) {
  23. //Add every basic shape to the list that gets drawn
  24. background.addShape(shapes.substring(0, idx));
  25. shapes = shapes.substring(idx);
  26. idx = shapes.indexOf(']')+1;
  27. }
  28. background.invalidate();
  29. DrawView drawView = activity.findViewById(R.id.drawView);
  30. //Button size and position
  31. String buttonText = content[2].substring(content[2].indexOf(':')+1);
  32. if (buttonText.charAt(1) == 'C') {
  33. buttonText = buttonText.substring(3);
  34. int index = buttonText.indexOf(';');
  35. float x = Float.parseFloat(buttonText.substring(0, index));
  36. buttonText = buttonText.substring(index + 1);
  37. index = buttonText.indexOf(';');
  38. float y = Float.parseFloat(buttonText.substring(0, index));
  39. buttonText = buttonText.substring(index + 1);
  40. index = buttonText.length()-1;
  41. float diameter = Float.parseFloat(buttonText.substring(0, index));
  42. drawView.setPosition(x, y, diameter, diameter);
  43. } else if (buttonText.charAt(1) == 'R') {
  44. buttonText = buttonText.substring(3);
  45. int index = buttonText.indexOf(';');
  46. float x = Float.parseFloat(buttonText.substring(0, index));
  47. buttonText = buttonText.substring(index + 1);
  48. index = buttonText.indexOf(';');
  49. float y = Float.parseFloat(buttonText.substring(0, index));
  50. buttonText = buttonText.substring(index + 1);
  51. index = buttonText.indexOf(';');
  52. float width = Float.parseFloat(buttonText.substring(0, index));
  53. buttonText = buttonText.substring(index + 1);
  54. index = buttonText.length()-1;
  55. float height = Float.parseFloat(buttonText.substring(0, index));
  56. drawView.setPosition(x, y, width, height);
  57. }
  58. }
  59. }