protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);



            b.WithText(Foo.Bar("hello via .java"));
            b.AtClick(
                v =>
                {
                    b.WithText(Foo.Bar("click!"));
                }
            );



            this.setContentView(sv);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);



            b.WithText("popup");
            b.AtClick(
                v =>
                {
                    XStandOutWindow.closeAll(this, typeof(XWidgetsWindow).ToClass());
                    XStandOutWindow.show(this, typeof(XWidgetsWindow).ToClass(), XStandOutWindow.DEFAULT_ID);

                    this.finish();

                }
            );

            this.setContentView(sv);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);


            
            b.WithText("before AtClick");
            b.AtClick(
                v =>
                {
                    b.setText("AtClick");
                }
            );

            var b2 = new Button(this);
            b2.setText("The other button!");
            ll.addView(b2);

            this.setContentView(sv);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            var activity = this;

            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);



            b.WithText("before AtClick");
            b.AtClick(
                v =>
                {
                    b.setText("AtClick");
                }
            );


        }
        static __InitializeAndroidActivity()
        {
            Console.WriteLine("StaticInvoke");

            //  Exception Ljava/lang/RuntimeException; thrown while initializing LTryHideActionbarExperiment/StaticInvoke;
            try
            {


                // https://groups.google.com/forum/?fromgroups=#!topic/android-developers/suLMCWiG0D8
                var c = ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext;


                (ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext as Activity).runOnUiThread(
                    a =>
                    {
                        // http://stackoverflow.com/questions/4451641/change-android-layout-programatically

                        var sv = new ScrollView(a);
                        var ll = new LinearLayout(a);
                        //ll.setOrientation(LinearLayout.VERTICAL);
                        sv.addView(ll);

                        var b = new Button(a).AttachTo(ll);



                        b.WithText("before AtClick");
                        b.AtClick(
                            v =>
                            {
                                b.setText("AtClick");
                            }
                        );

                        var b2 = new Button(a);
                        b2.setText("The other button!");
                        ll.addView(b2);

                        a.setContentView(sv);
                    }
                );
            }
            catch (Exception ex)
            {
                Console.WriteLine("error: " + new { ex.Message, ex.StackTrace });
            }
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);



            b.AtClick(
                v =>
                {
                    b.setText("AtClick");
                }
            );

            //var b2 = new Button(this);
            //b2.setText("The other button!");
            //ll.addView(b2);

            var ipa = Dns.GetHostAddresses(getLocalIpAddress())[0];

            var port = 8080;

            b.WithText(ipa + ":" + port);

            ClassLibrary1.Class1Shared.CreateServer(
                ipa,
                port,
                x =>
                {
                    //b.WithText(x);
                    android.util.Log.wtf("APKWebServer", x);
                }
            ).Start();

            this.setContentView(sv);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            {
                var b = new Button(this).AttachTo(ll);
                b.WithText("extras:");
            }

            // http://about-android.blogspot.com/2009/12/passing-data-or-parameter-to-another_02.html

            this.getIntent().With(
                intent =>
                {
                    intent.getExtras().With(
                        e =>
                        {
                            var keys = e.keySet().toArray();
                            foreach (string key in keys)
                            {
                                var b = new Button(this).AttachTo(ll);
                                b.WithText(new { key }.ToString());
                            }

                        }
                    );
                }
            );

            this.setContentView(sv);
        }
        // "x:\util\android-sdk-windows\platform-tools\adb.exe"  tcpip 5555
        // restarting in TCP mode port: 5555

        // "x:\util\android-sdk-windows\platform-tools\adb.exe" connect 192.168.1.126:5555
        // connected to 192.168.1.126:5555

        // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201505/20150513

        // lets verify this thing . deploy over wifi.

        //C:\Windows\system32> "x:\util\android-sdk-windows\platform-tools\adb.exe" shell netcfg
        //wlan0    UP                               192.168.1.126/24  0x00001043 e8:50:8b:7d:27:7c

        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);

            b.WithText("before AtClick");
            b.AtClick(
                v =>
                {
                    b.setText("AtClick");
                }
            );


            this.setContentView(sv);



            var s = new SemaphoreSlim(0);

            //java.lang.Object, rt
            //enter async { ManagedThreadId = 1 }
            //awaiting for SemaphoreSlim{ ManagedThreadId = 1 }
            //after delay{ ManagedThreadId = 8 }
            //http://127.0.0.1:8080
            //{ fileName = http://127.0.0.1:8080 }
            //enter catch { mname = <0032> nop.try } ClauseCatchLocal:
            //{ Message = , StackTrace = java.lang.RuntimeException
            //        at ScriptCoreLibJava.BCLImplementation.System.Net.Sockets.__TcpListener.AcceptTcpClientAsync(__TcpListener.java:131)

            new { }.With(
                async delegate
                {
                    //System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
                    //enter async { ManagedThreadId = 1 }
                    //awaiting for SemaphoreSlim{ ManagedThreadId = 1 }
                    //after delay{ ManagedThreadId = 4 }
                    //http://127.0.0.1:8080
                    //awaiting for SemaphoreSlim. done.{ ManagedThreadId = 1 }
                    //--
                    //accept { c = System.Net.Sockets.TcpClient, ManagedThreadId = 6 }
                    //System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
                    //accept { c = System.Net.Sockets.TcpClient, ManagedThreadId = 8 }
                    //{ ManagedThreadId = 6, input = GET / HTTP/1.1


                    Console.WriteLine("enter async " + new { Thread.CurrentThread.ManagedThreadId });

                    // X:\jsc.svn\examples\javascript\chrome\apps\ChromeTCPServerAsync\ChromeTCPServerAsync\Application.cs
                    await Task.Delay(100);

                    Console.WriteLine("after delay" + new { Thread.CurrentThread.ManagedThreadId });

                    // Additional information: Only one usage of each socket address (protocol/network address/port) is normally permitted
                    // close the other server!
                    var l = new TcpListener(IPAddress.Any, 8080);

                    l.Start();


                    var href =
                        "http://127.0.0.1:8080";

                    Console.WriteLine(
                        href
                    );



                    this.runOnUiThread(
                        delegate
                        {
                            var i = new Intent(Intent.ACTION_VIEW,
                               android.net.Uri.parse(href)
                           );

                            // http://vaibhavsarode.wordpress.com/2012/05/14/creating-our-own-activity-launcher-chooser-dialog-android-launcher-selection-dialog/
                            var ic = Intent.createChooser(i, href);


                            this.startActivity(ic);
                        }
                    );



                    new { }.With(
                        async delegate
                        {
                            while (true)
                            {
                                var c = await l.AcceptTcpClientAsync();

                                Console.WriteLine("accept " + new { c, Thread.CurrentThread.ManagedThreadId });

                                yield(c);
                            }
                        }
                    );

                    // jump back to main thread..
                    s.Release();
                }
            );
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);


            var b = new Button(this).AttachTo(ll);


            var ip = getLocalIpAddress();



            b.WithText("server at " + ip);
            b.AtClick(
                v =>
                {
                    var random = new System.Random();

                    // Error 312 (net::ERR_UNSAFE_PORT): Unknown error.
                    var port = random.Next(1024, 32000);

                    var uri = "http://" + ip;

                    uri += ":";
                    uri += ((object)(port)).ToString();

                    b.setText(uri);

                    Toast.makeText(
                          this,
                          "connect to this web server", 
                          Toast.LENGTH_LONG
                      ).show();

                    var ipa = Dns.GetHostAddresses(ip)[0];


                    Action<string> log = x => Log.wtf("ApplicationActivity", x);

                    // jsc does not import generic param, why?
                    //Action<NetworkStream> AtConnection =
                    NetworkStreamAction AtConnection =
                        s =>
                        {

                            //log("AtConnection");

                            var r = new StreamReader(s);

                            var h0 = r.ReadLine();

                            //log("ReadLine done");

                            var m = new MemoryStream();

                            Action<string> WriteLineASCII = (string e) =>
                            {
                                var x = Encoding.ASCII.GetBytes(e + "\r\n");

                                m.Write(x, 0, x.Length);
                            };

                            WriteLineASCII("HTTP/1.1 200 OK");
                            WriteLineASCII("Content-Type:	text/html; charset=utf-8");
                            //WriteLineASCII("Content-Length: " + data.Length);
                            WriteLineASCII("Connection: close");


                            WriteLineASCII("");
                            WriteLineASCII("");
                            WriteLineASCII("<html>");

                            WriteLineASCII("<body><h1 style='color: red;'>Hello world</h2><h3>jsc</h3><pre>" + h0 + "</pre></body>");

                            WriteLineASCII("</html>");

                            log("write done");

                            var oa = m.ToArray();

                            s.Write(oa, 0, oa.Length);

                            s.Flush();
                            s.Close();
                        };

                    //                    AndroidTcpListenerActivity.AndroidActivity 003e create: AndroidTcpListenerActivity.Activities.ApplicationActivity+<>c__DisplayClass8+<>c__DisplayClassb
                    //switch to STA Exception:
                    //System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: The IL Generator cannot be used while there are unclosed exceptions.
                    //   at System.Reflection.Emit.ILGenerator.BakeByteArray()
                    //   at System.Reflection.Emit.MethodBuilder.CreateMethodBodyHelper(ILGenerator il)
                    //   at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
                    //   at System.Reflection.Emit.TypeBuilder.CreateType()

                    new Thread(
                            delegate()
                            {
                                var r = new TcpListener(ipa, port);

                                //try
                                //{
                                r.Start();

                                while (true)
                                {
                                    //log("AcceptTcpClient");
                                    var c = r.AcceptTcpClient();
                                    //log("AcceptTcpClient done, GetStream");

                                    var s = c.GetStream();
                                    //log("AcceptTcpClient done, GetStream done");

                                    new Thread(
                                        delegate()
                                        {
                                            //log("before AtConnection");
                                            AtConnection(s);
                                        }
                                    )
                                    {
                                        IsBackground = true,
                                    }.Start();
                                }

                                //}
                                //catch
                                //{
                                //    log("AcceptTcpClient error!");

                                //    throw;
                                //}


                            }
                        )
                    {
                        IsBackground = true,
                    }.Start();
                }
            );

            var b2 = new Button(this);
            b2.setText("The other button!");
            ll.addView(b2);

            this.setContentView(sv);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);

            var goo = new foo.Goo();

            //Activator.CreateInstance<

            //var goo = (foo.Goo)Activator.CreateInstance(
            //    typeof(foo.Goo)
            //);

            //E/AndroidRuntime(32112): Caused by: java.lang.RuntimeException
            //E/AndroidRuntime(32112):        at foo.Bar.GetBarString(Bar.java:29)
            //E/AndroidRuntime(32112):        at foo.Goo.GetString(Goo.java:9)
            //E/AndroidRuntime(32112):        at TestJavaNativesOverride.Activities.ApplicationActivity.onCreate(ApplicationActivity.java:69)

            b.WithText(goo.GetString());
            b.AtClick(
                v =>
                {
                    b.setText(
                         new assets::foo.Bar().GetBarString()
                    );
                }
            );


            this.setContentView(sv);



        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var b2 = new Button(this);
            {
                var ll = new LinearLayout(this);
                //ll.setOrientation(LinearLayout.VERTICAL);
                sv.addView(ll);

                var b1 = new Button(this).AttachTo(ll);



                b1.WithText("LANBroadcastListener createMulticastLock");


                var c = 0;

                b1.AtClick(
                    v =>
                    {
                        //                 server error { Message = , StackTrace = android.os.NetworkOnMainThreadException
                        //at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117)
                        //at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:175)
                        //at libcore.io.IoBridge.sendto(IoBridge.java:473)
                        //at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:182)
                        //at java.net.DatagramSocket.send(DatagramSocket.java:284)

                        new Thread(
                            delegate()
                            {

                                try
                                {
                                    var socket = new DatagramSocket(); //construct a datagram socket and binds it to the available port and the localhos

                                    c++;

                                    var b = Encoding.UTF8.GetBytes(c + " hi from jvm!");    //creates a variable b of type byte
                                    var dgram = new DatagramPacket((sbyte[])(object)b, b.Length, InetAddress.getByName("239.1.2.3"), 40404);//sends the packet details, length of the packet,destination address and the port number as parameters to the DatagramPacket  
                                    //dgram.setData(b);
                                    //System.Console.WriteLine(
                                    //    "Sending " + b.Length + " bytes to " + dgram.getAddress() + ":" + dgram.getPort());//standard error output stream
                                    socket.send(dgram); //send the datagram packet from this port
                                }
                                catch (Exception ex)
                                {
                                    System.Console.WriteLine("server error " + new { ex.Message, ex.StackTrace });
                                }

                            }
                                )
                               {

                                   Name = "sender"
                               }.Start();
                    }
                );

                b2.setText("The other button!");
                ll.addView(b2);

                this.setContentView(sv);
            }


            // http://www.zzzxo.com/q/answers-android-device-not-receiving-multicast-package-13221736.html



            new Thread(
                delegate()
                {
                    // http://stackoverflow.com/questions/12610415/multicast-receiver-malfunction
                    // http://answers.unity3d.com/questions/250732/android-build-is-not-receiving-udp-broadcasts.html

                    // Acquire multicast lock
                    wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE);
                    multicastLock = wifi.createMulticastLock("multicastLock");
                    //multicastLock.setReferenceCounted(true);
                    multicastLock.acquire();

                    System.Console.WriteLine("LANBroadcastListener ready...");
                    try
                    {
                        byte[] b = new byte[0x100];

                        // https://code.google.com/p/android/issues/detail?id=40003

                        var port = 40404;

                        MulticastSocket socket = new MulticastSocket(port); // must bind receive side
                        socket.setBroadcast(true);
                        socket.setReuseAddress(true);
                        socket.setTimeToLive(30);
                        socket.setReceiveBufferSize(0x100);
                        
                        // https://code.google.com/p/android/issues/detail?id=40003
                        // http://stackoverflow.com/questions/6550618/multicast-support-on-android-in-hotspot-tethering-mode
                        // http://www.massapi.com/class/java/net/InetSocketAddress.java.html
                        // http://www.javadocexamples.com/java/net/MulticastSocket/joinGroup(SocketAddress%20mcastaddr,NetworkInterface%20netIf).html
                        // http://grokbase.com/t/hadoop/common-issues/117jsjk8d7/jira-created-hadoop-7472-rpc-client-should-deal-with-the-ip-address-changes

                        var group = InetAddress.getByName("239.1.2.3");
                        var groupSockAddr = new InetSocketAddress(group, port);

                        // what lan interfaces do we have?
                        socket.joinGroup(groupSockAddr,
                            NetworkInterface.getByName("wlan0")
                        );

                        System.Console.WriteLine("LANBroadcastListener joinGroup...");
                        while (true)
                        {
                            DatagramPacket dgram = new DatagramPacket((sbyte[])(object)b, b.Length);
                            socket.receive(dgram); // blocks until a datagram is received

                            var bytes = new MemoryStream((byte[])(object)dgram.getData(), 0, dgram.getLength());


                            var listen = Encoding.UTF8.GetString(bytes.ToArray());

                            System.Console.WriteLine("Received "
                                + dgram.getLength()
                                + " bytes from " + dgram.getAddress());
                            //dgram.setLength(b.Length); // must reset length field!s



                        }
                    }
                    catch
                    {
                        System.Console.WriteLine("client error");
                    }
                }
            )
            {

                Name = "client"
            }.Start();

        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            var file1 = "http://a.tumblr.com/tumblr_m8ueqqpyyy1rs64dko1.mp3";
            var name1 = "E43 Understanding the Dangers of Ego-Depletion by Tim";

            base.onCreate(savedInstanceState);

            var downloadManager = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
            var preferenceManager = PreferenceManager.getDefaultSharedPreferences(this);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new android.widget.Button(this).AttachTo(ll);

            downloadReceiver = new MyDownloadReceiver
            {

            };

            //            O:\src\AndroidDownloadManagerActivity\Activities\ApplicationActivity___c__DisplayClass2___c__DisplayClass4.java:60: cannot find symbol
            //symbol  : class Button
            //location: class AndroidDownloadManagerActivity.Activities.ApplicationActivity___c__DisplayClass2___c__DisplayClass4
            //                    ViewExtensions.<Button>WithText(this.CS___8__locals3.b, "Download " + this.CS___8__locals3.name1);
            //                                    ^

            b.WithText("Download " + name1);
            b.AtClick(
                v =>
                {

                    b.setText("Downloading...");
                    b.setEnabled(false);

                    var downloadUri = android.net.Uri.parse(file1);

                    // http://developer.android.com/reference/android/app/DownloadManager.Request.html
                    var request = new DownloadManager.Request(downloadUri);

                    request.setTitle("idea-remixer");
                    request.setDescription(name1);

                    // W/DownloadManager(15222): Aborting request for download 166: while trying to execute request: 
                    // java.net.UnknownHostException: Unable to resolve host "a.tumblr.com": 
                    // No address associated with hostname
                    var id = downloadManager.enqueue(request);

                    Toast.makeText(this, new { id, downloadUri }.ToString(), Toast.LENGTH_LONG).show();

                    //Save the request id   

                    //var PrefEdit = preferenceManager.edit();
                    //PrefEdit.putLong(strPref_Download_ID, id);
                    //PrefEdit.commit();

                    downloadReceiver.AtReceive = delegate
                    {
                        DownloadManager.Query query = new DownloadManager.Query();
                        //query.setFilterById(preferenceManager.getLong(strPref_Download_ID, 0));
                        // http://developer.android.com/reference/android/app/DownloadManager.Query.html#setFilterById(long...)
                        query.setFilterById(new[] { id });
                        Cursor cursor = downloadManager.query(query);

                        if (cursor.moveToFirst())
                        {
                            int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
                            int status = cursor.getInt(columnIndex);

                            if (status == DownloadManager.STATUS_FAILED)
                            {
                                Toast.makeText(this, new { id, status }.ToString(), Toast.LENGTH_LONG).show();

                                b.WithText("(failed) Download " + name1);
                                b.setEnabled(true);
                            }
                            else if (status == DownloadManager.STATUS_SUCCESSFUL)
                            {
                                //Retrieve the saved request id     
                                //long downloadID = preferenceManager.getLong(strPref_Download_ID, 0);
                                var uri = downloadManager.getUriForDownloadedFile(id);


                                Toast.makeText(this, new { id, uri }.ToString(), Toast.LENGTH_LONG).show();

                                // jsc ignores this type in import?
                                Button __ref0;

                                b.WithText("Download " + name1);
                                b.setEnabled(true);

                                //ParcelFileDescriptor file;
                                //try
                                //{
                                //    file = downloadManager.openDownloadedFile(downloadID);
                                //    //FileInputStream fileInputStream       = new ParcelFileDescriptor.AutoCloseInputStream(file); 
                                //    //Bitmap bm = BitmapFactory.decodeStream(fileInputStream);
                                //    //image.setImageBitmap(bm);   
                                //}
                                //catch // (FileNotFoundException e) 
                                //{      // TODO Auto-generated catch block   
                                //    //e.printStackTrace();     
                                //    throw;
                                //}
                            }
                        }
                    };

                }
            );


            this.setContentView(sv);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            var activity = this;
            // http://stackoverflow.com/questions/11425020/actionbar-in-a-dialogfragment
            //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
            //activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
            //activity.getWindow().setFlags(WindowManager_LayoutParams.FLAG_DIM_BEHIND, WindowManager_LayoutParams.FLAG_DIM_BEHIND);
            //activity.getWindow().setFlags(WindowManager_LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager_LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //var @params = activity.getWindow().getAttributes();
            ////@params.height = WindowManager_LayoutParams.FILL_PARENT;
            ////@params.width = 850; //fixed width
            ////@params.height = 450; //fixed width
            //@params.alpha = 1.0f;
            //@params.dimAmount = 0.5f;
            //activity.getWindow().setAttributes(@params);
            //activity.getWindow().setLayout(850, 850);
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);



            b.WithText("before AtClick");
            b.AtClick(
                v =>
                {
                    b.setText("AtClick");
                }
            );


            AtPrepareOptions +=
                value =>
                {
                    value.clear();

                    var item1 = value.add(
                         (java.lang.CharSequence)(object)"http://abstractatech.com"
                    );



                    item1.setIcon(android.R.drawable.ic_menu_view);

                    var item2 = value.add(
                        (java.lang.CharSequence)(object)"http://jsc-solutions.net"
                    );

                    //item2.setIcon(android.R.drawable.ic_menu_edit);
                    item2.setIcon(android.R.drawable.ic_menu_view);

                    var i = new Intent(Intent.ACTION_VIEW,
                        android.net.Uri.parse("http://jsc-solutions.net")
                    );

                    // http://vaibhavsarode.wordpress.com/2012/05/14/creating-our-own-activity-launcher-chooser-dialog-android-launcher-selection-dialog/
                    var ic = Intent.createChooser(i, "http://jsc-solutions.net");


                    item2.setIntent(
                        ic
                    );
                };

            AtOption +=
                item =>
                {

                    //b.WithText("menu was clicked!" + (string)(object)item.getTitle());
                    b.WithText("menu was clicked!" + new { item });
                };

            var b2 = new Button(this);
            b2.setText("The other button!");
            ll.addView(b2);

            this.setContentView(sv);
        }
        static __InitializeAndroidActivity()
        {
            Console.WriteLine("StaticInvoke");

            //  Exception Ljava/lang/RuntimeException; thrown while initializing LTryHideActionbarExperiment/StaticInvoke;
            try
            {


                // https://groups.google.com/forum/?fromgroups=#!topic/android-developers/suLMCWiG0D8
                var c = ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext;


                (ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext as ScriptCoreLib.Android.CoreAndroidWebServiceActivity).runOnUiThread(
                    a =>
                    {
                        //var c = ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext;



                        // http://stackoverflow.com/questions/4451641/change-android-layout-programatically

                        var sv = new ScrollView(a);
                        var ll = new LinearLayout(a);
                        //ll.setOrientation(LinearLayout.VERTICAL);
                        sv.addView(ll);

                        var b = new Button(a).AttachTo(ll);



                        b.WithText("before AtClick");
                        b.AtClick(
                            v =>
                            {
                                b.setText("AtClick");
                            }
                        );

                        var b2 = new Button(a);
                        b2.setText("The other button!");
                        ll.addView(b2);


                        //Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f050002
                        //       at android.content.res.Resources.getText(Resources.java:230)
                        //       at android.content.res.Resources.getString(Resources.java:314)
                        //       at com.facebook.widget.LoginButton.setButtonText(LoginButton.java:532)
                        //       at com.facebook.widget.LoginButton.finishInit(LoginButton.java:472)
                        //       at com.facebook.widget.LoginButton.<init>(LoginButton.java:189)

                        var login = new LoginButton(a);

                        // You have disabled Facebook Login in your app, but you must still specify Package Name or Key Hashes.
                        //login.loginText = "loginText";
                        login.setApplicationId("625051627510580");

                        //                        FATAL EXCEPTION: main
                        //java.lang.NullPointerException: Argument 'applicationId' cannot be null
                        //       at com.facebook.internal.Validate.notNull(Validate.java:29)
                        //       at com.facebook.Session.<init>(Session.java:224)
                        //       at com.facebook.Session.<init>(Session.java:213)
                        //       at com.facebook.Session$Builder.build(Session.java:1454)
                        //       at com.facebook.widget.LoginButton$LoginClickListener.onClick(LoginButton.java:621)


                        //                        FATAL EXCEPTION: main
                        //com.facebook.FacebookException: Cannot use SessionLoginBehavior SSO_WITH_FALLBACK when com.facebook.LoginActivity is not declared as an activity in AndroidManifest.xml
                        //       at com.facebook.Session.validateLoginBehavior(Session.java:992)
                        //       at com.facebook.Session.open(Session.java:915)
                        //       at com.facebook.Session.openForRead(Session.java:385)
                        //       at com.facebook.widget.LoginButton$LoginClickListener.onClick(LoginButton.java:641)

                        //                 Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f030001
                        //at android.content.res.Resources.getValue(Resources.java:1014)
                        //at android.content.res.Resources.loadXmlResourceParser(Resources.java:2139)
                        //at android.content.res.Resources.getLayout(Resources.java:853)
                        //at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
                        //at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
                        //at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
                        //at android.app.Activity.setContentView(Activity.java:1881)
                        //at com.facebook.LoginActivity.onCreate(LoginActivity.java:55)

                        login.setSessionStatusCallback(
                            new XStatusCallback
                            {
                                yield = (arg0, arg1, arg2) =>
                                {
                                    var AccessToken = arg0.getAccessToken();
                                    Console.WriteLine(new { AccessToken, arg0, arg1, arg2 });

                                }
                            }
                        );

                        login.setUserInfoChangedCallback(
                            new XUserInfoChangedCallback
                            {

                                yield = u =>
                                {
                                    var id = u.getId();
                                    var name = u.getName();

                                    Console.WriteLine(new { name, id });

                                    b2.WithText(new { name, id }.ToString());
                                }

                            }
                        );

                        login.AttachTo(ll);

                        a.setContentView(sv);
                    }
                );
            }
            catch (Exception ex)
            {
                Console.WriteLine("error: " + new { ex.Message, ex.StackTrace });
            }
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);



            b.WithText("UDP!");
            b.AtClick(
                v =>
                {

                    Action<IPAddress> sendTracking = nic =>
                    {
                        var port = new Random().Next(16000, 40000);

                        //new IHTMLPre { "about to bind... " + new { port } }.AttachToDocument();

                        // where is bind async?
                        // X:\jsc.svn\examples\java\android\vr\OVRWindWheelNDK\UDPWindWheel\Program.cs
                        var socket = new UdpClient(
                             new IPEndPoint(nic, port)
                            );

                        Console.WriteLine("about to bind " + new { nic, port });

                        //  x:\util\android-sdk-windows\platform-tools\adb.exe logcat 
//I/System.Console(15571): 3cd3:0001 enter __UdpClient ctor
//I/System.Console(15571): 3cd3:83e5 exit __IPAddress worker { ElapsedMilliseconds = 7 }
//I/System.Console(15571): 3cd3:0001 enter __UdpClient before this.Client
//I/System.Console(15571): 3cd3:0001 enter __UdpClient after this.Client { Client = ScriptCoreLibJava.BCLImplementation.System.Net.Sockets.__Socket@3777711a }
//I/System.Console(15571): 3cd3:0001 about to bind { nic = 192.168.1.126, port = 17052 }
//I/System.Console(15571): 3cd3:0001 enter __Socket Bind { vBind = ScriptCoreLibJava.BCLImplementation.System.Net.Sockets.__Socket_BindDelegate@166d444b }
//D/AndroidRuntime(15571): Shutting down VM
//E/AndroidRuntime(15571): FATAL EXCEPTION: main
//E/AndroidRuntime(15571): Process: TestUDPSend.Activities, PID: 15571
//E/AndroidRuntime(15571): java.lang.RuntimeException

                        //socket.Client.Bind(
                        //     new IPEndPoint(nic, port)
                        //);

                        // who is on the other end?
                        var nmessage = "hello!";

                        var data = Encoding.UTF8.GetBytes(nmessage);      //creates a variable b of type byte


                        //new IHTMLPre { "about to send... " + new { data.Length } }.AttachToDocument();

                        // X:\jsc.svn\examples\javascript\chrome\apps\ChromeUDPNotification\ChromeUDPNotification\Application.cs
                        Console.WriteLine("about to Send");
                        socket.Send(
                             data,
                             data.Length,
                             hostname: "239.1.2.3",
                             port: 49834
                         );




                    };

                    #region udp broadcast
                    // overkill at 60hz
                    NetworkInterface.GetAllNetworkInterfaces().WithEach(
                         n =>
                         {
                             // X:\jsc.svn\examples\java\android\forms\FormsUDPJoinGroup\FormsUDPJoinGroup\ApplicationControl.cs
                             // X:\jsc.svn\core\ScriptCoreLibJava\BCLImplementation\System\Net\NetworkInformation\NetworkInterface.cs

                             var IPProperties = n.GetIPProperties();
                             var PhysicalAddress = n.GetPhysicalAddress();



                             foreach (var ip in IPProperties.UnicastAddresses)
                             {
                                 // ipv4
                                 if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                                 {
                                     if (!IPAddress.IsLoopback(ip.Address))
                                         if (n.SupportsMulticast)
                                         {
                                             //fWASDC(ip.Address);
                                             //fParallax(ip.Address);
                                             //fvertexTransform(ip.Address);
                                             sendTracking(ip.Address);
                                         }
                                 }
                             }




                         }
                     );



                    #endregion

                }
            );


            this.setContentView(sv);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            var file1 = "http://a.tumblr.com/tumblr_m8ueqqpyyy1rs64dko1.mp3";
            var name1 = "E43 Understanding the Dangers of Ego-Depletion by Tim";

            base.onCreate(savedInstanceState);

            var downloadManager   = (DownloadManager)getSystemService(DOWNLOAD_SERVICE);
            var preferenceManager = PreferenceManager.getDefaultSharedPreferences(this);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);

            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new android.widget.Button(this).AttachTo(ll);

            downloadReceiver = new MyDownloadReceiver
            {
            };

            //            O:\src\AndroidDownloadManagerActivity\Activities\ApplicationActivity___c__DisplayClass2___c__DisplayClass4.java:60: cannot find symbol
            //symbol  : class Button
            //location: class AndroidDownloadManagerActivity.Activities.ApplicationActivity___c__DisplayClass2___c__DisplayClass4
            //                    ViewExtensions.<Button>WithText(this.CS___8__locals3.b, "Download " + this.CS___8__locals3.name1);
            //                                    ^

            b.WithText("Download " + name1);
            b.AtClick(
                v =>
            {
                b.setText("Downloading...");
                b.setEnabled(false);

                var downloadUri = android.net.Uri.parse(file1);

                // http://developer.android.com/reference/android/app/DownloadManager.Request.html
                var request = new DownloadManager.Request(downloadUri);

                request.setTitle("idea-remixer");
                request.setDescription(name1);

                // W/DownloadManager(15222): Aborting request for download 166: while trying to execute request:
                // java.net.UnknownHostException: Unable to resolve host "a.tumblr.com":
                // No address associated with hostname
                var id = downloadManager.enqueue(request);

                Toast.makeText(this, new { id, downloadUri }.ToString(), Toast.LENGTH_LONG).show();

                //Save the request id

                //var PrefEdit = preferenceManager.edit();
                //PrefEdit.putLong(strPref_Download_ID, id);
                //PrefEdit.commit();

                downloadReceiver.AtReceive = delegate
                {
                    DownloadManager.Query query = new DownloadManager.Query();
                    //query.setFilterById(preferenceManager.getLong(strPref_Download_ID, 0));
                    // http://developer.android.com/reference/android/app/DownloadManager.Query.html#setFilterById(long...)
                    query.setFilterById(new[] { id });
                    Cursor cursor = downloadManager.query(query);

                    if (cursor.moveToFirst())
                    {
                        int columnIndex = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS);
                        int status      = cursor.getInt(columnIndex);

                        if (status == DownloadManager.STATUS_FAILED)
                        {
                            Toast.makeText(this, new { id, status }.ToString(), Toast.LENGTH_LONG).show();

                            b.WithText("(failed) Download " + name1);
                            b.setEnabled(true);
                        }
                        else if (status == DownloadManager.STATUS_SUCCESSFUL)
                        {
                            //Retrieve the saved request id
                            //long downloadID = preferenceManager.getLong(strPref_Download_ID, 0);
                            var uri = downloadManager.getUriForDownloadedFile(id);


                            Toast.makeText(this, new { id, uri }.ToString(), Toast.LENGTH_LONG).show();

                            // jsc ignores this type in import?
                            Button __ref0;

                            b.WithText("Download " + name1);
                            b.setEnabled(true);

                            //ParcelFileDescriptor file;
                            //try
                            //{
                            //    file = downloadManager.openDownloadedFile(downloadID);
                            //    //FileInputStream fileInputStream       = new ParcelFileDescriptor.AutoCloseInputStream(file);
                            //    //Bitmap bm = BitmapFactory.decodeStream(fileInputStream);
                            //    //image.setImageBitmap(bm);
                            //}
                            //catch // (FileNotFoundException e)
                            //{      // TODO Auto-generated catch block
                            //    //e.printStackTrace();
                            //    throw;
                            //}
                        }
                    }
                };
            }
                );


            this.setContentView(sv);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            // http://www.mkyong.com/android/android-activity-from-one-screen-to-another-screen/

            base.onCreate(savedInstanceState);

            //this.getWindow().getDecorView()
            //this.getWindow().setTitle("secondary " + new { ApplicationActivity.foo});
            //this.getWindow().setTitleColor(0xff0000);

            // Set the IMMERSIVE flag.
            // Set the content to appear under the system bars so that the content
            // doesn't resize when the system bars hide and show.
            getWindow().getDecorView().setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                    | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);
            this.setContentView(sv);

            var b = new Button(this).AttachTo(ll);



            b.WithText(" secondary " + new { ApplicationActivity.foo });
            b.AtClick(
                v =>
                {
                    this.finish();
                }
            );

            //this.AtPause += delegate
            //{
            //    this.finish();
            //};

            //this.AtWindowFocusChanged += e =>
            //    {
            //        if (!e)
            //            this.finish();


            //    };

            //this.AtUserLeaveHint += delegate { this.finish(); };

            //this.onfo
            //this.onWindowFocusChanged
            //public void onWindowFocusChanged (boolean hasFocus)
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            // https://forums.oculus.com/viewtopic.php?f=67&t=22766

            var activity = this;
            // http://stackoverflow.com/questions/11425020/actionbar-in-a-dialogfragment
            //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
            //activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
            //activity.getWindow().setFlags(WindowManager_LayoutParams.FLAG_DIM_BEHIND, WindowManager_LayoutParams.FLAG_DIM_BEHIND);
            //activity.getWindow().setFlags(WindowManager_LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager_LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //var @params = activity.getWindow().getAttributes();
            ////@params.height = WindowManager_LayoutParams.FILL_PARENT;
            ////@params.width = 850; //fixed width
            ////@params.height = 450; //fixed width
            //@params.alpha = 1.0f;
            //@params.dimAmount = 0.5f;
            //activity.getWindow().setAttributes(@params);
            //activity.getWindow().setLayout(850, 850);
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);



            b.WithText("before AtClick");
            b.AtClick(
                v =>
                {
                    b.setText("AtClick");
                }
            );


            AtPrepareOptions +=
                value =>
                {
                    value.clear();

                    var item1 = value.add(
                         (java.lang.CharSequence)(object)"http://abstractatech.com"
                    );



                    item1.setIcon(android.R.drawable.ic_menu_view);

                    var item2 = value.add(
                        (java.lang.CharSequence)(object)"http://jsc-solutions.net"
                    );

                    //item2.setIcon(android.R.drawable.ic_menu_edit);
                    item2.setIcon(android.R.drawable.ic_menu_view);

                    var i = new Intent(Intent.ACTION_VIEW,
                        android.net.Uri.parse("http://jsc-solutions.net")
                    );

                    // http://vaibhavsarode.wordpress.com/2012/05/14/creating-our-own-activity-launcher-chooser-dialog-android-launcher-selection-dialog/
                    var ic = Intent.createChooser(i, "http://jsc-solutions.net");


                    item2.setIntent(
                        ic
                    );
                };

            AtOption +=
                item =>
                {

                    //b.WithText("menu was clicked!" + (string)(object)item.getTitle());
                    b.WithText("menu was clicked!" + new { item });
                };

            var b2 = new Button(this);

            var sw = System.Diagnostics.Stopwatch.StartNew();

            // SystemService
            Action update = delegate
            {
                // newer SDKS hide it

                // X:\opensource\ovr_mobile_sdk_0.5.1\VRLib\jni\VrApi\VrApi.cpp
                int cpuCore = 0;


                var online =
                    System.IO.File.ReadAllText("/sys/devices/system/cpu/cpu4/online").Trim();

                if (online == "1")
                    cpuCore = 4;

                var cpuFreq =
                    System.IO.File.ReadAllText("/sys/devices/system/cpu/cpu" + cpuCore + "/cpufreq/scaling_cur_freq").Trim();

                var cpuFrezMhz =
                    long.Parse(cpuFreq) / 1000;

                // 0 if gpu is not used?
                var gpuFreq =
                  System.IO.File.ReadAllText("/sys/devices/14ac0000.mali/clock").Trim();


                // const int64_t cpuFreq = ReadFreq( "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_cur_freq", cpuCore );

                b2.setText(
                    new { cpuCore, online, cpuFrezMhz, gpuFreq }.ToString()
                    + "\n " + sw.ElapsedMilliseconds
                    );
            };

            var h = new Handler();

            var next = default(Action);

            next = delegate
            {
                // await 1?

                update();

                h.postDelayed(
                    new xRunnable
                    {
                        yield = delegate
                        {
                            next();
                        }
                    },
                1);
            };

            next();


            ll.addView(b2);

            this.setContentView(sv);



            vConfigurationChanged = e =>
            {
                var orientation = getScreenOrientation();

                var SystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();

                //b2.setText(
                //    new
                //    {
                //        orientation,
                //        SystemUiVisibility
                //    }.ToString()
                //);


                if (orientation == Configuration.ORIENTATION_LANDSCAPE)
                {
                    hideSystemUI();
                }
                else
                {
                    showSystemUI();
                }
            };

            vConfigurationChanged(null);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);


            var b = new Button(this);
            ll.addView(b);

            var p = new Preview(this);

            b.WithText("take a picture");

            p.oncamera =
                camera =>
                    b.AtClick(
                        v =>
                        {
                            camera.takePicture(null, null,
                                new takePicture_handler
                                {
                                    handler =
                                        data =>
                                        {
                                            b.WithText("at click");
                                            try
                                            {
                                                // http://stackoverflow.com/questions/11874273/android-nexus-7-jelly-bean-startpreview-takepicture-calling-getcamerastereomode

                                                //E/NvOmxCamera(  126): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoMode(NvxComponent*, NvOmxCameraUserStereoMode&): Error: invalid NVX mode 0.
                                                //E/NvOmxCamera(  126): OMX_ERRORTYPE android::NvOmxCamera::getCameraStereoModeAndCaptureInfo(NvxComponent*, NvOmxCameraUserStereoMode&, NVX_STEREOCAPTUREINFO&): getCameraStereoMode failed with 0x00000000
                                                //D/NvOsDebugPrintf(  126): NvMMLiteJPEGEncSetAttribute: Incorrect value 0 for stereo capture type
                                                //E/NvOmxCameraSettings(  126): OMX_ERRORTYPE android::programStereoInfo(OMX_HANDLETYPE, const NVX_STEREOCAPTUREINFO&, android::NvxWrappers*): pNvxWrappers->OMX_SetConfigIL failed with 0x80001005
                                                //D/NvOsDebugPrintf(  126): Tryproc: INBuffer-Values of Width and Height 1280 960
                                                //D/dalvikvm(29535): GC_FOR_ALLOC freed 6686K, 52% free 7716K/15943K, paused 25ms, total 27ms


                                                var SAVE_PATH = android.os.Environment.getExternalStoragePublicDirectory(
                                                    android.os.Environment.DIRECTORY_PICTURES
                                                    );


                                                SAVE_PATH.mkdirs();

                                                var bmp = android.graphics.BitmapFactory.decodeByteArray(data, 0, data.Length);

                                                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                                                bmp.compress(android.graphics.Bitmap.CompressFormat.JPEG, 100, bytes);

                                                File f = new File(SAVE_PATH.ToString() + "/hello2.jpg");



                                                f.createNewFile();

                                                FileOutputStream fo = new FileOutputStream(f);
                                                fo.write(bytes.toByteArray());

                                                Intent intent = new Intent();
                                                intent.setAction(android.content.Intent.ACTION_VIEW);

                                                var imgUri = android.net.Uri.fromFile(f);

                                                intent.setDataAndType(imgUri, "image/*");

                                                b.WithText("done!");

                                                startActivity(intent);

                                            }
                                            // Error	1	The type caught or thrown must be derived from System.Exception	y:\jsc.svn\examples\java\android\AndroidCameraActivity\AndroidCameraActivity\ApplicationActivity.cs	154	52	AndroidCameraActivity
                                            catch (Exception ex)
                                            {
                                                b.WithText("saving.. error! " + ex.Message);

                                                //throw;
                                            }


                                        }
                                }
                            );

                        }
                    );


            this.setContentView(p);
            this.addContentView(sv, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            var activity = this;
            // http://stackoverflow.com/questions/11425020/actionbar-in-a-dialogfragment
            //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
            //activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);
            //activity.getWindow().setFlags(WindowManager_LayoutParams.FLAG_DIM_BEHIND, WindowManager_LayoutParams.FLAG_DIM_BEHIND);
            //activity.getWindow().setFlags(WindowManager_LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager_LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //var @params = activity.getWindow().getAttributes();
            ////@params.height = WindowManager_LayoutParams.FILL_PARENT;
            ////@params.width = 850; //fixed width
            ////@params.height = 450; //fixed width
            //@params.alpha = 1.0f;
            //@params.dimAmount = 0.5f;
            //activity.getWindow().setAttributes(@params);
            //activity.getWindow().setLayout(850, 850);
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);

            var b = new Button(this).AttachTo(ll);


            // https://stackoverflow.com/questions/1898886/removing-an-activity-from-the-history-stack

            b.WithText("start secondary");
            b.AtClick(
                v =>
                {
                    foo = "hi";

                    Intent intent = new Intent(this, typeof(SecondaryActivity).ToClass());
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
                    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(intent);
                }
            );

            this.AtPause += delegate { b.setText("AtPause"); };
            this.AtResume += delegate { b.setText("AtResume"); };


            AtPrepareOptions +=
                value =>
                {
                    value.clear();

                    var item1 = value.add(
                         (java.lang.CharSequence)(object)"http://abstractatech.com"
                    );



                    item1.setIcon(android.R.drawable.ic_menu_view);

                    var item2 = value.add(
                        (java.lang.CharSequence)(object)"http://jsc-solutions.net"
                    );

                    //item2.setIcon(android.R.drawable.ic_menu_edit);
                    item2.setIcon(android.R.drawable.ic_menu_view);

                    var i = new Intent(Intent.ACTION_VIEW,
                        android.net.Uri.parse("http://jsc-solutions.net")
                    );

                    // http://vaibhavsarode.wordpress.com/2012/05/14/creating-our-own-activity-launcher-chooser-dialog-android-launcher-selection-dialog/
                    var ic = Intent.createChooser(i, "http://jsc-solutions.net");


                    item2.setIntent(
                        ic
                    );
                };

            AtOption +=
                item =>
                {

                    //b.WithText("menu was clicked!" + (string)(object)item.getTitle());
                    b.WithText("menu was clicked!" + new { item });
                };

            var b2 = new Button(this);
            b2.setText("The other button!");
            ll.addView(b2);

            this.setContentView(sv);



            vConfigurationChanged = e =>
            {
                var orientation = getScreenOrientation();

                var SystemUiVisibility = getWindow().getDecorView().getSystemUiVisibility();

                b2.setText(
                    new
                    {
                        orientation,
                        SystemUiVisibility
                    }.ToString()
                );


                if (orientation == Configuration.ORIENTATION_LANDSCAPE)
                {
                    hideSystemUI();
                }
                else
                {
                    showSystemUI();
                }
            };

            vConfigurationChanged(null);
        }
        protected override void onCreate(Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

            var sv = new ScrollView(this);
            var ll = new LinearLayout(this);
            //ll.setOrientation(LinearLayout.VERTICAL);
            sv.addView(ll);


            var b = new Button(this).AttachTo(ll);



            b.WithText("before AtClick");
            b.AtClick(
                v =>
                {
                    b.setText("AtClick");
                }
            );

            var b2 = new Button(this);
            b2.setText("The other button!");
            ll.addView(b2);

            Action<string> __throw =
                message =>
                {
                    throw new InvalidOperationException(message);
                };

            var t1 = new Thread(
                () =>
                {
                    //Action<string> w = x => Log.wtf("ApplicationActivity", "thread " + new { id = 1, x });
                    Action<string> w = x => Log.wtf("ApplicationActivity", "thread 1 " + x);

                    w(" start");

                    for (int i = 0; i < 10; i++)
                    {
                        w(" before sleep");
                        Thread.Sleep(700);
                        w(" after sleep");
                    }

                    w(" exit");
                }
            );
            t1.Start();

            var t2 = new Thread(
                () =>
                {
                    Action<string> w = x => Log.wtf("ApplicationActivity", "thread 2 " + x);

                    w(" start");

                    for (int i = 0; i < 10; i++)
                    {
                        w(" before sleep");
                        Thread.Sleep(500);
                        w(" after sleep");
                    }

                    w(" exit");
                }
            );
            t2.Start();

            new Thread(
                () =>
                {
                    Action<string> w = x => Log.wtf("ApplicationActivity", "thread " + new { id = 3, x });

                    w(" start");

                    t1.Join();
                    t2.Join();

                    w(" exiting");

                    try
                    {
                        __throw("yay");
                    }
                    catch (Exception exc)
                    {

                        w(" exit - " + new { exc.Message });
                    }

                    w(" exit");

                }
            ).Start();

            this.setContentView(sv);
        }