From 497417760343bc0a8be91290968ef3fc3ce4dbdb Mon Sep 17 00:00:00 2001 From: Balint Kovacs Date: Wed, 4 May 2011 12:32:34 +0200 Subject: [PATCH] Added refresh menu option to the logview activity Signed-off-by: Balint Kovacs --- src/hu/blint/ssldroid/SSLDroidReadLogs.java | 78 +++++++++++---------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/src/hu/blint/ssldroid/SSLDroidReadLogs.java b/src/hu/blint/ssldroid/SSLDroidReadLogs.java index 9efa01a..9523289 100644 --- a/src/hu/blint/ssldroid/SSLDroidReadLogs.java +++ b/src/hu/blint/ssldroid/SSLDroidReadLogs.java @@ -7,56 +7,60 @@ import java.io.InputStreamReader; import android.app.Activity; import android.os.Bundle; import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; import android.widget.TextView; public class SSLDroidReadLogs extends Activity{ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.read_logs); - TextView logcontainer = (TextView) findViewById(R.id.logTextView); - logcontainer.setText(""); - Process mLogcatProc = null; - BufferedReader reader = null; - try - { - mLogcatProc = Runtime.getRuntime().exec(new String[] + @Override + public boolean onCreateOptionsMenu(Menu menu) { + MenuItem refresh = menu.add("Refresh"); + refresh.setIcon(android.R.drawable.ic_menu_rotate); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + refreshLogs(); + return true; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.read_logs); + refreshLogs(); + } + + public void refreshLogs(){ + TextView logcontainer = (TextView) findViewById(R.id.logTextView); + logcontainer.setText(""); + Process mLogcatProc = null; + BufferedReader reader = null; + try { + mLogcatProc = Runtime.getRuntime().exec(new String[] {"logcat", "-d", "-v", "time", "-b", "main", "SSLDroid:D SSLDroidGui:D *:S" }); reader = new BufferedReader(new InputStreamReader(mLogcatProc.getInputStream())); String line; - //final StringBuilder log = new StringBuilder(); String separator = System.getProperty("line.separator"); - while ((line = reader.readLine()) != null) - { - logcontainer.append(line); - logcontainer.append(separator); + while ((line = reader.readLine()) != null){ + logcontainer.append(line+separator); } - - //logcontainer.setText(log); + } catch (IOException e) { + Log.d("SSLDroid", "Logcat problem: "+e.toString()); } - - catch (IOException e) - { - Log.d("SSLDroid", "Logcat problem: "+e.toString()); - } - - finally - { + finally { if (reader != null) - try - { - reader.close(); - } - catch (IOException e) - { - Log.d("SSLDroid", "Logcat problem: "+e.toString()); - } - + try { + reader.close(); + } catch (IOException e) { + Log.d("SSLDroid", "Logcat problem: "+e.toString()); + } } - } - + } + }