×
Namespaces

Variants
Actions
(Difference between revisions)

Catching menu events in Symbian Web Runtime

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot change of template (Template:CodeSnippet) - now using Template:ArticleMetaData)
hamishwillee (Talk | contribs)
m (Hamishwillee - Fix categories)
 
(5 intermediate revisions by one user not shown)
Line 1: Line 1:
__NOTOC__
+
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:UI]]
__NOEDITSECTION__
+
{{ArticleMetaData <!-- v1.2 -->
{{KBCS}}
+
|sourcecode= [[Media:Catching menu events in WRT.zip]] [[Media:CatchingMenuEvents.diff.zip]]
{{ArticleMetaData
+
|id=CS001399
+
|platform=S60 5th Edition
+
|devices=Nokia 5800 XpressMusic
+
|category=Web Runtime (WRT)
+
|subcategory=UI
+
|creationdate=June 8, 2009
+
|keywords=menu, menu.onShow, MenuItem.onSelect
+
 
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
+
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|devices= Nokia 5800 XpressMusic
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|platform= S60 5th Edition
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices. -->)
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|author=[[User:Dekuykin]]
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= menu, menu.onShow, MenuItem.onSelect
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20090226
 +
|author= [[User:Dekuykin]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS001399
 
}}
 
}}
  
 
==Overview==
 
==Overview==
  
This code snippet demonstrates how to handle the <tt>onShow</tt> menu event. It shows the count of how many times a menu has been opened on-screen.
+
{{Abstract|This code snippet demonstrates how to handle the {{Icode|onShow}} menu event. It shows the count of how many times a menu has been opened on-screen.}}
  
The snippet uses the WRT's <tt>menu</tt> object and the <tt>menu.onShow</tt> property to set the handler for menu events.
+
The snippet uses the WRT's {{Icode|menu}} object and the {{Icode|menu.onShow}} property to set the handler for menu events.
  
The property <tt>MenuItem.onSelect</tt> is used to set the handler for menu item selecting events.
+
The property {{Icode|MenuItem.onSelect}} is used to set the handler for menu item selecting events.
  
 
==Source file: Relevant HTML components==
 
==Source file: Relevant HTML components==
Line 134: Line 139:
 
This code snippet is part of the stub concept, which means that it has been patched on top of a template application in order to be more useful to developers. The version of the WRT stub application used as a template in this snippet is v1.1.
 
This code snippet is part of the stub concept, which means that it has been patched on top of a template application in order to be more useful to developers. The version of the WRT stub application used as a template in this snippet is v1.1.
  
* The patched, executable application that can be used to test the features described in this snippet is available for download at [[Media:Catching_menu_events_in_WRT.zip]].  
+
* The patched, executable application that can be used to test the features described in this snippet is available for download at [[Media:Catching menu events in WRT.zip]].  
 
* You can view all the changes that are required to implement the above-mentioned features. The changes are provided in unified diff and colour-coded diff (HTML) formats in [[Media:CatchingMenuEvents.diff.zip]].
 
* You can view all the changes that are required to implement the above-mentioned features. The changes are provided in unified diff and colour-coded diff (HTML) formats in [[Media:CatchingMenuEvents.diff.zip]].
 
* For general information on applying the patch, see [[Using Diffs]].
 
* For general information on applying the patch, see [[Using Diffs]].
* For unpatched stub applications, see [[Example stub]].
+
* For unpatched stub applications, see [[Example app stubs with logging framework]].
 
+
[[Category:Symbian Web Runtime]][[Category:Code Examples]][[Category:Code Snippet]]
+

Latest revision as of 08:50, 4 October 2012

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 5th Edition
Article
Keywords: menu, menu.onShow, MenuItem.onSelect
Created: dekuykin (26 Feb 2009)
Last edited: hamishwillee (04 Oct 2012)

Contents

[edit] Overview

This code snippet demonstrates how to handle the onShow menu event. It shows the count of how many times a menu has been opened on-screen.

The snippet uses the WRT's menu object and the menu.onShow property to set the handler for menu events.

The property MenuItem.onSelect is used to set the handler for menu item selecting events.

[edit] Source file: Relevant HTML components

<p id="menuOpenCountPhrase">
The menu is opened <strong>0</strong> times.
</p>
<input id="menuOpenCount" type="hidden" value="0" />

[edit] Source file: JavaScript file

var menuItemReset = null;
 
var CMD_MENU_RESET = 11;
// Set menu's onShow event handler
window.menu.onShow = incrementCounter;
// Creates the main menu
function createMenu() {
// ...
 
// Create the "Reset" menu item
menuItemReset = new MenuItem("Reset", CMD_MENU_RESET);
menuItemReset.onSelect = onMenuItemSelected;
window.menu.append(menuItemReset);
 
window.menu.showSoftkeys();
 
// Set menu's onShow event handler
window.menu.onShow = incrementCounter;
}
// Gets called when a menu item is selected
function onMenuItemSelected(menuId) {
switch (menuId) {
case CMD_MENU_RESET:
// Reset the counter of menu events
try {
document.getElementById("menuOpenCount").value = "0";
} catch (e) {
alert("Error: " + e);
}
 
// Reset the menu openings count phrase
try {
document.getElementById("menuOpenCountPhrase").innerHTML =
"The menu is opened <strong>0</strong> times.";
} catch (e) {
alert("Error: " + e);
}
 
break;
}
}
/**
* Increments counter of menu opening events.
*/

function incrementCounter() {
// Get reference to counter value
try {
var counterLabel = document.getElementById("menuOpenCount");
} catch (e) {
alert("Error: " + e);
}
 
if (counterLabel == undefined) {
alert("Error: Menu events counter object is undefined!");
}
 
// Get current count of menu opening events
var menuOpenCount = Number(counterLabel.value);
// Increment counter
var menuOpenCountNew = menuOpenCount + 1;
counterLabel.value = String(menuOpenCountNew);
// Form the menu openings count phrase
try {
document.getElementById("menuOpenCountPhrase").innerHTML =
"The menu is opened <strong>" + menuOpenCountNew +
"</strong> times.";
} catch (e) {
alert("Error: " + e);
}
}

[edit] Postconditions

Every time the menu is opened the indicator on the screen will be updated.

Selecting the "Reset" menu item resets the counter value to "0".

[edit] Supplementary material

This code snippet is part of the stub concept, which means that it has been patched on top of a template application in order to be more useful to developers. The version of the WRT stub application used as a template in this snippet is v1.1.

This page was last modified on 4 October 2012, at 08:50.
113 page views in the last 30 days.
×