summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--same-android/res/layout/variable_test.xml34
-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
4 files changed, 77 insertions, 0 deletions
diff --git a/same-android/res/layout/variable_test.xml b/same-android/res/layout/variable_test.xml
new file mode 100644
index 0000000..4570577
--- /dev/null
+++ b/same-android/res/layout/variable_test.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/variable_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <EditText
+ android:id="@+id/set_variable_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="1" >
+ <requestFocus />
+ </EditText>
+
+ <Button
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_weight="0.18"
+ android:text="Set"
+ android:onClick="setVariable" />
+
+ </LinearLayout>
+
+</LinearLayout> \ No newline at end of file
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);
+ }
}