summaryrefslogtreecommitdiff
path: root/master/src/main/java/com/orbekk/HelloAndroidActivity.java
blob: a142214e2476c2886c6d47538ccc149789057412 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.orbekk;

import org.apache.log4j.Level;

import de.mindpipe.android.logging.log4j.LogConfigurator;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class HelloAndroidActivity extends Activity {

    private static String TAG = "master";
    private PingServer pingServer;
    
    private void configureLog4j() {
        final LogConfigurator logConfigurator = new LogConfigurator();

        //logConfigurator.setFileName(Environment.getExternalStorageDirectory() + "myapp.log");
        logConfigurator.setRootLevel(Level.DEBUG);
        logConfigurator.setUseLogCatAppender(true);
        logConfigurator.setUseFileAppender(false);
        // Set log level of a specific logger
        // logConfigurator.setLevel("org.apache", Level.ERROR);
        logConfigurator.configure();
        System.err.println("GOT HERE.");
    }
    
    /**
     * Called when the activity is first created.
     * @param savedInstanceState If the activity is being re-initialized after 
     * previously being shut down then this Bundle contains the data it most 
     * recently supplied in onSaveInstanceState(Bundle). <b>Note: Otherwise it is null.</b>
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        System.setProperty("java.net.preferIPv4Stack", "true");
        System.setProperty("java.net.preferIPv6Addresses", "false");
        
		Log.i(TAG, "onCreate");
		configureLog4j();
        setContentView(R.layout.main);

        pingServer = PingServer.createPingServer(10080);
        try {
            pingServer.start();
        } catch (Exception e) {
            throw new RuntimeException(e.getMessage());
        }
        
        Broadcast broadcast = new Broadcast(this);
        broadcast.sendBroadcast("Broadcast test".getBytes(), 10010);
    }
    
    @Override
    protected void onDestroy() {
        pingServer.stop();
        super.onDestroy();
    }
}