<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Últimas mensagens do tópico "Mojax (mobile Ajax): Exemplos"]]></title>
		<link>http://www.guj.com.br/posts/list/14.java</link>
		<description><![CDATA[Últimas mensagens enviadas no tópico "Mojax (mobile Ajax): Exemplos"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>Mojax (mobile Ajax): Exemplos</title>
				<description><![CDATA[ Primeiro, o que é o Mojax -&gt; um projeto interessante (ainda em versão beta). Uma framework suite de pacotes) que permite ao programador desenvolver aplicações no estilo JME sem usar diretamente a mesma e sem ter conhecimento integral de JAVA. Basta conhecer JavaScript e XML/CSS<br /> Com ajuda do Mojax você pode facilmente desenvolver uma aplicação J2ME com tabelas ou com funções de cliente do Google ou Yahoo Maps, Flickr, aplicativo de estoque, tudo isso com poucas linhas de código.<br /> <br /> Exemplo de "Hello World":<br /> Ex. em mojax com uso de XML<br /> <br /> [code]<br /> &lt;moblet default="main" name="HelloWorld"&gt;  <br />     &lt;screen id="main"&gt;  <br />          &lt;textbox&gt;  <br />               HELLO WORLD! <br />          &lt;/textbox&gt;  <br />     &lt;/screen&gt;  <br /> &lt;/moblet&gt;<br /> [/code]<br /> <br /> Ex. em Java<br /> [code]<br /> import javax.microedition.midlet.* ;  <br /> import javax.microedition.lcdui.*;  <br /> public class Hello extends MIDlet {  <br />      private Display display;  <br />           <br />      public Hello() {  <br />         display = Display.getDisplay(this);  <br />      }  <br />   <br />      public void startApp() {  <br />         Form f = new Form("main");  <br />         f.append("HELLO WORLD!");  <br />         display.setCurrent(f);  <br />      }  <br />      public void pauseApp() { }  <br />   <br />      public void destroyApp(boolean unconditional) { }  <br /> }  <br /> [/code]<br /> <br /> Ex. com uso de CSS<br /> [code]<br /> &lt;moblet default="main"&gt; <br />    &lt;screen id="main" layout="vertical"&gt; <br />        &lt;box layout="vertical" style="border: 1px  <br />            solid #FF0000" valign="center"  <br />            halign="center"&gt; <br />           &lt;textbox style="border: 1px solid #00ff00"&gt; <br />               HELLO<br />           &lt;/textbox&gt; <br />           &lt;textbox style="border: 1px solid #0000ff"&gt; <br />              WORLD<br />           &lt;/textbox&gt; <br />        &lt;/box&gt; <br />    &lt;/screen&gt; <br /> &lt;/moblet&gt;<br /> [/code]<br /> <br /> Ex. de um Menu com JavaScript<br /> [code]<br />  &lt;screen id="main" layout="vertical"  <br />        valign="center" halign="center"&gt; <br />        &lt;textbox focusable="true"  <br />           onClick="show(info, 1)" width="100%"&gt; <br />           Show info as Layer <br />        &lt;/textbox&gt; <br />        &lt;textbox focusable="true"  <br />           onClick="show(info)" width="100%"&gt; <br />           Show info as Screen <br />        &lt;/textbox&gt; <br />  &lt;/screen&gt;  <br /> [/code]<br /> <br /> Exemplo em Mojax (Mobile Ajax) de uma aplicação LBS, uma alternativa para a dispositivos sem suporte a API Location (JSR 179) usando o Yahoo! Maps<br /> <br /> [code]<br /> import java.io.IOException;<br /> import java.util.Hashtable;<br /> import javax.microedition.io.*;<br /> import javax.microedition.lcdui.*;<br /> import javax.microedition.midlet.MIDlet;<br /> import com.sun.me.web.path.Result;<br /> import com.sun.me.web.path.ResultException;<br /> import com.sun.me.web.request.Arg;<br /> import com.sun.me.web.request.ProgressInputStream;<br /> import com.sun.me.web.request.Request;<br /> import com.sun.me.web.request.RequestListener;<br /> import com.sun.me.web.request.Response;<br /> import java.io.InputStream;<br /> <br /> // Exemplo de MIDlet Mojax (Mobile Ajax) para pesquisa local com resultado exibido com o Yahoo! Maps <br /> public class LocalSearchMidlet extends MIDlet implements CommandListener, RequestListener {<br />     <br />     private static final boolean DEBUG = true;<br />     <br />     // Recupera o APP ID para uso no Yahoo Maps API<br />     private static final String APPID = &quot;&quot;;<br />     <br />     private static final int DEFAULT_RESULT_COUNT = 10;<br />     private static final int MAX_MAP_ZOOM = 12;<br />     private static final int DEFAULT_MAP_ZOOM = 6;<br />     private static final int MIN_MAP_ZOOM = 1;<br />     <br />     private Hashtable imageCache = new Hashtable(MAX_MAP_ZOOM - MIN_MAP_ZOOM);<br />     private int mapZoomLevel = DEFAULT_MAP_ZOOM;<br />     private Item selectedItem = null;<br />     <br />     private static final String LOCAL_BASE = &quot;http://local.yahooapis.com/LocalSearchService/V2/localSearch&quot;;<br />     <br />     private static final String MAP_BASE = &quot;http://api.local.yahoo.com/MapsService/V1/mapImage&quot;;<br />     <br />     private String mapAllLink = null;<br />     <br />     private static class Links {<br />         String title;<br />         String business;<br />         String listing;<br />         String map;<br />         String tel;<br />         String latitude;<br />         String longitude;<br />     };<br />     private Links[] links = null;<br />     <br />     private int start = 1;<br />     private int totalResultsAvailable = start;<br />     <br />     public LocalSearchMidlet() {<br />     }<br />     <br />     private Form queryForm; // MVDFields<br />     private Command exitCommand;<br />     private Form resultForm;<br />     private Command searchCommand;<br />     private Alert alert;<br />     private TextField searchFor;<br />     private TextField street;<br />     private TextField location;<br />     private Command mapCommand;<br />     private Command listingCommand;<br />     private Command businessCommand;<br />     private ChoiceGroup sortGroup;<br />     private Command mapAllCommand;<br />     private Command backCommand;<br />     private Command callCommand;<br />     private Form mapForm;<br />     private ImageItem mapImageItem;<br />     private Command mapBackCommand;<br />     private Command zoomInCommand;<br />     private Command zoomOutCommand;<br />     private Command selectCommand;<br />     private Command nextCommand;<br />     private Command prevCommand;<br />     <br />     // MVDMethods    <br />     // Inicialização da interface da aplicação     <br />     private void initialize() {<br />         getDisplay().setCurrent(get_queryForm());<br />     }<br />     <br />     public void commandAction(Command command, Displayable displayable) { // MVDCABegin<br />         if (displayable == queryForm) { // MVDCABody<br />             if (command == exitCommand) { //MVDCABody<br />                 exitMIDlet(); // MVDCAAction3<br />             } else if (command == searchCommand) { // MVDCACase3<br />                 getDisplay().setCurrent(get_alert(), get_queryForm()); // MVDCAAction13<br />                 search();<br />             } // MVDCACase13<br />         } <br />         else if (displayable == resultForm) { <br />             if (command == exitCommand) {<br />                 exitMIDlet();// MVDCAAction16<br />             } <br />             else if (command == businessCommand) { // MVDCACase16<br />                 showBusiness();<br />                 // MVDCAAction38<br />             } <br />             else if (command == listingCommand) { // MVDCACase38<br />                 showListing();<br />                 // MVDCAAction36<br />             } <br />             else if (command == mapAllCommand) { // MVDCACase36<br />                 showAllOnMap();<br />                 // MVDCAAction48<br />             } <br />             else if (command == backCommand) {  // MVDCACase48<br />                 getDisplay().setCurrent(get_queryForm()); // MVDCAAction50<br />             } <br />             else if (command == callCommand) { // MVDCACase50<br />                 call();<br />                 // MVDCAAction52<br />             } <br />             else if (command == mapCommand) { // MVDCACase52<br />                 getDisplay().setCurrent(get_alert(), get_resultForm()); // MVDCAAction89<br />                 map();<br />             } <br />             else if (command == prevCommand) { // MVDCACase89<br />                 start = Math.max(1, start - DEFAULT_RESULT_COUNT);<br />                 getDisplay().setCurrent(get_alert());<br />                 search();<br />                 // MVDCAAction98<br />             } <br />             else if (command == nextCommand) { // MVDCACase98<br />                 start = Math.min(totalResultsAvailable, start + DEFAULT_RESULT_COUNT);<br />                 getDisplay().setCurrent(get_alert());<br />                 search();<br />                 // MVDCAAction96<br />             }<br />         } <br />         else if (displayable == mapForm) {<br />             if (command == mapBackCommand) { // MVDCACase96<br />                 getDisplay().setCurrent(get_resultForm()); // MVDCAAction65<br />             } <br />             else if (command == exitCommand) {// MVDCACase65<br />                 exitMIDlet(); // MVDCAAction7<br />             } <br />             else if (command == zoomOutCommand) {// MVDCACase67<br />                 mapZoomLevel = Math.min(++mapZoomLevel, MAX_MAP_ZOOM);<br />                 switchZoomLevel(); // MVDCAAction94<br />             }<br />             else if (command == zoomInCommand) { // MVDCACase94<br />                 mapZoomLevel = Math.max(--mapZoomLevel, MIN_MAP_ZOOM);<br />                 switchZoomLevel();                <br />             } <br />         }<br /> } <br />     <br /> <br />     public Display getDisplay() { // MVDGetDisplay<br />         return Display.getDisplay(this);<br />     } <br />     <br />     public void exitMIDlet() { // MVDExitMidlet<br />         getDisplay().setCurrent(null);<br />         destroyApp(true);<br />         notifyDestroyed();<br />     } <br />     <br />     public Form get_queryForm() {<br />         if (queryForm == null) { // MVDGetBegin2<br />             queryForm = new Form(&quot;Local Search&quot;, new Item[] { // MVDGetInit2<br />                 get_searchFor(),<br />                 get_location(),<br />                 get_street(),<br />                 get_sortGroup()<br />             });<br />             queryForm.addCommand(get_exitCommand());<br />             queryForm.addCommand(get_searchCommand());<br />             queryForm.setCommandListener(this); <br />         } <br />         return queryForm;<br />     } <br />     <br />     <br />     // MVDGetBegin5    <br />     public Command get_exitCommand() {<br />         if (exitCommand == null) { <br />             exitCommand = new Command(&quot;Exit&quot;, Command.EXIT, 1); // MVDGetInit5<br />         }<br />     }<br />     <br />     public Form get_resultForm() {<br />         if (resultForm == null) { // MVDGetBegin6<br />             resultForm = new Form(&quot;Results&quot;, new Item[0]); // MVDGetInit6<br />             resultForm.addCommand(get_mapCommand());<br />             resultForm.addCommand(get_listingCommand());<br />             resultForm.addCommand(get_businessCommand());<br />             resultForm.addCommand(get_mapAllCommand());<br />             resultForm.addCommand(get_callCommand());<br />             resultForm.addCommand(get_backCommand());<br />             resultForm.addCommand(get_exitCommand());<br />             resultForm.addCommand(get_nextCommand());<br />             resultForm.addCommand(get_prevCommand());<br />             resultForm.setCommandListener(this); <br />         } <br />         return resultForm;<br />     } <br /> <br />     public Command get_searchCommand() {<br />         if (searchCommand == null) { // MVDGetBegin12<br />             searchCommand = new Command(&quot;Search&quot;, Command.OK, 1); // MVDGetInit12<br />         }<br />         return searchCommand;<br />     }<br />     <br />     public Alert get_alert() {<br />         if (alert == null) { // MVDGetBegin14<br />             alert = new Alert(null, &quot;&quot;, null, AlertType.INFO); // MVDGetInit14<br />             alert.setTimeout(-2);<br />         }<br />         return alert;<br />     }<br />     <br />     public TextField get_searchFor() {<br />         if (searchFor == null) { // MVDGetBegin20<br />             searchFor = new TextField(&quot;Search For:&quot;, &quot;coffee&quot;, 120, TextField.ANY); // MVDGetInit20<br />         }<br />         return searchFor;<br />     }<br />     <br />     public TextField get_street() {<br />         if (street == null) { // MVDGetBegin21<br />             street = new TextField(&quot;Street:&quot;, null, 120, TextField.ANY); // MVDGetInit21<br />         }<br />         return street;<br />     } <br />     <br />     public TextField get_location() {<br />         if (location == null) { // MVDGetBegin24<br />             location = new TextField(&quot;Location:&quot;, &quot;95054&quot;, 120, TextField.ANY);//GEN-LINE:MVDGetInit24<br />         }<br />         return location;<br />     }<br /> <br />     public Command get_mapCommand() {<br />         if (mapCommand == null) { // MVDGetBegin33<br />             mapCommand = new Command(&quot;Map&quot;, Command.OK, 1);//GEN-LINE:MVDGetInit33<br />         }<br />         return mapCommand;<br />     }<br />     <br />     public Command get_listingCommand() { //GEN-BEGIN:MVDGetBegin35<br />         if (listingCommand == null) {<br />             listingCommand = new Command(&quot;Listing&quot;, Command.ITEM, 1); // MVDGetInit35<br />         }<br />         return listingCommand;<br />     }<br />     <br />     //GEN-BEGIN:MVDGetBegin37<br />     public Command get_businessCommand() {<br />         if (businessCommand == null) {<br />             businessCommand = new Command(&quot;Business&quot;, Command.ITEM, 1); // MVDGetInit37<br />         }<br />         return businessCommand;<br />     }<br />     <br />     // MVDGetBegin39<br /> <br />     public ChoiceGroup get_sortGroup() {<br />         if (sortGroup == null) {<br />             sortGroup = new ChoiceGroup(&quot;Sort Results By:&quot;, Choice.POPUP, new String[] { // MVDGetInit39<br />                 &quot;Distance&quot;,<br />                 &quot;Title&quot;,<br />                 &quot;Rating&quot;,<br />                 &quot;Relevance&quot;<br />             }, new Image[] {<br />                 null,<br />                 null,<br />                 null,<br />                 null<br />             });<br />             sortGroup.setSelectedFlags(new boolean[] {<br />                 true,<br />                 false,<br />                 false,<br />                 false<br />             }); <br />         }<br />         return sortGroup;<br />     }<br />     <br />     // MVDGetBegin47<br />     public Command get_mapAllCommand() {<br />         if (mapAllCommand == null) {<br />             mapAllCommand = new Command(&quot;Map All&quot;, Command.ITEM, 1); // MVDGetInit47<br />         }<br />         return mapAllCommand;<br />     }<br />     <br />     // MVDGetBegin49<br />     public Command get_backCommand() {<br />         if (backCommand == null) { <br />             backCommand = new Command(&quot;Back&quot;, Command.BACK, 1); // MVDGetInit49<br />         }<br />         return backCommand;<br />     }<br />     <br />     // MVDGetBegin51<br />     public Command get_callCommand() {<br />         if (callCommand == null) { <br />             callCommand = new Command(&quot;Call&quot;, Command.ITEM, 1); // MVDGetInit51<br />         }<br />         return callCommand;<br />     }<br />     <br />     // MVDGetBegin53<br />     public Form get_mapForm() {<br />         if (mapForm == null) {<br />             mapForm = new Form(&quot;Map&quot;, new Item[] {get_mapImageItem()}); // MVDGetInit53<br />             mapForm.addCommand(get_zoomInCommand());<br />             mapForm.addCommand(get_zoomOutCommand());<br />             mapForm.addCommand(get_mapBackCommand());<br />             mapForm.addCommand(get_exitCommand());<br />             mapForm.setCommandListener(this); <br />         }<br />         return mapForm;<br />     }<br />     <br />     // MVDGetBegin54<br />     public ImageItem get_mapImageItem() {<br />         if (mapImageItem == null) { <br />             mapImageItem = new ImageItem(&quot;&quot;, null, ImageItem.LAYOUT_DEFAULT, null); // MVDGetInit54<br />             mapImageItem.setLayout(Item.LAYOUT_CENTER | Item.LAYOUT_VCENTER);<br />         }<br />         return mapImageItem;<br />     }<br />     <br /> <br />     // MVDGetBegin55<br />     public Command get_mapBackCommand() {<br />         if (mapBackCommand == null) { <br />             mapBackCommand = new Command(&quot;Back&quot;, Command.BACK, 1); // MVDGetInit55<br />         }<br />         return mapBackCommand;<br />     } <br />     <br />     // método para aumentaro zoom <br />     // MVDGetBegin58<br />     public Command get_zoomInCommand() {<br />         if (zoomInCommand == null) {<br />             zoomInCommand = new Command(&quot;Zoom In&quot;, Command.ITEM, 1); // MVDGetInit58<br />         }<br />         return zoomInCommand;<br />     }<br />     <br />     // MVDGetBegin60<br />     public Command get_zoomOutCommand() {<br />         if (zoomOutCommand == null) { // MVDGetBegin60<br />             zoomOutCommand = new Command(&quot;Zoom Out&quot;, Command.ITEM, 1);//GEN-LINE:MVDGetInit60<br />         }<br />         return zoomOutCommand;<br />     }<br />         <br />     // MVDGetBegin90<br />     public Command get_selectCommand() {<br />         if (selectCommand == null) { <br />             selectCommand = new Command(&quot;Select&quot;, Command.OK, 1); // MVDGetInit90<br />         }<br />         return selectCommand;<br />     }<br />     <br />     // MVDGetBegin95    <br />     public Command get_nextCommand() {<br />         if (nextCommand == null) { <br />             nextCommand = new Command(&quot;Next&quot;, Command.ITEM, 1); // MVDGetInit95<br />         }<br />         return nextCommand;<br />     }<br />     <br />     // método que executa o comando/tela anterior diretamente<br />     // MVDGetBegin97<br />     public Command get_prevCommand() {<br />         if (prevCommand == null) { <br />             prevCommand = new Command(&quot;Previous&quot;, Command.ITEM, 1);//GEN-LINE:MVDGetInit97<br />         }<br />         return prevCommand;<br />     }<br />     <br />     private void switchZoomLevel() {<br />         final Image img = (Image) imageCache.get(new Integer(mapZoomLevel));<br />         if (img == null) {<br />             getDisplay().setCurrent(get_alert());<br />             map();<br />         } else {<br />             get_mapImageItem().setImage(img);<br />             getDisplay().setCurrent(get_mapForm());<br />         }<br />     }<br />     <br />     public void startApp() {<br />         initialize();<br />     }<br />     <br />     public void pauseApp() { }<br />     <br />     public void destroyApp(boolean unconditional) { }<br />     <br />     private void errorAlert(final String message, final Exception ex, final Displayable next) {<br />         final Alert alert = get_alert();<br />         final String exMsg = ex == null ? null : ex.getMessage();<br />         final String text = exMsg == null ? message : message + &quot;: &quot; + exMsg;<br />         alert.setString(text);<br />         alert.setTimeout(Math.max(3000, alert.getDefaultTimeout()));<br />         <br />         if (DEBUG)<br />             System.err.println(&quot;ERROR: &quot; + text);<br />         getDisplay().setCurrent(alert, next);<br />     }<br />     <br />     private Links getSelectedLink() {<br />         if (selectedItem == null || links == null) {<br />             errorAlert(&quot;No item selected!&quot;, null, get_resultForm());<br />             return null;<br />         }<br />         <br />         final String label = selectedItem.getLabel();<br />         if (label == null) {<br />             errorAlert(&quot;No item selected!&quot;, null, get_resultForm());<br />             return null;<br />         }<br />         <br />         for (int i=0; i &lt; links.length; i++) {<br />             if (label.equals(links[i].title))<br />                 return links[i];<br />         }        <br />         return null;<br />     }    <br />     private void map() {<br />         final Links link = getSelectedLink();<br />         if (link == null) {<br />             return;<br />         }<br />         <br />         final Arg[] args = {<br />             new Arg(&quot;output&quot;, &quot;json&quot;),<br />             new Arg(&quot;appid&quot;, APPID),<br />             new Arg(&quot;latitude&quot;, link.latitude),<br />             new Arg(&quot;longitude&quot;, link.longitude),<br />             new Arg(&quot;image_height&quot;, Integer.toString(get_mapForm().getHeight())),<br />             new Arg(&quot;image_width&quot;, Integer.toString(get_mapForm().getWidth())),<br />             new Arg(&quot;zoom&quot;, Integer.toString(mapZoomLevel))<br />         };        <br />         get_alert().setString(&quot;Getting map image location...&quot;);<br />         Request.get(MAP_BASE, args, null, this, get_mapForm());<br />     }<br />     <br />     private void mapResponse(final Response response) {        <br />         final Exception ex = response.getException();<br />         if (ex != null || response.getCode() != HttpConnection.HTTP_OK) {<br />             errorAlert(&quot;Error connecting to map service&quot;, ex, get_resultForm());<br />             return;<br />         }<br />         <br />         final Result result = response.getResult();<br />         final String location;<br />         try {<br />             location = result.getAsString(&quot;ResultSet.Result&quot;);<br />         } <br />         catch (ResultException rex) {<br />             errorAlert(&quot;Error extracting map location&quot;, rex, get_resultForm());<br />             return;<br />         }<br />         <br />         get_alert().setString(&quot;Getting map image...&quot;);<br />         <br />         final int imgResponseCode;<br />         final HttpConnection imgConn;<br />         try {<br />             imgConn = (HttpConnection) Connector.open(location);<br />             imgConn.setRequestProperty(&quot;Accept&quot;, &quot;image/png&quot;);<br />             imgResponseCode = imgConn.getResponseCode();<br />         } <br />         catch (IOException iex) {<br />             errorAlert(&quot;Error downloading map image&quot;, iex, get_resultForm());<br />             return;<br />         }<br />         <br />         if (imgResponseCode != HttpConnection.HTTP_OK) {<br />             errorAlert(&quot;HTTP error downloading map image: &quot; + imgResponseCode, null, get_resultForm());<br />             return;<br />         }<br />         <br />         final Image mapImage;<br />         try {<br />             final int totalToReceive = imgConn.getHeaderFieldInt(Arg.CONTENT_LENGTH, 0);<br />             final InputStream is = <br />                 new ProgressInputStream(imgConn.openInputStream(), totalToReceive, this, null, 512);        <br />             mapImage = Image.createImage(is);<br />         }<br />         catch (IOException iex) {<br />             errorAlert(&quot;Failed to create map image&quot;, iex, get_resultForm());<br />             return;<br />         }<br />         finally {<br />             try { imgConn.close(); } catch (IOException ignore) {}<br />         }        <br />         imageCache.put(new Integer(mapZoomLevel), mapImage);<br />         get_mapImageItem().setImage(mapImage);<br />         getDisplay().setCurrent(get_mapForm());<br />     }<br />     <br />     private void showAllOnMap() {<br />         launch(mapAllLink);<br />     }<br />     <br />     private void showListing() {<br />         final Links link = getSelectedLink();<br />         if (link == null)<br />             return;        <br />         launch(link.listing);<br />     }<br />     <br />     private void showBusiness() {<br />         final Links link = getSelectedLink();<br />         if (link == null)<br />             return;<br />         launch(link.business);<br />     }<br />     <br />     private void call() {<br />         final Links link = getSelectedLink();<br />         if (link == null) <br />             return;<br />         launch(&quot;tel:&quot; + stripPhoneNumber(link.tel));<br />     }<br />     <br />     private void launch(final String url) {<br />         final boolean exitNeeded;<br />         try {<br />             if (DEBUG) {<br />                 System.out.println(&quot;Launching Platform Request for: &quot; + url);<br />             }<br />             exitNeeded = platformRequest(url);<br />             if (exitNeeded) {<br />                 errorAlert(&quot;Please exit the MIDlet to access the page or to make the call&quot;, null, resultForm);<br />             }<br />         } catch (ConnectionNotFoundException cx) {<br />             errorAlert(url.substring(0, url.indexOf(':')) + &quot; connection not found for platformRequest&quot;, cx, resultForm);<br />         }<br />     }<br />     <br />     private void search() {        <br />         final Arg[] args = {<br />             new Arg(&quot;output&quot;, &quot;json&quot;),<br />             new Arg(&quot;appid&quot;, APPID),<br />             new Arg(&quot;query&quot;, searchFor.getString()),<br />             new Arg(&quot;location&quot;, location.getString()),<br />             new Arg(&quot;sort&quot;, sortGroup.getString(sortGroup.getSelectedIndex()).toLowerCase()),<br />             new Arg(&quot;start&quot;, Integer.toString(start)),<br />             null<br />         };<br />         <br />         final String str = street.getString();<br />         if (!&quot;&quot;.equals(str)) {<br />             args[6] = new Arg(&quot;street&quot;, str);<br />         }        <br />         get_alert().setString(&quot;Searching...&quot;);<br />         Request.get(LOCAL_BASE, args, null, this, get_resultForm());<br />     }<br />     <br />     private void searchResponse(final Response response) {        <br />         final Exception ex = response.getException();<br />         if (ex != null || response.getCode() != HttpConnection.HTTP_OK) {<br />             errorAlert(&quot;Error connecting to search service&quot;, ex, get_resultForm());<br />             return;<br />         }<br />         <br />         final Result result = response.getResult();<br />         try {<br />             mapAllLink = result.getAsString(&quot;ResultSet.ResultSetMapUrl&quot;);<br />             totalResultsAvailable = result.getAsInteger(&quot;ResultSet.totalResultsAvailable&quot;);<br />             final int resultCount = result.getSizeOfArray(&quot;ResultSet.Result&quot;);<br />             links = new Links[resultCount];<br />             get_resultForm().deleteAll();<br />             for (int i=0; i &lt; resultCount; i++) {<br />                 final String title = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].Title&quot;);<br />                 final String address = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].Address&quot;);<br />                 final String phone = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].Phone&quot;);<br />                 final String distance = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].Distance&quot;);<br />                 <br />                 links[i] = new Links();<br />                 links[i].title = title;<br />                 links[i].map = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].MapUrl&quot;);<br />                 links[i].listing = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].ClickUrl&quot;);<br />                 links[i].business = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].BusinessClickUrl&quot;);<br />                 links[i].tel = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].Phone&quot;);<br />                 links[i].latitude = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].Latitude&quot;);<br />                 links[i].longitude = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].Longitude&quot;);<br />                 <br />                 final String avgRating = result.getAsString(&quot;ResultSet.Result[&quot;+i+&quot;].Rating.AverageRating&quot;);<br />                 <br />                 final String displayString = <br />                     address + &quot;\n&quot; +<br />                     distance + &quot; miles&quot; +<br />                     (&quot;&quot;.equals(avgRating) ? &quot;&quot; : &quot;, &quot; + avgRating + &quot;*&quot;) + &quot;\n&quot; +<br />                     phone;<br />                 <br />                 final StringItem stringItem = new StringItem(title, displayString, StringItem.PLAIN);<br />                 stringItem.setLayout(Item.LAYOUT_NEWLINE_BEFORE | Item.LAYOUT_NEWLINE_AFTER | Item.LAYOUT_LEFT);<br />                 stringItem.setDefaultCommand(get_selectCommand());<br />                 stringItem.setItemCommandListener(new ItemCommandListener() {<br />                     public void commandAction(Command command, Item item) {<br />                         if (selectedItem != item) {<br />                             selectedItem = item;<br />                             imageCache.clear();<br />                         }<br />                     }<br />                 });<br />                 get_resultForm().append(stringItem);<br />             }<br />         } catch (ResultException rex) {<br />             errorAlert(&quot;Error extracting result information&quot;, rex, get_resultForm());<br />             return;<br />         }        <br />         getDisplay().setCurrent(get_resultForm());<br />     }<br />     <br />     private String stripPhoneNumber(final String str) {<br />         final char[] buf = new char[str.length()];<br />         str.getChars(0, buf.length, buf, 0);<br />         final StringBuffer sbuf = new StringBuffer(buf.length);<br />         for (int i=0; i &lt; buf.length; i++) {<br />             if (buf[i] == '(') { }<br />             else if (buf[i] == ')') { }<br />             else if (buf[i] == '-') { } <br />             else {<br />                 sbuf.append(buf[i]);<br />             }<br />         }<br />         return sbuf.toString();<br />     }<br />     <br />     public void readProgress(final Object context, final int bytes, final int total) {<br />         get_alert().setString(&quot;Read &quot; + bytes + (total &gt; 0 ? &quot;/&quot; + total : &quot;&quot;));<br />     }<br />     <br />     public void writeProgress(final Object context, final int bytes, final int total) {<br />         get_alert().setString(&quot;Wrote &quot; + bytes + (total &gt; 0 ? &quot;/&quot; + total : &quot;&quot;));<br />     }<br />     <br />     public void done(final Object context, final Response response) throws Exception {<br />         get_alert().setString(null);        <br />         if (context == mapForm) {<br />             mapResponse(response);<br />         } <br />         else if (context == resultForm) {<br />             searchResponse(response);<br />         }<br />         else {<br />             throw new IllegalArgumentException(&quot;unknown context returned: &quot; + context.toString());<br />         }<br />     }<br /> }<br /> [/code]<br /> <br /> Mais info sobre o exemplo: https://meapplicationdevelopers.dev.java.net/source/browse/meapplicationdevelopers/demobox/mobileajax/samples/midp/local/?rev=284<br /> Site oficial do Mojax -&gt; http://mojax.mfoundry.com/display/mojax/Main+Page]]></description>
				<guid isPermaLink="true">http://www.guj.com.br/prepost/70435/370057/mojax-mobile-ajax-exemplos
</guid>
				<link>http://www.guj.com.br/prepost/70435/370057/mojax-mobile-ajax-exemplos
</link>
				<pubDate><![CDATA[Sat, 29 Sep 2007 11:43:22]]> GMT</pubDate>
				<author><![CDATA[ liclopes]]></author>
			</item>
	</channel>
</rss>
