Thursday, November 5, 2009

Build Your Own Tweets Widget for the Symbian Platform

If you are a Web developer interested in developing a social networking application such as a Twitter app that can retrieve tweets on a Series 60 Symbian phone, then here are code snippets to demonstrate how easy it is to implement it using Nokia Web Runtime using Javascript, and HTML.  If you are new to mobile Web development on Symbian, take a look at the Web Runtime Quickstart tutorial.

Now to retrieve tweets on a Series 60 Symbian phone, you can implement the index.html (see slide 11 in the presentation attached below), which will invoke init() function within main.js.  The init() function will simply instantiate the UIManager and set up the views (see slides 12 and 13). Then, if the user selects the 'Tweetz' icon, then Twitter.Update() will be invoked as listed below.  The function Twitter.Update() will simply initialize the twitter buttons including adding the separator, and will display "Loading twitter feed" as it waits for the twitter feed to download.

Twitter.prototype.Update= function(numToShow){
    this.numToShow= numToShow;
    if ( this.buttons== null ) {

       // add the separator
       var separator = new NavigationButton(null, 
                           "tweetz-icon.png","");
       separator.setEnabled(false);
       this.parentView.addControl(separator);
       // create buttons
       this.buttons= new Array();
       for( var i = 0 ; i < this.numToShow; i++ ) {
           var button = 

           new NavigationButton("twitter_button_"+i, 
                                 null ,"");
           this.parentView.addControl(button);

           this.buttons.push(button);
       }
       this.buttons[0].setText(

           "Loading twitter feed...");
    }


Next, initialize the twitter URL for getting a user's RSS feed. In this case, it is initialized to the TwitMyMobile user account. Then, you can get the RSS feed by instantiating the AJAX request. The http.open() API is passed, "GET" for retrieving the data, the second parameter is the twitter URL, and the third parameter is set to true to indicate that this is an asynchronous request. The http.onreadstatechange is set when the request state changes, then the Twitter.DoUpdate() function is invoked for parsing the returned data. The code fragment for getting the user's tweets will look as follows:



 // Twitter API for getting a user’s RSS feed 
var twitterurl= "http://twitter.com/statuses/user_timeline/TwitMyMobile.rss"; 


// Get the rss feed 
// Prepare for asynchronous download 
this.http= new Ajax(); // true means asynchronous request this.http.open("GET", twitterurl, true); 
// When the AJAX request is done, it will call self.DoUpdate() this.http.onreadystatechange= function() { self.DoUpdate(); }; 


// send the AJAX request 
this.http.send(null);


Now, the Twitter.DoUpdate() method can easily parse the data. Use the DOMParser API to parse through the response XML. If the content type is not set correctly, we get the response as text. Next, we loop through traversing the elements, creating buttons and gathering tweets. The while loop traverses through the child nodes, and retrieves the title, and publishing date for each of the tweets. The tweet image is set to tweet.png for simplicity. If we get any exceptions and get no data, then we display "Tweetz not tweeting right now" message and intialize the title and date fields accordingly.


Twitter.prototype.DoUpdate= function() {
    if (this.http.readyState== 4) {
        try {
            // Get parsed Doc 
            var xmlDoc= this.http.responseXML;
            if (xmlDoc== null)
            { // if the content type is not set  
              // correctly, we get the response 
              // as text 
              var xmlparser= new DOMParser(); 
              xmlDoc = xmlparser.parseFromString(
                       this.http.responseText, 
                       "text/xml");
              var itemElements =
                  xmlDoc.getElementsByTagName("item");
              var loopEnd =
                     Math.min(this.numToShow,
                              itemElements.length);
              // traverse elements & create buttons 
              for (var i = 0; i < loopEnd; i++) { 
                 // iterate through child nodes of 
                 // this item and gather tweets
                 var title = null; 
                 var date = null; 
                 node = itemElements[i].firstChild; 
                 while (node != null) { 
                    if (node.nodeType == 
                         Node.ELEMENT_NODE) {
                       if (node.nodeName == "title") { 
                          // item title 
                          title = getTextOfNode(node); 
                       }else if 
                         (node.nodeName== "pubDate" ||
                          node.nodeName== "dc:date") { 
                          // item publishing date 
                          date = getTextOfNode(node); 
                       } 
                 } end while  


                 node = node.nextSibling; 
             } // end for  
             this.buttons[i].setText("
                 + date + " " + title + "");
             this.buttons[i].setImage("tweet.png");
          } // end if (xmldoc== null
      } // end try
      catch (x) {
         this.buttons[0].setText(
           "Uh-Oh! Tweetz not tweeting right now.");
         for (var i = 0; i < this.numToShow; i++) {

            this.buttons[i].setText("");
            this.buttons[i].setImage(null); 
         } // end for  
      } // end catch
  } // if (this.http.readyState== 4) {} 


 For a complete listing of the code, take a look at the slides I had presented at SEE 2009 on Improving the Mobile Web Developer Experience illustrated below.  If you find this article useful, please feel free to retweet and forward me any comments.

Monday, October 19, 2009

Mobile 2.0: Developer Pitfalls & Strategies for Improving Mobile Web Developer Experience

Last Friday, I gave a presentation on Developer Pitfalls & Strategies for Improving Mobile Web Developer Experience at Mobile 2.0 in Silicon Valley (Mountain View, California).  It started out by defining the mobile Web, then provided an overview on the mobile device constraints that led to mobile development challenges. I briefly talked about the "Tool Trends" then took an in-depth look at strategies for improving performance when utilizing web technologies (i.e. JavaScript, CSS and HTML) based on Yahoo's 14 Performance Rules. It concluded highlighting the activities of the Symbian Foundation Tools team including a roadmap of how the Symbian tools are being evolved to further improve and enhance the mobile web developer experience.
In case you were not able to attend Mobile 2.0 or would like to take a closer look at the slides presented, it is attached below.

Monday, September 14, 2009

Implementing Incremental Project Builder for an Eclipse Web Runtime Plugin

In order to develop an Eclipse Plugin, you will need to install the Eclipse Plugin Development Environment (PDE) and for web development, you will need to install Eclipse Web Tools Platform (WTP).
This article discusses two major mechanisms that are associated with projects in an Eclipse workspace. The first of these is incremental project builders, which create a built state based on the project contents, and then keep that built state synchronized as the project contents change. The second is project natures, which define and manage the association between a given project and a particular plug-in or feature.



  • Builder - Builders take raw materials and produce some output based on those materials. In Eclipse, both the raw materials and the output of builders are resources in the Eclipse workspace.
  • Incremental - It would be inefficient if builders rebuilt their entire output from scratch every time they were invoked. Instead, builders in Eclipse are incremental. This means that after the first build, subsequent builds should only rebuild based on what has changed since the last build.
  • Project - A builder operates on the resources in a single project in the Eclipse workspace. If there are many projects in the workspace, builders need to be installed on each one separately.
How does the JavaScript compiler know which files need to be recompiled?

The Eclipse builder maintains a built state that includes a list of all types (classes or interfaces) that are referenced by each type in the workspace. This information is returned by the compiler each time a source file is compiled. This state is computed from scratch on a full build, and updated incrementally on each subsequent build.

Whenever files are modified, the builder receives a resource delta that describes which files were added, removed, or changed.

For deleted JavaScript source files, the corresponding class files are deleted. Added and changed source files are added to a queue of files that need to be compiled.

The builder then processes this queue as follows:  
  • Remove a file from the queue, and compile it.  
  • Compare the resulting type to the old class file, and see if the type has structural changes
  • Structural changes are changes that can affect the compilation of a referencing type: added or removed methods, fields or types, or changed method signatures. 
  • If the type has structural changes, find all types in the project that references the changed type, and add them to the queue. 
  • If the type has changed at all, write it to disk in the builder's output folder. Update the built state with the new reference information for the compiled type.  
  • Repeat until the queue is empty.  
  • As a final step, the builder generates problem markers for each compiled type that had compilation problems.
What are Project Natures?
Create an association between a project and a given tool, plug-in or feature set.  By adding a nature to a project, you indicate that your plug-in is configured to use that project.


Natures also provide a way of handling the lifecycle of a tool's interaction with a project.  When a nature is added to a project, the project nature's configure() method is called.  This gives the tool an opportunity to initialize its state for that project and install any incremental project builders that are needed for that project.  When a nature is removed from a project, the nature's deconfigure() method is called.  This gives the tool an opportunity to remove or clean up any meta-data it has created for that project, and to remove any listeners and builders associated with that tool.


How do we implement an Incremental Project Builder?  To implement an incremental project builder, you first have to create an extension: org.eclipse.core.resources.builders.  Next, create a Builder class that must extend the abstract IncrementalProjectBuilder superclass.

<extension
id="Builder"
name="eScript Builder"
point="org.eclipse.core.resources.builders">
<builder>
<run class="org.eclipse.escript.builder.Builder">
<parameter name="optimize" value="true"/>
<parameter name="comment" value="escriptBuilder"/>
</run>
</builder>
</extension>

public class Builder extends IncrementalProjectBuilder {

protected IProject[] build(int kind, Map args, IProgressMonitor monitor) { 
if (kind == IncrementalProjectBuilder.FULL_BUILD) { fullBuild(monitor);
} else { 
   IResourceDelta delta = getDelta(getProject()); 

if (delta == null) { 
   fullBuild(monitor); }
else { 
   incrementalBuild(delta, monitor); 
}

return null;
}

private void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) {
System.out.println("incremental build on "+delta);
try {

delta.accept(new IResourceDeltaVisitor()
{ public boolean visit(IResourceDelta delta) {
System.out.println("changed: "+
delta.getResource().getRawLocation());
return true; // visit children too
}
});
} catch (CoreException e) { e.printStackTrace(); }
}

private void fullBuild(IProgressMonitor monitor) {
    System.out.println("full build");
}
}

If you are interested in seeing a Web Runtime (WRT) Plugin demo in action, then come to the Symbian Silicon Valley SIG event on September 16.  If you found this article useful, please retweet it!

Friday, June 5, 2009

How to Share Photos & Contacts on iPhone

One of the most intuitive and appealing applications for sharing photos and contacts on the iPhone is called Mover developed by Infinite Labs.  Mover was developed for the iPhone.  No need for pairing. It only requires an iPhone or iPod Touch to be connected via WiFi network.  Mover is available now for download for free on App Store.



Here is how it works:
  1. Download the Mover app from iTunes App store and open it
  2. Click the '+' sign to add items that you wish to share with the other iPhone or iPod Touch
  3. Mover will display the options to "Add Image" or "Add Contact"
  4. After selection is made, an icon will appear on your iPhone or iPod Touch screen
  5. It will display the photo or contact along with an "arrow" (indicates the other iPhone device)
  6. Just slide the icon you want to transfer (towards the other device)
  7. To delete any item, select 'Edit' to remove the item (note: it does not remove it from the iPhone)
The photos and contacts transferred are automatically saved in the camera gallery and addressbook, respectively.

The transfer of photos may take some time depending on the image size, but the transfer of contacts is very fast and it even sends the contact's photo.

The Mover app is very intuitive and fun to use, but obviously only works on an iPhone or iPod Touch device.  You may want to take a closer look on YouTube

If you found this article useful, please add a rating, comment and retweet!

Thursday, June 4, 2009

Does the Palm Pre really live up to its hype?

Palm Pre is an internet connected multimedia smartphone designed and marketed by Palm, Inc., with a multi-touch screen and a sliding keyboard.  It has been the most highly anticipated gadget since the debut of the iPhone. Now that the Palm Pre is scheduled to launch on June 6, 2009, and will be the first to use Palm's new Linux-based WebOS operating system. Does it really live up to its hype?


Quick Features Overview:
  • Layered Calendars & Linked Contacts via Palm Synergy feature to bring together your Outlook, Google & Facebook calendars
  • Intuitive Notifications appear at the bottom of the screen to let you know what's going on
  • Universal Search for searching your contacts, and applications, or Google, Google Maps, Wikipedia or Twitter
  • Photos, Music and Videos 
  • Built-in Media Player supports MP3, AAC, AAC+, WAV and AMR music files, and MPEG4, H263 and H264 video formats
  • Download Applications from Palm Pre Catalog or buy movie tickets and add movie times right to your calendar
  • Activity Cards that allow opening multiple applications by flipping them, moving them around or throwing them off screen
  • Combined Messaging via Palm Synergy conversations grouped together in one chat-style view
  • Email, WiFi and GPS
  • Web browser is based on WebKit
  • Breakthrough Design (Slide out keyboard for faster texting, accelerometer will automatically change the orientation of the display between landscape and portrait mode for music, websites, photos & videos when the device is rotated in the user's hands)
Pros:
  • The Palm Pre is based on WebOS which is built around a system of "activity cards" used to manage multitasking.  The multitasking capabilities and system notifications are unparalleled.
  • The Palm Pre showcases a sharp display and supports multitouch gestures, enabling most navigational input to be made using the touchscreen. However, since it includes the slide-out keyboard, it does not include a virtual keyboard as many other touchscreen smartphones do.
  • The Palm Pre uses the WebOS' feature called Synergy that integrates well information from many sources. WebOS allows contacts from multiple sources (i.e. Gmail, Facebook and Exchange) to be integrated together.  Also, Calendars from multiple sources can be viewed together or one at a time. For messaging, Synergy combines all conversations with each contact into a single chat-style window.  
  • Palm Pre offers good call quality, and the wireless options include 3G, WiFi, Bluetooth and GPS.
Cons:
  • Palm Pre's keyboard is cramped
  • Battery life drains quickly and the smartphone can be sluggish at times
  • Lacks expansion slot, video recording capabilities, on-screen keyboard, flash support (Note: On Feb 16, 2009, Adobe announced that it will be developing a version of Adobe Flash Player for WebOS). 
  • Palm Pre App Catalog is still in beta and there are only a limited number of titles 
In summary, Palm Pre may not be the iPhone killer device just as yet. Nonetheless, Palm has made a solid and smart device that offers something more in its multitasking and personal information management capabilities. 

Finally, what are your thoughts on the Palm Pre?  Do you plan to develop your applications for the Palm Pre within the next 6 months?  If you found this article useful, please retweet!

Monday, May 4, 2009

Add YouTube Video On Your Twitter Page



TwitterAnalyzer, BubbleTweet, TwitZap and BubbleGuru are some of the many services that allow you to overlay a service on top of your Twitter page. VidTweeter lets you tweet YouTube, Vimeo and Dailymotion videos. All you have to do is to provide your Twitter user name, and select the type of video from a choice of YouTube, Vimeo or Dailymotion videos. When someone opens the URL you have tweeted, in this case, the YouTube video will play on top of your Twitter page as shown above. The cool thing is that you actually get to see how many people actually viewed your tweeted video!  If you found this article useful, please retweet

Click the link to see it in action: http://yttwt.com/xny5n

Friday, April 10, 2009

8 Nifty Twitter Mobile Clients

For any Twitter newbie, it can be a very daunting task when you first start twittering to figure out which Twitter client of the numerous others is appropriate for a specific mobile platform.  You quickly discover that it is hard to find a way to follow all of your Twitter updates without being interrupted constantly by a flow of updates. While you can update your status via SMS, keeping track of your friends and followers is difficult to do particularly while you are on the go.  Due to the huge success of the iPhone launch, there is no shortage of the number of Twitter clients out there on the iPhone or even other emerging platforms such as Android.  Below is a concised list of the more popular mobile Twitter applications listed by platform.
  1. Tiny Twitter (Java-enabled phones, Windows Mobile, Blackberry platform)                          
  2. TwitterBerry (Blackberry)
  3. CeTwit (Windows Mobile)
  4. Twitteresce (Java-enabled phones)
  5. Twibble (Java-enabled phones)
  6. Twinkle (iPhone)
  7. Twidroid (Google Android G1)
  8. Tweetie (iPhone)
Tiny Twitter is a twitter client for Java-enabled, Windows Mobile and Blackberry phones.
Features:
  • Set automatic update interval
  • Click update from [menu] to fetch friends timeline
  • Send tweets/direct message
  • Hide friends temporarily
  • Collapse tweets, hide user's image and truncate text to get more real estate
  • Retrieve direct message
Overall: good for mass-market phones, but other Twitter clients have better UI (see below)

Twitterberry is a mobile Twitter client for posting updates for the Blackberry platform.

Features:
  • Pictures support via TwitPic
  • ping.fm support
  • Timeline updates while device is sleeping
  • Audible/vibrate alerts
  • Retweet
  • Favorite
  • Delete
  • Picture support via TwitPic.com
  • Refresh timelines
  • Configurable auto-updating of timelines
  • Longer list of tweets: 200
  • View & reply to tweets and direct messages
  • Favorite and delete tweets from any timeline
  • View friends list
  • Allow overflow of 140 characters when typing your tweet
  • Optimize menu screen so most commonly used choices are easy to access
  • URLs in tweets can be selected and opened in your Blackberry browser
  • User customizable default application entry screen
  • BES connection support
Overall: best app for Blackberry

CeTwit is a Windows Mobile Twitter client written in C# leveraging the .net compact framework.


Features:
  • Timeline display
  • Account storage
  • Status updates
  • Direct Messages
  • Click to reply
  • Automated refresh
  • Smartphone support
  • Avatars in timeline
  • Local caching of avatars
  • Squeezer support
  • Relative timestamps
  • Follow/unfollow
  • Pictures support via TwitPic
  • ping.fm support
  • Timeline updates while device is sleeping
  • Audible/vibrate alerts
  • Retweet
  • Favorite 
  • Delete
Overall: Nicer UI compared to Tiny Twitter and fully featured, except for URL shortening

Twitteresce is a Twitter client for Java-enabled phones with a slick background for text updates.
Features:
  • Displays all status updates
  • Retrieve and delete tweets & direct messages
  • Autoupdate
  • Refresh rate
Overall: basic tweeting functionality for Java enabled phones, but lacks several nifty features


Twibble is a location-aware Twitter client that uses GPS on Blackberry Curve 8330 or Symbian phones like Nokia E71 or N95

Features:
  • Post Messages
  • Auto refresh
  • Notifications
  • Uploading of photos via TwitPic
  • Themes
  • Integrated tweets & direct messages displayed in a single list
  • Open web URLs within tweets
  • Retweet
  • Quick @replies
  • Follow users
  • Mark tweets as favorite
  • SSL support
  • Cancel network requests
  • Location-based (shows location of friends on a map) via GPS
Overall: good for Java-enabled phones or GPS supported phones

Twinkle is an iPhone client that has location aware features.



Features:
  • Discover, connect and send messages to people nearby
  • Upload photos and update your status on your Twitter account
  • Using the power of geolocation, join the discussion with the people around you
Overall: cool UI and looks slick on the iPhone

Twidroid is a Twitter client for the Google Android phone.

Tweetie is a full featured Twitter client for the iPhone and iPod Touch.

It offers everything you would want from your timeline to trends - all within an incredibly polished user interface, great performance and ease-of-use.
Features:
  • Handles multiple Twitter accounts
  • View  your timeline, replies and direct messages
  • Manage favorites
  • Browse friends and followers
  • Post new tweets, Retweet
  • Reply directly to tweets and send direct messages
  • Follow and unfollow people
  • Block/unblock users
  • Navigate reply chains
  • Inline web browser
  • Integrated with TwitPic for posting photos
  • Update Twitter location
  • Post tweets w/auto URL shortener
  • Uses secure connection (https)
  • View Twitter trends and custom searches
  • Nearby searching
  • Links to StockTwits
  • Optional landscape keyboard
  • Themes
There are several other Twitter clients that were developed earlier for the iPhone such as Twitterific, Twitterfon, Twittelator and Twinkle (above).  However, of all of them, my favorite one is Tweetie for the iPhone. Tweetie includes four main buttons: Tweets, Replies, Messages, Favorites.  Under More, you will find My Profile, Following, Followers, Trends and Search.  You can easily view @replies, see URL links directly in the inline browser, retweet messages, turn links in the browser into short URLs and much more. Perhaps, the only thing missing is that it doesn't let you browse the web and shorten a URL on the fly.  Tweetie is definitely a solid app overall and is probably the most full-featured Twitter client available for the iPhone to date.

What is your favorite Twitter mobile client? Please let me know in your comments.  If you found this article interesting, feel free to retweet (upper left corner) and follow me on Twitter.