summaryrefslogtreecommitdiffstats
path: root/src/com/mcserver
diff options
context:
space:
mode:
authorfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-19 02:35:19 +0200
committerfaketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-08-19 02:35:19 +0200
commite5bef782fcac6c55770d4a234a3a2c4beb26fc27 (patch)
treed8ab7d5173c5a4329da2087dc38742a80e170944 /src/com/mcserver
parentAndroid: Showing last MCServer related logcat message (diff)
downloadcuberite-e5bef782fcac6c55770d4a234a3a2c4beb26fc27.tar
cuberite-e5bef782fcac6c55770d4a234a3a2c4beb26fc27.tar.gz
cuberite-e5bef782fcac6c55770d4a234a3a2c4beb26fc27.tar.bz2
cuberite-e5bef782fcac6c55770d4a234a3a2c4beb26fc27.tar.lz
cuberite-e5bef782fcac6c55770d4a234a3a2c4beb26fc27.tar.xz
cuberite-e5bef782fcac6c55770d4a234a3a2c4beb26fc27.tar.zst
cuberite-e5bef782fcac6c55770d4a234a3a2c4beb26fc27.zip
Diffstat (limited to '')
-rw-r--r--src/com/mcserver/MCServerActivity.java76
1 files changed, 44 insertions, 32 deletions
diff --git a/src/com/mcserver/MCServerActivity.java b/src/com/mcserver/MCServerActivity.java
index f21c5f9d0..2bdea0524 100644
--- a/src/com/mcserver/MCServerActivity.java
+++ b/src/com/mcserver/MCServerActivity.java
@@ -6,6 +6,7 @@ import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
+import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Timer;
import java.util.TimerTask;
@@ -16,13 +17,19 @@ import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
+import android.widget.ArrayAdapter;
import android.widget.Button;
+import android.widget.ListView;
import android.widget.TextView;
public class MCServerActivity extends Activity {
MainThread mThread = null;
Thread ServerStatusThread = null;
boolean mbExiting = false;
+ boolean mbEnabledLogging = false;
+
+ ArrayList<String> mLogList = new ArrayList<String>();
+ ArrayAdapter<String> mAdapter;
/** Called when the activity is first created. */
@Override
@@ -35,6 +42,7 @@ public class MCServerActivity extends Activity {
((Button)findViewById(R.id.start_server)).setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
+ mbEnabledLogging = true;
if( mThread == null || mThread.isAlive() == false ) {
mThread = new MainThread( (MCServerActivity)v.getContext() );
mThread.start();
@@ -44,11 +52,21 @@ public class MCServerActivity extends Activity {
((Button)findViewById(R.id.stop_server)).setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
+ mbEnabledLogging = true;
NativeCleanUp();
}
});
-
+
+
+ ListView lv = (ListView)this.findViewById(R.id.listView1);
+ mAdapter = new ArrayAdapter<String>(this,
+ R.layout.list_item,
+ mLogList);
+ lv.setAdapter(mAdapter);
+
+
+ mLogList.add("---- LOG ----");
ServerStatusThread = new Thread( new Runnable() {
public void run() {
@@ -77,8 +95,6 @@ public class MCServerActivity extends Activity {
Thread loggerThread = new Thread( new Runnable() {
public void run() {
Process process = null;
-
- SetText( "herpaderpa" );
try {
process = Runtime.getRuntime().exec("logcat -v raw *:s MCServer ");// Verbose filter
@@ -88,15 +104,16 @@ public class MCServerActivity extends Activity {
BufferedReader reader = null;
try {
- reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ InputStreamReader isr = new InputStreamReader(process.getInputStream());
+ reader = new BufferedReader( isr );
String line;
while( mbExiting == false ) {
line = reader.readLine();
- if( line != null )
+ if( mbEnabledLogging == true && line != null )
{
- SetText( line );
+ AddToLog( line );
}
}
@@ -181,32 +198,27 @@ public class MCServerActivity extends Activity {
- public void AddToLog( String logMessage ) {
-
- }
-
-
-
-
-
- public void SetText( final String aText ) {
- //Log.d("MCServer", "in SetText " + aText);
- /*
- final MCServerActivity context = this;
- this.runOnUiThread(new Runnable()
- {
- public void run()
- {
- ((TextView)context.findViewById(R.id.textView1)).setText(aText);
- }
- } );
- */
- final TextView tv = (TextView)this.findViewById(R.id.textView1);
- tv.post(new Runnable() {
- public void run() {
- tv.setText(aText);
- }
- });
+ public void AddToLog( final String logMessage ) {
+ final ListView lv = ((ListView)findViewById(R.id.listView1));
+ lv.post(new Runnable() {
+ public void run() {
+ //final boolean bAutoscroll = lv.getLastVisiblePosition() >= mAdapter.getCount() - 1 ? true : false;
+
+ mLogList.add(logMessage);
+ while( mLogList.size() > 100 ) // only allow 100 messages in the list, otherwise it might slow the GUI down
+ {
+ mLogList.remove(0);
+ }
+ mAdapter.notifyDataSetChanged();
+
+
+ // Autoscroll detection is dodgy
+ //if( bAutoscroll )
+ {
+ lv.setSelection(mAdapter.getCount() - 1);
+ }
+ }
+ });
}