123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package de.tudarmstadt.informatik.hostage.ui;
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.HashMap;
- import org.apache.http.client.ClientProtocolException;
- import org.apache.http.client.HttpClient;
- import org.apache.http.client.methods.HttpPost;
- import org.apache.http.entity.StringEntity;
- import de.tudarmstadt.informatik.hostage.R;
- import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
- import de.tudarmstadt.informatik.hostage.logging.DatabaseHandler;
- import de.tudarmstadt.informatik.hostage.logging.Record;
- import de.tudarmstadt.informatik.hostage.logging.SQLLogger;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- public class ViewLog extends Activity {
- HashMap<String, TextView> statisticCounter;
- DatabaseHandler dbh;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_viewlog);
- dbh = new DatabaseHandler(getApplicationContext());
- initStatistic();
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle item selection
- switch (item.getItemId()) {
- case R.id.action_settings:
- startActivity(new Intent(this, SettingsActivity.class));
- default:
- return super.onOptionsItemSelected(item);
- }
- }
- public void exportDatabase(View view){
- SQLLogger log = new SQLLogger(this);
- log.exportDatabase("DEFAULT");
- }
-
- public void uploadDatabase(View view){
- SQLLogger log = new SQLLogger(this);
- log.uploadDatabase();
- }
-
- public void showLog(View view){
- startActivity(new Intent(this, ViewLogTable.class));
- }
-
- public void deleteLog(View view){
- dbh.clearData();
- }
- private void initStatistic() {
- LinearLayout container = (LinearLayout) findViewById(R.id.layoutContainer);
- statisticCounter = new HashMap<String, TextView>();
- ArrayList<String> protocols = new ArrayList<String>();
- protocols.add("Total");
- protocols.addAll(Arrays.asList(getResources().getStringArray(
- R.array.protocols)));
- for (String protocol : protocols) {
- LinearLayout containerRow = new LinearLayout(this);
- TextView text = new TextView(this);
- text.setText("-" + protocol + ": ");
- text.setTextAppearance(this, android.R.style.TextAppearance_Medium);
- containerRow.addView(text);
- text = new TextView(this);
- text.setTextAppearance(this, android.R.style.TextAppearance_Medium);
- containerRow.addView(text);
- if(protocol.equals("Total")){
- text.setText("" + dbh.getAttackCount());
- }else{
- text.setText("" + dbh.getAttackPerProtokolCount(protocol));
- }
- statisticCounter.put(protocol, text);
- container.addView(containerRow);
- }
-
- int attackCount = dbh.getRecordCount();
- if(attackCount > 0){
- SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
- Date resultdate = new Date(dbh.getRecord(1).getTimestamp());
- TextView text = (TextView) findViewById(R.id.textFirstAttackValue);
- text.setText(sdf.format(resultdate));
- text = (TextView) findViewById(R.id.textLastAttackValue);
- resultdate = new Date(dbh.getRecord( dbh.getRecordCount()).getTimestamp());
- text.setText(sdf.format(resultdate));
- } else {
- TextView text = (TextView) findViewById(R.id.textFirstAttackValue);
- text.setText("-");
- text = (TextView) findViewById(R.id.textLastAttackValue);
- text.setText("-");
- }
- }
- }
|