setPositiveButton() публичный Метод

public setPositiveButton ( int arg0, global arg1 ) : android.app.AlertDialog.Builder
arg0 int
arg1 global
Результат android.app.AlertDialog.Builder
Пример #1
0
        public static global::System.Windows.Forms.DialogResult Show(string text, string caption)
        {

            // or are we called on a background thread? 
            // for java, we can block a worker thread until ui is shown. for javascript cannot do it without async?
            // assume we are activity based..
            var context = ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext as Activity;
            var ui = context.getMainLooper() == Looper.myLooper();
            Console.WriteLine("enter MessageBox.Show " + new { ui });

            var value = default(global::System.Windows.Forms.DialogResult);
            var thread0 = Thread.CurrentThread;
            var sync = new AutoResetEvent(false);

            context.runOnUiThread(
                a =>
                {
                    //thread0 = Thread.CurrentThread;
                    //sync0ui.Set();

                    // X:\jsc.svn\examples\java\android\forms\FormsMessageBox\FormsMessageBox\Library\ApplicationControl.cs
                    // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201410/20141025
                    // X:\jsc.svn\examples\java\android\Test\TestAlertDialog\TestAlertDialog\ApplicationActivity.cs


                    var alertDialog = new AlertDialog.Builder(context);

                    alertDialog.setTitle(caption);

                    if (!string.IsNullOrEmpty(caption))
                    {
                        alertDialog.setMessage(text);
                    }

                    // https://sites.google.com/a/jsc-solutions.net/backlog/knowledge-base/2014/201410/20141026


                    alertDialog.setPositiveButton("OK",
                            new xDialogInterface_OnClickListener
                            {
                                yield = delegate
                                {
                                    Console.WriteLine(" alertDialog.setPositiveButton");
                                    value = global::System.Windows.Forms.DialogResult.OK;
                                    //sync.Set();
                                }
                            }
                        );

                    // skip icons?
                    //alertDialog.setIcon(android.R.drawable.star_off);
                    var dialog = alertDialog.create();

                    dialog.setOnDismissListener(
                        new xDialogInterface_OnDismissListener
                        {
                            yield = delegate
                            {
                                Console.WriteLine("  dialog.setOnDismissListener");
                                sync.Set();

                                if (ui)
                                    throw null;
                            }
                        }
                    );

                    dialog.show();


                    // http://stackoverflow.com/questions/13974661/runonuithread-vs-looper-getmainlooper-post-in-android
                    // http://developer.android.com/reference/android/os/Looper.html



                    //sync.Set();
                }
            );




            // need to poll? discard?


            if (ui)
            {
                try
                {
                    // loop until we throw null
                    // where is it thrown?
                    android.os.Looper.loop();
                }
                catch
                {
                }
            }
            else
            {
                sync.WaitOne();
            }

            Console.WriteLine("exit MessageBox.Show " + new { ui, value });
            return value;
        }
Пример #2
0
        void ProcessCollisions()
        {
            bool gameOver = false;
            int ai = 0;
            // check which asteroids are colliding with bullets
            while (ai < myAsteroids.Count)
            {
                Asteroid asteroid = myAsteroids[ai];
                int asteroidRadiusSquare = 16 * (1 << asteroid.Size);
                asteroidRadiusSquare *= asteroidRadiusSquare;
                bool collisionFound = false;
                for (int bi = 0; bi < myBullets.Count; bi++)
                {
                    PhysicsObject bullet = myBullets[bi];
                    Vector4f v = bullet.Location - asteroid.PhysicsObject.Location;
                    if (v.LengthSquare < asteroidRadiusSquare)
                    {
                        // remove the asteroid and bullet
                        collisionFound = true;
                        myAsteroids.RemoveAt(ai);
                        myBullets.RemoveAt(bi);

                        // split the asteroid into two if it's not tiny
                        if (asteroid.Size > 0)
                        {
                            Asteroid one = CreateAsteroid();
                            Asteroid two = CreateAsteroid();
                            one.Size = two.Size = asteroid.Size - 1;
                            one.CreationTime = two.CreationTime = asteroid.CreationTime;
                            one.PhysicsObject.Location = two.PhysicsObject.Location = asteroid.PhysicsObject.Location;
                            myAsteroids.Add(one);
                            myAsteroids.Add(two);
                        }
                        break;
                    }
                }

                // see if the asteroid is hitting the ship
                Vector4f sv = myShip.Location - asteroid.PhysicsObject.Location;
                if (sv.LengthSquare < asteroidRadiusSquare && System.Environment.TickCount - asteroid.CreationTime > AsteroidGracePeriod)
                    gameOver = true;

                // dont increment if we removed the asteroid
                if (!collisionFound)
                    ai++;
            }

            // if there zero asteroids, add one
            if (myAsteroids.Count == 0)
            {
                // reset the timer
                //myAsteroidTimer.Enabled = false;
                //myAsteroidTimer.Enabled = true;
                myAsteroids.Add(CreateAsteroid());
            }

            // show the gamer over form if the ship exploded
            if (gameOver)
            {
                if (!mIsDialogShowing)
                {
                    mIsDialogShowing = true;
                    mHandler.post(() =>
                    {
                        var b = new AlertDialog.Builder(this);
                        b.setTitle("Game Over!");
                        b.setMessage("Try again?");
                        b.setPositiveButton(global::[email protected], (d, which) => { mIsDialogShowing = false; ResetGame(); });
                        b.setNegativeButton(global::[email protected], (d, which) => { mIsDialogShowing = false; finish(); });
                        b.setCancelable(false);
                        b.create().show();
                    });
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            // http://stackoverflow.com/questions/2028697/dialogs-alertdialogs-how-to-block-execution-while-dialog-is-up-net-style
            // http://mindfiremobile.wordpress.com/2014/04/21/displaying-alert-dialog-in-android-using-xamarin/

            //button1.Text = "Clicked!";

            // X:\jsc.svn\examples\java\android\forms\FormsMessageBox\FormsMessageBox\ApplicationActivity.cs
            // X:\jsc.svn\examples\java\android\Test\TestAlertDialog\TestAlertDialog\ApplicationActivity.cs
            var alertDialog = new AlertDialog.Builder(ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext);

            alertDialog.setTitle("Reset...");
            alertDialog.setMessage("Are you sure?");

            alertDialog.setOnDismissListener(
                new xDialogInterface_OnDismissListener
                {
                    yield = delegate
                    {
                        throw null;
                    }
                }
            );

            alertDialog.setPositiveButton("OK",
                new xOnClickListener
            {
                yield = delegate
                {
                    button1.Text = "clicked! " + new
                    {


                        Thread.CurrentThread.ManagedThreadId
                    };



                }
            }

                );

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

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

            // http://stackoverflow.com/questions/13974661/runonuithread-vs-looper-getmainlooper-post-in-android

            //android.os.Looper.getMainLooper().loop();

            // http://developer.android.com/reference/android/os/Looper.html

            try
            {
                // loop until we throw null
                android.os.Looper.loop();
            }
            catch
            {

            }

            button1.Text = "clicked! after looper " + new
            {


                Thread.CurrentThread.ManagedThreadId
            };

            //alertDialog.create().show();


        }
        // http://www.codeproject.com/Tips/623446/Style-Any-Activity-as-an-Alert-Dialog-in-Android
        // android:theme="@android:style/Theme.Holo.Dialog"



        protected override void onCreate(global::android.os.Bundle savedInstanceState)
        {
            ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext = this;

            // X:\jsc.svn\examples\java\android\forms\AndroidFormsActivity\AndroidFormsActivity\ApplicationActivity.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 });
            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("Hello world");
               


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

               );


                var cc = new AndroidFormsActivity.ApplicationControl();


                //ScriptCoreLib.Extensions.Android.AndroidFormsExtensions.AttachTo(
                //    cc, 

                // X:\jsc.svn\core\ScriptCoreLibAndroid.Windows.Forms\ScriptCoreLibAndroid.Windows.Forms\Extensions\Android\AndroidFormsExtensions.cs

                __Control _cc = cc;

                _cc.InternalSetContext(this);

                alertDialog.setView(_cc.InternalGetElement());


                // 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	'FormsMessageBox.Activities.ApplicationActivity' does not contain a definition for 'ShowLongToast' and no extension method 'ShowLongToast' accepting a first argument of type 'FormsMessageBox.Activities.ApplicationActivity' could be found (are you missing a using directive or an assembly reference?)	X:\jsc.svn\examples\java\android\FormsMessageBox\FormsMessageBox\ApplicationActivity.cs	80	18	FormsMessageBox
            //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();
        }