public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            // add system property providers
            SystemPropertyManager.mSystemPropertyProviders.Clear();

            /**
             * Register system properties
             */
            SystemPropertyManager.SystemPropertyProvider myDelegateForDeviceInfo = new SystemPropertyManager.SystemPropertyProvider(getDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.imei",              myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.imsi",              myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.iso-639-1",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.iso-639-2",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device",            myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.name",       myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.UUID",       myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.OS",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.OS.version", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.network.type",      myDelegateForDeviceInfo);

            ioctls.maWriteLog = delegate(int src, int size)
            {
                byte[] bytes = new byte[size];
                core.GetDataMemory().ReadBytes(bytes, src, size);
                MoSync.Util.Log(bytes);
                return 0;
            };

            ioctls.maGetSystemProperty = delegate(int _key, int _buf, int _size)
            {
                String key = core.GetDataMemory().ReadStringAtAddress(_key);
                String value = MoSync.SystemPropertyManager.GetSystemProperty(key);
                if (value == null)
                    return -2;
                if (value.Length + 1 <= _size)
                    core.GetDataMemory().WriteStringAtAddress(_buf, value, _size);
                return value.Length + 1;
            };
        }
Esempio n. 2
0
        /*
        private void OnAlertMessageBoxClosed(IAsyncResult ar)
        {
            int? buttonIndex = Guide.EndShowMessageBox(ar);

            Memory eventData = new Memory(8);
            eventData.WriteInt32(MoSync.Struct.MAEvent.type, MoSync.Constants.EVENT_TYPE_ALERT);
            eventData.WriteInt32(MoSync.Struct.MAEvent.alertButtonIndex, (int)(buttonIndex + 1));

            mRuntime.PostEvent(new Event(eventData));
        }
        */
        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            mRuntime = runtime;
            mCore = core;
            /**
             * Register system properties
             */
            SystemPropertyManager.SystemPropertyProvider myDelegateForDeviceInfo = new SystemPropertyManager.SystemPropertyProvider(getDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.imei",              myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.imsi",              myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.iso-639-1",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.iso-639-2",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device",            myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.name",       myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.UUID",       myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.OS",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.OS.version", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.network.type",      myDelegateForDeviceInfo);

            ioctls.maWriteLog = delegate(int src, int size)
            {
                byte[] bytes = new byte[size];
                core.GetDataMemory().ReadBytes(bytes, src, size);
                MoSync.Util.Log(bytes);
                return 0;
            };

            ioctls.maMessageBox = delegate(int _caption, int _message)
            {
                String message = core.GetDataMemory().ReadStringAtAddress(_message);
                String caption = core.GetDataMemory().ReadStringAtAddress(_caption);
                MoSync.Util.ShowMessage(message, false, caption);
                return 0;
            };

            ioctls.maTextBox = delegate(int _title, int _inText, int _outText, int _maxSize, int _constraints)
            {
                bool passwordMode = false;
                if ((_constraints & MoSync.Constants.MA_TB_FLAG_PASSWORD) != 0)
                    passwordMode = true;

                if ((_constraints & MoSync.Constants.MA_TB_TYPE_MASK) != MoSync.Constants.MA_TB_TYPE_ANY)
                    return MoSync.Constants.MA_TB_RES_TYPE_UNAVAILABLE;

                try
                {
                    Guide.BeginShowKeyboardInput(Microsoft.Xna.Framework.PlayerIndex.One,
                        core.GetDataMemory().ReadWStringAtAddress(_title), "",
                        core.GetDataMemory().ReadWStringAtAddress(_inText),
                        delegate(IAsyncResult result)
                        {
                            string text = Guide.EndShowKeyboardInput(result);

                            Memory eventData = new Memory(12);
                            eventData.WriteInt32(MoSync.Struct.MAEvent.type, MoSync.Constants.EVENT_TYPE_TEXTBOX);
                            int res = MoSync.Constants.MA_TB_RES_OK;
                            int len = 0;
                            if (text == null)
                            {
                                res = MoSync.Constants.MA_TB_RES_CANCEL;
                            }
                            else
                            {
                                len = text.Length;
                            }

                            eventData.WriteInt32(MoSync.Struct.MAEvent.textboxResult, res);
                            eventData.WriteInt32(MoSync.Struct.MAEvent.textboxLength, len);
                            core.GetDataMemory().WriteWStringAtAddress(_outText, text, _maxSize);
                            mRuntime.PostEvent(new Event(eventData));
                        },
                        null
                        , passwordMode);
                }
                catch (Exception)
                {
                    return -1;
                }

                return 0;
            };

            /**
             * @author: Ciprian Filipas
             * @brief: The maAlert ioctl implementation.
             * @note: On WP7 only 2 buttons are available, OK and CANCEL. Also if the buttons get null values from
             *        MoSync WP7 platform will automatically add the OK button. Regarding these facts the _b2 button will
             *        be ignored in the current implementation.
             */
            ioctls.maAlert = delegate(int _title, int _message, int _b1, int _b2, int _b3)
            {
                String title = "", message = "";

                if( 0 != _title )
                    title = core.GetDataMemory().ReadStringAtAddress(_title);
                if( 0 != _message )
                    message = core.GetDataMemory().ReadStringAtAddress(_message);

                if (0 != _b3)
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                        {
                            MessageBoxResult result = MessageBox.Show(message, title, MessageBoxButton.OKCancel);
                            if (result == MessageBoxResult.OK)
                            {
                                Memory eventData = new Memory(8);
                                const int MAWidgetEventData_eventType = 0;
                                const int MAWidgetEventData_eventArgumentValue = 4;

                                //write 1 down since the buttone clicked is the first one
                                eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.EVENT_TYPE_ALERT);
                                eventData.WriteInt32(MAWidgetEventData_eventArgumentValue, 1);
                                //Posting a CustomEvent
                                mRuntime.PostEvent(new Event(eventData));
                            }
                            else if (result == MessageBoxResult.Cancel)
                            {
                                Memory eventData = new Memory(8);
                                const int MAWidgetEventData_eventType = 0;
                                const int MAWidgetEventData_eventArgumentValue = 4;

                                //write 1 down since the buttone clicked is the first one
                                eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.EVENT_TYPE_ALERT);
                                eventData.WriteInt32(MAWidgetEventData_eventArgumentValue, 3);
                                //Posting a CustomEvent
                                mRuntime.PostEvent(new Event(eventData));
                            }
                        }
                    );
                }
                else
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                        {
                            MessageBox.Show(message, title, MessageBoxButton.OK);

                            // Since the only way to exit the messageBox is by pressing OK there is no
                            // need for a result object.

                            Memory eventData = new Memory(8);
                            const int MAWidgetEventData_eventType = 0;
                            const int MAWidgetEventData_eventArgumentValue = 4;

                            //write 1 down since the buttone clicked is the first one
                            eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.EVENT_TYPE_ALERT);
                            eventData.WriteInt32(MAWidgetEventData_eventArgumentValue, 1);
                            //Posting a CustomEvent
                            mRuntime.PostEvent(new Event(eventData));
                        }
                    );
                }

                return 0;
            };

            ioctls.maGetSystemProperty = delegate(int _key, int _buf, int _size)
            {
                String key = core.GetDataMemory().ReadStringAtAddress(_key);
                String value = MoSync.SystemPropertyManager.GetSystemProperty(key);
                if (value == null)
                    return -2;
                if (value.Length + 1 <= _size)
                {
                    if(key.Equals("mosync.network.type"))
                    {
                        /**
                         * This code converts the result return by the GetSystemProperty
                         * for the "mosync.network.type" key to be supported by the current
                         * MoSync SDK 3.0
                         */
                        if (value.ToLower().Contains("wireless"))
                        {
                            value = "wifi";
                        }
                        else if(value.ToLower().Contains("ethernet"))
                        {
                            value = "ethernet";
                        }
                        else if(value.ToLower().Contains("mobilebroadbandgsm"))
                        {
                            value = "2g";
                        }
                        else if (value.ToLower().Contains("mobilebroadbandcdma"))
                        {
                            value = "3g";
                        }
                    }
                    core.GetDataMemory().WriteStringAtAddress(_buf, value, _size);
                }
                return value.Length + 1;
            };

            ioctls.maWakeLock = delegate(int flag)
            {
                if (MoSync.Constants.MA_WAKE_LOCK_ON == flag)
                {
                    Microsoft.Phone.Shell.PhoneApplicationService.Current.
                        UserIdleDetectionMode =
                            Microsoft.Phone.Shell.IdleDetectionMode.Enabled;
                }
                else
                {
                    Microsoft.Phone.Shell.PhoneApplicationService.Current.
                        UserIdleDetectionMode =
                            Microsoft.Phone.Shell.IdleDetectionMode.Disabled;
                }
                return 1;
            };

            // validates image input data and dispaches a delegate to save the image to camera roll
            ioctls.maSaveImageToDeviceGallery = delegate(int imageHandle, int imageNameAddr)
            {
                int returnCode = MoSync.Constants.MA_MEDIA_RES_IMAGE_EXPORT_FAILED;

                //Get the resource with the specified handle
                Resource res = mRuntime.GetResource(MoSync.Constants.RT_IMAGE, imageHandle);
                String imageName = mCore.GetDataMemory().ReadStringAtAddress(imageNameAddr);

                if ( (null != res) && !String.IsNullOrEmpty(imageName))
                {
                    object[] myArray = new object[3];
                    myArray[0] = imageHandle;
                    myArray[1] = imageName;
                    myArray[2] = res;

                    Deployment.Current.Dispatcher.BeginInvoke(
                        new Delegate_SaveImageToCameraRoll(SaveImageToCameraRoll),myArray);

                    returnCode = MoSync.Constants.MA_MEDIA_RES_OK;
                }

                return returnCode;
            };
        }
Esempio n. 3
0
        /*
        private void OnAlertMessageBoxClosed(IAsyncResult ar)
        {
            int? buttonIndex = Guide.EndShowMessageBox(ar);

            Memory eventData = new Memory(8);
            eventData.WriteInt32(MoSync.Struct.MAEvent.type, MoSync.Constants.EVENT_TYPE_ALERT);
            eventData.WriteInt32(MoSync.Struct.MAEvent.alertButtonIndex, (int)(buttonIndex + 1));

            mRuntime.PostEvent(new Event(eventData));
        }
        */
        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            mRuntime = runtime;

            /**
             * Register system properties
             */
            SystemPropertyManager.SystemPropertyProvider myDelegateForDeviceInfo = new SystemPropertyManager.SystemPropertyProvider(getDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.imei",              myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.imsi",              myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.iso-639-1",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.iso-639-2",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device",            myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.name",       myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.UUID",       myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.OS",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.OS.version", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.network.type",      myDelegateForDeviceInfo);

            ioctls.maWriteLog = delegate(int src, int size)
            {
                byte[] bytes = new byte[size];
                core.GetDataMemory().ReadBytes(bytes, src, size);
                MoSync.Util.Log(bytes);
                return 0;
            };

            ioctls.maMessageBox = delegate(int _caption, int _message)
            {
                String message = core.GetDataMemory().ReadStringAtAddress(_message);
                String caption = core.GetDataMemory().ReadStringAtAddress(_caption);
                MoSync.Util.ShowMessage(message, false, caption);
                return 0;
            };

            ioctls.maTextBox = delegate(int _title, int _inText, int _outText, int _maxSize, int _constraints)
            {
                bool passwordMode = false;
                if ((_constraints & MoSync.Constants.MA_TB_FLAG_PASSWORD) != 0)
                    passwordMode = true;

                if ((_constraints & MoSync.Constants.MA_TB_TYPE_MASK) != MoSync.Constants.MA_TB_TYPE_ANY)
                    return MoSync.Constants.MA_TB_RES_TYPE_UNAVAILABLE;

                try
                {
                    Guide.BeginShowKeyboardInput(Microsoft.Xna.Framework.PlayerIndex.One,
                        core.GetDataMemory().ReadWStringAtAddress(_title), "",
                        core.GetDataMemory().ReadWStringAtAddress(_inText),
                        delegate(IAsyncResult result)
                        {
                            string text = Guide.EndShowKeyboardInput(result);

                            Memory eventData = new Memory(12);
                            eventData.WriteInt32(MoSync.Struct.MAEvent.type, MoSync.Constants.EVENT_TYPE_TEXTBOX);
                            int res = MoSync.Constants.MA_TB_RES_OK;
                            int len = 0;
                            if (text == null)
                            {
                                res = MoSync.Constants.MA_TB_RES_CANCEL;
                            }
                            else
                            {
                                len = text.Length;
                            }

                            eventData.WriteInt32(MoSync.Struct.MAEvent.textboxResult, res);
                            eventData.WriteInt32(MoSync.Struct.MAEvent.textboxLength, len);
                            core.GetDataMemory().WriteWStringAtAddress(_outText, text, _maxSize);
                            mRuntime.PostEvent(new Event(eventData));
                        },
                        null
                        , passwordMode);
                }
                catch (Exception)
                {
                    return -1;
                }

                return 0;
            };

            /*
            ioctls.maAlert = delegate(int _title, int _message, int _b1, int _b2, int _b3)
            {
                String title = core.GetDataMemory().ReadStringAtAddress(_title);
                String message = core.GetDataMemory().ReadStringAtAddress(_message);
                List<string> buttons = new List<string>();
                if (_b1 != 0)
                    buttons.Add(core.GetDataMemory().ReadStringAtAddress(_b1));
                if (_b2 != 0)
                    buttons.Add(core.GetDataMemory().ReadStringAtAddress(_b2));
                if (_b3 != 0)
                    buttons.Add(core.GetDataMemory().ReadStringAtAddress(_b3));

                Guide.BeginShowMessageBox(title, message,
                    buttons, 0, MessageBoxIcon.None, new AsyncCallback(OnAlertMessageBoxClosed), null);

                return 0;
            };
            */

            ioctls.maGetSystemProperty = delegate(int _key, int _buf, int _size)
            {
                String key = core.GetDataMemory().ReadStringAtAddress(_key);
                String value = MoSync.SystemPropertyManager.GetSystemProperty(key);
                if (value == null)
                    return -2;
                if (value.Length + 1 <= _size)
                {
                    if(key.Equals("mosync.network.type"))
                    {
                        /**
                         * This code converts the result return by the GetSystemProperty
                         * for the "mosync.network.type" key to be supported by the current
                         * MoSync SDK 3.0
                         */
                        if (value.ToLower().Contains("wireless"))
                        {
                            value = "wifi";
                        }
                        else if(value.ToLower().Contains("ethernet"))
                        {
                            value = "ethernet";
                        }
                        else if(value.ToLower().Contains("mobilebroadbandgsm"))
                        {
                            value = "2g";
                        }
                        else if (value.ToLower().Contains("mobilebroadbandcdma"))
                        {
                            value = "3g";
                        }
                    }
                    core.GetDataMemory().WriteStringAtAddress(_buf, value, _size);
                }
                return value.Length + 1;
            };

            ioctls.maWakeLock = delegate(int flag)
            {
                if (MoSync.Constants.MA_WAKE_LOCK_ON == flag)
                {
                    Microsoft.Phone.Shell.PhoneApplicationService.Current.
                        UserIdleDetectionMode =
                            Microsoft.Phone.Shell.IdleDetectionMode.Enabled;
                }
                else
                {
                    Microsoft.Phone.Shell.PhoneApplicationService.Current.
                        UserIdleDetectionMode =
                            Microsoft.Phone.Shell.IdleDetectionMode.Disabled;
                }
                return 1;
            };
        }
Esempio n. 4
0
        /*
         * private void OnAlertMessageBoxClosed(IAsyncResult ar)
         * {
         *      int? buttonIndex = Guide.EndShowMessageBox(ar);
         *
         *      Memory eventData = new Memory(8);
         *      eventData.WriteInt32(MoSync.Struct.MAEvent.type, MoSync.Constants.EVENT_TYPE_ALERT);
         *      eventData.WriteInt32(MoSync.Struct.MAEvent.alertButtonIndex, (int)(buttonIndex + 1));
         *
         *      mRuntime.PostEvent(new Event(eventData));
         * }
         */

        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            mRuntime = runtime;
            mCore    = core;

            /**
             * Register system properties
             */
            SystemPropertyManager.SystemPropertyProvider myDelegateForDeviceInfo = new SystemPropertyManager.SystemPropertyProvider(getDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.imei", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.imsi", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.iso-639-1", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.iso-639-2", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.name", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.UUID", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.OS", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.OS.version", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.network.type", myDelegateForDeviceInfo);

            ioctls.maWriteLog = delegate(int src, int size)
            {
                byte[] bytes = new byte[size];
                core.GetDataMemory().ReadBytes(bytes, src, size);
                MoSync.Util.Log(bytes);
                return(0);
            };

            ioctls.maMessageBox = delegate(int _caption, int _message)
            {
                String message = core.GetDataMemory().ReadStringAtAddress(_message);
                String caption = core.GetDataMemory().ReadStringAtAddress(_caption);
                MoSync.Util.ShowMessage(message, false, caption);
                return(0);
            };

            ioctls.maTextBox = delegate(int _title, int _inText, int _outText, int _maxSize, int _constraints)
            {
                bool passwordMode = false;
                if ((_constraints & MoSync.Constants.MA_TB_FLAG_PASSWORD) != 0)
                {
                    passwordMode = true;
                }

                if ((_constraints & MoSync.Constants.MA_TB_TYPE_MASK) != MoSync.Constants.MA_TB_TYPE_ANY)
                {
                    return(MoSync.Constants.MA_TB_RES_TYPE_UNAVAILABLE);
                }

                try
                {
                    Guide.BeginShowKeyboardInput(Microsoft.Xna.Framework.PlayerIndex.One,
                                                 core.GetDataMemory().ReadWStringAtAddress(_title), "",
                                                 core.GetDataMemory().ReadWStringAtAddress(_inText),
                                                 delegate(IAsyncResult result)
                    {
                        string text = Guide.EndShowKeyboardInput(result);

                        Memory eventData = new Memory(12);
                        eventData.WriteInt32(MoSync.Struct.MAEvent.type, MoSync.Constants.EVENT_TYPE_TEXTBOX);
                        int res = MoSync.Constants.MA_TB_RES_OK;
                        int len = 0;
                        if (text == null)
                        {
                            res = MoSync.Constants.MA_TB_RES_CANCEL;
                        }
                        else
                        {
                            len = text.Length;
                        }

                        eventData.WriteInt32(MoSync.Struct.MAEvent.textboxResult, res);
                        eventData.WriteInt32(MoSync.Struct.MAEvent.textboxLength, len);
                        core.GetDataMemory().WriteWStringAtAddress(_outText, text, _maxSize);
                        mRuntime.PostEvent(new Event(eventData));
                    },
                                                 null
                                                 , passwordMode);
                }
                catch (Exception)
                {
                    return(-1);
                }

                return(0);
            };

            /**
             * @author: Ciprian Filipas
             * @brief: The maAlert ioctl implementation.
             * @note: On WP7 only 2 buttons are available, OK and CANCEL. Also if the buttons get null values from
             *        MoSync WP7 platform will automatically add the OK button. Regarding these facts the _b2 button will
             *        be ignored in the current implementation.
             */
            ioctls.maAlert = delegate(int _title, int _message, int _b1, int _b2, int _b3)
            {
                String title = "", message = "";

                if (0 != _title)
                {
                    title = core.GetDataMemory().ReadStringAtAddress(_title);
                }
                if (0 != _message)
                {
                    message = core.GetDataMemory().ReadStringAtAddress(_message);
                }

                if (0 != _b3)
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                    {
                        MessageBoxResult result = MessageBox.Show(message, title, MessageBoxButton.OKCancel);
                        if (result == MessageBoxResult.OK)
                        {
                            Memory eventData = new Memory(8);
                            const int MAWidgetEventData_eventType          = 0;
                            const int MAWidgetEventData_eventArgumentValue = 4;

                            //write 1 down since the buttone clicked is the first one
                            eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.EVENT_TYPE_ALERT);
                            eventData.WriteInt32(MAWidgetEventData_eventArgumentValue, 1);
                            //Posting a CustomEvent
                            mRuntime.PostEvent(new Event(eventData));
                        }
                        else if (result == MessageBoxResult.Cancel)
                        {
                            Memory eventData = new Memory(8);
                            const int MAWidgetEventData_eventType          = 0;
                            const int MAWidgetEventData_eventArgumentValue = 4;

                            //write 1 down since the buttone clicked is the first one
                            eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.EVENT_TYPE_ALERT);
                            eventData.WriteInt32(MAWidgetEventData_eventArgumentValue, 3);
                            //Posting a CustomEvent
                            mRuntime.PostEvent(new Event(eventData));
                        }
                    }
                                                          );
                }
                else
                {
                    MoSync.Util.RunActionOnMainThreadSync(() =>
                    {
                        MessageBox.Show(message, title, MessageBoxButton.OK);

                        // Since the only way to exit the messageBox is by pressing OK there is no
                        // need for a result object.

                        Memory eventData = new Memory(8);
                        const int MAWidgetEventData_eventType          = 0;
                        const int MAWidgetEventData_eventArgumentValue = 4;

                        //write 1 down since the buttone clicked is the first one
                        eventData.WriteInt32(MAWidgetEventData_eventType, MoSync.Constants.EVENT_TYPE_ALERT);
                        eventData.WriteInt32(MAWidgetEventData_eventArgumentValue, 1);
                        //Posting a CustomEvent
                        mRuntime.PostEvent(new Event(eventData));
                    }
                                                          );
                }

                return(0);
            };

            ioctls.maGetSystemProperty = delegate(int _key, int _buf, int _size)
            {
                String key   = core.GetDataMemory().ReadStringAtAddress(_key);
                String value = MoSync.SystemPropertyManager.GetSystemProperty(key);
                if (value == null)
                {
                    return(-2);
                }
                if (value.Length + 1 <= _size)
                {
                    if (key.Equals("mosync.network.type"))
                    {
                        /**
                         * This code converts the result return by the GetSystemProperty
                         * for the "mosync.network.type" key to be supported by the current
                         * MoSync SDK 3.0
                         */
                        if (value.ToLower().Contains("wireless"))
                        {
                            value = "wifi";
                        }
                        else if (value.ToLower().Contains("ethernet"))
                        {
                            value = "ethernet";
                        }
                        else if (value.ToLower().Contains("mobilebroadbandgsm"))
                        {
                            value = "2g";
                        }
                        else if (value.ToLower().Contains("mobilebroadbandcdma"))
                        {
                            value = "3g";
                        }
                    }
                    core.GetDataMemory().WriteStringAtAddress(_buf, value, _size);
                }
                return(value.Length + 1);
            };

            ioctls.maWakeLock = delegate(int flag)
            {
                if (MoSync.Constants.MA_WAKE_LOCK_ON == flag)
                {
                    Microsoft.Phone.Shell.PhoneApplicationService.Current.
                    UserIdleDetectionMode =
                        Microsoft.Phone.Shell.IdleDetectionMode.Enabled;
                }
                else
                {
                    Microsoft.Phone.Shell.PhoneApplicationService.Current.
                    UserIdleDetectionMode =
                        Microsoft.Phone.Shell.IdleDetectionMode.Disabled;
                }
                return(1);
            };

            // validates image input data and dispaches a delegate to save the image to camera roll
            ioctls.maSaveImageToDeviceGallery = delegate(int imageHandle, int imageNameAddr)
            {
                int returnCode = MoSync.Constants.MA_MEDIA_RES_IMAGE_EXPORT_FAILED;

                //Get the resource with the specified handle
                Resource res       = mRuntime.GetResource(MoSync.Constants.RT_IMAGE, imageHandle);
                String   imageName = mCore.GetDataMemory().ReadStringAtAddress(imageNameAddr);

                if ((null != res) && !String.IsNullOrEmpty(imageName))
                {
                    object[] myArray = new object[3];
                    myArray[0] = imageHandle;
                    myArray[1] = imageName;
                    myArray[2] = res;

                    Deployment.Current.Dispatcher.BeginInvoke(
                        new Delegate_SaveImageToCameraRoll(SaveImageToCameraRoll), myArray);

                    returnCode = MoSync.Constants.MA_MEDIA_RES_OK;
                }

                return(returnCode);
            };
        }
Esempio n. 5
0
        /*
        private void OnAlertMessageBoxClosed(IAsyncResult ar)
        {
            int? buttonIndex = Guide.EndShowMessageBox(ar);

            Memory eventData = new Memory(8);
            eventData.WriteInt32(MoSync.Struct.MAEvent.type, MoSync.Constants.EVENT_TYPE_ALERT);
            eventData.WriteInt32(MoSync.Struct.MAEvent.alertButtonIndex, (int)(buttonIndex + 1));

            mRuntime.PostEvent(new Event(eventData));
        }
        */
        public void Init(Ioctls ioctls, Core core, Runtime runtime)
        {
            mRuntime = runtime;

            // add system property providers
            SystemPropertyManager.mSystemPropertyProviders.Clear();

            /**
             * Register system properties
             */
            SystemPropertyManager.SystemPropertyProvider myDelegateForDeviceInfo = new SystemPropertyManager.SystemPropertyProvider(getDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.imei",              myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.imsi",              myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.iso-639-1",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.iso-639-2",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device",            myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.name",       myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.UUID",       myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.OS",         myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.device.OS.version", myDelegateForDeviceInfo);
            SystemPropertyManager.RegisterSystemPropertyProvider("mosync.network.type",      myDelegateForDeviceInfo);

            ioctls.maWriteLog = delegate(int src, int size)
            {
                byte[] bytes = new byte[size];
                core.GetDataMemory().ReadBytes(bytes, src, size);
                MoSync.Util.Log(bytes);
                return 0;
            };

            ioctls.maMessageBox = delegate(int _caption, int _message)
            {
                String message = core.GetDataMemory().ReadStringAtAddress(_message);
                String caption = core.GetDataMemory().ReadStringAtAddress(_caption);
                MoSync.Util.ShowMessage(message, false, caption);
                return 0;
            };

            ioctls.maTextBox = delegate(int _title, int _inText, int _outText, int _maxSize, int _constraints)
            {
                bool passwordMode = false;
                if ((_constraints & MoSync.Constants.MA_TB_FLAG_PASSWORD) != 0)
                    passwordMode = true;

                if ((_constraints & MoSync.Constants.MA_TB_TYPE_MASK) != MoSync.Constants.MA_TB_TYPE_ANY)
                    return MoSync.Constants.MA_TB_RES_TYPE_UNAVAILABLE;

                try
                {
                    Guide.BeginShowKeyboardInput(Microsoft.Xna.Framework.PlayerIndex.One,
                        core.GetDataMemory().ReadWStringAtAddress(_title), "",
                        core.GetDataMemory().ReadWStringAtAddress(_inText),
                        delegate(IAsyncResult result)
                        {
                            string text = Guide.EndShowKeyboardInput(result);

                            Memory eventData = new Memory(12);
                            eventData.WriteInt32(MoSync.Struct.MAEvent.type, MoSync.Constants.EVENT_TYPE_TEXTBOX);
                            int res = MoSync.Constants.MA_TB_RES_OK;
                            int len = 0;
                            if (text == null)
                            {
                                res = MoSync.Constants.MA_TB_RES_CANCEL;
                            }
                            else
                            {
                                len = text.Length;
                            }

                            eventData.WriteInt32(MoSync.Struct.MAEvent.textboxResult, res);
                            eventData.WriteInt32(MoSync.Struct.MAEvent.textboxLength, len);
                            core.GetDataMemory().WriteWStringAtAddress(_outText, text, _maxSize);
                            mRuntime.PostEvent(new Event(eventData));
                        },
                        null
                        , passwordMode);
                }
                catch (Exception)
                {
                    return -1;
                }

                return 0;
            };

            /*
            ioctls.maAlert = delegate(int _title, int _message, int _b1, int _b2, int _b3)
            {
                String title = core.GetDataMemory().ReadStringAtAddress(_title);
                String message = core.GetDataMemory().ReadStringAtAddress(_message);
                List<string> buttons = new List<string>();
                if (_b1 != 0)
                    buttons.Add(core.GetDataMemory().ReadStringAtAddress(_b1));
                if (_b2 != 0)
                    buttons.Add(core.GetDataMemory().ReadStringAtAddress(_b2));
                if (_b3 != 0)
                    buttons.Add(core.GetDataMemory().ReadStringAtAddress(_b3));

                Guide.BeginShowMessageBox(title, message,
                    buttons, 0, MessageBoxIcon.None, new AsyncCallback(OnAlertMessageBoxClosed), null);

                return 0;
            };
            */

            ioctls.maGetSystemProperty = delegate(int _key, int _buf, int _size)
            {
                String key = core.GetDataMemory().ReadStringAtAddress(_key);
                String value = MoSync.SystemPropertyManager.GetSystemProperty(key);
                if (value == null)
                    return -2;
                if (value.Length + 1 <= _size)
                    core.GetDataMemory().WriteStringAtAddress(_buf, value, _size);
                return value.Length + 1;
            };
        }