Showing posts with label 诺基亚. Show all posts
Showing posts with label 诺基亚. Show all posts

10.9.10

Unofficial Qt Web Runtime tutorial 2: Menu API

If there is no API, Qt WRT is merely nothing but a naive web browser. Then what APIs are supported other than standard HTML and JavaScript now? You can first get a list of features already supported, or to be supported in the near future here.

As a summary, we have already supported the APIs of menus, widget object, URI schemes, web inspector, console log, some Device APIs, as well as some HTML 5 features and standard JavaScript from Qt WebKit. Let's start with the menu API.

1 view menu
You can create the menu items to the chrome's menu bar (we call it view menu) with the following JavaScript code:
var menuItem = new nokia.device.MenuItem("Menu item", changeTitle);
nokia.device.menu.addMenuItem(menuItem);
function changeTitle()
{
  nokia.device.menu.title = "New title";
}


Here, you have created a menu item named "Menu item" and added it to the menu bar. When it's triggered, the function changeTitle() will be called to set the menu's title to "New title".

Note that since on the device the menu's title is also the same as the window's title, it actually changes the window's title too.

2 context menu
The context menu can be created with the following piece of code:
var contextMenu = new nokia.device.ContextMenu("contextMenuArea");
var changeTitleItem = new nokia.device.MenuItem("Change Title");
changeTitleItem.onselect = changeTitle;
contextMenu.addMenuItem(changeTitleItem);


Here, a context menu is created and an item named "Change Title" is added to the menu. When you long tap on the HTML element with id "contextMenuArea", this context menu will pop up. Then if you select the "Change Title" item, the changeTitle() function will be called.

Of course, only the widgets in the windowed or fullscreen mode could have context menus; and only the widgets in the windowed mode can have view menus.

Note that there's a known bug (already fixed for the next release) that if you long tap on the area where no context menu is defined, an empty context menu is popped-up.

3 sample
Only the HTML file this time ;)
<html>
<header>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>Menu sample</title>
  <script type="text/javascript">
    function changeTitle()
    {
      if (nokia.device.menu.title == "Title 1")
        nokia.device.menu.title = "Title 2";
      else
        nokia.device.menu.title = "Title 1";
    }

    function init()
    {
      var menuItem = new nokia.device.MenuItem("item", changeTitle);
      nokia.device.menu.addMenuItem(menuItem);

      var contextMenu = new nokia.device.ContextMenu("contextMenuArea");
      contextMenu.addMenuItem(menuItem);
    }
  </script>
</header>
<body onload="init()">
  <div id="contextMenuArea">There is a context menu.</div>
</body>
</html>


As you can see, one menu item can be added to multiple menus, exactly the same as native Qt apps. Here goes some screenshots:
 
 

The first one shows the simple sample when launched. The second and third one show the view menu and the context menu, respectively, while the last one shows that the title has been updated after you tap on the menu. More screenshots can be found here, while the sample code is available here.

18.8.10

Unofficial QtWRT tutorial 1: Hello, view modes!

Almost one month ago, we announced Qt Web Runtime, and released some snapshot for N900. Basically, QtWRT is a framework, using which you can write "native" application with standard web technology, e.g. HTML, CSS, and JavaScript. As a good starting point, you should take a look at this article.

Note that we're still working on it, and it's now just in the technology preview state ;)

1 install QtWRT
You should enable the extras-devel repository on your Rover and install the qtwrt-experimental package from there. Then, you can find in your Application Manager that Qt Web Runtime Technology Preview for N900 installed.


2 config.xml
To write your own web applications, besides the normal HTML pages, you also need a config.xml file to define e.g. the starting file, icon, features you need (i.e. access to Device APIs), as well as author's information, etc. More details and default values are defined here.

The following piece shows a minimum sample:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns = "http://www.w3.org/ns/widgets">
</widget>


You can also define the name and icon (only PNG files supported) of the web app in config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns = "http://www.w3.org/ns/widgets">
  <name>A sample web app</name>
  <icon src="app_icon.png" />
</widget>

The name and icon will be appeared in the Application Grid or the Desktop menu --> Add widget based on the view mode the web app supports (see below).

3 view modes
View modes define the visual presentation of web applications. The W3C spec has defined five different view modes, but we only support three of them in this snapshot:
windowed - The default view mode. You can find / launch web apps in this mode from the Application Grid. It also supports the native chromes and user-defined menus.
fullscreen - It can also be found / launched from the Application Grid. No need to say what is full screen, right ;)
minimized - It equals to the native widgets on the Home Screen.

The following piece defines the view modes in config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns = "http://www.w3.org/ns/widgets"
    viewmodes = "someviewmode fullscreen minimized" >
</widget>

The unknown view mode "someviewmode" is ignored. It supports both "fullscreen" and "minimized" mode in this case. If no supported view mode is defined, "windowed" mode is used.

You can get the current view mode through the widget.viewMode interface in JavaScript.

Also, the transfer among different view modes is supported, with the exception from windowed / fullscreen to minimized, e.g.:
<a href="javascript:widget.viewMode='windowed'">Go to windowed mode</a>

With the following code, you can handle the view mode change event in the viewModeChanged function:
widget.onviewmodechange = viewModeChanged;
function viewModeChanged(mode)
{
  if (mode == "windowed") {
    // going to windowed mode
  } else if (mode == "minimized") {
    // going to minimized mode
  } else if (mode == "fullscreen") {
    // going to full screen mode
  }
}


4 package your application and install it
Well, I just assume you have enough knowledge to write whatever HTML page you like, and have renamed it to index.htm (the default starting file name).

Now just zip all your HTML files together with the config.xml file. Note that the config.xml file should be at the top level of the zip, and the name is case sensitive.

Then please rename it to *.wgt and copy it to your Rover. To make it like a native application, you can install it from the File Manager, and you can find your installed web applications in Application Manager!

Eh, I'm talking about some details during the installation here. You can skip this if not interested.

When you tap on the wgt file in File Manager, widgetinstaller is launched. It does some sanity checking of it, e.g. whether it's a valid zip file, if the config.xml is valid, etc., then convert it to a Debian file, and use the Application Manager to install the generated Debian file.

If you are interested in the generated Debian file, you can use the "--no-install" option of the widgetinstaller to have it copied to the current directory.

5 a sample
First, let's write the config.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets"
    id="http://xizhizhu.blogspot.com/qtwrt/view-modes-sample"
    viewmodes="minimized fullscreen windowed">
  <name>View Modes Sample</name>
  <description>
    Well, it shows how the view modes work.
  </description>
  <author href="http://xizhizhu.blogspot.com/" email="xizhi.zhu@gmail.com">Xizhi Zhu</author>
  <license>In the public domain without any warranty.</license>
</widget>


Then the HTML file.
<html>
<header>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title>View Modes</title>
  <script type="text/javascript">
    function init()
    {
      output = document.getElementById("viewmode");
      output.innerHTML = widget.viewMode;

      widget.onviewmodechange = changeViewMode;
    }

    function changeViewMode(mode)
    {
      output.innerHTML = widget.viewMode;
    }
  </script>
</header>

<body onload="init()">
  <div id="viewmode"></div><br />
  <a href="javascript:widget.viewMode='minimized'">minimized</a><br />
  <a href="javascript:widget.viewMode='windowed'">windowed</a><br />
  <a href="javascript:widget.viewMode='fullscreen'">fullscreen</a>
</body>
</html>


Now let's zip the file, send it to N900 and install it from the File Manager. You can find it installed in the Application Manager and already launched in the home screen.


You may ask, why the last line of "fullscreen" is not shown there? Well, that's due to the fixed size in the minimized mode, 312x82. Also, in the minimized mode, you can't actually interact with it, but only tap on it and open the windowed or fullscreen mode if supported. In the minimized mode, it's the same as native widgets that you can move it around, close it and add it back, as well as the transparent background by default.

Then you can tap the links to toggle between windowed and fullscreen mode. And for sure you'll find another "limitation" that you can't go back to minimized mode from the link. The only way is to close the window. Well, that's exactly what is expected.



Another thing is, in the fullscreen mode, it automatically shows the "go back to windowed" button if windowed mode is supported, otherwise the "close" button. Emm, the same as the browser, right?


Updated on 19.8.2010
Screenshots added into the posts ;)

15.5.10

这位评论真的用过N900吗?!

刚看了一篇谈论手机杯具的文章,说的是N900。不过很怀疑这位老兄是否真的用过N900......

文章说:N900最大的尴尬在于它那被消极淡化的通话功能。
话说Nokia对Maemo/MeeGo系列的定义是“移动电脑”(mobile computer)吧!打开N900的官方首页,上面就写得非常清楚:Nokia N900 mobile computer。本来定位就不是智能手机,所以通话功能被“淡化”不正常吗?或者说你见过哪部PDA会“强化”电话功能的?好吧,你会说我这样强词夺理了,那我们接着看......

然后文章对N900的“消极淡化通话功能”列出了几个“铁证”:
1,机身正面没有任何拨号快捷键,哪怕是触控按键都没有。
2,默认桌面菜单也没有任何与通话相关的快捷方式。
3,QWERTY全键盘采用了三排式的布局,因此并没有单独的数字键。也就是说,打开侧滑盖还是没法直接拨号。
4,没有竖屏模式,也就是说诺基亚设计它的初衷就是让你始终横着拿它。横着打电话?有难度吧。。。

好吧,我们看图说话:
这是我N900上四个桌面之一,上面可以任意摆设各种Widget、快捷方式和联系人,也可以自行调整其放置的位置。标号为1的红圈就是联系人的快捷方式,标号为2的红圈是最近通话和拨号功能的快捷方式,标号为3的红圈则是放在单个联系人的快捷方式。当然单个联系人也是可以自定义头像的,只不过考虑到隐私我暂时删除罢了。

当然了,默认情况下,桌面也是有联系人和最近通话的快捷方式的,好像也有邮件或者短信息的快捷方式......我就不刷机证明了啊;)

当然了,既然有如此方便的软键盘拨号,为何还要打开侧滑盖呢?

然后我们再看看“没有竖屏模式”的笑话!你点开最近通话和拨号功能,然后看下图:
我觉得这个应该叫做“竖屏模式”了吧?!而且通话功能的竖屏模式是默认开启的......

我想,我只能说这位搞评论的朋友没有用过N900吧!

PS 这三张照片都是用另一部N900的相机在晚上10点左右拍摄的,外界光线不好,室内也没开灯:)