// 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");
        }
示例#2
0
        public override void InternalBeforeSetContext(android.content.Context c)
        {
            InternalEditText = new EditText(c);
            InternalSetText(InternalText);

            //InternalEditText.addTextChangedListener(
            //    new xTextWatcher
            //{
            //    yield = delegate
            //    {
            //        this.InternalText = InternalEditText.getText();
            //    }
            //}
            //);


            PasswordChar = InternalPasswordChar;
            Height = InternalHeight;
            Width = InternalWidth;
        }
        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);

            MainView = ll;

            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 title = new TextView(this);
            title.setText("JSC Shopping Cart 2");
            ll.addView(title);

            TextView namelabel1 = new TextView(this);
            namelabel1.setText("First Name:");
            ll.addView(namelabel1);


            EditText nameET = new EditText(this);
            nameET.setText("");
            ll.addView(nameET);


            TextView lastnamelabel1 = new TextView(this);
            lastnamelabel1.setText("Last Name:");
            ll.addView(lastnamelabel1);


            EditText lastnameET = new EditText(this);
            lastnameET.setText("");
            ll.addView(lastnameET);


            TextView pkglabel1 = new TextView(this);
            pkglabel1.setText("Select Package:");
            //ll.addView(pkglabel1);

            RadioButton personalRb = new RadioButton(this);
            personalRb.setText("Personal License ($200)");
            //personalRb.AttachTo(ll);

            RadioButton enterpriseRb = new RadioButton(this);
            enterpriseRb.setText("Enterprise License ($400)");
            //enterpriseRb.AttachTo(ll);

            RadioButton commercialRb = new RadioButton(this);
            commercialRb.setText("Commercial License ($600)");
            //commercialRb.AttachTo(ll);

            RadioGroup groupRb = new RadioGroup(this);
            groupRb.addView(personalRb);
            groupRb.addView(enterpriseRb);
            groupRb.addView(commercialRb);
            groupRb.AttachTo(ll);

            Button submitBtn = new Button(this);
            submitBtn.setText("Submit");
            submitBtn.setOnClickListener(new Listener(ll));
            ll.addView(submitBtn);

            this.setContentView(sv);

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


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

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


            var b = new 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 });
            int counter = 0;



            // http://stackoverflow.com/questions/12900795/how-to-get-a-pin-number-password-keyboard-in-android
            //var t = new EditText(this);
            //t.setInputType(android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD);
            //t.setTransformationMethod(android.text.method.PasswordTransformationMethod.getInstance());
            //ll.addView(t);

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

                // X:\jsc.svn\examples\javascript\android\Test\TestPINDialog\TestPINDialog\ApplicationWebService.cs

                var alertDialog = new AlertDialog.Builder(this);

                alertDialog.setTitle("Authentication");
                alertDialog.setMessage("PIN1");



                var xll = new LinearLayout(this);
                xll.setOrientation(LinearLayout.VERTICAL);

                var xt = new EditText(this);

                //http://stackoverflow.com/questions/6443286/type-number-variation-password-not-present-in-inputtype-class
                // https://groups.google.com/forum/#!topic/android-developers/UZuZjEbAnLE


                // http://kmansoft.com/2011/02/27/an-edittext-for-entering-ip-addresses/
                xt.setInputType(

                    android.text.InputType.TYPE_CLASS_NUMBER |
                    android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD);
                xt.setTransformationMethod(android.text.method.PasswordTransformationMethod.getInstance());
                xll.addView(xt);


                alertDialog.setPositiveButton("OK",
               new xOnClickListener
                {
                    yield = delegate
                    {
                        b.setText("clicked! " + new { id = Thread.currentThread().getId() });
                    }
                }

               );

                //{
                //    var xb = new Button(this);
                //    xb.setText("1");
                //    xll.addView(xb);
                //}

                //{
                //    var xb = new Button(this);
                //    xb.setText("2");
                //    xll.addView(xb);
                //}

                //{
                //    var xb = new Button(this);
                //    xb.setText("3");
                //    xll.addView(xb);
                //}



                alertDialog.setView(xll);


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

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

            ll.addView(b);

            this.setContentView(sv);

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

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


        }
        /// <summary>
        /// This Method is a javascript callable method.
        /// </summary>
        /// <param name="e">A parameter from javascript.</param>
        /// <param name="y">A callback to javascript.</param>
        //public async Task<string> WebMethod2()
        public Task<string> WebMethod2()
        {
            // http://stackoverflow.com/questions/25003121/how-to-use-alertdialog-to-prompt-for-pin
            // X:\jsc.svn\examples\java\android\Test\TestAlertDialog\TestAlertDialog\ApplicationActivity.cs

            // https://android.googlesource.com/platform/frameworks/base/+/b896b9f/packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java
            // http://seek-for-android.googlecode.com/svn-history/r172/trunk/applications/SecureFileManager/SecurityFileManager/src/org/openintents/filemanager/FileManagerActivity.java
            // https://github.com/Paldom/PinDialog

            var c = (Activity)ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext;

            // #5 java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

            var a = new AutoResetEvent(false);

            //c.runOnUiThread(
            new { }.With(
                async delegate
                {
                    await default(HopToUIAwaitable);

                    //// the context. lets find it
                    //var alertDialogBuilder = new AlertDialog.Builder(c);


                    //LayoutInflater inflater = LayoutInflater.from(c);

                    // https://github.com/chinloong/Android-PinView/blob/master/res/layout/activity_pin_entry_view.xml
                    // http://lifehacker.com/three-ways-to-improve-your-androids-lock-screen-securi-1293317441

                    var alertDialog = new AlertDialog.Builder(c);

                    alertDialog.setTitle("Authentication");
                    alertDialog.setMessage("PIN1");



                    var xll = new LinearLayout(c);
                    xll.setOrientation(LinearLayout.VERTICAL);

                    var xt = new EditText(c);

                    //http://stackoverflow.com/questions/6443286/type-number-variation-password-not-present-in-inputtype-class
                    // https://groups.google.com/forum/#!topic/android-developers/UZuZjEbAnLE


                    // http://kmansoft.com/2011/02/27/an-edittext-for-entering-ip-addresses/
                    xt.setInputType(

                        android.text.InputType.TYPE_CLASS_NUMBER |
                        android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD);
                    xt.setTransformationMethod(android.text.method.PasswordTransformationMethod.getInstance());
                    xll.addView(xt);

                    // set button
                    alertDialog.setPositiveButton("OK",
                   new xOnClickListener
                    {
                        yield = delegate
                        {
                            // I/System.Console(23890): OK {{ ManagedThreadId = 1 }}
                            Console.WriteLine(
                                "OK " +
                     new { Thread.CurrentThread.ManagedThreadId }

                                );

                            a.Set();
                        }
                    }

                   );

                    //{
                    //    var xb = new Button(this);
                    //    xb.setText("1");
                    //    xll.addView(xb);
                    //}

                    //{
                    //    var xb = new Button(this);
                    //    xb.setText("2");
                    //    xll.addView(xb);
                    //}

                    //{
                    //    var xb = new Button(this);
                    //    xb.setText("3");
                    //    xll.addView(xb);
                    //}



                    alertDialog.setView(xll);


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

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

                }
            );


            a.WaitOne();

            // report service thread
            return new { Thread.CurrentThread.ManagedThreadId }.ToString().AsResult();
        }