關于Windows Mobile Widget開發Emulator
關于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對象。
- var widget = {
- menu: {
- createMenuItem: function(id) {
- this.id = id;
- this.text = '';
- this.onSelect = function() { };
- return this;
- },
- setSoftKey: function(menuItem, idx) {
- var menuItemmenuItemCopy = menuItem.Copy();
- if (idx == 1) {
- var el = window.parent.document.getElementById('leftMenu');
- var newItem = window.parent.document.createElement('li');
- var newLink = window.parent.document.createElement('a');
- newLink.onclick = function() {
- menuItemCopy.onSelect()
- };
- newLink.href = '#';
- newLink.innerHTML = menuItemCopy.text;
- newItem.appendChild(newLink);
- el.insertBefore(newItem, el.firstChild);
- return this;
- }
- else {
- var el = window.parent.document.getElementById('rightMenu');
- var arrlength = widget.menu.menuItems.length;
- var newItem = window.parent.document.createElement('li');
- var newLink = window.parent.document.createElement('a');
- newLink.onclick = function() {
- menuItemCopy.onSelect()
- };
- newLink.setAttribute('id', 'widgetmenu-' + arrlength);
- newLink.href = '#';
- newLink.innerHTML = menuItemCopy.text;
- widget.menu.menuItems[arrlength] = menuItemCopy;
- newItem.appendChild(newLink);
- el.insertBefore(newItem, el.firstChild);
- return this;
- }
- },
- append: function(menuItem) {
- widget.menu.setSoftKey(menuItem);
- },
- clear: function() {
- var el = window.parent.document.getElementById('rightMenu');
- el.innerHTML = '';
- },
- leftSoftKeyIndex: 1,
- menuItems: []
- },
- preferenceForKey: function(key) {
- if (document.cookie.length > 0) {
- idx = document.cookie.indexOf(key + '=');
- if (idx != -1) {
- idxidx = idx + key.length + 1;
- idxlast = document.cookie.indexOf(';', idx);
- if (idxlast == -1) idxlast = document.cookie.length;
- return unescape(document.cookie.substring(idx, idxlast));
- }
- }
- return '';
- },
- setPreferenceForKey: function(value, key) {
- if (!key) return;
- if (!value && key) {
- var d = new Date();
- var c = document.cookie.split(";");
- for (var i = 0; i < c.length; i++) {
- document.cookie = c[i] + "; expires =" + d.toGMTString();
- }
- return;
- }
- var saveValue = value;
- if (value.text) saveValue = value.text;
- if (value.value) saveValue = value.value;
- if (saveValue.length == undefined || saveValue.length < 1) return;
- if (saveValue.length == undefined || saveValue < 1) return;
- var exdate = new Date();
- exdate.setFullYear(2020, 12, 31);
- document.cookie = key + '=' + escape(saveValue) + ';expires=' + exdate.toGMTString();
- },
- authorEmail: 'Placeholder: E-mail address of author.',
- authorName: 'Placeholder: Name of author.',
- authorURL: 'Placeholder: Web site URL for author.',
- currentIcon: {
- height: 100,
- src: 'icon.png',
- width: 100
- },
- description: 'Placeholder: Description of widget.',
- height: 'Placeholder: Height of widget.',
- identifier: 'Placeholder: A unique identifier for the widget.',
- locale: 'Placeholder: Locale of widget.',
- name: 'Placeholder: Name of widget.',
- version: 'Placeholder: Version of widget.',
- width: 'Placeholder: Width of widget.'
- };
第二個目標是可以動態調整resolution。Windows Mobile Widget Emulator也實現了,和我想法是一樣的。


我當初的想法是直接使用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的引用。原文如下
- How to use
- Put your widget in a new folder in the widgets folder.
- Modify the iframe in index.html to show your widget.
- Add this code to the html file used by your widget:
- <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開發內容的學習能對你有所幫助。