|
@@ -1,157 +0,0 @@
|
|
|
-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.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 {
|
|
|
-
|
|
|
- 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);
|
|
|
-
|
|
|
- try {
|
|
|
- if (file.exists()) {
|
|
|
- FileInputStream is = new FileInputStream(file);
|
|
|
-
|
|
|
- BufferedReader reader = new BufferedReader(new InputStreamReader(is));
|
|
|
- String line = reader.readLine();
|
|
|
- while (line != null) {
|
|
|
- lines.add(line);
|
|
|
-
|
|
|
- line = reader.readLine();
|
|
|
- }
|
|
|
- }
|
|
|
- } 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);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
- if (keyCode == KeyEvent.KEYCODE_BACK
|
|
|
- && event.getRepeatCount() == 0) {
|
|
|
- this.finishAffinity();
|
|
|
- return true;
|
|
|
- }
|
|
|
- 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);
|
|
|
- }
|
|
|
-}
|