summaryrefslogtreecommitdiff
path: root/same-android/src
diff options
context:
space:
mode:
Diffstat (limited to 'same-android/src')
-rw-r--r--same-android/src/main/java/com/orbekk/same/StateViewerActivity.java1
-rw-r--r--same-android/src/main/java/com/orbekk/same/VariableTestActivity.java38
-rw-r--r--same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java4
3 files changed, 43 insertions, 0 deletions
diff --git a/same-android/src/main/java/com/orbekk/same/StateViewerActivity.java b/same-android/src/main/java/com/orbekk/same/StateViewerActivity.java
index 9dfb61e..5b8fd41 100644
--- a/same-android/src/main/java/com/orbekk/same/StateViewerActivity.java
+++ b/same-android/src/main/java/com/orbekk/same/StateViewerActivity.java
@@ -52,4 +52,5 @@ public class StateViewerActivity extends Activity {
client.removeStateListener(stateListener);
client.disconnect();
}
+
}
diff --git a/same-android/src/main/java/com/orbekk/same/VariableTestActivity.java b/same-android/src/main/java/com/orbekk/same/VariableTestActivity.java
index f98e204..ba33058 100644
--- a/same-android/src/main/java/com/orbekk/same/VariableTestActivity.java
+++ b/same-android/src/main/java/com/orbekk/same/VariableTestActivity.java
@@ -5,21 +5,59 @@ import org.slf4j.LoggerFactory;
import android.app.Activity;
import android.os.Bundle;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
+import android.widget.Toast;
import com.orbekk.same.android.ClientInterfaceBridge;
public class VariableTestActivity extends Activity {
private Logger logger = LoggerFactory.getLogger(getClass());
private ClientInterfaceBridge client;
+ private Variable<String> variable;
+
+ private Variable.OnChangeListener<String> onChangeListener =
+ new Variable.OnChangeListener<String>() {
+ @Override
+ public void valueChanged(Variable<String> unused) {
+ variable.update();
+ displayVariable();
+ }
+ };
+
+ private void displayVariable() {
+ TextView tv = (TextView)findViewById(R.id.variable_text);
+ if (variable.get() != null) {
+ tv.setText(variable.get());
+ }
+ }
+
+ public void setVariable(View unused) {
+ EditText et = (EditText)findViewById(R.id.set_variable_text);
+ String newValue = et.getText().toString();
+ try {
+ variable.set(newValue);
+ } catch (UpdateConflict e) {
+ Toast.makeText(this, "Failed to update.", Toast.LENGTH_SHORT)
+ .show();
+ e.printStackTrace();
+ }
+ }
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ setContentView(R.layout.variable_test);
}
@Override public void onResume() {
super.onResume();
client = new ClientInterfaceBridge(this);
client.connect();
+ variable = client.createVariableFactory()
+ .createString("TestVariable");
+ variable.setOnChangeListener(onChangeListener);
+ displayVariable();
}
@Override public void onStop() {
diff --git a/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java b/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java
index f885b5a..a38f16f 100644
--- a/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java
+++ b/same-android/src/main/java/com/orbekk/same/android/ClientInterfaceBridge.java
@@ -20,6 +20,7 @@ import com.orbekk.same.SameService;
import com.orbekk.same.State;
import com.orbekk.same.StateChangedListener;
import com.orbekk.same.UpdateConflict;
+import com.orbekk.same.VariableFactory;
public class ClientInterfaceBridge implements ClientInterface {
private State state;
@@ -126,4 +127,7 @@ public class ClientInterfaceBridge implements ClientInterface {
listeners.remove(listener);
}
+ public VariableFactory createVariableFactory() {
+ return VariableFactory.create(this);
+ }
}