ViewLog.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package de.tudarmstadt.informatik.hostage.ui;
  2. import java.text.SimpleDateFormat;
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5. import java.util.Date;
  6. import java.util.HashMap;
  7. import de.tudarmstadt.informatik.hostage.R;
  8. import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
  9. import android.app.Activity;
  10. import android.content.Intent;
  11. import android.os.Bundle;
  12. import android.view.Menu;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.widget.LinearLayout;
  16. import android.widget.TextView;
  17. public class ViewLog extends Activity {
  18. HashMap<String, TextView> statisticCounter;
  19. DatabaseHandler dbh;
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. super.onCreate(savedInstanceState);
  23. setContentView(R.layout.activity_viewlog);
  24. dbh = new DatabaseHandler(getApplicationContext());
  25. initStatistic();
  26. }
  27. @Override
  28. public boolean onCreateOptionsMenu(Menu menu) {
  29. getMenuInflater().inflate(R.menu.main, menu);
  30. return true;
  31. }
  32. @Override
  33. public boolean onOptionsItemSelected(MenuItem item) {
  34. // Handle item selection
  35. switch (item.getItemId()) {
  36. case R.id.action_settings:
  37. startActivity(new Intent(this, SettingsActivity.class));
  38. default:
  39. return super.onOptionsItemSelected(item);
  40. }
  41. }
  42. public void showLog(View view){
  43. startActivity(new Intent(this, ViewLogTable.class));
  44. }
  45. public void deleteLog(View view){
  46. dbh.clearData();
  47. }
  48. private void initStatistic() {
  49. LinearLayout container = (LinearLayout) findViewById(R.id.layoutContainer);
  50. statisticCounter = new HashMap<String, TextView>();
  51. ArrayList<String> protocols = new ArrayList<String>();
  52. protocols.add("Total");
  53. protocols.addAll(Arrays.asList(getResources().getStringArray(
  54. R.array.protocols)));
  55. for (String protocol : protocols) {
  56. LinearLayout containerRow = new LinearLayout(this);
  57. TextView text = new TextView(this);
  58. text.setText("-" + protocol + ": ");
  59. text.setTextAppearance(this, android.R.style.TextAppearance_Medium);
  60. containerRow.addView(text);
  61. text = new TextView(this);
  62. text.setTextAppearance(this, android.R.style.TextAppearance_Medium);
  63. containerRow.addView(text);
  64. if(protocol.equals("Total")){
  65. text.setText("" + dbh.getAttackCount());
  66. }else{
  67. text.setText("" + dbh.getAttackPerProtokolCount(protocol));
  68. }
  69. statisticCounter.put(protocol, text);
  70. container.addView(containerRow);
  71. }
  72. int attackCount = dbh.getRecordCount();
  73. if(attackCount > 0){
  74. SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
  75. Date resultdate = new Date(Long.parseLong(dbh.getRecord(1).getTimestamp()));
  76. TextView text = (TextView) findViewById(R.id.textFirstAttackValue);
  77. text.setText(sdf.format(resultdate));
  78. text = (TextView) findViewById(R.id.textLastAttackValue);
  79. resultdate = new Date(Long.parseLong(dbh.getRecord( dbh.getRecordCount()).getTimestamp()));
  80. text.setText(sdf.format(resultdate));
  81. } else {
  82. TextView text = (TextView) findViewById(R.id.textFirstAttackValue);
  83. text.setText("-");
  84. text = (TextView) findViewById(R.id.textLastAttackValue);
  85. text.setText("-");
  86. }
  87. }
  88. }