|
@@ -1,62 +1,134 @@
|
|
|
package de.tu_darmstadt.informatik.tk.olir;
|
|
|
|
|
|
+import android.content.ContextWrapper;
|
|
|
import android.content.Intent;
|
|
|
+import android.graphics.Color;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
import android.os.Bundle;
|
|
|
-import android.util.TypedValue;
|
|
|
import android.view.KeyEvent;
|
|
|
+import android.view.Menu;
|
|
|
+import android.view.MenuInflater;
|
|
|
+import android.view.MenuItem;
|
|
|
import android.view.View;
|
|
|
+import android.widget.LinearLayout;
|
|
|
+import android.widget.TableLayout;
|
|
|
+import android.widget.TableRow;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
+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.io.OutputStreamWriter;
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
|
-public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
+public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
- public static String stringFalse = "";
|
|
|
- public static String stringTrue = "";
|
|
|
- private static DrawView drawView;
|
|
|
- private float scale;
|
|
|
+ private ArrayList<String> lines;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setContentView(R.layout.activity_main);
|
|
|
|
|
|
+ getSupportActionBar().setTitle("Previous Sensors");
|
|
|
+
|
|
|
+ parseHistory();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
+ MenuInflater inflater = getMenuInflater();
|
|
|
+ inflater.inflate(R.menu.menu, menu);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
+
|
|
|
+ if (item.getItemId() == R.id.clear_history) {
|
|
|
+ try {
|
|
|
+ OutputStreamWriter writer = new OutputStreamWriter(openFileOutput("history.txt", MODE_PRIVATE));
|
|
|
+ String content = "";
|
|
|
+ writer.write(content);
|
|
|
+ writer.flush();
|
|
|
+ writer.close();
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ TableLayout table = findViewById(R.id.tableLayout);
|
|
|
+ table.removeAllViews();
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void parseHistory() {
|
|
|
+ lines = new ArrayList<>();
|
|
|
+ ContextWrapper cw = new ContextWrapper(this);
|
|
|
+ File file = new File(cw.getFilesDir(), "history.txt");
|
|
|
|
|
|
+ TableLayout table = findViewById(R.id.tableLayout);
|
|
|
|
|
|
- //FROM http://stackoverflow.com/questions/8656968/convert-mm-to-pixels 17.3.17 16.30
|
|
|
- scale = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, 1,
|
|
|
- getResources().getDisplayMetrics());
|
|
|
+ try {
|
|
|
+ if (file.exists()) {
|
|
|
+ FileInputStream is = new FileInputStream(file);
|
|
|
|
|
|
- /*drawView = (DrawView) this.findViewById(R.id.drawView);
|
|
|
- drawView.setScale(scale);
|
|
|
- drawView.setBackgroundColor(Color.WHITE);
|
|
|
- this.findViewById(R.id.button2).setOnTouchListener(new View.OnTouchListener() {
|
|
|
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
|
|
+ String line = reader.readLine();
|
|
|
+ while (line != null) {
|
|
|
+ lines.add(line);
|
|
|
|
|
|
- @Override
|
|
|
- public boolean onTouch(View v, MotionEvent event) {
|
|
|
- if (event.getAction() == MotionEvent.ACTION_DOWN ) {
|
|
|
- changeText(v);
|
|
|
- return true;
|
|
|
+ line = reader.readLine();
|
|
|
}
|
|
|
- return false;
|
|
|
}
|
|
|
- });*/
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ for (int i = lines.size()-1; i >= 0; i--) {
|
|
|
+ String line = lines.get(i);
|
|
|
+
|
|
|
+ String name = line.substring(line.indexOf("|")+1);
|
|
|
+ name = name.substring(0, name.indexOf("|"));
|
|
|
+
|
|
|
+ TableRow row = new TableRow(this);
|
|
|
+ row.setPadding(10,30,10,30);
|
|
|
+ row.setTag(i);
|
|
|
+ row.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View v) {
|
|
|
+ openHistoryEntry(v);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ TextView textView = new TextView(this);
|
|
|
+ textView.setText(name);
|
|
|
+ textView.setTextSize(20);
|
|
|
+ row.addView(textView);
|
|
|
+ table.addView(row);
|
|
|
+
|
|
|
+ View v = new View(this);
|
|
|
+ v.setLayoutParams(new LinearLayout.LayoutParams(
|
|
|
+ LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
+ 2
|
|
|
+ ));
|
|
|
+ v.setBackgroundColor(Color.parseColor("#000000"));
|
|
|
+ table.addView(v);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public void addObject(View view) {
|
|
|
Intent intent = new Intent(this, ObjectsActivity.class);
|
|
|
startActivity(intent);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public void changeText(View view) {
|
|
|
- /*TextView text = (TextView)this.findViewById(R.id.textView2);
|
|
|
- text.setText(stringTrue);
|
|
|
- text.setTextColor(Color.RED);*/
|
|
|
- }
|
|
|
-
|
|
|
@Override
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
if (keyCode == KeyEvent.KEYCODE_BACK
|
|
@@ -66,4 +138,20 @@ public class MainActivity extends AppCompatActivity {
|
|
|
}
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
}
|
|
|
+
|
|
|
+ public void openHistoryEntry(View view) {
|
|
|
+ TableRow row = (TableRow) view;
|
|
|
+ int index = Integer.valueOf((Integer) row.getTag());
|
|
|
+ String line = lines.get(index);
|
|
|
+ String date = line.substring(0, line.indexOf("|"));
|
|
|
+ line = line.substring(line.indexOf("|") + 1);
|
|
|
+ String name = line.substring(0, line.indexOf("|"));
|
|
|
+ String result = line.substring(line.indexOf("|") + 1);
|
|
|
+
|
|
|
+ Intent intent = new Intent(this, ResultActivity.class);
|
|
|
+ intent.putExtra("time", date);
|
|
|
+ intent.putExtra("name", name);
|
|
|
+ intent.putExtra("result", Boolean.parseBoolean(result));
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
}
|