diff options
author | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-18 23:00:51 +0200 |
---|---|---|
committer | faketruth <faketruth@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-18 23:00:51 +0200 |
commit | b6138129e668681d2c16146dea3d66b0ea2f0381 (patch) | |
tree | 0888a6d4f115fd02ba1ea65c944a4daca1eda85e /src/com | |
parent | Chat packet handled in the new way; fixed missing packet sending for inventory slot. (diff) | |
download | cuberite-b6138129e668681d2c16146dea3d66b0ea2f0381.tar cuberite-b6138129e668681d2c16146dea3d66b0ea2f0381.tar.gz cuberite-b6138129e668681d2c16146dea3d66b0ea2f0381.tar.bz2 cuberite-b6138129e668681d2c16146dea3d66b0ea2f0381.tar.lz cuberite-b6138129e668681d2c16146dea3d66b0ea2f0381.tar.xz cuberite-b6138129e668681d2c16146dea3d66b0ea2f0381.tar.zst cuberite-b6138129e668681d2c16146dea3d66b0ea2f0381.zip |
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/mcserver/MCServerActivity.java | 155 |
1 files changed, 146 insertions, 9 deletions
diff --git a/src/com/mcserver/MCServerActivity.java b/src/com/mcserver/MCServerActivity.java index ff1a4fae2..f9bb363f4 100644 --- a/src/com/mcserver/MCServerActivity.java +++ b/src/com/mcserver/MCServerActivity.java @@ -1,12 +1,22 @@ package com.mcserver; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Enumeration; + import android.app.Activity; +import android.graphics.Color; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; public class MCServerActivity extends Activity { MainThread mThread = null; + Thread ServerStatusThread = null; /** Called when the activity is first created. */ @Override @@ -14,51 +24,178 @@ public class MCServerActivity extends Activity { super.onCreate(savedInstanceState); setContentView(R.layout.main); - mThread = new MainThread(); - mThread.start(); + ((Button)findViewById(R.id.start_server)).setOnClickListener( new View.OnClickListener() { + public void onClick(View v) { + if( mThread == null || mThread.isAlive() == false ) { + mThread = new MainThread( (MCServerActivity)v.getContext() ); + mThread.start(); + } + } + }); + + ((Button)findViewById(R.id.stop_server)).setOnClickListener( new View.OnClickListener() { + public void onClick(View v) { + NativeCleanUp(); + } + }); + + + + ServerStatusThread = new Thread( new Runnable() { + public void run() { + for(;;) + { + try { + runOnUiThread( new Runnable() { + public void run() { + UpdateServerStatus(); + } + }); + Thread.sleep(1000); + } catch (InterruptedException e) { + } + } + } + }); + ServerStatusThread.start(); + + + + + ((TextView)findViewById(R.id.ip_address)).setText("Connect to: " + getLocalIpAddress()); + } + + + + public String getLocalIpAddress() { + try { + for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { + NetworkInterface intf = en.nextElement(); + for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { + InetAddress inetAddress = enumIpAddr.nextElement(); + if (!inetAddress.isLoopbackAddress()) { + return inetAddress.getHostAddress().toString(); + } + } + } + } catch (SocketException ex) { + Log.e("MCServer", ex.toString()); + } + return null; + } + + + + public void UpdateServerStatus() + { + if( NativeIsServerRunning() ) { + ((TextView)findViewById(R.id.server_status_text)).setText(R.string.mcserver_is_running); + ((TextView)findViewById(R.id.server_status_text)).setTextColor(Color.GREEN); + ((Button)findViewById(R.id.stop_server)).setEnabled(true); + ((Button)findViewById(R.id.start_server)).setEnabled(false); + } else { + ((TextView)findViewById(R.id.server_status_text)).setText(R.string.mcserver_is_not_running); + ((TextView)findViewById(R.id.server_status_text)).setTextColor(Color.RED); + ((Button)findViewById(R.id.stop_server)).setEnabled(false); + ((Button)findViewById(R.id.start_server)).setEnabled(true); + } } + + + + public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode==KeyEvent.KEYCODE_BACK) { //android.os.Process.killProcess(android.os.Process.myPid()); - mThread.NativeCleanUp(); + NativeCleanUp(); return super.onKeyDown(keyCode, event); } return false; } + + + + 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 Testtt() + { + //Log.d("MCServer", "in Testtt"); + } + + + + + static { System.loadLibrary("mcserver"); } - + public native void NativeOnCreate(); + public native void NativeCleanUp(); + public native boolean NativeIsServerRunning(); } class MainThread extends Thread { - MainThread() { + MCServerActivity mContext = null; + int numlogs = 0; + + MainThread( MCServerActivity aContext ) { + mContext = aContext; } public void AddToLog( String logMessage ) { + mContext.SetText( logMessage ); //Log.d("MCServer", "Add to log: " + logMessage); } public void TestTest(){ - Log.d("MCServer", "in testtest"); + numlogs++; + //Log.d("MCServer", "in testtest" + numlogs); + mContext.Testtt(); + mContext.SetText("log no. " + numlogs); } public void run() { - NativeOnCreate(); + mContext.NativeOnCreate(); } - public native void NativeOnCreate(); - public native void NativeCleanUp(); + } |