Parser.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package de.tu_darmstadt.informatik.tk.olir;
  2. import android.content.Context;
  3. import android.graphics.Color;
  4. import android.graphics.drawable.Drawable;
  5. import android.graphics.drawable.GradientDrawable;
  6. import android.support.constraint.ConstraintLayout;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.util.Log;
  9. import android.util.TypedValue;
  10. import android.view.View;
  11. import android.view.ViewGroup;
  12. import android.widget.Button;
  13. import android.widget.LinearLayout;
  14. import android.widget.TextView;
  15. import java.io.File;
  16. import java.io.FileNotFoundException;
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import java.util.Scanner;
  20. /**
  21. * Parses an objectSpecs.txt file
  22. * Created by Martin Herbers on 17.03.2017.
  23. */
  24. public class Parser {
  25. public static void parseFile(String[] content, ReadingActivity activity) {
  26. //First line: Object title
  27. TextView textView = activity.findViewById(R.id.textView);
  28. String title = content[0].substring(content[0].indexOf(':')+1);
  29. textView.setText(title);
  30. activity.name = title;
  31. //Set the two status strings
  32. activity.stringTrue = content[3].substring(content[3].indexOf(':')+1);
  33. activity.stringFalse = content[4].substring(content[4].indexOf(':')+1);
  34. DrawView background = activity.findViewById(R.id.drawView);
  35. //Outer shapes
  36. String shapes = content[1].substring(content[1].indexOf(':')+1);
  37. background.clearShapes();
  38. int idx = shapes.indexOf(']')+1;
  39. while (idx > 0) {
  40. //Add every basic shape to the list that gets drawn
  41. background.addShape(shapes.substring(0, idx));
  42. shapes = shapes.substring(idx);
  43. idx = shapes.indexOf(']')+1;
  44. }
  45. background.invalidate();
  46. DrawView drawView = activity.findViewById(R.id.drawView);
  47. //Button size and position
  48. String buttonText = content[2].substring(content[2].indexOf(':')+1);
  49. if (buttonText.charAt(1) == 'C') {
  50. buttonText = buttonText.substring(3);
  51. int index = buttonText.indexOf(';');
  52. float x = Float.parseFloat(buttonText.substring(0, index));
  53. buttonText = buttonText.substring(index + 1);
  54. index = buttonText.indexOf(';');
  55. float y = Float.parseFloat(buttonText.substring(0, index));
  56. buttonText = buttonText.substring(index + 1);
  57. index = buttonText.length()-1;
  58. float diameter = Float.parseFloat(buttonText.substring(0, index));
  59. drawView.setPosition(x, y, diameter, diameter);
  60. } else if (buttonText.charAt(1) == 'R') {
  61. buttonText = buttonText.substring(3);
  62. int index = buttonText.indexOf(';');
  63. float x = Float.parseFloat(buttonText.substring(0, index));
  64. buttonText = buttonText.substring(index + 1);
  65. index = buttonText.indexOf(';');
  66. float y = Float.parseFloat(buttonText.substring(0, index));
  67. buttonText = buttonText.substring(index + 1);
  68. index = buttonText.indexOf(';');
  69. float width = Float.parseFloat(buttonText.substring(0, index));
  70. buttonText = buttonText.substring(index + 1);
  71. index = buttonText.length()-1;
  72. float height = Float.parseFloat(buttonText.substring(0, index));
  73. drawView.setPosition(x, y, width, height);
  74. }
  75. }
  76. }