Commit eb11cbf8 authored by Dave Griffiths's avatar Dave Griffiths
Browse files

new widgets

parent 3318b1fa
......@@ -289,6 +289,18 @@
(define (linear-layout-layout t) (list-ref t 3))
(define (linear-layout-children t) (list-ref t 4))
(define (frame-layout id layout children)
(list "frame-layout" id layout children))
(define (frame-layout-id t) (list-ref t 1))
(define (frame-layout-layout t) (list-ref t 2))
(define (frame-layout-children t) (list-ref t 3))
(define (scroll-view id layout children)
(list "scroll-view" id layout children))
(define (scroll-view-id t) (list-ref t 1))
(define (scroll-view-layout t) (list-ref t 2))
(define (scroll-view-children t) (list-ref t 3))
(define (space layout) (list "space" "999" layout))
(define (space-view-layout t) (list-ref t 2))
......@@ -331,6 +343,14 @@
(define (button-layout t) (list-ref t 4))
(define (button-listener t) (list-ref t 5))
(define (toggle-button id text text-size layout listener) (list "toggle-button" id text text-size layout listener))
(define (toggle-button-id t) (list-ref t 1))
(define (toggle-button-text t) (list-ref t 2))
(define (toggle-button-modify-text t v) (list-replace t 2 v))
(define (toggle-button-text-size t) (list-ref t 3))
(define (toggle-button-layout t) (list-ref t 4))
(define (toggle-button-listener t) (list-ref t 5))
(define (seek-bar id max layout listener) (list "seek-bar" id max layout listener))
(define (seek-bar-id t) (list-ref t 1))
(define (seek-bar-max t) (list-ref t 2))
......@@ -449,6 +469,12 @@
((equal? (widget-type (car widget-list)) "linear-layout")
(let ((ret (widget-find (linear-layout-children (car widget-list)) id)))
(if ret ret (widget-find (cdr widget-list) id))))
((equal? (widget-type (car widget-list)) "frame-layout")
(let ((ret (widget-find (frame-layout-children (car widget-list)) id)))
(if ret ret (widget-find (cdr widget-list) id))))
((equal? (widget-type (car widget-list)) "scroll-view")
(let ((ret (widget-find (scroll-view-children (car widget-list)) id)))
(if ret ret (widget-find (cdr widget-list) id))))
(else (widget-find (cdr widget-list) id))))
(define root 0)
......@@ -543,6 +569,8 @@
((edit-text-listener widget) (car args)))
((equal? (widget-type widget) "button")
((button-listener widget)))
((equal? (widget-type widget) "toggle-button")
((button-listener widget (car args))))
((equal? (widget-type widget) "seek-bar")
((seek-bar-listener widget) (car args)))
((equal? (widget-type widget) "spinner")
......
......@@ -34,6 +34,7 @@
(lambda (activity) '())
(lambda (activity requestcode resultcode) '()))
(activity
"main"
(vert
......@@ -56,7 +57,4 @@
(list
(update-widget 'linear-layout (get-id "main-field-list") 'contents
(build-field-buttons)))))
)
......@@ -54,7 +54,8 @@ public class StarwispActivity extends Activity
String json = m_Scheme.eval("(activity-callback 'on-create \""+m_Name+"\" (list \""+arg+"\"))");
View root = findViewById(R.id.main);
m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/Pfennig.ttf");
//m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/Pfennig.ttf");
m_Typeface = Typeface.createFromAsset(getAssets(), "fonts/grstylus.ttf");
try {
m_Builder.Build(this, new JSONArray(json), (ViewGroup) root);
......
......@@ -33,7 +33,11 @@ import java.io.InputStreamReader;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Button;
import android.widget.ToggleButton;
import android.widget.LinearLayout;
import android.widget.FrameLayout;
import android.widget.ScrollView;
import android.widget.HorizontalScrollView;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.ArrayAdapter;
......@@ -165,6 +169,31 @@ public class StarwispBuilder
return;
}
if (type.equals("frame-layout")) {
FrameLayout v = new FrameLayout(ctx);
v.setId(arr.getInt(1));
v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
parent.addView(v);
JSONArray children = arr.getJSONArray(3);
for (int i=0; i<children.length(); i++) {
Build(ctx,new JSONArray(children.getString(i)), v);
}
return;
}
if (type.equals("scroll-view")) {
HorizontalScrollView v = new HorizontalScrollView(ctx);
v.setId(arr.getInt(1));
v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2)));
parent.addView(v);
JSONArray children = arr.getJSONArray(3);
for (int i=0; i<children.length(); i++) {
Build(ctx,new JSONArray(children.getString(i)), v);
}
return;
}
if (type.equals("space")) {
// Space v = new Space(ctx); (class not found runtime error??)
TextView v = new TextView(ctx);
......@@ -266,6 +295,25 @@ public class StarwispBuilder
parent.addView(v);
}
if (type.equals("toggle-button")) {
ToggleButton v = new ToggleButton(ctx);
v.setId(arr.getInt(1));
v.setText(arr.getString(2));
v.setTextSize(arr.getInt(3));
v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4)));
v.setTypeface(((StarwispActivity)ctx).m_Typeface);
final String fn = arr.getString(5);
v.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String arg="#f";
if (((ToggleButton) v).isChecked()) arg="#t";
CallbackArgs(ctx,v.getId(),arg);
}
});
parent.addView(v);
}
if (type.equals("seek-bar")) {
SeekBar v = new SeekBar(ctx);
v.setId(arr.getInt(1));
......
......@@ -60,7 +60,51 @@ public class starwisp extends StarwispActivity
ActivityManager.Register("main",MainActivity.class);
};
NetworkManager nm;
/* void RequestThread() {
Runnable runnable = new Runnable() {
public void run() {
Request();
}
};
Thread mythread = new Thread(runnable);
mythread.start();
}
void Request() {
try {
URL url = new URL("http://192.168.2.1:8888/mongoose?function_name=ping");
HttpURLConnection con = (HttpURLConnection) url
.openConnection();
readStream(con.getInputStream());
} catch (Exception e) {
e.printStackTrace();
}
}
private void readStream(InputStream in) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(in));
String line = "";
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
*/
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
......@@ -72,6 +116,8 @@ public class starwisp extends StarwispActivity
File appdir = new File(m_AppDir);
appdir.mkdirs();
nm = new NetworkManager("mongoose-web",this);
// build static things
m_Scheme = new Scheme(this);
m_Builder = new StarwispBuilder(m_Scheme);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment