Moved hello world code into its own package, fixed service injection.

This commit is contained in:
akwizgran
2012-11-07 15:07:08 +00:00
parent e3b6775760
commit ccff166650
7 changed files with 82 additions and 55 deletions

View File

@@ -17,8 +17,8 @@
includeantruntime='false' debug='off'>
<src path='.'/>
<include name='net/sf/briar/**'/>
<exclude name='net/sf/briar/*.java'/>
<exclude name='net/sf/briar/android/invitation/*.java'/>
<exclude name='net/sf/briar/android/helloworld/**'/>
<exclude name='net/sf/briar/android/invitation/**'/>
<classpath>
<fileset refid='prototype-jars'/>
<path refid='android-jar'/>

View File

@@ -1,11 +1,16 @@
package net.sf.briar;
package net.sf.briar.android.helloworld;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
import static android.widget.LinearLayout.VERTICAL;
import static java.util.logging.Level.INFO;
import java.util.logging.Logger;
import net.sf.briar.R;
import net.sf.briar.android.invitation.NetworkSetupActivity;
import android.app.Activity;
import roboguice.activity.RoboActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
@@ -15,11 +20,16 @@ import android.widget.LinearLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;
public class HelloWorldActivity extends Activity implements OnClickListener {
public class HelloWorldActivity extends RoboActivity
implements OnClickListener {
private static final Logger LOG =
Logger.getLogger(HelloWorldActivity.class.getName());
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(LOG.isLoggable(INFO)) LOG.info("Created");
LinearLayout layout = new LinearLayout(this);
layout.setLayoutParams(new LayoutParams(MATCH_PARENT, MATCH_PARENT));
layout.setOrientation(VERTICAL);
@@ -46,7 +56,13 @@ public class HelloWorldActivity extends Activity implements OnClickListener {
setContentView(layout);
startService(new Intent("net.sf.briar.HelloWorldService"));
startService(new Intent(HelloWorldService.class.getName()));
}
@Override
public void onDestroy() {
super.onDestroy();
if(LOG.isLoggable(INFO)) LOG.info("Destroyed");
}
public void onClick(View view) {

View File

@@ -1,4 +1,4 @@
package net.sf.briar;
package net.sf.briar.android.helloworld;
import static android.content.Context.MODE_PRIVATE;

View File

@@ -1,4 +1,4 @@
package net.sf.briar;
package net.sf.briar.android.helloworld;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
@@ -10,13 +10,13 @@ import net.sf.briar.api.crypto.KeyManager;
import net.sf.briar.api.db.DatabaseComponent;
import net.sf.briar.api.db.DbException;
import net.sf.briar.api.plugins.PluginManager;
import android.app.Service;
import roboguice.service.RoboService;
import android.content.Intent;
import android.os.IBinder;
import com.google.inject.Inject;
public class HelloWorldService extends Service implements Runnable {
public class HelloWorldService extends RoboService implements Runnable {
private static final Logger LOG =
Logger.getLogger(HelloWorldService.class.getName());
@@ -27,6 +27,8 @@ public class HelloWorldService extends Service implements Runnable {
@Override
public void onCreate() {
super.onCreate();
if(LOG.isLoggable(INFO)) LOG.info("Created");
Thread t = new Thread(this);
t.setDaemon(false);
t.start();
@@ -42,6 +44,12 @@ public class HelloWorldService extends Service implements Runnable {
return null;
}
@Override
public void onDestroy() {
super.onDestroy();
if(LOG.isLoggable(INFO)) LOG.info("Destroyed");
}
public void run() {
try {
// Start...
@@ -71,5 +79,6 @@ public class HelloWorldService extends Service implements Runnable {
} catch(IOException e) {
if(LOG.isLoggable(WARNING)) LOG.warning(e.toString());
}
stopSelf();
}
}