setView() public method

public setView ( android arg0 ) : global::android.app.AlertDialog.Builder
arg0 android
return global::android.app.AlertDialog.Builder
示例#1
0
        public DialogResult ShowDialog()
        {
            this.InternalSetContext(
                global::ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext
            );

            // 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 value = default(global::System.Windows.Forms.DialogResult);
            var alertDialog = new AlertDialog.Builder(ScriptCoreLib.Android.ThreadLocalContextReference.CurrentContext);

            alertDialog.setTitle(this.Text);



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

            //E/AndroidRuntime( 1380): Caused by: java.lang.NoSuchMethodError: android.app.AlertDialog$Builder.setOnDismissListener
            //E/AndroidRuntime( 1380):        at ScriptCoreLib.Android.BCLImplementation.System.Windows.Forms.__Form.ShowDialog(__Form.java:110)

            // ?
            // alertDialog.setOnDismissListener(
            //    new xDialogInterface_OnDismissListener()
            //);

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

            alertDialog.setView(this.InternalGetContainer());

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

            dialog.setOnDismissListener(
               new xDialogInterface_OnDismissListener()
            );

            dialog.show();

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

            __dismissOnClose(dialog);

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

            return value;
        }
        // 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();
        }