Hi everyone. Here's a quick and dirty tinywebdb sample. Note that
usfwebservice.appspot.com is down due to overuse with App Engine, so
this uses appinvtinywebd.appspot.com...
Note also that what is returned in GotValue is a string even if you
put in a list, so for now at least you'll have to parse. We'll discuss
in class.
package com.javabridge.samples;
import java.util.ArrayList;
import
com.google.devtools.simple.runtime.components.android.ComponentContainer;
import com.google.devtools.simple.runtime.components.android.Form;
import com.google.devtools.simple.runtime.components.android.Label;
import
com.google.devtools.simple.runtime.components.android.TinyWebDB;
import android.app.Activity;
import android.os.Bundle;
public class TinyWebDBSampleActivity extends Form {
/** Called when the activity is first created. */
MyTinyWebDB webDB;
Label nameListLabel;
void $define ()
{
webDB = new MyTinyWebDB(this);
webDB.ServiceURL("
http://appinvtinywebdb.appspot.com");
nameListLabel= new Label(this);
nameListLabel.Text("hello there");
ArrayList<String> list = new ArrayList<String>();
list.add("abc");
list.add("def");
webDB.StoreValue("wolberList", list); // note, this is for test
purposes, generally happens on event
webDB.GetValue("wolberList"); // request the data
}
class MyTinyWebDB extends TinyWebDB
{
@Override
public void WebServiceError(String message) {
// TODO Auto-generated method stub
super.WebServiceError(message);
nameListLabel.Text(message);
}
public MyTinyWebDB(ComponentContainer container) {
super(container);
// TODO Auto-generated constructor stub
}
@Override
public void GotValue(String tagFromWebDB, Object valueFromWebDB) {
ArrayList<String> list;
// list = (ArrayList<String>) valueFromWebDB;
//nameListLabel.Text(list.toString());
String s = (String) valueFromWebDB; // we know its a string of
form [x,y]
nameListLabel.Text(s);
String[] items = s.split(",");
nameListLabel.Text(items[0]);
}
}
}