×
Namespaces

Variants
Actions

Example: handset review

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code ExampleArticle
Created: rdrincon (25 Aug 2008)
Last edited: hamishwillee (27 Jul 2012)
FNWID.gif

Contents

About

This is a small example showing two screens using the concepts stated in the article Archived:Understanding WidSets. The source code is shown bellow, but you can download the whole example in the following link File:Example handset review.zip


Source Code File

review.he


/**																	
*	Widset Example																					
*/																	
																	
class phone_review																	
{																	
																	
/* Define some Action Ids constant values.																	
*/																	
																	
const int CMD_SELECT=100;																	
const int CMD_BACK=101;																	
const int CMD_EXIT=102;																	
const int CMD_UPDATE=103;																	
																	
																	
/*																	
* The riht softkey will be bounded to a back screen functionality.  As this Command is present in every screen																	
* it will be global. 																	
*/																	
																	
MenuItem back= new MenuItem(CMD_BACK,"Back");																	
																	
																	
/*																	
* A Value is a useful element that allows to arrange information into a single object.																	
* In this case, there will be a set of handsets and each one will have a name, a text and an image associated to it.																	
*/																	
																	
Value handsets = [																	
["name"=> "Nokia N96",																	
 "text"=> "Use the Nokia N96 for connecting to mobile Broadband using WLAN or HSDPA (3.5G) with faster downloading than 3G. Find directions and locations with the integrated A-GPS and included maps. Use the Nokia N96 to take photos with a 5.0 megapixel auto focus camera. Enjoy videos, music and graphics on the 2.8” QVGA (240 x 320 pixels), 16M color display.",																	
 "img" => "n96.jpg"																	
],																	
["name"=> "Nokia 5320 XpressMusic",																	
 "text"=> "The Nokia 5320 XpressMusic supports video calls, photos, and videos with two built-in cameras. Enjoy superior audio quality with dedicated audio chip, and fast and easy music downloads with HSDPA and USB 2.0 High Speed. Additional Nokia 5320 XpressMusic features include Bluetooth 2.0 EDR with A2DP, and 8GB MicroSD memory card support.",																	
 "img" => "5320.jpg"																	
],																	
["name"=> "Nokia 2680 slide",																	
 "text"=> "The Nokia 2680 slide is a Dual-band GSM phone E900/1800 or E850/1900 (for some markets) that includes a VGA camera, FM radio, Bluetooth, E-mail and mobile Internet access via a WAP browser. Additionally, the Nokia 2680 slide supports MMS and Nokia Xpress Audio Messaging, for recording and editing messages on the go.",																	
 "img" => "2860.jpg"																	
]																	
];																	
																	
																	
//---------------------------------------------------------																	
/**																	
*  This method populates the mainList screen with a list of handsets.																	
*  It creates a Shell and then associates to it:																	
*		Softkeys:  using the mySoftKeyHandler callback															
*		Menu:  using the myMenuHandler callback															
*		Event Handling: triggered by softkeys or a menu element with the myActionHandler callback															
*/																	
																	
Shell createHandsetsList(){																	
																	
																	
	Flow handsetsFlow= new Flow(getStyle("default"));							//Creates a flow with default style and resized to the whole screen									
	handsetsFlow.setPreferredSize(-100,-100);																
																	
	Label title = new Label(getStyle("title"),"New Handsets");					//Creates the Title of the page and adds it to the flow											
	title.setFlags(VISIBLE|LINEFEED);																
	handsetsFlow.add(title);																
																	
	foreach (Value handset : handsets)																
	{																
		Label label = new Label(getStyle("items"),handset.name);				//Creates a label with the name of the movie for each movie											
		label.setFlags(VISIBLE|FOCUSABLE|LINEFEED);								//Makes the element focusable and adds a line break							
		handsetsFlow.add(label);															
	}																
																	
	Shell mainList=new Shell(handsetsFlow);										//Shell to be displayed using the background style from the xml file						
	mainList.setStyle(getStyle("_background"));																
																	
																	
	//Set customer-defined callbacks																
	mainList.setSoftKeyHandler(softKeyHandler);									//softkeys							
	mainList.setMenuHandler(myMenuHandler);										//menu						
	mainList.setActionHandler(actionHandler);									//events							
																	
																	
																	
	//Defines the softkey actions																
	MenuItem softKeyHandler(Shell shell, Component focused, int key){			//Adds the select, back and menu softkeys to the screen													
																	
		if(key==SOFTKEY_OK){															
			return new MenuItem(OPEN_MENU, "Menu");								//Uses the system Action Id:  OPEN_MENU						
		}															
		else if (key ==SOFTKEY_MIDDLE)															
		{															
			return new MenuItem(CMD_SELECT,"Select");														
		}															
		else if (key == SOFTKEY_BACK)															
		{															
			return back;														//Back MenuItem is global
		}															
		else{															
			return null;														
		}															
	}																
																	
																	
	Menu myMenuHandler( Shell shell, Component source){							//Creates the menu for the screen									
																	
		Menu m = new Menu().add(CMD_UPDATE, "Update")															
						   .add(OPEN_HELP, "Help")								//Uses the system Action Id:  OPEN_HELP			   
						   .add(CMD_EXIT, "Cancel");											
																	
		return m;															
	} 																
																	
																	
    void actionHandler(Shell shell, Component source, int action){				//Actions trigerred by the softkeys													
																	
		switch(action){															
																	
			case CMD_BACK:														
				popShell(shell);												//shows the prior screen	
			break;														
																	
			case CMD_SELECT:														
				int index =handsetsFlow.indexOf(source)-1;						//Remember that first element in the flow is the Header text so it is substracted 1							
				Shell newShell = createHandsetsFlow(index);						//Creates a new Shell to be displayed passing the index of the selected movie							
				int w, int h = getScreenSize();													
				slideIn(w, h, w, h, newShell);									//Pushes the shell into the stack in a slide-fashion way				
			break;														
																	
			case CMD_UPDATE:														
				Shell updateScreen=createUpdateScreen();						//Update Screen							
				pushShell(updateScreen);													
			break;														
																	
		}															
	} 																
																	
	return mainList;																
}																	
																	
																	
/**																	
*	This method creates a Shell containing general information about the phone selected																
*	The Screen consists of a picture of the phone and a short description																
*	This screen uses the menu, softkeys and event handler by default																
*/																	
																	
Shell createHandsetsFlow(int index){																	
																	
	Flow flow = new Flow(getStyle("default"));									//This flow will contain a Picture and a Text components							
	flow.setPreferredSize(-100,-100);																
																	
																	
	String path=handsets[index].img;																
	Image img = getImage(path);																
	Picture pic = new Picture(getStyle("description"),img);																
	pic.setFlags(VISIBLE|LINEFEED);																
	Text text = new Text(getStyle("description"),handsets[index].text);			//Information is in the value object													
																	
	flow.add(pic);																
	flow.add(text);																
																	
	Shell handsetShell = new Shell(flow);																
	handsetShell.setStyle(getStyle("_background"));								//Adds a style to the Shell								
																	
	return handsetShell;																
																	
}																	
																	
																	
/**																	
*	Creates a Popup window with information related to the update function																
*/																	
																	
Popup createUpdateScreen(){																	
	Popup popup=null;															//Popup is a small window not covering all the display	
	Flow flow= new Flow(getStyle("menu"));																
	Text flowText= new Text(getStyle("menuText"),"This function has not been implemented.");																
	flow.add(flowText);																
	popup= new Popup(flow);																
	return popup;																
}																	
																	
																	
																	
//---------------------------------------------------------																	
/*																	
*	Methods used by default																
*	The following methods are only for those shells that don't implement their own setSoftKeyHandler, setActionHandler or setMenuHandler methods.																
*/																	
																	
																	
//   catches the events by default																	
void actionPerformed(Shell shell, Component source, int action) {																	
	switch(action) {                                                            																
      case CMD_BACK:                                                            																	
        popShell(shell);														// Takes the current Shell out of the stack so the last one will be displayed                                                  			
        break;																	
    }																	
 }  																	
																	
																	
// Shells have only a back softkey by default																	
MenuItem getSoftKey(Shell shell, Component focused, int key) {					// This function sets bindings for the softkeys.												
																	
    if (key == SOFTKEY_BACK) {                                                  // Back softkey is allways necesary																	
      return back;                                                              																	
    }else {																	
      return null;                                                              // Null is returned for SOFTKEY_MIDDLE and SOFTKEY_OK.																	
    }																	
  }																	
																	
																	
//	Shells have no menu by default																
Menu getMenu(Shell shell, Component focused)																	
 {																	
   return null;																	
 }																	
	 																
																	
																	
//---------------------------------------------------------																	
/**																	
*	Control methods																
*/																	
																	
																	
// Called when the widget is loaded (displayed in the dashboard)																	
void startWidget()																	
  {																	
   setMinimizedView(createMinimizedView("viewMini", null));																	
  }																	
																	
																	
// Called when the user clicks on the minimized view of the widget in the dashboard																	
Shell openWidget()																	
  {																	
    return createHandsetsList();																	
																	
	}																
																	
}


XML File

widget.xml



<?xml version="1.0" encoding="utf-8"?>
 
 <widget spec_version="2.0">
  <info>
    <name>Handsets Example</name>
    <version>1.0</version>
    <author>Ruben Rincon</author>
    <shortdescription>Newest handsets available</shortdescription>
    <longdescription>Newest handsets available</longdescription>
	

	<help default="en" showFirstTime="true">
		<text lang="en">This Widget shows a list of handsets and a short description of each of them. Synchronization is not implemented as it's only an example.</text>
	</help>

  </info>
   
  <parameters>
    <parameter type="string" name="widgetname" description="Name of widget" editable="no">Review</parameter>
  </parameters>
  
  <resources>
    <img src="n96.jpg"/>
    <img src="5320.jpg"/>
	<img src="2860.jpg"/>
	<code src="review.he"/>

	<stylesheet>

	_background{
		margin: 2 2 2 2;
		background: vgradient rgb(255,255,255) rgb(193,200,203);
		border-type: rectangle rgb(193,200,203);
	}

	title{
		color: white;
		width: 100%;
		border: 2 2 2 2;
		border-type: rectangle #FF0069;
		align: hcenter vcenter;
		font-1: large bold;
		background: vgradient rgb(237,160,190) #FF0069;
	}

	items{
		background: none;
		font-1: proportional medium bold;
		color: rgb(72,51,232);
		width: 100%;
		focused{
			border: 1 1 1 1;
			border-type: rectangle rgb(193,197,199);	
			background: solid rgb(215, 218, 219);
			color: rgb(98,68,118);
		
		}	
	}

	description {
		background: none;
		width: 100%;
		font-1: monospace medium plain;
		align: hcenter vcenter;		
	}

	menu{
		width: 100%;
		background: solid white;		
		border: 1 1 1 1;
		border-type: rectangle rgb(255,128,0);
		align: left bottom;		
	}

	menuText{
		width: 100%;
		padding: 2 2 2 2;
		font-1: small plain;
		color: rgb(255,128,0);	
	}

	minimized{
		width: 100%;
		border: 2 2 2 2;
		border-type: rectangle #FF0069;
		align: hcenter vcenter;
		background: vgradient rgb(237,160,190) #FF0069;
	}

	minimized_text{
		background:none;
		color: white;
		align: hcenter vcenter;
		font-1: large bold;	
	}
	
    </stylesheet>
  </resources>
    
  <layout minimizedheight="65sp">
    <view id="viewMini">
	  <decorate class="minimized"/>
	  <text class="minimized_text">Handset Review</text>

    </view> 
  </layout>

</widget>

																	

See Also

This page was last modified on 27 July 2012, at 09:24.
42 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×