關(guān)于Windows Mobile Widget開發(fā)Emulator
關(guān)于Windows Mobile Widget開發(fā)Emulator是本文要介紹的內(nèi)容,主要是來了解并學(xué)習(xí)Windows Mobile Widget開發(fā)應(yīng)用,今天Vimpyboy在codeplex發(fā)布了Windows Mobile Widget Emulator,具體內(nèi)容的實現(xiàn)來看本文詳解。
這是一個用來調(diào)試Windows Mobile6.5 Widget的工具,我在做Windows Mobile 6.5新功能widget開發(fā)的時候就發(fā)現(xiàn)調(diào)試Widget很麻煩。也有想法做一個Emulator,其實這個Emulator目標(biāo)很明顯,第一個目標(biāo)就是實現(xiàn)MSWidget提供的javascript的menu對象。下面代碼來自于Windows Mobile Widget Emulator。實現(xiàn)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.'
- };
第二個目標(biāo)是可以動態(tài)調(diào)整resolution。Windows Mobile Widget Emulator也實現(xiàn)了,和我想法是一樣的。


我當(dāng)初的想法是直接使用MS的emulator的圖片,這些圖片保存在C:\ProgramFiles\Windows Mobile6SDK\PocketPC\DeviceemulationV650下,而且每個emulator都有XML定義文件,可以直接取出這些定義文件和圖片進(jìn)行resolution的選擇。
第三個要實現(xiàn)的目標(biāo)是,不需要修改開發(fā)中的widget的源代碼,直接可以調(diào)試。這個我想比較難實現(xiàn),我開始想用firefox的addon來實現(xiàn),可是firefox的javascript和ie有區(qū)別,在ff調(diào)試通過不一定在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的發(fā)布。以后開發(fā)widget我會使用他進(jìn)行調(diào)試。
小結(jié):關(guān)于Windows Mobile Widget開發(fā)Emulator的內(nèi)容介紹完了,希望通過Windows Mobile Widget開發(fā)內(nèi)容的學(xué)習(xí)能對你有所幫助。