From d11cd76a7f64262424687421a1d78496dde356fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjetil=20=C3=98rbekk?= Date: Thu, 26 Jan 2012 17:29:37 +0100 Subject: Rename DiscoveryService => SameService. --- same-android/AndroidManifest.xml | 2 +- .../com/orbekk/discovery/DiscoveryService.java | 76 ---------------------- .../java/com/orbekk/discovery/SameService.java | 76 ++++++++++++++++++++++ 3 files changed, 77 insertions(+), 77 deletions(-) delete mode 100644 same-android/src/main/java/com/orbekk/discovery/DiscoveryService.java create mode 100644 same-android/src/main/java/com/orbekk/discovery/SameService.java diff --git a/same-android/AndroidManifest.xml b/same-android/AndroidManifest.xml index 66ceb4f..332cade 100644 --- a/same-android/AndroidManifest.xml +++ b/same-android/AndroidManifest.xml @@ -11,7 +11,7 @@ - + diff --git a/same-android/src/main/java/com/orbekk/discovery/DiscoveryService.java b/same-android/src/main/java/com/orbekk/discovery/DiscoveryService.java deleted file mode 100644 index e9aac5f..0000000 --- a/same-android/src/main/java/com/orbekk/discovery/DiscoveryService.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.orbekk.discovery; - -import java.net.DatagramPacket; - -import android.app.Service; -import android.content.Intent; -import android.os.Handler; -import android.os.IBinder; -import android.os.Message; -import android.widget.Toast; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class DiscoveryService extends Service { - private Logger logger = LoggerFactory.getLogger(getClass()); - private Thread thread = null; - - public final class DiscoveryThread extends Thread { - Broadcast broadcast; - - public DiscoveryThread() { - broadcast = new Broadcast(DiscoveryService.this); - } - - @Override public void run() { - while (!Thread.interrupted()) { - byte[] data = new byte[1024]; - DatagramPacket packet = broadcast.receiveBroadcast(15066); - String content = new String(packet.getData(), 0, packet.getLength()); - Message message = Message.obtain(); - message.obj = content; - toastHandler.sendMessage(message); - } - } - - @Override public void interrupt() { - super.interrupt(); - broadcast.interrupt(); - } - } - - private Handler toastHandler = new Handler() { - @Override public void handleMessage(Message message) { - Toast.makeText(DiscoveryService.this, - (String)message.obj, Toast.LENGTH_SHORT) - .show(); - logger.info("Display toast: {}", (String)message.obj); - } - }; - - @Override - public IBinder onBind(Intent intent) { - return null; - } - - @Override - public int onStartCommand(Intent intent, int flags, int startId) { - Toast.makeText(this, "service start: " + intent.getAction(), - Toast.LENGTH_SHORT).show(); - if (thread == null) { - synchronized (this) { - thread = new DiscoveryThread(); - thread.start(); - } - } - return START_STICKY; - } - - @Override - public void onDestroy() { - Toast.makeText(this, "service stopped", Toast.LENGTH_SHORT).show(); - thread.interrupt(); - } - -} diff --git a/same-android/src/main/java/com/orbekk/discovery/SameService.java b/same-android/src/main/java/com/orbekk/discovery/SameService.java new file mode 100644 index 0000000..149b882 --- /dev/null +++ b/same-android/src/main/java/com/orbekk/discovery/SameService.java @@ -0,0 +1,76 @@ +package com.orbekk.discovery; + +import java.net.DatagramPacket; + +import android.app.Service; +import android.content.Intent; +import android.os.Handler; +import android.os.IBinder; +import android.os.Message; +import android.widget.Toast; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SameService extends Service { + private Logger logger = LoggerFactory.getLogger(getClass()); + private Thread discoveryThread = null; + + public final class DiscoveryThread extends Thread { + Broadcast broadcast; + + public DiscoveryThread() { + broadcast = new Broadcast(SameService.this); + } + + @Override public void run() { + while (!Thread.interrupted()) { + byte[] data = new byte[1024]; + DatagramPacket packet = broadcast.receiveBroadcast(15066); + String content = new String(packet.getData(), 0, packet.getLength()); + Message message = Message.obtain(); + message.obj = content; + toastHandler.sendMessage(message); + } + } + + @Override public void interrupt() { + super.interrupt(); + broadcast.interrupt(); + } + } + + private Handler toastHandler = new Handler() { + @Override public void handleMessage(Message message) { + Toast.makeText(SameService.this, + (String)message.obj, Toast.LENGTH_SHORT) + .show(); + logger.info("Display toast: {}", (String)message.obj); + } + }; + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public int onStartCommand(Intent intent, int flags, int startId) { + Toast.makeText(this, "service start: " + intent.getAction(), + Toast.LENGTH_SHORT).show(); + if (discoveryThread == null) { + synchronized (this) { + discoveryThread = new DiscoveryThread(); + discoveryThread.start(); + } + } + return START_STICKY; + } + + @Override + public void onDestroy() { + Toast.makeText(this, "service stopped", Toast.LENGTH_SHORT).show(); + discoveryThread.interrupt(); + } + +} -- cgit v1.2.3