From ccff1666507fdbd115bb68ef2d8c549d706b1518 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Wed, 7 Nov 2012 15:07:08 +0000 Subject: [PATCH] Moved hello world code into its own package, fixed service injection. --- AndroidManifest.xml | 24 +++---- res/values/roboguice.xml | 4 +- res/values/strings.xml | 64 +++++++++---------- src/build.xml | 4 +- .../helloworld}/HelloWorldActivity.java | 24 +++++-- .../helloworld}/HelloWorldModule.java | 2 +- .../helloworld}/HelloWorldService.java | 15 ++++- 7 files changed, 82 insertions(+), 55 deletions(-) rename src/net/sf/briar/{ => android/helloworld}/HelloWorldActivity.java (74%) rename src/net/sf/briar/{ => android/helloworld}/HelloWorldModule.java (96%) rename src/net/sf/briar/{ => android/helloworld}/HelloWorldService.java (84%) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 92245565b..a48b0ef0d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -16,13 +16,15 @@ android:theme="@android:style/Theme.Light" android:icon="@drawable/ic_launcher" android:label="@string/app_name" > - + - + @@ -31,35 +33,35 @@ + android:label="@string/add_a_contact" > + android:label="@string/add_a_contact" > + android:label="@string/add_a_contact" > + android:label="@string/add_a_contact" > + android:label="@string/add_a_contact" > + android:label="@string/add_a_contact" > + android:label="@string/add_a_contact" > + android:label="@string/add_a_contact" > diff --git a/res/values/roboguice.xml b/res/values/roboguice.xml index c7d58a7a3..82fd88cbc 100644 --- a/res/values/roboguice.xml +++ b/res/values/roboguice.xml @@ -1,8 +1,8 @@ - + - net.sf.briar.HelloWorldModule net.sf.briar.android.AndroidModule + net.sf.briar.android.helloworld.HelloWorldModule net.sf.briar.android.invitation.AndroidInvitationModule net.sf.briar.clock.ClockModule net.sf.briar.crypto.CryptoModule diff --git a/res/values/strings.xml b/res/values/strings.xml index 58c646fb8..351de8241 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1,35 +1,35 @@ - Briar - Add a Contact - Welcome to Briar! Add a contact to get started. - Add a contact - For security reasons you must be face to face with someone to add them as a contact. - Briar can add contacts via Wi-Fi or Bluetooth. To use Wi-Fi you must both be connected to the same network. - Wi-Fi is not available on this device - Wi-Fi is OFF - Wi-Fi is DISCONNECTED - Wi-Fi is CONNECTED to %1$s - Bluetooth is not available on this device - Bluetooth is OFF - Bluetooth is NOT DISCOVERABLE - Bluetooth is ON - Continue - Your invitation code is - Please enter your contact\'s invitation code: - Connecting via %1$s\u2026 - Connecting via Bluetooth\u2026 - Connection failed - Please check that you are both using the same network. - Try again - Connected to contact - Your confirmation code is - Please enter your contact\'s confirmation code: - Waiting for contact\u2026 - Codes do not match - This could mean that someone is trying to interfere with your connection. - Contact added - Please enter a nickname for this contact: - Add another contact - Done + Briar + Welcome to Briar! Add a contact to get started. + For security reasons you must be face to face with someone to add them as a contact. + Add a contact + Add a Contact + Briar can add contacts via Wi-Fi or Bluetooth. To use Wi-Fi you must both be connected to the same network. + Wi-Fi is not available on this device + Wi-Fi is OFF + Wi-Fi is DISCONNECTED + Wi-Fi is CONNECTED to %1$s + Bluetooth is not available on this device + Bluetooth is OFF + Bluetooth is NOT DISCOVERABLE + Bluetooth is ON + Continue + Your invitation code is + Please enter your contact\'s invitation code: + Connecting via %1$s\u2026 + Connecting via Bluetooth\u2026 + Connection failed + Please check that you are both using the same network. + Try again + Connected to contact + Your confirmation code is + Please enter your contact\'s confirmation code: + Waiting for contact\u2026 + Codes do not match + This could mean that someone is trying to interfere with your connection. + Contact added + Please enter a nickname for this contact: + Add another contact + Done diff --git a/src/build.xml b/src/build.xml index b58556445..2979431ed 100644 --- a/src/build.xml +++ b/src/build.xml @@ -17,8 +17,8 @@ includeantruntime='false' debug='off'> - - + + diff --git a/src/net/sf/briar/HelloWorldActivity.java b/src/net/sf/briar/android/helloworld/HelloWorldActivity.java similarity index 74% rename from src/net/sf/briar/HelloWorldActivity.java rename to src/net/sf/briar/android/helloworld/HelloWorldActivity.java index 3b0355a31..794495d24 100644 --- a/src/net/sf/briar/HelloWorldActivity.java +++ b/src/net/sf/briar/android/helloworld/HelloWorldActivity.java @@ -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) { diff --git a/src/net/sf/briar/HelloWorldModule.java b/src/net/sf/briar/android/helloworld/HelloWorldModule.java similarity index 96% rename from src/net/sf/briar/HelloWorldModule.java rename to src/net/sf/briar/android/helloworld/HelloWorldModule.java index 5fe4fad75..c96fec94f 100644 --- a/src/net/sf/briar/HelloWorldModule.java +++ b/src/net/sf/briar/android/helloworld/HelloWorldModule.java @@ -1,4 +1,4 @@ -package net.sf.briar; +package net.sf.briar.android.helloworld; import static android.content.Context.MODE_PRIVATE; diff --git a/src/net/sf/briar/HelloWorldService.java b/src/net/sf/briar/android/helloworld/HelloWorldService.java similarity index 84% rename from src/net/sf/briar/HelloWorldService.java rename to src/net/sf/briar/android/helloworld/HelloWorldService.java index ef2dec27c..eeb74c315 100644 --- a/src/net/sf/briar/HelloWorldService.java +++ b/src/net/sf/briar/android/helloworld/HelloWorldService.java @@ -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(); } }