Windows Mobile Widget Emulator

简介:

今天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也实现了,和我想法是一样的。

 widget1

widget2

 

 

我当初的想法是直接使用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我会使用他进行调试。



    本文转自Jake Lin博客园博客,原文链接:http://www.cnblogs.com/procoder/archive/2009/08/07/1540967.html,如需转载请自行联系原作者


相关文章
|
Windows 网络协议
Windows Mobile远程控制软件Pocket Controller Pro简介
不仅PPC/WindowsMobile系统可以使用该控制软件,只要是WINCE内核的系统都可以使用,我在WinCE.net 4.2系统测试通过,只不过640*480的分辨率,控制速度不是那么理想。
933 0
|
数据格式 XML Windows
Windows Mobile 5.0编程—奥运场馆速查
我忙里偷闲,用VS2005开发了一个关于奥运场馆的小程序,时值2008北京奥运前夕,也算是为奥运做了“贡献”
666 0
|
Windows Web App开发 API
UWP 判断windows mobile是使用的实体键还是虚拟按键
原文:UWP 判断windows mobile是使用的实体键还是虚拟按键 最近在写启动屏幕,发现虚拟按钮会挡住,启动屏幕的最下面的元素,大概有50 px。可是有什么办法知道手机是用的实体键还是虚拟按键吗? 如下图。
1126 0
|
虚拟化 Windows
win8.1使用WP8SDK出现Windows Phone Emulator无法启动的问题解决方案
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq1010885678/article/details/37571213 近期在win8.
898 0
|
Windows
Windows Phone 模拟器(Emulator) 加载程序一闪而过就自动退出的解决办法
今天在做一个Windows Phone 程序。在一番重构之后突然发现按F5调试程序时,模拟器可以启动,并且加载了程序,不过只是闪了一下,然后程序迅速退出了。没有任何出错信息,也没有任何log文件。在程序的任何地方设置断点也没法中断。