Android: Finally a log! :D
git-svn-id: http://mc-server.googlecode.com/svn/trunk@754 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
parent
cc13cbbe3d
commit
e5bef782fc
@ -37,12 +37,10 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/your_ip" />
|
android:text="@string/your_ip" />
|
||||||
|
<ListView
|
||||||
<TextView
|
android:id="@+id/listView1"
|
||||||
android:id="@+id/textView1"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="fill_parent"
|
android:layout_height="wrap_content" >
|
||||||
android:layout_height="wrap_content"
|
</ListView>
|
||||||
android:layout_weight="0.73"
|
|
||||||
android:text="@string/hello" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -6,6 +6,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.NetworkInterface;
|
import java.net.NetworkInterface;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
@ -16,13 +17,19 @@ import android.os.Bundle;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class MCServerActivity extends Activity {
|
public class MCServerActivity extends Activity {
|
||||||
MainThread mThread = null;
|
MainThread mThread = null;
|
||||||
Thread ServerStatusThread = null;
|
Thread ServerStatusThread = null;
|
||||||
boolean mbExiting = false;
|
boolean mbExiting = false;
|
||||||
|
boolean mbEnabledLogging = false;
|
||||||
|
|
||||||
|
ArrayList<String> mLogList = new ArrayList<String>();
|
||||||
|
ArrayAdapter<String> mAdapter;
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
@ -35,6 +42,7 @@ public class MCServerActivity extends Activity {
|
|||||||
|
|
||||||
((Button)findViewById(R.id.start_server)).setOnClickListener( new View.OnClickListener() {
|
((Button)findViewById(R.id.start_server)).setOnClickListener( new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
mbEnabledLogging = true;
|
||||||
if( mThread == null || mThread.isAlive() == false ) {
|
if( mThread == null || mThread.isAlive() == false ) {
|
||||||
mThread = new MainThread( (MCServerActivity)v.getContext() );
|
mThread = new MainThread( (MCServerActivity)v.getContext() );
|
||||||
mThread.start();
|
mThread.start();
|
||||||
@ -44,11 +52,21 @@ public class MCServerActivity extends Activity {
|
|||||||
|
|
||||||
((Button)findViewById(R.id.stop_server)).setOnClickListener( new View.OnClickListener() {
|
((Button)findViewById(R.id.stop_server)).setOnClickListener( new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
mbEnabledLogging = true;
|
||||||
NativeCleanUp();
|
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() {
|
ServerStatusThread = new Thread( new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -77,8 +95,6 @@ public class MCServerActivity extends Activity {
|
|||||||
Thread loggerThread = new Thread( new Runnable() {
|
Thread loggerThread = new Thread( new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Process process = null;
|
Process process = null;
|
||||||
|
|
||||||
SetText( "herpaderpa" );
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
process = Runtime.getRuntime().exec("logcat -v raw *:s MCServer ");// Verbose filter
|
process = Runtime.getRuntime().exec("logcat -v raw *:s MCServer ");// Verbose filter
|
||||||
@ -88,15 +104,16 @@ public class MCServerActivity extends Activity {
|
|||||||
BufferedReader reader = null;
|
BufferedReader reader = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
InputStreamReader isr = new InputStreamReader(process.getInputStream());
|
||||||
|
reader = new BufferedReader( isr );
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
|
|
||||||
while( mbExiting == false ) {
|
while( mbExiting == false ) {
|
||||||
line = reader.readLine();
|
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 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
|
||||||
public void SetText( final String aText ) {
|
{
|
||||||
//Log.d("MCServer", "in SetText " + aText);
|
mLogList.remove(0);
|
||||||
/*
|
}
|
||||||
final MCServerActivity context = this;
|
mAdapter.notifyDataSetChanged();
|
||||||
this.runOnUiThread(new Runnable()
|
|
||||||
{
|
|
||||||
public void run()
|
// Autoscroll detection is dodgy
|
||||||
{
|
//if( bAutoscroll )
|
||||||
((TextView)context.findViewById(R.id.textView1)).setText(aText);
|
{
|
||||||
}
|
lv.setSelection(mAdapter.getCount() - 1);
|
||||||
} );
|
}
|
||||||
*/
|
}
|
||||||
final TextView tv = (TextView)this.findViewById(R.id.textView1);
|
});
|
||||||
tv.post(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
tv.setText(aText);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user