ObjectsActivity.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package de.tu_darmstadt.informatik.tk.olir;
  2. import android.content.Intent;
  3. import android.net.Uri;
  4. import android.os.Bundle;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.view.MenuItem;
  7. import android.view.View;
  8. import com.ipaulpro.afilechooser.utils.FileUtils;
  9. import java.io.BufferedReader;
  10. import java.io.File;
  11. import java.io.FileInputStream;
  12. import java.io.FileNotFoundException;
  13. import java.io.IOException;
  14. import java.io.InputStream;
  15. import java.io.InputStreamReader;
  16. public class ObjectsActivity extends AppCompatActivity {
  17. static final int FILE_SELECT_CODE = 1;
  18. @Override
  19. protected void onCreate(Bundle savedInstanceState) {
  20. super.onCreate(savedInstanceState);
  21. setContentView(R.layout.activity_objects);
  22. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  23. }
  24. @Override
  25. public boolean onOptionsItemSelected(MenuItem item) {
  26. if (item.getItemId() == android.R.id.home) {
  27. Intent intent = new Intent(this, MainActivity.class);
  28. startActivity(intent);
  29. return true;
  30. }
  31. return false;
  32. }
  33. public void openFile(View view) {
  34. // Create the ACTION_GET_CONTENT Intent
  35. Intent getContentIntent = FileUtils.createGetContentIntent();
  36. Intent intent = Intent.createChooser(getContentIntent, "1. Select a file");
  37. startActivityForResult(intent, FILE_SELECT_CODE);
  38. }
  39. //FROM http://stackoverflow.com/questions/7856959/android-file-chooser 14.3.17 13:00
  40. protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  41. switch (requestCode) {
  42. case FILE_SELECT_CODE:
  43. if (resultCode == RESULT_OK) {
  44. // Get the Uri of the selected file
  45. Uri uri = data.getData();
  46. // Get the path
  47. String path = FileUtils.getPath(this, uri);
  48. if (path != null && FileUtils.isLocal(path)) {
  49. File file = new File(path);
  50. try {
  51. openReadingActivityWith(new FileInputStream(file));
  52. } catch (FileNotFoundException e) {
  53. e.printStackTrace();
  54. }
  55. /* Parser.parseFile(file, drawView, (TextView) this.findViewById(R.id.textView), (Button) this.findViewById(R.id.button2), scale);
  56. TextView text = (TextView)this.findViewById(R.id.textView2);
  57. text.setText(stringFalse);
  58. text.setTextColor(Color.BLACK);*/
  59. }
  60. }
  61. break;
  62. }
  63. super.onActivityResult(requestCode, resultCode, data);
  64. }
  65. public void openLoad(View view) {
  66. openReadingActivityWith(getResources().openRawResource(R.raw.object_specs_load));
  67. }
  68. public void openPressure(View view) {
  69. openReadingActivityWith(getResources().openRawResource(R.raw.object_specs_pressure));
  70. }
  71. public void openAcceleration(View view) {
  72. openReadingActivityWith(getResources().openRawResource(R.raw.object_specs_acceleration));
  73. }
  74. public void openTilt90(View view) {
  75. openReadingActivityWith(getResources().openRawResource(R.raw.object_specs_tilt90));
  76. }
  77. public void openTilt180(View view) {
  78. openReadingActivityWith(getResources().openRawResource(R.raw.object_specs_tilt180));
  79. }
  80. public void openTempRising(View view) {
  81. openReadingActivityWith(getResources().openRawResource(R.raw.object_specs_temp_rising));
  82. }
  83. public void openTempFalling(View view) {
  84. openReadingActivityWith(getResources().openRawResource(R.raw.object_specs_temp_falling));
  85. }
  86. public void openReadingActivityWith(InputStream stream) {
  87. BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
  88. String[] content = new String[5];
  89. String line;
  90. int i = 0;
  91. try {
  92. while ((line = reader.readLine()) != null) {
  93. content[i++] = line;
  94. }
  95. } catch (IOException e) {
  96. e.printStackTrace();
  97. }
  98. Intent intent = new Intent(this, ReadingActivity.class);
  99. intent.putExtra("file", content);
  100. startActivity(intent);
  101. }
  102. }