summaryrefslogtreecommitdiff
path: root/same-android/src
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-19 17:15:03 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-19 17:15:03 +0100
commit081b90f0e64ce7796692bc2b6d3528279c5a1e59 (patch)
tree12bb678fe330ab9342e72b06f43767ae223134c9 /same-android/src
parent3c33d22719225630761cb1ad97252dab977e2e36 (diff)
Change the android client to use the Same interface.
Diffstat (limited to 'same-android/src')
-rw-r--r--same-android/src/main/java/com/orbekk/GameView.java24
-rw-r--r--same-android/src/main/java/com/orbekk/HelloAndroidActivity.java3
2 files changed, 13 insertions, 14 deletions
diff --git a/same-android/src/main/java/com/orbekk/GameView.java b/same-android/src/main/java/com/orbekk/GameView.java
index edb41cb..1240671 100644
--- a/same-android/src/main/java/com/orbekk/GameView.java
+++ b/same-android/src/main/java/com/orbekk/GameView.java
@@ -6,6 +6,8 @@ import org.slf4j.LoggerFactory;
import com.orbekk.same.State.Component;
import com.orbekk.same.ClientService;
import com.orbekk.same.ClientServiceImpl;
+import com.orbekk.same.SameInterface;
+import com.orbekk.same.UpdateConflict;
import android.content.Context;
import android.graphics.Canvas;
@@ -28,13 +30,13 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
private Context context;
private Paint background;
private Paint paint;
- private ClientServiceImpl client;
+ private SameInterface same;
public GameThread(SurfaceHolder holder, Context context,
- ClientServiceImpl client) {
+ SameInterface client) {
this.holder = holder;
this.context = context;
- this.client = client;
+ this.same = client;
posX = 100;
posY = 100;
paint = new Paint();
@@ -72,20 +74,16 @@ public class GameView extends SurfaceView implements SurfaceHolder.Callback {
posX = x;
posY = y;
run();
- long rev = 0;
- Component c = client.getState("position");
- if (c != null) {
- rev = c.getRevision();
- }
-
- if (client.sendStateUpdate("position", this.posX + "," + this.posY,
- rev + 1)) {
- logger.warn("Unable to set state.");
+ try {
+ same.set("position", this.posX + "," + this.posY);
+ } catch (UpdateConflict e) {
+ logger.warn("Update conflict.", e);
}
+
}
}
- public GameView(Context context, ClientServiceImpl client) {
+ public GameView(Context context, SameInterface client) {
super(context);
getHolder().addCallback(this);
thread = new GameThread(getHolder(), context, client);
diff --git a/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java b/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java
index 9df93d9..87c349c 100644
--- a/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java
+++ b/same-android/src/main/java/com/orbekk/HelloAndroidActivity.java
@@ -3,6 +3,7 @@ package com.orbekk;
import com.orbekk.net.Broadcaster;
import com.orbekk.same.ClientApp;
import com.orbekk.same.ClientServiceImpl;
+import com.orbekk.same.SameInterface;
import android.app.Activity;
import android.os.Bundle;
@@ -28,7 +29,7 @@ public class HelloAndroidActivity extends Activity {
Log.i(TAG, "onCreate");
// setContentView(R.layout.main);
ClientApp client = new ClientApp();
- ClientServiceImpl client_ = client.getClient(10015, "ClientNetwork",
+ SameInterface client_ = client.getClient(10015, "ClientNetwork",
"http://10.0.0.6:10010/");
setContentView(new GameView(this, client_));