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

@@ -16,13 +16,15 @@
android:theme="@android:style/Theme.Light"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<service android:name=".HelloWorldService" android:exported="false" >
<service
android:name=".android.helloworld.HelloWorldService"
android:exported="false" >
<intent-filter>
<action android:name=".HelloWorldService" />
<action android:name="net.sf.briar.android.helloworld.HelloWorldService" />
</intent-filter>
</service>
<activity
android:name=".HelloWorldActivity"
android:name=".android.helloworld.HelloWorldActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -31,35 +33,35 @@
</activity>
<activity
android:name=".android.invitation.NetworkSetupActivity"
android:label="@string/title" >
android:label="@string/add_a_contact" >
</activity>
<activity
android:name=".android.invitation.InvitationCodeActivity"
android:label="@string/title" >
android:label="@string/add_a_contact" >
</activity>
<activity
android:name=".android.invitation.ConnectionActivity"
android:label="@string/title" >
android:label="@string/add_a_contact" >
</activity>
<activity
android:name=".android.invitation.ConnectionFailedActivity"
android:label="@string/title" >
android:label="@string/add_a_contact" >
</activity>
<activity
android:name=".android.invitation.ConfirmationCodeActivity"
android:label="@string/title" >
android:label="@string/add_a_contact" >
</activity>
<activity
android:name=".android.invitation.WaitForContactActivity"
android:label="@string/title" >
android:label="@string/add_a_contact" >
</activity>
<activity
android:name=".android.invitation.CodesDoNotMatchActivity"
android:label="@string/title" >
android:label="@string/add_a_contact" >
</activity>
<activity
android:name=".android.invitation.ContactAddedActivity"
android:label="@string/title" >
android:label="@string/add_a_contact" >
</activity>
</application>
</manifest>

View File

@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources>
<string-array name="roboguice_modules">
<item>net.sf.briar.HelloWorldModule</item>
<item>net.sf.briar.android.AndroidModule</item>
<item>net.sf.briar.android.helloworld.HelloWorldModule</item>
<item>net.sf.briar.android.invitation.AndroidInvitationModule</item>
<item>net.sf.briar.clock.ClockModule</item>
<item>net.sf.briar.crypto.CryptoModule</item>

View File

@@ -1,35 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Briar</string>
<string name="title">Add a Contact</string>
<string name="welcome">Welcome to Briar! Add a contact to get started.</string>
<string name="add_contact_button">Add a contact</string>
<string name="face_to_face">For security reasons you must be face to face with someone to add them as a contact.</string>
<string name="same_network">Briar can add contacts via Wi-Fi or Bluetooth. To use Wi-Fi you must both be connected to the same network.</string>
<string name="wifi_not_available">Wi-Fi is not available on this device</string>
<string name="wifi_disabled">Wi-Fi is OFF</string>
<string name="wifi_disconnected">Wi-Fi is DISCONNECTED</string>
<string name="wifi_connected">Wi-Fi is CONNECTED to %1$s</string>
<string name="bluetooth_not_available">Bluetooth is not available on this device</string>
<string name="bluetooth_disabled">Bluetooth is OFF</string>
<string name="bluetooth_not_discoverable">Bluetooth is NOT DISCOVERABLE</string>
<string name="bluetooth_enabled">Bluetooth is ON</string>
<string name="continue_button">Continue</string>
<string name="your_invitation_code">Your invitation code is</string>
<string name="enter_invitation_code">Please enter your contact\'s invitation code:</string>
<string name="connecting_wifi">Connecting via %1$s\u2026</string>
<string name="connecting_bluetooth">Connecting via Bluetooth\u2026</string>
<string name="connection_failed">Connection failed</string>
<string name="check_same_network">Please check that you are both using the same network.</string>
<string name="try_again_button">Try again</string>
<string name="connected_to_contact">Connected to contact</string>
<string name="your_confirmation_code">Your confirmation code is</string>
<string name="enter_confirmation_code">Please enter your contact\'s confirmation code:</string>
<string name="waiting_for_contact">Waiting for contact\u2026</string>
<string name="codes_do_not_match">Codes do not match</string>
<string name="interfering">This could mean that someone is trying to interfere with your connection.</string>
<string name="contact_added">Contact added</string>
<string name="enter_nickname">Please enter a nickname for this contact:</string>
<string name="add_another_contact_button">Add another contact</string>
<string name="done_button">Done</string>
<string name="app_name">Briar</string>
<string name="welcome">Welcome to Briar! Add a contact to get started.</string>
<string name="face_to_face">For security reasons you must be face to face with someone to add them as a contact.</string>
<string name="add_contact_button">Add a contact</string>
<string name="add_a_contact">Add a Contact</string>
<string name="same_network">Briar can add contacts via Wi-Fi or Bluetooth. To use Wi-Fi you must both be connected to the same network.</string>
<string name="wifi_not_available">Wi-Fi is not available on this device</string>
<string name="wifi_disabled">Wi-Fi is OFF</string>
<string name="wifi_disconnected">Wi-Fi is DISCONNECTED</string>
<string name="wifi_connected">Wi-Fi is CONNECTED to %1$s</string>
<string name="bluetooth_not_available">Bluetooth is not available on this device</string>
<string name="bluetooth_disabled">Bluetooth is OFF</string>
<string name="bluetooth_not_discoverable">Bluetooth is NOT DISCOVERABLE</string>
<string name="bluetooth_enabled">Bluetooth is ON</string>
<string name="continue_button">Continue</string>
<string name="your_invitation_code">Your invitation code is</string>
<string name="enter_invitation_code">Please enter your contact\'s invitation code:</string>
<string name="connecting_wifi">Connecting via %1$s\u2026</string>
<string name="connecting_bluetooth">Connecting via Bluetooth\u2026</string>
<string name="connection_failed">Connection failed</string>
<string name="check_same_network">Please check that you are both using the same network.</string>
<string name="try_again_button">Try again</string>
<string name="connected_to_contact">Connected to contact</string>
<string name="your_confirmation_code">Your confirmation code is</string>
<string name="enter_confirmation_code">Please enter your contact\'s confirmation code:</string>
<string name="waiting_for_contact">Waiting for contact\u2026</string>
<string name="codes_do_not_match">Codes do not match</string>
<string name="interfering">This could mean that someone is trying to interfere with your connection.</string>
<string name="contact_added">Contact added</string>
<string name="enter_nickname">Please enter a nickname for this contact:</string>
<string name="add_another_contact_button">Add another contact</string>
<string name="done_button">Done</string>
</resources>

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();
}
}