Commit 90e8000b authored by Dave Griffiths's avatar Dave Griffiths
Browse files

local activities work, more formatting, title page

parent 036b1e9c
......@@ -9,7 +9,7 @@
android:hardwareAccelerated="true"
>
<activity android:name="foam.starwisp.starwisp"
<activity android:name="foam.symbai.starwisp"
android:configChanges="orientation"
android:label="@string/app_name">
<intent-filter>
......@@ -17,6 +17,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="foam.symbai.VillageActivity" android:configChanges="orientation"></activity>
</application>
......
......@@ -639,10 +639,10 @@
(list 0 0 0 0)
l))
(define (relative-rules rules . l)
(define (relative rules colour . l)
(relative-layout
0 (rlayout 'fill-parent 'wrap-content 20 rules)
(list 0 255 0 127)
colour
l))
(define (activity name layout on-create on-start on-resume on-pause on-stop on-destroy on-activity-result)
......
......@@ -42,41 +42,99 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; user interface abstraction
;;;;;;;;;;;;; i18n ;;;;;;;;;;;;;;;;;;;;;;
(define i18n-lang 0)
(define i18n-text
(list
(list 'title (list "Symbai" "Symbai" "Symbai"))
(list 'sync (list "Sync" "Sync" "Sync"))
(list 'languages (list "Choose language" "Choose language" "Choose language"))
(list 'english (list "English" "English" "English"))
(list 'khasi (list "Khasi" "Khasi" "Khasi"))
(list 'hindi (list "Hindi" "Hindi" "Hindi"))
(list 'user-id (list "User ID" "User ID" "User ID"))
(list 'ok (list "Ok" "Ok" "Ok"))
(list 'cancel (list "Cancel" "Cancel" "Cancel"))
))
(define (mtext-lookup id)
(alog id)
(define (_ l)
(cond
((null? l) (string-append (symbol->string id) " not translated"))
((eq? (car (car l)) id) (list-ref (cadr (car l)) i18n-lang))
(else (_ (cdr l)))))
(_ i18n-text))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (mbutton id title fn)
(button (make-id id) title 30 (layout 'fill-parent 'wrap-content -1 'left 0) fn))
(button (make-id id)
(mtext-lookup title)
40 (layout 'fill-parent 'wrap-content -1 'left 5) fn))
(define (mbutton-scale id title fn)
(button (make-id id) title 30 (layout 'fill-parent 'wrap-content 1 'left 0) fn))
(define (mbutton2 id title fn)
(button (make-id id) title 30 (layout 150 100 1 'left 0) fn))
(button (make-id id)
(mtext-lookup title)
40 (layout 'fill-parent 'wrap-content 1 'left 5) fn))
(define (mtoggle-button id title fn)
(toggle-button (make-id id) title 30 (layout 'fill-parent 'wrap-content 1 'left 0) "fancy" fn))
(toggle-button (make-id id)
(mtext-lookup title)
30 (layout 'fill-parent 'wrap-content 1 'left 0) "fancy" fn))
(define (mtoggle-button-yes id title fn)
(toggle-button (make-id id) title 30 (layout 49 43 1 'left 0) "yes" fn))
(toggle-button (make-id id)
(mtext-lookup title)
30 (layout 49 43 1 'left 0) "yes" fn))
(define (mtoggle-button-maybe id title fn)
(toggle-button (make-id id) title 30 (layout 49 43 1 'left 0) "maybe" fn))
(toggle-button (make-id id)
(mtext-lookup title)
30 (layout 49 43 1 'left 0) "maybe" fn))
(define (mtoggle-button-no id title fn)
(toggle-button (make-id id) title 30 (layout 49 43 1 'left 0) "no" fn))
(define (mtoggle-button2 id title fn)
(toggle-button (make-id id) title 30 (layout 150 100 1 'left 0) "plain" fn))
(toggle-button (make-id id)
(mtext-lookup title)
30 (layout 49 43 1 'left 0) "no" fn))
(define (mtext id text)
(text-view (make-id id) text 30 wrap))
(text-view (make-id id)
(mtext-lookup text)
30 (layout 'wrap-content 'wrap-content -1 'left 0)))
(define (mtext-scale id text)
(text-view (make-id id)
(mtext-lookup text)
30 (layout 'wrap-content 'wrap-content 1 'left 0)))
(define (mtitle id text)
(text-view (make-id id) text 50 (layout 'fill-parent 'wrap-content -1 'left 0)))
(text-view (make-id id)
(mtext-lookup text)
50 (layout 'fill-parent 'wrap-content -1 'left 0)))
(define (medit-text id text type fn)
(vert
(mtext (string-append id "-title") text)
(edit-text (make-id id) "" 30 type fillwrap fn)))
(define (mspinner id name types fn)
(vert
(mtext "" name)
(spinner (make-id (string-append id "-spinner")) (map mtext-lookup types) fillwrap
(lambda (c) (fn c)))))
(define (mspinner-other id name types fn)
(horiz
(mspinner id name types fn (lambda (c) (fn c)))
(vert
(mtext "" 'other)
(edit-text (make-id (string-append id "-edit-text")) "" 30 "normal" fillwrap
(lambda (t) (fn t))))))
(define (mclear-toggles id-list)
(map
(lambda (id)
......@@ -90,16 +148,6 @@
r (cons (update-widget 'toggle-button (get-id id) 'checked 0) r)))
'() id-list))
(define (xwise n l)
(define (_ c l)
(cond
((null? l) (if (null? c) '() (list c)))
((eqv? (length c) (- n 1))
(cons (append c (list (car l))) (_ '() (cdr l))))
(else
(_ (append c (list (car l))) (cdr l)))))
(_ '() l))
;;;;
(define (db-mongooses-by-pack)
......@@ -221,26 +269,49 @@
(define-fragment-list
(fragment
"pf-timer"
(relative-layout
(make-id "") fillwrap trans-col
(list
(mtitle "pf-details" "Pack: xxx Pup: xxx")))
"top"
(horiz
(image-view 0 "face" (layout 48 64 -1 'left 0))
(text-view (make-id "") 'title 30
(layout 'fill-parent 'fill-parent 0.25 'centre 10))
(linear-layout
0 'vertical
(layout 'fill-parent 'wrap-content 0.75 'left 0)
(list 0 0 0 0)
(list
(text-view (make-id "") 'name 20
(layout 'fill-parent 'wrap-content 1 'left 0))
(text-view (make-id "") 'photoid 20
(layout 'fill-parent 'wrap-content 1 'left 0)))))
(lambda (fragment arg)
(activity-layout fragment))
(lambda (fragment arg)
(list
(update-widget 'text-view (get-id "pf-details") 'text
(string-append
"Pack: " (ktv-get (get-current 'pack '()) "name") " "
"Pup: " (ktv-get (get-current 'individual '()) "name"))
)))
(list))
(lambda (fragment) '())
(lambda (fragment) '())
(lambda (fragment) '())
(lambda (fragment) '()))
(fragment
"bottom"
(linear-layout
0 'horizontal
(layout 'fill-parent 'fill-parent 1 'left 0)
(list 0 0 0 0)
(list
(mbutton-scale "cancel" 'cancel (lambda () (list)))
(mbutton-scale "ok" 'ok (lambda () (list)))))
(lambda (fragment arg)
(activity-layout fragment))
(lambda (fragment arg)
(list))
(lambda (fragment) '())
(lambda (fragment) '())
(lambda (fragment) '())
(lambda (fragment) '()))
)
......@@ -257,28 +328,86 @@
"main"
(vert-fill
(relative-rules
(relative
'(("parent-top"))
(horiz
(mbutton-scale "cancel" "Cancel" (lambda () (list)))
(mbutton-scale "ok" "Ok" (lambda () (list)))))
(list 100 100 255 127)
(build-fragment "top" (make-id "top") fillwrap))
(scroll-view-vert
0 (layout 'fill-parent 'fill-parent 1 'left 0)
(list
(vert-fill
(mtitle "" 'title)
(horiz
(medit-text "user-id" 'user-id "normal" (lambda () (list)))
(mbutton-scale "sync" 'sync (lambda () (list))))
(vert
;;(image-view (make-id "face") "face" (layout 640 470 1 'left 0))
(mtitle "" "Symbai")
(mtext "" "Database")
(mbutton "main-sync" "Sync database1" (lambda () (list (start-activity "sync" 0 ""))))
(mbutton "main-sync" "Sync database2" (lambda () (list (start-activity "sync" 0 ""))))
(mbutton "main-sync" "Sync database3" (lambda () (list (start-activity "sync" 0 ""))))
)
(mspinner "languages" 'languages (list 'english 'khasi 'hindi) (lambda (c) (list)))
(mbutton "new-village" 'new-village (lambda () (list (start-activity "village" 0 ""))))
(relative-rules
)))
(relative
'(("parent-bottom"))
(horiz
(mbutton-scale "cancel" "Cancel" (lambda () (list)))
(mbutton-scale "ok" "Ok" (lambda () (list)))))
(list 100 100 255 127)
(vert
(spacer 5)
(build-fragment "bottom" (make-id "bottom") fillwrap)))
)
(lambda (activity arg)
(activity-layout activity))
(lambda (activity arg)
(let ((user-id (ktv-get (get-entity db "local" 1) "user-id")))
(set-current! 'user-id user-id)
(list)))
(lambda (activity) '())
(lambda (activity) '())
(lambda (activity) '())
(lambda (activity) '())
(lambda (activity requestcode resultcode) '()))
(activity
"village"
(vert-fill
(relative
'(("parent-top"))
(list 100 100 255 127)
(build-fragment "top" (make-id "top") fillwrap))
(scroll-view-vert
0 (layout 'fill-parent 'fill-parent 1 'left 0)
(list
(vert-fill
;;(image-view (make-id "face") "face" (layout 640 470 1 'left 0))
(mtitle "" 'title)
(mtext "" 'database)
(mbutton "main-sync" 'sync (lambda () (list (start-activity "sync" 0 ""))))
(mspinner-other "test" 'test (list 'one 'two 'three) (lambda (c) (list)))
(mbutton "main-sync" 'sync (lambda () (list (start-activity "sync" 0 ""))))
(mspinner-other "test" 'test (list 'one 'two 'three) (lambda (c) (list)))
(mbutton "main-sync" 'sync (lambda () (list (start-activity "sync" 0 ""))))
(mspinner-other "test" 'test (list 'one 'two 'three) (lambda (c) (list)))
(mbutton "main-sync" 'sync (lambda () (list (start-activity "sync" 0 ""))))
(mspinner-other "test" 'test (list 'one 'two 'three) (lambda (c) (list)))
(mbutton "main-sync" 'sync (lambda () (list (start-activity "sync" 0 ""))))
(mspinner-other "test" 'test (list 'one 'two 'three) (lambda (c) (list)))
(mbutton "main-sync" 'sync (lambda () (list (start-activity "sync" 0 ""))))
(mspinner-other "test" 'test (list 'one 'two 'three) (lambda (c) (list)))
(mbutton "main-sync" 'sync (lambda () (list (start-activity "sync" 0 ""))))
(mspinner-other "test" 'test (list 'one 'two 'three) (lambda (c) (list)))
)))
(relative
'(("parent-bottom"))
(list 100 100 255 127)
(vert
(spacer 5)
(build-fragment "bottom" (make-id "bottom") fillwrap)))
)
(lambda (activity arg)
(activity-layout activity))
......
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/bgpaw"
android:tileMode="repeat"
/>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape>
<gradient android:endColor="#eeffa276"
android:startColor="#eeefa276" android:angle="270" />
<corners android:radius="10dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
</shape>
</item>
<item android:state_pressed="true">
<shape>
<gradient android:endColor="#77ffa276"
android:startColor="#77efa276" android:angle="270" />
<corners android:radius="10dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
</shape>
</item>
<item android:state_focused="true">
<shape>
<gradient android:endColor="#ffffa276"
android:startColor="#ffefa276" android:angle="270" />
<corners android:radius="10dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
</shape>
</item>
<item>
<shape>
<gradient android:endColor="#ffff8256"
android:startColor="#ffefa276" android:angle="270" />
<corners android:radius="10dp" />
<padding android:left="4dp" android:top="4dp"
android:right="4dp" android:bottom="4dp" />
</shape>
</item>
</selector>
// Starwisp Copyright (C) 2013 Dave Griffiths
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package foam.symbai;
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
public class VillageActivity extends foam.starwisp.StarwispActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
m_Name = "village";
super.onCreate(savedInstanceState);
}
}
// Starwisp Copyright (C) 2013 Dave Griffiths
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package foam.symbai;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.content.Context;
import android.graphics.Color;
import java.io.File;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import android.widget.TextView;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.Spinner;
import android.widget.ArrayAdapter;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.Toast;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager;
import android.view.View;
import android.view.Gravity;
import android.view.KeyEvent;
import android.text.TextWatcher;
import android.text.Editable;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;
import java.util.Calendar;
import foam.starwisp.StarwispActivity;
import foam.starwisp.ActivityManager;
import foam.starwisp.Scheme;
import foam.starwisp.StarwispBuilder;
public class starwisp extends StarwispActivity
{
static {
// register all activities here
ActivityManager.RegisterActivity("main",starwisp.class);
ActivityManager.RegisterActivity("village",VillageActivity.class);
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
setContentView(R.layout.main);
String dirname = "starwisp/";
m_AppDir = "/sdcard/"+dirname;
File appdir = new File(m_AppDir);
appdir.mkdirs();
// build static things
m_Scheme = new Scheme(this);
m_Builder = new StarwispBuilder(m_Scheme);
m_Name = "main";
// tell scheme the date
final Calendar c = Calendar.getInstance();
int day = c.get(Calendar.DAY_OF_MONTH);
int month = c.get(Calendar.MONTH)+1;
int year = c.get(Calendar.YEAR);
// pass in a bunch of useful stuff
m_Scheme.eval("(define dirname \"/sdcard/"+dirname+"\")(define date-day "+day+") (define date-month "+month+") (define date-year "+year+")");
Log.i("starwisp","started, now running starwisp.scm...");
m_Scheme.eval(m_Scheme.readRawTextFile(this, "starwisp.scm"));
super.onCreate(savedInstanceState);
}
}
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