关于Windows Mobile Widget开发Emulator

移动开发
关于Windows Mobile Widget开发Emulator是本文要介绍的内容,主要是来了解并学习Windows Mobile Widget开发应用,来看内容。

关于Windows Mobile Widget开发Emulator是本文要介绍的内容,主要是来了解并学习Windows Mobile Widget开发应用,今天Vimpyboy在codeplex发布了Windows Mobile Widget Emulator,具体内容的实现来看本文详解。

这是一个用来调试Windows Mobile6.5 Widget的工具,我在做Windows Mobile 6.5新功能widget开发的时候就发现调试Widget很麻烦。也有想法做一个Emulator,其实这个Emulator目标很明显,第一个目标就是实现MSWidget提供的javascript的menu对象。下面代码来自于Windows Mobile Widget Emulator。实现menu对象。

  1.     var widget = {  
  2.     menu: {  
  3.         createMenuItem: function(id) {  
  4.             this.id = id;  
  5.             this.text = '';  
  6.             this.onSelect = function() { };  
  7.  
  8.             return this;  
  9.         },  
  10.         setSoftKey: function(menuItem, idx) {  
  11.             var menuItemmenuItemCopy = menuItem.Copy();  
  12.  
  13.             if (idx == 1) {  
  14.                 var el = window.parent.document.getElementById('leftMenu');  
  15.  
  16.                 var newItem = window.parent.document.createElement('li');  
  17.                 var newLink = window.parent.document.createElement('a');  
  18.  
  19.                 newLink.onclick = function() {  
  20.                     menuItemCopy.onSelect()  
  21.                 };  
  22.                 newLink.href = '#';  
  23.                 newLink.innerHTML = menuItemCopy.text;  
  24.  
  25.                 newItem.appendChild(newLink);  
  26.                 el.insertBefore(newItem, el.firstChild);  
  27.  
  28.                 return this;  
  29.             }  
  30.             else {  
  31.                 var el = window.parent.document.getElementById('rightMenu');  
  32.                 var arrlength = widget.menu.menuItems.length;  
  33.  
  34.                 var newItem = window.parent.document.createElement('li');  
  35.                 var newLink = window.parent.document.createElement('a');  
  36.  
  37.                 newLink.onclick = function() {  
  38.                     menuItemCopy.onSelect()  
  39.                 };  
  40.  
  41.                 newLink.setAttribute('id', 'widgetmenu-' + arrlength);  
  42.                 newLink.href = '#';  
  43.                 newLink.innerHTML = menuItemCopy.text;  
  44.  
  45.                 widget.menu.menuItems[arrlength] = menuItemCopy;  
  46.  
  47.                 newItem.appendChild(newLink);  
  48.                 el.insertBefore(newItem, el.firstChild);  
  49.  
  50.                 return this;  
  51.             }  
  52.         },  
  53.         append: function(menuItem) {  
  54.             widget.menu.setSoftKey(menuItem);  
  55.         },  
  56.         clear: function() {  
  57.             var el = window.parent.document.getElementById('rightMenu');  
  58.             el.innerHTML = '';  
  59.         },  
  60.         leftSoftKeyIndex: 1,  
  61.         menuItems: []  
  62.     },  
  63.     preferenceForKey: function(key) {  
  64.         if (document.cookie.length > 0) {  
  65.             idx = document.cookie.indexOf(key + '=');  
  66.             if (idx != -1) {  
  67.                 idxidx = idx + key.length + 1;  
  68.                 idxlast = document.cookie.indexOf(';', idx);  
  69.  
  70.                 if (idxlast == -1) idxlast = document.cookie.length;  
  71.  
  72.                 return unescape(document.cookie.substring(idx, idxlast));  
  73.             }  
  74.         }  
  75.         return '';  
  76.     },  
  77.     setPreferenceForKey: function(value, key) {  
  78.  
  79.         if (!key) return;  
  80.  
  81.         if (!value && key) {  
  82.             var d = new Date();  
  83.             var c = document.cookie.split(";");  
  84.               
  85.             for (var i = 0; i < c.length; i++) {  
  86.                 document.cookie = c[i] + "; expires =" + d.toGMTString();  
  87.             }  
  88.               
  89.             return;  
  90.         }  
  91.  
  92.         var saveValue = value;  
  93.  
  94.         if (value.text) saveValue = value.text;  
  95.  
  96.         if (value.value) saveValue = value.value;  
  97.  
  98.         if (saveValue.length == undefined || saveValue.length < 1) return;  
  99.         if (saveValue.length == undefined || saveValue < 1) return;  
  100.  
  101.         var exdate = new Date();  
  102.         exdate.setFullYear(2020, 12, 31);  
  103.  
  104.         document.cookie = key + '=' + escape(saveValue) + ';expires=' + exdate.toGMTString();  
  105.     },  
  106.     authorEmail: 'Placeholder: E-mail address of author.',  
  107.     authorName: 'Placeholder: Name of author.',  
  108.     authorURL: 'Placeholder: Web site URL for author.',  
  109.     currentIcon: {  
  110.         height: 100,  
  111.         src: 'icon.png',  
  112.         width: 100  
  113.     },  
  114.     description: 'Placeholder: Description of widget.',  
  115.     height: 'Placeholder: Height of widget.',  
  116.     identifier: 'Placeholder: A unique identifier for the widget.',  
  117.     locale: 'Placeholder: Locale of widget.',  
  118.     name: 'Placeholder: Name of widget.',  
  119.     version: 'Placeholder: Version of widget.',  
  120.     width: 'Placeholder: Width of widget.'  
  121. }; 

第二个目标是可以动态调整resolution。Windows Mobile Widget Emulator也实现了,和我想法是一样的。

widget1
widget2

我当初的想法是直接使用MS的emulator的图片,这些图片保存在C:\ProgramFiles\Windows Mobile6SDK\PocketPC\DeviceemulationV650下,而且每个emulator都有XML定义文件,可以直接取出这些定义文件和图片进行resolution的选择。

第三个要实现的目标是,不需要修改开发中的widget的源代码,直接可以调试。这个我想比较难实现,我开始想用firefox的addon来实现,可是firefox的javascript和ie有区别,在ff调试通过不一定在ie能用,可能做ie的addon可以解决这个问题。

Windows Mobile WidgetEmulator也没有解决这个问题,需要修改iframe和增加一个javascript的引用。原文如下

  1. How to use  
  2.  
  3. Put your widget in a new folder in the widgets folder.   
  4. Modify the iframe in index.html to show your widget.   
  5. Add this code to the html file used by your widget:   
  6. <script src="http://www.cnblogs.com/assets/Widget.js" type="text/javascript"></script> 

Anyway,很高兴Windows Mobile Widget Emulator的发布。以后开发widget我会使用他进行调试。

小结:关于Windows Mobile Widget开发Emulator的内容介绍完了,希望通过Windows Mobile Widget开发内容的学习能对你有所帮助。

责任编辑:zhaolei 来源: 博客园
相关推荐

2011-09-08 10:04:07

Windows MobWidget

2010-03-31 16:36:35

Windows CE

2011-09-08 10:18:09

Windows MobWidgets

2009-03-05 18:08:01

Windows Mob升级

2010-05-23 10:29:29

Widget开发

2012-02-13 15:50:59

2009-08-10 09:26:56

2009-08-14 15:02:09

Visual Stud

2009-06-23 10:06:03

2011-04-25 16:40:21

开发环境搭建Windows Mob

2009-09-18 10:02:23

Windows Mob

2011-09-07 13:42:36

Android Wid实例

2009-04-16 08:05:27

Windows Mob微软移动OS

2009-05-18 09:06:37

微软WMWindows Mob

2009-05-17 10:48:19

微软Windows Mob移动OS

2011-05-03 15:13:23

BlackBerryWidget

2010-07-13 09:02:19

Widget开发

2011-09-09 20:14:58

Android Wid

2009-12-15 15:31:47

2009-12-07 17:42:07

Windows Mob
点赞
收藏

51CTO技术栈公众号