setOrientation() public method

public setOrientation ( int arg0 ) : void
arg0 int
return void
        //        connect s6 via usb .
        // turn on wifi!
        // kill adb

        //"x:\util\android-sdk-windows\platform-tools\adb.exe"  tcpip 5555
        // restarting in TCP mode port: 5555

        //13: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        //    inet 192.168.1.126/24 brd 192.168.1.255 scope global wlan0
        //       valid_lft forever preferred_lft forever

        // on red
        // "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/201511/20151121
        // http://stackoverflow.com/questions/17513502/support-for-multi-window-app-development

        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

            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);

            b.setText("Vibrate!");

            b.AtClick(
                delegate
                {
                    var vibrator = (Vibrator)this.getSystemService(Context.VIBRATOR_SERVICE);

                    vibrator.vibrate(600);
                }
            );

            ll.addView(b);



            this.setContentView(sv);


            //this.ShowLongToast("http://my.jsc-solutions.net x");
        }
        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);
            var ll = new LinearLayout(this);
            ll.setOrientation(LinearLayout.VERTICAL);

            textLatitude = new TextView(this).AttachTo(ll);
            textLongitude = new TextView(this).AttachTo(ll);

            textLatitude.setText("?");
 
            setContentView(ll);

            locationManager = (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
            Location lastLocation = locationManager.getLastKnownLocation(PROVIDER);
            if (lastLocation != null)
            {
                updateLoc(lastLocation);
            }

            this.myLocationListener = new MyLocationListener
            {
                __this = this
            };

            this.ShowToast("http://jsc-solutions.net");
        }
        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

            base.onCreate(savedInstanceState);

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

            var key = new TextView(this).AttachTo(ll);
            var value = new TextView(this).AttachTo(ll);
            var xml = new TextView(this).AttachTo(ll);

            key.setText("foo");
            value.setText("bar");

            xml.setText(
             new XElement("KeyValuePair",
                 new XAttribute("Key", "foo"),
                 new XElement("Value", "bar")
             ).ToString()
            );

            setContentView(sv);

            //this.ShowToast("http://jsc-solutions.net");
        }
        // X:\opensource\ovr_mobile_sdk_0.5.0
        // https://developer.oculus.com/downloads/#version=mobile-0.5.0

        //<ItemGroup>
        //  <Content Include="X:\opensource\ovr_mobile_sdk_20141111\VRLib\src\**\*.*">
        //    <Link>opensource\ovr_mobile_sdk_20141111\VRLib\src\%(RecursiveDir)%(FileName)%(Extension)</Link>
        //  </Content>
        //</ItemGroup>

        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150402
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20141127
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150504/dae

        // http://stackoverflow.com/questions/9821875/where-is-buildconfig-debug
        // tested by?

        protected override void onCreate(global::android.os.Bundle savedInstanceState)
		{
			// cmd /K c:\util\android-sdk-windows\platform-tools\adb.exe logcat
			// Camera PTP

			// http://developer.android.com/guide/topics/ui/notifiers/notifications.html

			base.onCreate(savedInstanceState);

			ScrollView sv = new ScrollView(this);

			LinearLayout ll = new LinearLayout(this);

			ll.setOrientation(LinearLayout.VERTICAL);

			sv.addView(ll);


			Button b = new Button(this);

			b.setText("Notify!");
			int counter = 0;




			ll.addView(b);

			this.setContentView(sv);

			this.ShowToast("http://jsc-solutions.net");


		}
        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");
                }
            );


        }
        TextView zCoor; // declare Z axis object

        // running it on device:
        // attach device to usb

        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

            base.onCreate(savedInstanceState);

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

            xCoor = new TextView(this).AttachTo(ll);
            yCoor = new TextView(this).AttachTo(ll);
            zCoor = new TextView(this).AttachTo(ll);
            setContentView(sv);

            this.onaccelerometer +=
                (x, y, z) =>
                {
                    xCoor.setText("X: " + ((object)x).ToString());
                    yCoor.setText("Y: " + ((object)y).ToString());
                    zCoor.setText("Z: " + ((object)z).ToString());
                };



            //setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

            //this.ShowToast("http://jsc-solutions.net");
        }
        // called by?
        public override void InternalBeforeSetContext(android.content.Context c)
        {
            InternalScrollView = new ScrollView(c);
            InternalLinearLayout = new LinearLayout(c);

            var p = this.Padding;
            InternalLinearLayout.setPadding(
                          p.Left,
                          p.Top,
                          p.Right,
                          p.Bottom
                          );


            // shal we allow dynamic change after we have been shown?
            //InternalLinearLayout.setPadding(
            //    this.Padding.Left,
            //    this.Padding.Top,
            //    this.Padding.Right,
            //    this.Padding.Bottom
            //    );

            InternalLinearLayout.setOrientation(1);

            InternalScrollView.addView(InternalLinearLayout);


            // X:\jsc.svn\examples\java\android\forms\InteractivePortForwarding\InteractivePortForwarding\UserControl1.cs
            if (Load != null)
                Load(this, new EventArgs());
        }
        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

            base.onCreate(savedInstanceState);

            ScrollView sv = new ScrollView(this);

            LinearLayout ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);

            //// http://stackoverflow.com/questions/9784570/webview-inside-scrollview-disappears-after-zooming
            //// http://stackoverflow.com/questions/8123804/unable-to-add-web-view-dynamically
            //// http://developer.android.com/reference/android/webkit/WebView.html



            TextView tv = new TextView(this);

            tv.setText("What would you like to create today?");

            ll.addView(tv);



            this.setContentView(sv);

            var version = SDKVersionCheck.GetSDKVersion();

            this.ShowLongToast(new { version }.ToString());

        }
        // http://stackoverflow.com/questions/6274141/trigger-background-service-at-a-specific-time-in-android
        // http://stackoverflow.com/questions/7144908/how-is-an-intent-service-declared-in-the-android-manifest
        // http://developer.android.com/guide/topics/manifest/service-element.html


        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://developer.android.com/guide/topics/ui/notifiers/notifications.html

            base.onCreate(savedInstanceState);

            ScrollView sv = new ScrollView(this);

            LinearLayout ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);

            #region startservice
            var startservice = new Button(this);
            startservice.setText("Start Service to send Notification");
            startservice.AtClick(
               delegate
               {
                   this.ShowToast("startservice_onclick");

                   var intent = new Intent(this, typeof(NotifyService).ToClass());

                   this.startService(intent);
               }
            );
            ll.addView(startservice);
            #endregion

            #region stopservice
            var stopservice = new Button(this);
            stopservice.setText("Stop Service");
            stopservice.AtClick(
                delegate
                {
                    this.ShowToast("stopservice_onclick");

                    Intent intent = new Intent();
                    intent.setAction(NotifyService.ACTION);
                    intent.putExtra("RQS", NotifyService.RQS_STOP_SERVICE);
                    this.sendBroadcast(intent);

                }
            );
            ll.addView(stopservice);
            #endregion

            this.setContentView(sv);

            this.ShowToast("http://jsc-solutions.net");


        }
        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // why isnt jsc doing automatic ref?
            var r = default(global::ScriptCoreLib.Android.Windows.Forms.IAssemblyReferenceToken_Forms);
            ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext = this;

            // X:\jsc.svn\examples\java\android\forms\FormsMessageBox\FormsMessageBox\Library\ApplicationControl.cs

            // cmd /K c:\util\android-sdk-windows\platform-tools\adb.exe logcat
            // Camera PTP

            // http://developer.android.com/guide/topics/ui/notifiers/notifications.html

            base.onCreate(savedInstanceState);

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


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

            // jsc is doing the wrong thing here
            //var SDK_INT = android.os.Build.VERSION.SDK_INT;

            //b.setText("Notify! " + new { SDK_INT, android.os.Build.VERSION.SDK });
            b.setText("Notify! " );
            int counter = 0;

            b.AtClick(
                delegate
            {
                counter++;



                var f = new Form1();

                var value = f.ShowDialog();

                b.setText("ShowDialog! " + new { value, f.textBox1.Text });
            }
            );

            ll.addView(b);

            this.setContentView(sv);
        }
        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            //// http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

            base.onCreate(savedInstanceState);

            ScrollView sv = new ScrollView(this);

            LinearLayout ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);


            var b = new Button(this);

            b.setText("Vibrate!");

            b.AtClick(
                delegate
                {
                    var vibrator = (Vibrator)this.getSystemService(Context.VIBRATOR_SERVICE);

                    vibrator.vibrate(600);
                }
            );

            ll.addView(b);





            this.setContentView(sv);


            //this.ShowLongToast("Monese circle progressbar");

            //circularSeekbar = new CircularSeekBar(this);
            //circularSeekbar.setMaxProgress(100);
            //circularSeekbar.setProgress(100);
            //setContentView(circularSeekbar);
            //circularSeekbar.invalidate();

            //circularSeekbar.setSeekBarChangeListener(new TestAndroidCircleProgressbar.Activities.CircularSeekBar.MyOnSeekChangeListener());

        }
        // http://stackoverflow.com/questions/6274141/trigger-background-service-at-a-specific-time-in-android
        // http://stackoverflow.com/questions/7144908/how-is-an-intent-service-declared-in-the-android-manifest
        // http://developer.android.com/guide/topics/manifest/service-element.html

        //AtBootCompleted hack1;

        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://developer.android.com/guide/topics/ui/notifiers/notifications.html

            base.onCreate(savedInstanceState);

            ScrollView sv = new ScrollView(this);

            LinearLayout ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);

            var btn = new Button(this);
            btn.setText("wifi");

            ll.addView(btn);

            {
                ConnectivityManager connManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
                NetworkInfo wifiNetInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
                NetworkInfo mobileNetInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);


                if (wifiNetInfo != null)
                    if (wifiNetInfo.isConnectedOrConnecting())
                    {
                        btn.setText("we are connected via WiFi");
                    }

                if (mobileNetInfo != null)
                    if (mobileNetInfo.isAvailable())
                        if (mobileNetInfo.isConnected())
                        {
                            btn.setText(" we are connected via mobile data (GPRS, 3G, etc.)");
                        }
            }


            this.setContentView(sv);

            this.StartPendingAlarm(typeof(NotifyService), 1000 * 1, 0);


        }
        // http://stackoverflow.com/questions/19954156/android-build-separate-apks-for-different-processor-architectures
        // "X:\jsc.svn\examples\java\android\Test\TestChromeAsAsset\TestChromeAsAsset.sln"

        //  [aapt] W:\bin\AndroidManifest.xml:14: error: Error: No resource found that matches the given name (at 'label' with value '@string/app_name').



        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

            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);

            b.setText(
                // X:\jsc.svn\examples\c\android\Test\TestNDKAsAsset\TestNDKAsAsset\Program.cs
                // http://stackoverflow.com/questions/19954156/android-build-separate-apks-for-different-processor-architectures


                //  <package id="TestNDKAsAssetFromSharedLibrary" version="1.0.0.0" targetFramework="net4" userInstalled="true" />
                // X:\jsc.svn\examples\java\android\synergy\OVRVrCubeWorldNativeActivity\OVRVrCubeWorldNativeActivity\ApplicationActivity.cs

                // can we load that native so into a separate process?
                // switch to native and back?
                TestNDKAsAsset.xActivity.stringFromJNI()
            //"Vibrate!"
            );

            b.AtClick(
                delegate
                {
                    var vibrator = (Vibrator)this.getSystemService(Context.VIBRATOR_SERVICE);

                    vibrator.vibrate(600);
                }
            );

            ll.addView(b);



            this.setContentView(sv);


            //this.ShowLongToast("http://my.jsc-solutions.net x");
        }
		//		BUILD FAILED
		//x:\util\android-sdk-windows\tools\ant\build.xml:542: Unable to resolve project target 'Google Inc.:Google APIs:21'

		// https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2015/201505/20150503/udp
		// http://www.happygeek.in/programmatically-get-device-imei-in-android


		protected override void onCreate(global::android.os.Bundle savedInstanceState)
		{
			// http://developer.android.com/guide/topics/ui/notifiers/notifications.html

			base.onCreate(savedInstanceState);

			var sv = new ScrollView(this);

			var ll = new LinearLayout(this);

			ll.setOrientation(LinearLayout.VERTICAL);

			sv.addView(ll);


			Button b = new Button(this).WithText("Whats my IMEI?").AtClick(
				delegate
				{
					TelephonyManager telephonyManager = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);

					string imei = telephonyManager.getDeviceId();


					this.setTitle(new { imei }.ToString());

					//this.ShowLongToast("IMEI: " + imei);
				}
			);


			ll.addView(b);

			this.setContentView(sv);



		}
Example #15
0
 protected override void onCreate (android.os.Bundle arg0)
 {
     base.onCreate (arg0);
     
     LinearLayout layout = new LinearLayout (this);
     layout.setOrientation (LinearLayout.VERTICAL);
     Button btn = new Button (this);
     btn.setOnClickListener (this);
     btn.setText ("threaD");
     layout.addView (btn);
     
     btn2 = new Button (this);
     btn2.setText ("debug");
     btn2.setOnClickListener (new com.koushikdutta.monojavabridge.android.OnClickListener { OnClick = v =>
     {
         Console.WriteLine ("Foobar");
     } });
     layout.addView (btn2);
     
     tv = new TextView(this);
     layout.addView(tv);
     setContentView (layout);
     
 }
        protected override void onCreate(Bundle savedInstanceState)
        {
            // http://unix.stackexchange.com/questions/10050/proc-pid-fd-x-link-number
            // http://stackoverflow.com/questions/21955273/sharing-shared-memory-file-descriptors-across-android-app-processes-using-binder
            // http://permalink.gmane.org/gmane.comp.handhelds.android.porting/10904

            // http://www.mkyong.com/android/android-activity-from-one-screen-to-another-screen/
            // https://groups.google.com/forum/#!topic/android-ndk/sjIiMsLkHCM

            base.onCreate(savedInstanceState);


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

            var activity = this;

            // does it work for us?
            var fs = default(java.io.FileDescriptor);

            try
            {
                var ls = new LocalSocket();
                ls.connect(new LocalSocketAddress("MemoryFileDescriptor0"));

                var i8 = ls.getInputStream().read();

                fs = ls.getAncillaryFileDescriptors().FirstOrDefault();

                new Button(this).AttachTo(ll).WithText(new { i8, fs }.ToString());


                //var memory0 = new FileInputStream(ls_fd).read();

                //new Button(this).AttachTo(ll).WithText(new { memory0 }.ToString());
            }
            catch { }

            var m = default(MemoryFile);

            //try { m = new MemoryFile(default(string), 0); }
            try { m = new MemoryFile("name1", 0x07); }
            catch { throw; }
            var m_descriptor = this.getIntent().getIntExtra("m_descriptor", 0);
            var parentpid = this.getIntent().getIntExtra("pid", 0);

            //var pfd = (ParcelFileDescriptor)this.getIntent().getParcelableExtra("pfd");

            ////var fs = new java.io.FileDescriptor { };

            ////var xfields = typeof(java.io.FileDescriptor).GetFields(
            ////    System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
            ////);

            ////xfields.WithEach(
            ////    xFileDescriptor_SourceField =>
            ////    {
            ////        var xvalue = xFileDescriptor_SourceField.GetValue(fs);

            ////        //if (xFileDescriptor_SourceField.FieldType == typeof(int))
            ////        if (xFileDescriptor_SourceField.Name == "descriptor")
            ////        {
            ////            xFileDescriptor_SourceField.SetValue(fs, m_descriptor);

            ////        }
            ////    }
            ////);



            // need to call native_mmap

            var t = typeof(MemoryFile);

            // internal static int native_mmap(java.io.FileDescriptor fd, int length, int mode);
            //var native_mmap = t.GetMethod("native_mmap", new[] {
            //        typeof(java.io.FileDescriptor), 
            //        typeof(int), 
            //        typeof(int)
            //    }
            //);

            //var methods = t.GetMethods(
            //    System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static
            //);

            //var native_mmap = methods.FirstOrDefault(x => x.Name == "native_mmap");

            //#region time to patch it?

            //#endregion

            //var available = 0;
            var buffer = new byte[0x07];
            //X:\jsc.svn\examples\java\android\Test\TestNewByteArray7\TestNewByteArray7\Class1.cs
            //try { m.readBytes(buffer, 0, 0, 0x07); }
            //catch { }

            //try
            //{
            //    //buffer0 = new java.io.FileInputStream(fs).read();
            //    available = new java.io.FileInputStream(fs).available();
            //}
            //catch
            //{ }


            //var parentpidfd = "/proc/" + parentpid + "/fd/" + m_descriptor;

            //var parentpidfdx = global::System.IO.File.Exists(parentpidfd);

            //var parentpidf = new java.io.File(parentpidfd);


            //new Button(this).AttachTo(ll).WithText(new { parentpidfdx }.ToString());
            //new Button(this).AttachTo(ll).WithText(new { parentpidfd }.ToString());
            //new Button(this).AttachTo(ll).WithText(new { size = parentpidf.length() }.ToString());


            //var parentfd = ParcelFileDescriptor.open(parentpidf, ParcelFileDescriptor.MODE_READ_WRITE);

            var pid = android.os.Process.myPid();
            var uid = android.os.Process.myUid();

            this.setTitle(
                 new
                 {
                     pid,
                     uid

                     //m_descriptor,
                     //parentpid,
                     ////pfg = pfd.getFd(),
                     ////size = pfd.getStatSize()
                     //parentpidfdx,
                     //parentpidfd
                 }.ToString()
            );


            //new Button(this).AttachTo(ll).WithText("methods: " + new
            //{
            //    methods.Length
            //    ,
            //    native_mmap
            //}.ToString());


            //methods.WithEach(
            //    SourceMethod =>
            //    {
            //        new Button(this).AttachTo(ll).WithText(new { SourceMethod }.ToString());
            //    }
            //);

            Action patch = delegate { };




            #region fields
            var fields = t.GetFields(
                System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
            );

            new Button(this).AttachTo(ll).WithText("fields: " + new { fields.Length }.ToString());

            fields.WithEach(
                SourceField =>
                {
                    //E/AndroidRuntime( 9919): Caused by: java.lang.IllegalAccessException: Cannot access field: java.io.FileDescriptor android.os.MemoryFile.mFD
                    //E/AndroidRuntime( 9919):        at java.lang.reflect.Field.get(Native Method)
                    //E/AndroidRuntime( 9919):        at java.lang.reflect.Field.get(Field.java:279)
                    //E/AndroidRuntime( 9919):        at ScriptCoreLibJava.BCLImplementation.System.Reflection.__FieldInfo.GetValue(__FieldInfo.java:46)

                    var value = SourceField.GetValue(m);

                    var xFileDescriptor = value as java.io.FileDescriptor;
                    if (xFileDescriptor != null)
                    {
                        var xfields = typeof(java.io.FileDescriptor).GetFields(
                            System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                        );

                        xfields.WithEach(
                            xFileDescriptor_SourceField =>
                            {
                                var xvalue = xFileDescriptor_SourceField.GetValue(value);

                                //if (xFileDescriptor_SourceField.FieldType == typeof(int))
                                if (xFileDescriptor_SourceField.Name == "descriptor")
                                {
                                    //m_descriptor = (int)xvalue;

                                    patch = delegate
                                    {
                                        Console.WriteLine("enter patch " + new { SourceField });

                                        //mAddress = native_mmap(mFD, length, modeToProt(mode));
                                        //mOwnsRegion = false;

                                        SourceField.SetValue(m, fs);
                                        //xFileDescriptor_SourceField.SetValue(value, m_descriptor);
                                        value = SourceField.GetValue(m);
                                        xvalue = xFileDescriptor_SourceField.GetValue(value);

                                        var field_mAddress = fields.FirstOrDefault(xx => xx.Name == "mAddress");

                                        Console.WriteLine("enter patch " + new { xvalue } + " invoke mmap");


                                        var PROT_READ = 0x1;

                                        //E/AndroidRuntime( 8047): Caused by: java.lang.IllegalAccessException: access to method denied
                                        //E/AndroidRuntime( 8047):        at java.lang.reflect.Method.invokeNative(Native Method)
                                        //E/AndroidRuntime( 8047):        at java.lang.reflect.Method.invoke(Method.java:507)
                                        //E/AndroidRuntime( 8047):        at ScriptCoreLibJava.BCLImplementation.System.Reflection.__MethodInfo.InternalInvoke(__MethodInfo.java:93)

                                        //I/System.Console( 8648): 21c8:0001 enter patch { field_mAddress = int mAddress } invoke native_mmap

                                        //I/System.Console( 8936): 22e8:0001 GetFields { Length = 5, IsPublic = false, IsNonPublic = true, IsStatic = fal
                                        //I/System.Console( 8936): 22e8:0001 enter patch
                                        //I/System.Console( 8936): 22e8:0001 enter patch { field_mAddress = int mAddress, m_descriptor = 39 } invoke mmap
                                        //I/System.Console( 8936): 22e8:0001 lib: libs/armeabi_v7a/libTestNDKAsAsset.so
                                        //I/System.Console( 8936): 22e8:0001 loadLibrary: TestNDKAsAsset
                                        //I/System.Console( 8936): 22e8:0001 exit patch { mAddress = -1 }

                                        //var z = ScriptCoreLibNative.SystemHeaders.sys.mman_h.mmap(
                                        //    null,
                                        //    length,
                                        //    PROT_READ | PROT_WRITE,
                                        //    MAP_SHARED,
                                        //    fd,
                                        //    0
                                        //    );

                                        //                                        I/System.Console( 8016): 1f50:0001 enter patch { SourceField = java.io.FileDescriptor mFD }
                                        //I/System.Console( 8016): 1f50:0001 enter patch { field_mAddress = long mAddress, xvalue = 32 } invoke mmap
                                        //I/System.Console( 8016): 1f50:0001 lib: libs/armeabi_v7a/libTestNDKAsAsset.so
                                        //I/System.Console( 8016): 1f50:0001 loadLibrary: TestNDKAsAsset
                                        //I/System.Console( 8016): 1f50:0001 exit patch { mAddress = -1 }


                                        //I/System.Console( 9792): 2640:0001 enter patch { SourceField = java.io.FileDescriptor mFD }
                                        //I/System.Console( 9792): 2640:0001 enter patch { xvalue = 32 } invoke mmap
                                        //I/xNativeActivity( 9792): x:\jsc.svn\examples\c\android\Test\TestNDKAsAsset\TestNDKAsAsset\Program.cs:139 mmap -1 errno: 13 Permission denied
                                        //I/System.Console( 9792): 2640:0001 exit patch { mAddress = -1 }
                                        //E/audit   ( 5152): type=1400 msg=audit(1433328685.131:566): avc:  denied  { mmap_zero } for  pid=9792 comm="Activities:foo1" scontext=u:r:untrusted_app:s0 tcontext=u:r:untrusted_app:s0 tclass=memprotect permissive=0
                                        //E/audit   ( 5152):  SEPF_SM-G925F_5.0.2_0009
                                        //E/audit   ( 5152): type=1300 msg=audit(1433328685.131:566): arch=40000028 syscall=192 success=no exit=-13 a0=0 a1=7 a2=3 a3=10 items=0 ppid=2962 ppcomm=main pid=9792 auid=4294967295 uid=10315 gid=10315 euid=10315 suid=10315 fsuid=10315 egid=10315 sgid=10315 fsgid=10315 ses=4294967295 tty=(none) comm="Activities:foo1" exe="/system/bin/app_process32" subj=u:r:untrusted_app:s0 key=(null)
                                        //E/audit   ( 5152): type=1320 msg=audit(1433328685.131:566):
                                        //D/SSRM:n  ( 3468): SIOP:: AP = 290, PST = 300, CP = 395, CUR = 268

                                        // https://github.com/realm/realm-java/issues/1037

                                        var mAddress = (int)
                                            // ???
                                            TestNDKAsAsset.xActivity.mmap(
                                            (int)xvalue,
                                            0x07
                                           );

                                        // https://android.googlesource.com/platform/development/+/858086e/ndk/sources/android/libportable/arch-mips/mmap.c
                                        // https://groups.google.com/forum/#!msg/android-ndk/tNYpTsHNQEY/8S7VS2j8f_8J

                                        // jint result = (jint)mmap(NULL, length, prot, MAP_SHARED, fd, 0);

                                        //native_mmap.Invoke(null,
                                        //    new object[]
                                        //                {
                                        //                    value,
                                        //                    0x07,
                                        //                    PROT_READ
                                        //                }
                                        //);

                                        Console.WriteLine("exit patch " + new { mAddress });

                                        field_mAddress.SetValue(m, mAddress);

                                        // http://stackoverflow.com/questions/8165216/what-is-the-use-of-memoryfile-in-android
                                        // http://osdir.com/ml/Android-Developers/2013-01/msg00793.html
                                    };
                                }

                                new Button(this).AttachTo(ll).WithText(xFileDescriptor_SourceField + new { xvalue }.ToString());
                            }
                        );


                    }
                    else
                    {
                        new Button(this).AttachTo(ll).WithText(new { SourceField, value }.ToString());
                    }

                }
            );
            #endregion

            new Button(activity).WithText("Patch n Read!").AttachTo(ll).AtClick(
               delegate
               {
                   patch();
                   //return;

                   //this.finish();

                   //E/AndroidRuntime( 7526): Caused by: java.lang.NoSuchMethodError: android.app.Activity.finishAndRemoveTask
                   //E/AndroidRuntime( 7526):        at TestMultiProcMemoryFile.Activities.SecondaryActivity._onCreate_b__0(SecondaryActivity.java:66)

                   //this.finishAndRemoveTask();

                   //try { m.readBytes(buffer, 0, 0, 0x07); }
                   //catch { }
                   //var buffer0 = buffer[0];


                   //this.setTitle(
                   //     new { m_descriptor, buffer0 }.ToString()
                   //);



               }
            );

            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);


            // 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);
        }
        private void InitializeContent()
        {
            // http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html

            var r = default(global::ScriptCoreLib.Android.Windows.Forms.IAssemblyReferenceToken_Forms);

            var u = new ApplicationControl();

            u.AttachTo(this);

            u.button1.Click += delegate
            {
                //var temp = (__UserControl)(object)u;
                var popupView = new android.widget.LinearLayout(this);
                var dispWidth = getWindowManager().getDefaultDisplay().getWidth() - 60;

                var popupText = new TextView(this);
                popupText.setText("This is Popup Window!");
                popupText.setPadding(0, 0, 0, 20);
                popupText.setTextColor(-16711936);

                var popupFormsTextBox = new TextBox();
                popupFormsTextBox.PasswordChar = '*';
                ((__TextBox)(object)popupFormsTextBox).InternalBeforeSetContext(this);
                var t = ((__TextBox)(object)popupFormsTextBox).InternalGetElement();
                ((EditText)t).setWidth(dispWidth);


                var submitButt = new System.Windows.Forms.Button();
                submitButt.Text = "Submit";
                ((__Button)(object)submitButt).InternalBeforeSetContext(this);
                var b = ((__Button)(object)submitButt).InternalGetElement();

                var cancelButt = new System.Windows.Forms.Button();
                cancelButt.Text = "Cancel";
                ((__Button)(object)cancelButt).InternalBeforeSetContext(this);
                var cb = ((__Button)(object)cancelButt).InternalGetElement();

                popupView.addView(popupText);
                popupView.addView(t);
                popupView.addView(b);
                popupView.addView(cb);

                popupView.setOrientation(1);
                popupView.setBackgroundColor(-3355444);

                var popup = new android.widget.PopupWindow(popupView, dispWidth, 250);
                popup.setContentView(popupView);
                popup.setFocusable(true);
                popup.setOutsideTouchable(true);

                // E/AndroidRuntime( 4979): Caused by: java.lang.NoSuchMethodError: android.widget.PopupWindow.showAsDropDown
                popup.showAsDropDown(((__Button)(object)u.button1).InternalGetElement(), android.view.Gravity.CENTER, 40, 0);
                u.button1.Text = "Now popup must show!!";

                submitButt.Click += delegate
                {
                    submitButt.Text = ((EditText)t).getText().ToString();
                };

                cancelButt.Click += delegate
                {
                    popup.dismiss();
                };
            };



            ////// http://stackoverflow.com/questions/9784570/webview-inside-scrollview-disappears-after-zooming
            ////// http://stackoverflow.com/questions/8123804/unable-to-add-web-view-dynamically
            ////// http://developer.android.com/reference/android/webkit/WebView.html



            //this.ShowLongToast("http://jsc-solutions.net");

            //[javac] Compiling 527 source files to V:\bin\classes
            //[javac] V:\src\AndroidFormsActivity\ApplicationControl.java:129: error: cannot find symbol
            //[javac]         super.Dispose_06000006(disposing);
            //[javac]              ^
            //[javac]   symbol: method Dispose_06000006(boolean)
            //[javac] Note: V:\src\ScriptCoreLibJava\BCLImplementation\System\Threading\__Thread.java uses or overrides a deprecated API.
        }
        // http://www.techwavedev.com/?p=14
        // http://www.androidhive.info/2011/08/android-tab-layout-tutorial/
        // http://stackoverflow.com/questions/6685257/android-tabhost-addtab-null-pointer-exception
        // http://stackoverflow.com/questions/6674044/android-application-is-not-runnning-errorresourcesnotfoundexception-resource
        // http://www.devdaily.com/java/jwarehouse/android/core/java/android/widget/TabHost.java.shtml

        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

            base.onCreate(savedInstanceState);

            var c = this;

            var th = new TabHost(c);

            LinearLayout ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            th.addView(ll);


            var tw = new TabWidget(c);
            tw.setId(android.R.id.tabs);
            tw.AttachTo(ll);

            var fl = new FrameLayout(c);
            fl.setId(android.R.id.tabcontent);
            fl.AttachTo(ll);


            //th.str

            this.setContentView(th);


            //  Your TabHost must have a TabWidget whose id attribute is 'android.R.id.tabs'
            // what?
            // android.widget.TabHost cannot be cast to android.widget.TabWidget
            th.setup();
            // for some reason R.layout.tab_indicator cannot be loaded and causes a fault!
            // http://www.devdaily.com/java/jwarehouse/android/core/java/android/widget/TabHost.java.shtml
            // http://ericharlow.blogspot.com/2010/10/experience-customizing-androids-tab.html

            {
                var a = new TextView(c);

                a.setText("Hello1");

                var ts =
                    th
                    .newTabSpec("")
                    .setIndicator(
                    a
                    //(CharSequence)(object)"Hello"
                    //,  res.getDrawable(R.drawable.ic_tab_main)
                    )
                    .setContent(

                        new XTabContentFactory { c = this }

                    );

                //E/AndroidRuntime( 1610): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
                //E/AndroidRuntime( 1610):        at android.content.res.Resources.getValue(Resources.java:1018)
                //E/AndroidRuntime( 1610):        at android.content.res.Resources.loadXmlResourceParser(Resources.java:2105)
                //E/AndroidRuntime( 1610):        at android.content.res.Resources.getLayout(Resources.java:857)
                //E/AndroidRuntime( 1610):        at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
                //E/AndroidRuntime( 1610):        at android.widget.TabHost$LabelIndicatorStrategy.createIndicatorView(TabHost.java:531)
                //E/AndroidRuntime( 1610):        at android.widget.TabHost.addTab(TabHost.java:223)
                //E/AndroidRuntime( 1610):        at AndroidTabViewActivity.Activities.ApplicationActivity.onCreate(ApplicationActivity.java:54)

                th.addTab(ts
                );
            }

            {
                var a = new TextView(c);

                a.setText("Hello2");

                var ts =
                    th
                    .newTabSpec("")
                    .setIndicator(
                    a
                    //(CharSequence)(object)"Hello"
                    //,  res.getDrawable(R.drawable.ic_tab_main)
                    )
                    .setContent(

                        new YTabContentFactory { c = this }

                    );

                //E/AndroidRuntime( 1610): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
                //E/AndroidRuntime( 1610):        at android.content.res.Resources.getValue(Resources.java:1018)
                //E/AndroidRuntime( 1610):        at android.content.res.Resources.loadXmlResourceParser(Resources.java:2105)
                //E/AndroidRuntime( 1610):        at android.content.res.Resources.getLayout(Resources.java:857)
                //E/AndroidRuntime( 1610):        at android.view.LayoutInflater.inflate(LayoutInflater.java:394)
                //E/AndroidRuntime( 1610):        at android.widget.TabHost$LabelIndicatorStrategy.createIndicatorView(TabHost.java:531)
                //E/AndroidRuntime( 1610):        at android.widget.TabHost.addTab(TabHost.java:223)
                //E/AndroidRuntime( 1610):        at AndroidTabViewActivity.Activities.ApplicationActivity.onCreate(ApplicationActivity.java:54)

                th.addTab(ts
                );
            }

            //th.addTab(th
            //    .newTabSpec("")
            //    .setIndicator(
            //        (CharSequence)(object)"World"
            //        //,  res.getDrawable(R.drawable.ic_tab_setup)
            //        )
            //    .setContent(new Intent(c, GetMainActivityClass()))
            //);

            this.ShowLongToast("http://jsc-solutions.net");


        }
        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)
        }
            public android.view.View createTabContent(string value)
            {
                ScrollView sv = new ScrollView(c);

                LinearLayout ll = new LinearLayout(c);

                ll.setOrientation(LinearLayout.VERTICAL);

                sv.addView(ll);


                Button b = new Button(c);

                b.setText("Yay. This almost works!");

                ll.addView(b);





                return sv;
            }
            public android.view.View createTabContent(string value)
            {
                ScrollView sv = new ScrollView(c);

                LinearLayout ll = new LinearLayout(c);

                ll.setOrientation(LinearLayout.VERTICAL);

                sv.addView(ll);


                Button b = new Button(c);

                b.setText("I don't do anything, but I was added dynamically. :)");

                ll.addView(b);




          
                return sv;
            }
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20151212/androidudpclipboard
        // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20160101/ovrwindwheelndk

        //        connect s6 via usb .
        // turn on wifi!
        // kill adb

        //"x:\util\android-sdk-windows\platform-tools\adb.exe"  tcpip 5555
        // restarting in TCP mode port: 5555

        //13: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        //    inet 192.168.1.126/24 brd 192.168.1.255 scope global wlan0
        //       valid_lft forever preferred_lft forever

        // on red
        // "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/201511/20151121
        // http://stackoverflow.com/questions/17513502/support-for-multi-window-app-development

        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

            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);

            b.setText("Vibrate!");

            var sw = Stopwatch.StartNew();



            Action cleanup = delegate { };

            Notification reuse = null;
            var notificationIntent = new Intent(this, typeof(ApplicationActivity).ToClass());
            var contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

            Action<string> SetClipboard = value =>
            {
                Console.WriteLine("SetClipboard " + new { value });

                this.runOnUiThread(
                    delegate
                    {
                        cleanup();

                        b.setText(value);




                        if (reuse != null)
                        {
                            reuse.setLatestEventInfo(
                                 this,
                                 contentTitle: value,
                                 contentText: "",
                                 contentIntent: contentIntent);

                            return;
                        }

                        var xNotificationManager = (NotificationManager)this.getSystemService(Activity.NOTIFICATION_SERVICE);

                        // see http://developer.android.com/reference/android/app/Notification.html
                        var xNotification = new Notification(
                            //android.R.drawable.ic_dialog_alert,
                            android.R.drawable.ic_menu_view,
                            //tickerText: "not used?",
                            tickerText: value,


                            when: 0
                            //java.lang.System.currentTimeMillis()
                        );

                        //notification.defaults |= Notification.DEFAULT_SOUND;



                        // flags = Notification.FLAG_ONGOING_EVENT 

                        var FLAG_ONGOING_EVENT = 0x00000002;
                        //notification.flags |= Notification.FLAG_ONGOING_EVENT;
                        //xNotification.flags |= FLAG_ONGOING_EVENT;

                        xNotification.setLatestEventInfo(
                            this,
                            contentTitle: value,
                            contentText: "",
                            contentIntent: contentIntent);

                        //notification.defaults |= Notification.DEFAULT_VIBRATE;
                        //notification.defaults |= Notification.DEFAULT_LIGHTS;
                        // http://androiddrawableexplorer.appspot.com/

                        var id = (int)sw.ElapsedMilliseconds;

                        xNotificationManager.notify(id, xNotification);

                        var xVibrator = (Vibrator)this.getSystemService(Context.VIBRATOR_SERVICE);
                        xVibrator.vibrate(600);



                        #region setPrimaryClip
                        android.content.ClipboardManager clipboard = (android.content.ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("label", value);
                        clipboard.setPrimaryClip(clip);
                        #endregion

                        reuse = xNotification;


                        cleanup += delegate
                        {
                            // https://developer.android.com/reference/android/app/Notification.html

                            if (xNotification == null)
                                return;

                            xNotificationManager.cancel(id);
                        };
                    }
                );
            };


            b.AtClick(
                delegate
                {
                    SetClipboard("hello");
                }
            );



            // Z:\jsc.svn\examples\c\android\Test\TestNDKUDP\TestNDKUDP\xNativeActivity.cs

            #region lets listen to incoming udp
            // could we define our chrome app inline in here?
            // or in a chrome app. could we define the android app inline?
            #region ReceiveAsync
            Action<IPAddress> f = async nic =>
            {
                b.setText("awaiting at " + nic);


                WifiManager wifi = (WifiManager)this.getSystemService(Context.WIFI_SERVICE);
                var lo = wifi.createMulticastLock("udp:49814");
                lo.acquire();

                // Z:\jsc.svn\examples\java\android\AndroidUDPClipboard\ApplicationActivity.cs
                // X:\jsc.svn\examples\java\android\forms\FormsUDPJoinGroup\FormsUDPJoinGroup\ApplicationControl.cs
                // X:\jsc.svn\examples\java\android\LANBroadcastListener\LANBroadcastListener\ApplicationActivity.cs
                var uu = new UdpClient(49814);
                uu.JoinMulticastGroup(IPAddress.Parse("239.1.2.3"), nic);
                while (true)
                {
                    // cannot get data from RED?
                    var x = await uu.ReceiveAsync(); // did we jump to ui thread?
                    //Console.WriteLine("ReceiveAsync done " + Encoding.UTF8.GetString(x.Buffer));
                    var data = Encoding.UTF8.GetString(x.Buffer);



                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150704
                    // https://sites.google.com/a/jsc-solutions.net/work/knowledge-base/15-dualvr/20150704/mousedown
                    SetClipboard(data);
                }
            };

            // WithEach defined at?
            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)
                                    f(ip.Address);
                        }
                    }




                }
            );
            #endregion


            #endregion

            // jsc could pass this ptr to ctor for context..
            var t = new EditText(this) { };

            t.AttachTo(ll);

            ll.addView(b);



            this.setContentView(sv);


            //this.ShowLongToast("http://my.jsc-solutions.net x");
        }
        public override void onCreate()
        {
            base.onCreate();

            Console.WriteLine("enter LocalApplication onCreate, first time?");

            // https://stackoverflow.com/questions/7686482/when-does-applications-oncreate-method-is-called-on-android
            Toast.makeText(this, "LocalApplication", Toast.LENGTH_LONG).show();

            // . To open these resources with a raw InputStream, call Resources.openRawResource() with the resource ID, which is R.raw.filename.
            // However, if you need access to original file names and file hierarchy, you might consider saving some resources in the assets/ directory (instead of res/raw/). Files in assets/ are not given a resource ID, so you can read them only using AssetManager.

            var listByRoot = default(Action<Activity, LinearLayout, string>);

            listByRoot =
                (activity, ll, root) =>
                {
                    try
                    {
                        // http://developer.android.com/reference/android/content/res/AssetManager.html
                        var assets = activity.getResources().getAssets();

                        var list = assets.list(root);


                        new Button(activity).WithText("assets: " + new { list.Length, root }).AttachTo(ll);

                        foreach (var item in list)
                        {
                            //                            E/AndroidRuntime(25423): Caused by: java.io.FileNotFoundException: images
                            //E/AndroidRuntime(25423):        at android.content.res.AssetManager.openNonAssetFdNative(Native Method)

                            //var a = fd.getFileDescriptor();
                            var _item = item;

                            new Button(activity).AttachTo(ll).With(
                                i =>
                                {
                                    var fd = default(AssetFileDescriptor);

                                    try
                                    {
                                        // http://stackoverflow.com/questions/5647253/is-there-a-way-to-open-file-as-file-object-from-androids-assets-folder

                                        fd = assets.openFd(item);
                                        //fd = assets.openNonAssetFd(item);
                                        i.WithText(root + "/" + item + " " + new { Length = fd.getLength() });
                                    }
                                    catch
                                    {
                                        i.WithText("dir: " + item);

                                        i.AtClick(
                                            delegate
                                            {
                                                // hop to another activity

                                                Intent intent = new Intent(activity, typeof(SecondaryActivity).ToClass());
                                                intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

                                                // share scope
                                                intent.putExtra("_item", _item);

                                                //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                                activity.startActivity(intent);

                                                //E/AndroidRuntime(10688): Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
                                                //E/AndroidRuntime(10688):        at android.app.ContextImpl.startActivity(ContextImpl.java:1611)
                                                //E/AndroidRuntime(10688):        at android.app.ContextImpl.startActivity(ContextImpl.java:1598)
                                                //E/AndroidRuntime(10688):        at android.content.ContextWrapper.startActivity(ContextWrapper.java:337)

                                                //listByRoot(_item);
                                            }
                                        );

                                    }

                                }
                            );
                        }
                    }
                    catch
                    {
                        throw;
                    }
                };

            #region ApplicationActivity
            ApplicationActivity.vCreate = (activity, savedInstanceState) =>
            {
                var myPid = android.os.Process.myPid();

                activity.setTitle("root " + new { myPid });

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

                activity.setContentView(sv);

                // how many readonly assets have we added via nugets?

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


                //[javac] W:\src\TestNuGetAssetsConsumer\Activities\ApplicationActivity___c__DisplayClass1.java:32: error: unreported exception IOException; must be caught or declared to be thrown
                //[javac]         stringArray0 = assets.list("");



                listByRoot(activity, ll, "");

            };
            #endregion

            #region SecondaryActivity
            SecondaryActivity.vCreate = (activity, savedInstanceState) =>
            {
                var sv = new ScrollView(activity);
                var ll = new LinearLayout(activity);
                ll.setOrientation(LinearLayout.VERTICAL);
                sv.addView(ll);
                activity.setContentView(sv);

                // resume scope
                var _item = activity.getIntent().getExtras().getString("_item");

                // http://stackoverflow.com/questions/19631894/is-there-a-way-to-get-current-process-name-in-android
                // http://stackoverflow.com/questions/6567768/how-can-an-android-application-have-more-than-one-process
                var myPid = android.os.Process.myPid();
                //Process.GetCurrentProcess().Id;

                //activity.getPackageManager

                activity.setTitle(_item + new { myPid });


                //b.WithText("! secondary " + new { _item });
                //b.AtClick(
                //    v =>
                //    {
                //        activity.finish();
                //    }
                //);

                listByRoot(activity, ll, _item);

            };
            #endregion

        }
        // http://stackoverflow.com/questions/17513502/support-for-multi-window-app-development

        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // http://www.dreamincode.net/forums/topic/130521-android-part-iii-dynamic-layouts/

            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);

            b.setText("Vibrate!");

            b.AtClick(
                async delegate
                {
                    var vibrator = (Vibrator)this.getSystemService(Context.VIBRATOR_SERVICE);

                    vibrator.vibrate(600);

                    // or jump to laptop pointerlock?

                    SwitchToCompiler.Invoke(
                        delegate
                        {
                            // did we jump back to compiler?
                            // UDP?
                            // RSA?


                        }
                    );

                    // or

                    //        [javac] W:\src\ADBSwitchToCompiler\Activities\ApplicationActivity___onCreate_b__0_0_d__MoveNext_0600000f.java:48: error: cannot find symbol
                    //[javac]         ApplicationActivity___onCreate_b__0_0_d__MoveNext_0600000f.__workflow(next_0600000f0, ref_awaiter1, ref_compiler2, ref_create_b__0_0_d3);
                    //[javac]                                                                                                                            ^

                    // roslyn wont like it?
                    await default(SwitchToCompiler);
                    // X:\jsc.svn\examples\javascript\chrome\extensions\ChromeExtensionHopToTab\ChromeExtensionHopToTab\Application.cs

                    // did we jump back to compiler?
                    // UDP?
                    // RSA?


                    Console.WriteLine("record screen");

                    Console.WriteLine("pull");

                    // https://developers.google.com/youtube/v3/code_samples/dotnet

                }
            );

            ll.addView(b);



            this.setContentView(sv);


            //this.ShowLongToast("http://my.jsc-solutions.net x");
        }
        public override void createAndAttachView(int id, FrameLayout frame)
        {
            // http://stackoverflow.com/questions/2761577/android-start-an-intent-into-a-framelayout
            // http://gamma-point.com/content/android-how-have-multiple-activities-under-single-tab-tabactivity#comment-37
            // http://stackoverflow.com/questions/4882776/start-another-activity-inside-the-framelayout-of-tabactivity

            //     Caused by: java.lang.RuntimeException: You must attach your view to the given frame in createAndAttachView()
            //at wei.mark.standout.ui.Window.<init>(Window.java:154)
            //at wei.mark.standout.StandOutWindow.show(StandOutWindow.java:1078)
            //at wei.mark.standout.StandOutWindow.onStartCommand(StandOutWindow.java:381)
            //at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2656)

            var ll = new LinearLayout(
               frame.getContext()
            );

            //ll.setAlpha(0.8f);

            ll.setOrientation(LinearLayout.VERTICAL);

            #region lltab
            var lltab = new LinearLayout(
              frame.getContext()
            );
            lltab.AttachTo(ll);


            var captionpadding = new TextView(frame.getContext());

            captionpadding.setText("    ");
            // http://stackoverflow.com/questions/3297437/shadow-effect-for-a-text-in-android
            captionpadding.setShadowLayer(1, 0, 0, Color.WHITE);
            captionpadding.setTextColor(Color.WHITE);
            captionpadding.setBackgroundColor(Color.argb(0x7F, 0, 0, 0));

            captionpadding.AttachTo(lltab);

            var caption = new TextView(frame.getContext());

            caption.setText("XWidgetsWindow");
            // http://stackoverflow.com/questions/3297437/shadow-effect-for-a-text-in-android
            caption.setShadowLayer(1, 0, 0, Color.WHITE);
            caption.setTextColor(Color.WHITE);
            caption.setBackgroundColor(Color.argb(0x7F, 0, 0, 0));

            caption.AttachTo(lltab);


            var close = new TextView(frame.getContext());

            close.setText("    x    ");
            // http://stackoverflow.com/questions/3297437/shadow-effect-for-a-text-in-android
            close.setShadowLayer(1, 0, 0, Color.RED);
            close.setTextColor(Color.RED);
            close.setBackgroundColor(Color.argb(0x7F, 0, 0, 0));

            close.AttachTo(lltab);
            close.setClickable(true);

            close.AtClick(
                delegate
                {

                    this.close(id);
                }
            );

            #endregion


            //wei.mark.standout.WindowCache r;

            #region WebView
            var webview = new WebView(frame.getContext());
            //webview.setAlpha(0.8f);

            //frame.startAnimation(new AlphaAnimation(1f, 0.7f));

            //     java.lang.NoSuchMethodError: android.webkit.WebView.setAlpha
            //at PopupWebView.Activities.XWidgetsWindow.createAndAttachView(XWidgetsWindow.java:83)
            //at wei.mark.standout.ui.Window.<init>(Window.java:142)
            //at wei.mark.standout.StandOutWindow.show(StandOutWindow.java:1026)
            //at wei.mark.standout.StandOutWindow.onStartCommand(StandOutWindow.java:381)
            //at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2043)
            //at android.app.ActivityThread.access$2800(ActivityThread.java:117)
            //at android.app.ActivityThread$H.handleMessage(ActivityThread.java:998)
            //at android.os.Handler.dispatchMessage(Handler.java:99)
            //at android.os.Looper.loop(Looper.java:123)
            //at android.app.ActivityThread.main(ActivityThread.java:3687)
            //at java.lang.reflect.Method.invokeNative(Native Method)
            //at java.lang.reflect.Method.invoke(Method.java:507)
            //at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
            //at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            //at dalvik.system.NativeStart.main(Native Method)


            //getWindow().setFlags(
            //    WindowManager_LayoutParams.FLAG_HARDWARE_ACCELERATED,
            //    WindowManager_LayoutParams.FLAG_HARDWARE_ACCELERATED);

            //setContentView(webview);

            //webview.getSettings().setSupportZoom(true); 
            //webview.getSettings().setLoadsImagesAutomatically(true);
            webview.getSettings().setJavaScriptEnabled(true);
            //webview.getSettings().setBuiltInZoomControls(true);
            //webview.setInitialScale(1);

            webview.setWebViewClient(new MyWebViewClient
            {
                //__this = this 
            });

            webview.setWebChromeClient(
                new MyWebChromeClient
                {
                    yield_title =
                        // implicit version does not work?
                        value =>
                        {
                            caption.setText(value);

                            PersistentNotifications
                                .Where(k => k.id == id)
                                .WithEach(
                                n =>
                                {
                                    n.contentText = value;

                                    n.Notification.setLatestEventInfo(
                                        n.context,
                                        n.contentTitle,
                                        n.contentText,
                                        n.contentIntent
                                    );
                                    n.update();
                                }
                            );
                        }
                }
            );

            //webview.getSettings().setSupportZoom(true);
            //webview.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);

            //webview.getSettings().setJavaScriptEnabled(true);

            // no flash in emulator?
            // works on my phone!
            // no Flash since android 4.1.0!!!
            //webview.getSettings().setPluginsEnabled(true);
            //webview.getSettings().setPluginState(android.webkit.WebSettings.PluginState.ON);



            // OR, you can also load from an HTML string:
            //var summary = "<html><body>You scored <b>192</b> points.</body></html>";
            //webview.loadData(summary, "text/html", null);
            //Log.i(TAG, "loadUrl");

            //var uri = "http://cubiq.org/dropbox/3dcity/";
            var uri = "http://abstractatech.com";
            webview.loadUrl(uri);
            #endregion

            // http://forum.xda-developers.com/showthread.php?t=1688531

            var rr = new RelativeLayout(frame.getContext());

            rr.setBackgroundColor(Color.argb(0x1F, 255, 255, 255));

            webview.AttachTo(rr);

            var resizer = new Button(frame.getContext());

            resizer.setText(".:");
            //resizer.setAlpha(0.4f);

            resizer.setWidth(96);
            resizer.setHeight(96);
            resizer.setBackgroundColor(Color.argb(0x7F, 255, 255, 255));



            // http://stackoverflow.com/questions/8397152/androidlayout-alignparentbottom-by-code
            // http://stackoverflow.com/questions/8397152/androidlayout-alignparentbottom-by-code




            resizer.AttachTo(rr);

            RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(
               RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT
             );

            //400, 250,
            p.setMargins(400 - 64, 250 - 64 - 32, 0, 0);
            resizer.setLayoutParams(p);



            resizer.setOnTouchListener(
                new __OnTouchListener
                {
                    yield = (view, e) =>
                    {
                        var ww = getWindow(id);

                        // handle dragging to move
                        var consumed = this.onTouchHandleResize(id,
                            ww,
                            view,
                            e
                        );

                        {
                            p.setMargins(ww.getWidth() - 64 + 10, ww.getHeight() - 64 - 20, 0, 0);
                            resizer.setLayoutParams(p);
                        }
                        return consumed;
                    }
                }
            );

            rr.AttachTo(ll);
            ll.AttachTo(frame);

            {
                //Caused by: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to wei.mark.standout.StandOutWindow$StandOutLayoutParams
                //at wei.mark.example.XWidgetsWindow.createAndAttachView(XWidgetsWindow.java:101)
                //at wei.mark.standout.ui.Window.<init>(Window.java:150)
                //at wei.mark.standout.StandOutWindow.show(StandOutWindow.java:1078)
                //at wei.mark.standout.StandOutWindow.onStartCommand(StandOutWindow.java:381)
                //at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2656)

                //p.setMargins(ww.getWidth() - 64, ww.getHeight() - 64 - 32, 0, 0);
                //resizer.setLayoutParams(p);
            }
        }
        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            // cmd /K c:\util\android-sdk-windows\platform-tools\adb.exe logcat
            // Camera PTP

            // http://developer.android.com/guide/topics/ui/notifiers/notifications.html

            base.onCreate(savedInstanceState);

            ScrollView sv = new ScrollView(this);

            LinearLayout ll = new LinearLayout(this);

            ll.setOrientation(LinearLayout.VERTICAL);

            sv.addView(ll);


            Button b = new Button(this);

            b.setText("AlertDialog! " + new { id = Thread.currentThread().getId() });
            int counter = 0;

            // ScriptCoreLib.Ultra ?
            b.AtClick(
                delegate
            {
                counter++;

                // http://www.tomswebdesign.net/Articles/Android/number-pad-input-class.html
                // https://android.googlesource.com/platform/frameworks/base/+/b896b9f/packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java
                // http://xmlstackoverflow.blogspot.com/2014/07/how-to-use-alertdialog-to-prompt-for-pin.html
                // http://incidencias-ctt.administracionelectronica.gob.es/websvn/filedetails.php?repname=clienteafirma&path=%2Fproject%2Fafirma-mobile%2Fafirma-android%2Ftrunk%2Fafirma-ui-android%2Fsrc%2Fes%2Fgob%2Fafirma%2Fandroid%2Fgui%2FPinDialog.java&peg=4040

                // X:\jsc.svn\examples\java\android\forms\FormsMessageBox\FormsMessageBox\ApplicationActivity.cs
                // X:\jsc.svn\examples\java\android\Test\TestAlertDialog\TestAlertDialog\ApplicationActivity.cs
                AlertDialog alertDialog = new AlertDialog.Builder(this).create();

                alertDialog.setTitle("Reset...");
                alertDialog.setMessage("Are you sure?");
                alertDialog.setButton("OK",
                    new xOnClickListener
                {
                    yield = delegate
                    {
                        b.setText("clicked! " + new { id = Thread.currentThread().getId() });
                    }
                }

                    );

                // skip icons?
                //alertDialog.setIcon(android.R.drawable.star_off);

                // can we do async yet?
                alertDialog.show();


            }
            );

            ll.addView(b);

            this.setContentView(sv);

            // X:\jsc.svn\examples\java\android\HelloOpenGLES20Activity\HelloOpenGLES20Activity\ScriptCoreLib.Android\Shader.cs

            // Error	1	'TestAlertDialog.Activities.ApplicationActivity' does not contain a definition for 'ShowLongToast' and no extension method 'ShowLongToast' accepting a first argument of type 'TestAlertDialog.Activities.ApplicationActivity' could be found (are you missing a using directive or an assembly reference?)	X:\jsc.svn\examples\java\android\TestAlertDialog\TestAlertDialog\ApplicationActivity.cs	80	18	TestAlertDialog
            //this.ShowLongToast("http://jsc-solutions.net");
            //this.ShowToast("http://jsc-solutions.net");


        }
        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);

            new Button(this)
                .WithText("Create Event!")
                .AttachTo(ll)
                .AtClick(
                    b =>
                    {
                        b.setText("Done!");

                        // http://developer.android.com/reference/android/provider/CalendarContract.EventsColumns.html#DESCRIPTION

                        Intent calIntent = new Intent(Intent.ACTION_INSERT);
                        calIntent.setType("vnd.android.cursor.item/event");
                        calIntent.putExtra("title", "My House Party");
                        calIntent.putExtra("eventLocation", "My Beach House");
                        calIntent.putExtra("description", "A Pig Roast on the Beach");

                        GregorianCalendar calDate = new GregorianCalendar(2012, 7, 15);
                        calIntent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);
                        calIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
                             calDate.getTimeInMillis());
                        calIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
                             calDate.getTimeInMillis());





                        //ttdw


                        calIntent.putExtra("accessLevel", 0x00000002);
                        calIntent.putExtra("availability", 0x00000000);

                        calIntent.putExtra("rrule", "FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH");

                        startActivity(calIntent);
                    }
            );

            var COLS = new[]
            { 
                "title",
                "dtstart"
            };


            var at = new TextView(this).AttachTo(ll);

            at.setText("at " + CalendarContract.Events.CONTENT_URI.ToString());

            // from t in calendars
            // select t.title

            var mCursor = this.getContentResolver().query(
                CalendarContract.Events.CONTENT_URI, COLS, null, null, null
            );

            mCursor.moveToLast();

            var tv = new TextView(this).AttachTo(ll);
            tv.setText("n/a");
            Action update =
                delegate
                {
                    var title = "";
                    var start = "";
                    var w = "";

                    //Format df = android.text.format.DateFormat.getDateFormat(this);
                    //Format tf = android.text.format.DateFormat.getTimeFormat(this);

                    //try
                    //{
                    title = mCursor.getString(0);
                    start = ((object)mCursor.getLong(1)).ToString();


                    w += title;
                    w += " at ";
                    w += start;

                    tv.setText(w);
                    //}
                    //catch
                    //{
                    //    tv.setText("n/a error");

                    //    throw;
                    //}



                };

            Button prev, next = null;

            prev = new Button(this)
                  .WithText("Prev")
                  .AttachTo(ll)
                  .AtClick(
                      b =>
                      {
                          if (!mCursor.isFirst())
                          {
                              mCursor.moveToPrevious();
                              next.setEnabled(true);
                          }
                          else
                              b.setEnabled(false);

                          update();
                      }
            );

            next = new Button(this)
                .WithText("Next")
                .AttachTo(ll)
                .AtClick(
                    b =>
                    {

                        if (!mCursor.isLast())
                        {
                            mCursor.moveToNext();
                            prev.setEnabled(true);
                        }
                        else
                            b.setEnabled(false);

                        update();
                    }
          );

            update();


            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 t = typeof(MemoryFile);

            //var m = Activator.CreateInstance(t);

            //E/AndroidRuntime( 4217): Caused by: java.lang.InstantiationException: class android.os.MemoryFile has no zero argument constructor
            //E/AndroidRuntime( 4217):        at java.lang.Class.newInstance(Class.java:1641)
            //E/AndroidRuntime( 4217):        at ScriptCoreLibJava.BCLImplementation.System.__Activator.CreateInstance(__Activator.java:27)
            //E/AndroidRuntime( 4217):        ... 14 more
            //E/AndroidRuntime( 4217): Caused by: java.lang.NoSuchMethodException: <init> []
            //E/AndroidRuntime( 4217):        at java.lang.Class.getConstructor(Class.java:531)
            //E/AndroidRuntime( 4217):        at java.lang.Class.getDeclaredConstructor(Class.java:510)
            //E/AndroidRuntime( 4217):        at java.lang.Class.newInstance(Class.java:1639)
            //E/AndroidRuntime( 4217):        ... 15 more

            var m_descriptor = 0;
            var m_fd = default(java.io.FileDescriptor);
            var pid = android.os.Process.myPid();
            var uid = android.os.Process.myUid();

            //try { m = new MemoryFile(default(string), 0); }
            try { m = new MemoryFile("name1", 0x07); }
            catch { throw; }

            try
            {
                m.writeBytes(
                    new byte[] { 7, 6, 5, 4, 3, 2, 1 }, 0, 0, 0x07
                );
            }
            catch { }

            var buffer = new byte[0x07];
            try
            {
                m.readBytes(buffer, 0, 0, 0x07);
            }
            catch { }
            var buffer0 = buffer[0];

            //new Button(this).AttachTo(ll).WithText(new { t, m, buffer0 }.ToString());
            new Button(this).AttachTo(ll).WithText(new { buffer0 }.ToString());

            #region fields
            var fields = t.GetFields(
                System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
            );

            new Button(this).AttachTo(ll).WithText("fields: " + new { fields.Length }.ToString());

            fields.WithEach(
                SourceField =>
                {
                    //E/AndroidRuntime( 9919): Caused by: java.lang.IllegalAccessException: Cannot access field: java.io.FileDescriptor android.os.MemoryFile.mFD
                    //E/AndroidRuntime( 9919):        at java.lang.reflect.Field.get(Native Method)
                    //E/AndroidRuntime( 9919):        at java.lang.reflect.Field.get(Field.java:279)
                    //E/AndroidRuntime( 9919):        at ScriptCoreLibJava.BCLImplementation.System.Reflection.__FieldInfo.GetValue(__FieldInfo.java:46)

                    var value = SourceField.GetValue(m);

                    var xFileDescriptor = value as java.io.FileDescriptor;
                    if (xFileDescriptor != null)
                    {
                        m_fd = xFileDescriptor;

                        var xfields = typeof(java.io.FileDescriptor).GetFields(
                            System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance
                        );

                        xfields.WithEach(
                            xFileDescriptor_SourceField =>
                            {
                                var xvalue = xFileDescriptor_SourceField.GetValue(value);

                                //if (xFileDescriptor_SourceField.FieldType == typeof(int))
                                if (xFileDescriptor_SourceField.Name == "descriptor")
                                {
                                    m_descriptor = (int)xvalue;
                                }

                                new Button(this).AttachTo(ll).WithText(xFileDescriptor_SourceField + new { xvalue }.ToString());
                            }
                        );


                    }
                    else
                    {
                        new Button(this).AttachTo(ll).WithText(new { SourceField, value }.ToString());
                    }

                }
            );
            #endregion

            //var pfd = default(android.os.ParcelFileDescriptor);

            //try
            //{
            //    pfd = android.os.ParcelFileDescriptor.dup(
            //        m_fd
            //    );
            //}
            //catch
            //{
            //}

            new Button(activity).WithText("Next \n " + new
            {
                pid,
                uid
                //,
                //pfd = pfd.getFd(),
                //size = pfd.getStatSize()
            }).AttachTo(ll).AtClick(
                delegate
                {
                    Intent intent = new Intent(activity, typeof(SecondaryActivity).ToClass());
                    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

                    // share scope
                    intent.putExtra("m_descriptor", m_descriptor);
                    intent.putExtra("pid", pid);

                    //intent.putExtra("pfd", pfd);

                    //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);

                    try
                    {
                        Console.WriteLine("new LocalServerSocket");
                        var ss = new LocalServerSocket("MemoryFileDescriptor0");

                        // cached backgroun process?
                        // switching to another process.. easy...
                        activity.startActivity(intent);

                        Console.WriteLine("before LocalServerSocket accept");


                        // http://alvinalexander.com/java/jwarehouse/android/core/tests/coretests/src/android/net/LocalSocketTest.java.shtml
                        var ls = ss.accept();
                        Console.WriteLine("after LocalServerSocket accept");

                        ls.setFileDescriptorsForSend(new[] { m_fd });
                        ls.getOutputStream().write(42);
                    }
                    catch
                    {
                        throw;
                    }

                }
            );

            this.setContentView(sv);

            // https://developer.android.com/training/run-background-service/create-service.html
        }
        // inspired by http://baroqueworksdev.blogspot.com/2012/09/how-to-handle-screen-onoff-and-keygurad.html



        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            base.onCreate(savedInstanceState);

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


            this.setContentView(sv);


            new Button(this).WithText("register").AttachTo(ll).AtClick(
                btn =>
                {
                    btn.setEnabled(false);

                    // get KeyGuardManager
                    var mKeyguard = (KeyguardManager)getSystemService(Context.KEYGUARD_SERVICE);

                    var mReceiver = new MyBroadcastReceiver();

                    mReceiver.AtReceive +=
                        (Context context, Intent intent) =>
                        {
                            #region Notify
                            int counter = 0;
                            Action<string> Notify =
                                Title =>
                                {
                                    counter++;

                                    var nm = (NotificationManager)this.getSystemService(Activity.NOTIFICATION_SERVICE);

                                    // see http://developer.android.com/reference/android/app/Notification.html
                                    var notification = new Notification(
                                        android.R.drawable.star_on,
                                        Title,
                                         java.lang.System.currentTimeMillis()
                                    );

                                    // ToClass is like GetTypeInfo
                                    var notificationIntent = new Intent(this, typeof(AndroidUnlockActivity).ToClass());
                                    var contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);


                                    notification.setLatestEventInfo(
                                        this,
                                        Title,
                                        "",
                                        contentIntent);

                                    // http://stackoverflow.com/questions/10402686/how-to-have-led-light-notification
                                    notification.defaults |= Notification.DEFAULT_VIBRATE;
                                    notification.defaults |= Notification.DEFAULT_SOUND;
                                    //notification.defaults |= Notification.DEFAULT_LIGHTS;
                                    notification.defaults |= Notification.FLAG_SHOW_LIGHTS;
                                    // http://androiddrawableexplorer.appspot.com/
                                    nm.notify(counter, notification);

                                    //context.ToNotification(
                                    //      Title: Title,
                                    //      Content: Title,

                                    //      id: (int)java.lang.System.currentTimeMillis(),
                                    //        icon: android.R.drawable.star_on,
                                    //      uri: "http://my.jsc-solutions.net"
                                    //  );
                                };
                            #endregion

                            var action = intent.getAction();
                            if (action == Intent.ACTION_SCREEN_OFF)
                            {
                                // Screen is off
                                Notify("ACTION_SCREEN_OFF");
                            }
                            else if (action == Intent.ACTION_SCREEN_ON)
                            {
                                // Intent.ACTION_USER_PRESENT will be broadcast when the screen
                                // is
                                // unlocked.

                                // if API Level 16
                                /*
                                 * if(mKeyguard.isKeyguardLocked()){ // the keyguard is
                                 * currently locked. Log.e("","ACTION_SCREEN_ON : locked"); }
                                 */
                                if (mKeyguard.inKeyguardRestrictedInputMode())
                                {
                                    // the keyguard is currently locked.
                                    Notify("ACTION_SCREEN_ON : locked");
                                }
                                else
                                {
                                    // unlocked
                                    Notify("ACTION_SCREEN_ON : unlocked");
                                }

                            }
                            else if (action == Intent.ACTION_USER_PRESENT)
                            {
                                // The user has unlocked the screen. Enabled!
                                Notify("ACTION_USER_PRESENT");


                            }
                        };


                    // IntetFilter with Action
                    IntentFilter intentFilter = new IntentFilter();
                    intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
                    intentFilter.addAction(Intent.ACTION_SCREEN_ON);
                    intentFilter.addAction(Intent.ACTION_USER_PRESENT);// Keyguard is GONE

                    // register BroadcastReceiver and IntentFilter
                    registerReceiver(mReceiver, intentFilter);
                }
            );

            //this.ShowToast("http://jsc-solutions.net");
        }
Example #31
-1
        protected override void onCreate(Bundle arg0)
        {
            base.onCreate(arg0);

            LinearLayout layout = new LinearLayout(this);
            layout.setOrientation(LinearLayout.VERTICAL);

            TextView tv = new TextView(this);
            tv.setText("Hello");
            tv.setTextSize(20);
            layout.addView(tv);

            tv = new TextView(this);
            tv.setText("World!");
            tv.setTextSize(15);
            tv.setTextColor(unchecked((int)0xFF00FFFF));
            layout.addView(tv);

            button = new Button(this);
            button.setText("wtf");
            layout.addView(button);
            button.setOnClickListener(new OnClickListener()
            {
                OnClick = (v) =>
                {
                    Console.WriteLine(toString());
                    button.setText(System.Environment.TickCount.ToString());
                }
            });
            /* 
             * Normally in Java, you'd handle the onClickListener with an inner class.
             * In C# there is no inner class construct.
            button.setOnClickListener(new OnClickListener()
            {
                @Override
                public void onClick()
                {
                }
            });
            */

            setContentView(layout);
        }