Windows Mobile Widget Emulator

來源:互聯網
上載者:User

今天Vimpyboy 在codeplex發布了Windows Mobile Widget Emulator。這是一個用來調試Windows Mobile 6.5 Widget的工具,我在做Windows Mobile 6.5 新功能widget開發 的時候就發現調試Widget很麻煩。也有想法做一個Emulator,其實這個Emulator目標很明顯,第一個目標就是實現MS Widget提供的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 menuItemCopy = 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) {
idx = 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:\Program Files\Windows Mobile 6 SDK\PocketPC\DeviceemulationV650下,而且每個emulator都有XML定義檔案,可以直接取出這些定義檔案和圖片進行resolution的選擇。

 

第三個要實現的目標是,不需要修改開發中的widget的原始碼,直接可以調試。這個我想比較難實現,我開始想用firefox的addon來實現,可是firefox的javascript和ie有區別,在ff調試通過不一定在ie能用,可能做ie的addon可以解決這個問題。

Windows Mobile Widget Emulator也沒有解決這個問題,需要修改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我會使用他進行調試。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.