Build Your Own Windows Mobile RSS Reader

Build Your Own Windows Mobile RSS Reader

ith the recent introduction of the Windows Mobile 6 platforms, we are now beginning to see a proliferation of new devices supporting the Windows Mobile 6 Standard (aka Smartphone). Because Windows Mobile 6 Standard devices do not have touch screens, they pose certain challenges when developing applications to run on them. This article will show you how to develop a Windows Mobile 6 Standard application, and at the same time, build a useful RSS Reader application that you can actually use if you have one such device.

Building the User Interface
To get started, launch Visual Studio 2005 and create a new Windows Mobile 6 Standard application. Name the application RSSReader.

Author’s Note: You need to download the free Windows Mobile 6 Standard SDK in order to create the application detailed in this article.

Populate the default Form1 with the following controls (see Figure 1):

  • TreeView control
  • MenuItem controls

Add an ImageList control to Form1 and add three images to its Images property (see Figure 2).


Figure 1. Form1: Populating the default Form1 with the various controls.
 
Figure 2. Adding Images: Adding three images to the ImageList control.

Set the ImageList property of the TreeView control to ImageList1.

Add a new Windows Form to the project and populate it with a WebBrowser and MenuItem control (see Figure 3).

Figure 3. Form2: Adding a WebBrowser and MenuItem control to Form2.

Switch to the code behind of Form1 and import the following namespaces:

Imports System.IOImports System.NetImports System.XmlImports System.Text.RegularExpressions

Declare the following constants and variable:

Public Class Form1    '---constants for icons---    Const ICO_OPEN As Short = 0    Const ICO_CLOSE As Short = 1    Const ICO_POST As Short = 2    '---file containing the list of subscribed feeds---    Const FEEDS_LIST As String = "My DocumentsFeeds.txt"    '---used for displaying a wait message panel---    Dim displayPanel As Panel

Creating the Helper Methods
When RSS feeds are being downloaded, you would display a message on the screen so that users know that the application is busy (see Figure 4).

Figure 4. Operation Status: The device displays a message informing the user of the operation’s status.

For this purpose, you can improvise with the aid of the Panel and Label controls.

Define the CreatePanel() function so that you can dynamically create the message panel using a couple of Panel controls and a Label control, as shown in Listing 1.

Next, define the IsConnected() function to test whether the user is connected to the Internet:

    '---check whether you are connected to the Internet---    Private Function IsConnected() As Boolean        Try            Dim hostName As String = Dns.GetHostName()            Dim curhost As IPHostEntry = Dns.GetHostEntry(hostName)            Return curhost.AddressList(0).ToString() <> _               IPAddress.Loopback.ToString()        Catch ex As Exception            Return False        End Try    End Function

Basically, you compare the IP address of the device with that of localhost (127.0.0.1). As long as the device’s IP address is not 127.0.0.1, it is assumed that there is Internet connectivity (as shown in Listing 2).

Each post title and its description are separated by the ASCII character 3 and each posting is separated with the ASCII character 12. Notice that after the XML feed for an URL is downloaded, it is saved onto storage. This is to ensure that the application continues to work in offline mode (i.e. when user disconnects from the Internet). The URL of the feed is used as the filename, minus all the special characters inside within the URL, with the “.xml” extension appended. To strip off all the special characters in the URL, define the RemoveSpecialChars() function as follows:

Figure 5. Adding Posts: Adding each post to the TreeView control.

    '---removes special chars from an URL string---    Private Function RemoveSpecialChars(ByVal str As String) As String        Dim NewString As String = String.Empty        Dim reg As Regex = New Regex("[A-Z]|[a-z]")        Dim coll As MatchCollection = reg.Matches(str)        For i As Integer = 0 To coll.Count - 1            NewString = NewString + coll(i).Value        Next        Return NewString    End Function

Next, define the SubscribeFeed() function to subscribe to a feed and then add each individual post to the TreeView control (see Figure 5).

Next, for each node representing a feed, the Text property is set to the feed’s title and its URL is stored in the Tag property of the node. For each node representing a posting, the Text property is set to the posting’s title and its description is stored in the Tag property (see Listing 3).

Wiring Up all the Event Handlers
With the helper functions defined, it’s time to wire up all the event handlers for the various controls.

First, code the Form1_Load event handler, as shown in Listing 4.

When the form is first loaded, you have to create a root node for the TreeView control and load all existing feeds. All subscribed feeds are saved in a plain text file, with the following format:

Feed URL|Feed URL|Feed URL|

An example would be:

http://news.google.com/?output=rss|http://rss.cnn.com/rss/cnn_topstories.rss|

In the Subscribe MenuItem control’s Click event handler, prompt the user to input a feed’s URL and then subscribe to the feed. If the subscription is successful, save the feed URL to file:

'---Subscribe MenuItem control---    Private Sub mnuSubscribe_Click( _       ByVal sender As System.Object, _       ByVal e As System.EventArgs) _       Handles mnuSubscribe.Click        Dim url As String = InputBox( _           "Please enter the feed URL", "Feed URL", "http://")        If url <> String.Empty Then            '---if feed is subscribed successfully---            If SubscribeFeed(url) Then                '---save in feed list---                Dim textwriter As TextWriter                textwriter = File.AppendText(FEEDS_LIST)                textwriter.Write(url & "|")                textwriter.Close()            Else                MsgBox("Feed not subscribed. " & _                "Please check that you have entered " & _                "the correct URL and that you have " & _                "Internet access.")            End If        End If    End Sub

Whenever a node in the TreeView control is selected, perform a check to see if it is a posting node and enable/disable the MenuItem controls appropriately (see also Figure 6).

    '---fired when each node is selected---    Private Sub TreeView1_AfterSelect( _       ByVal sender As System.Object, _       ByVal e As System.Windows.Forms.TreeViewEventArgs) _       Handles TreeView1.AfterSelect        If e.Node.ImageIndex <> ICO_POST And _           e.Node.Parent IsNot Nothing Then            mnuUnsubscribe.Enabled = True            mnuRefreshFeed.Enabled = True        Else            mnuUnsubscribe.Enabled = False            mnuRefreshFeed.Enabled = False        End If    End Sub

Figure 6. Everything’s Working: Enabling/disabling the MenuItem controls.
 
Figure 7. Viewing the Post: Using the WebBrowser control in Form2.

When the user selects a post using the Select button on the navigation pad, Form2 containing the WebBrowser control will be loaded and its content set accordingly (see Figure 7). This is handled by the KeyDown event handler:

    '---when the user presses the Select key on the keypad---    Private Sub TreeView1_KeyDown( _       ByVal sender As Object, _       ByVal e As System.Windows.Forms.KeyEventArgs) _       Handles TreeView1.KeyDown        Dim node As TreeNode = TreeView1.SelectedNode        If (e.KeyCode = System.Windows.Forms.Keys.Enter) Then            '---Enter key was pressed---            If node.ImageIndex = ICO_POST Then                Dim frm2 As New Form2                With frm2                    .Text = node.Text                    .WebBrowser1.DocumentText = node.Tag                    .Show()                End With            End If        End If    End Sub

To unsubscribe a feed, you will need to remove the feed’s URL from the text file and then remove the feed node from the TreeView control. This is handled by the Unsubscribe MenuItem control, shown in Listing 5.

When the user needs to refresh a feed, first make a backup copy of the feed XML document and proceed to subscribe to the same feed again. If the subscription is successful, remove the node containing the old feed. If the subscription is not successful (such as device is disconnected from the Internet, etc), restore the backup feed XML document. This is handled by the Refresh Feed MenuItem control, shown in Listing 6.

Finally, in the Back MenuItem control in Form2, code its Click event handler as follows:

    Private Sub mnuBack_Click( _       ByVal sender As System.Object, _       ByVal e As System.EventArgs) _       Handles mnuBack.Click        Me.Hide()    End Sub

That’s it! Press F5 to test the application. If you are testing the application using an emulator, you need to cradle the emulator to ActiveSync first so that you have Internet connectivity on the emulator. To cradle the emulator to ActiveSync, select Tools | Device Emulator Manager… in Visual Studio 2005 and right-click on the emulator you want to test and select Cradle.

Windows Mobile 6 Basics
Now you know how to:

  • Use the TreeView control to display information hierarchically
  • Manipulate files and read and write to text files
  • Download files using the WebRequest and WebResponse classes
  • Manipulate XML files using XPath expressions

devx-admin

devx-admin

Share the Post:
Bold Evolution

Intel’s Bold Comeback

Intel, a leading figure in the semiconductor industry, has underperformed in the stock market over the past five years, with shares dropping by 4% as

Semiconductor market

Semiconductor Slump: Rebound on the Horizon

In recent years, the semiconductor sector has faced a slump due to decreasing PC and smartphone sales, especially in 2022 and 2023. Nonetheless, as 2024

Learn Web Security

An Easy Way to Learn Web Security

The Web Security Academy has recently introduced new educational courses designed to offer a comprehensible and straightforward journey through the intricate realm of web security.

Military Drones Revolution

Military Drones: New Mobile Command Centers

The Air Force Special Operations Command (AFSOC) is currently working on a pioneering project that aims to transform MQ-9 Reaper drones into mobile command centers

Tech Partnership

US and Vietnam: The Next Tech Leaders?

The US and Vietnam have entered into a series of multi-billion-dollar business deals, marking a significant leap forward in their cooperation in vital sectors like

Bold Evolution

Intel’s Bold Comeback

Intel, a leading figure in the semiconductor industry, has underperformed in the stock market over the past five years, with shares dropping by 4% as opposed to the 176% return

Semiconductor market

Semiconductor Slump: Rebound on the Horizon

In recent years, the semiconductor sector has faced a slump due to decreasing PC and smartphone sales, especially in 2022 and 2023. Nonetheless, as 2024 approaches, the industry seems to

Elevated Content Deals

Elevate Your Content Creation with Amazing Deals

The latest Tech Deals cater to creators of different levels and budgets, featuring a variety of computer accessories and tools designed specifically for content creation. Enhance your technological setup with

Learn Web Security

An Easy Way to Learn Web Security

The Web Security Academy has recently introduced new educational courses designed to offer a comprehensible and straightforward journey through the intricate realm of web security. These carefully designed learning courses

Military Drones Revolution

Military Drones: New Mobile Command Centers

The Air Force Special Operations Command (AFSOC) is currently working on a pioneering project that aims to transform MQ-9 Reaper drones into mobile command centers to better manage smaller unmanned

Tech Partnership

US and Vietnam: The Next Tech Leaders?

The US and Vietnam have entered into a series of multi-billion-dollar business deals, marking a significant leap forward in their cooperation in vital sectors like artificial intelligence (AI), semiconductors, and

Huge Savings

Score Massive Savings on Portable Gaming

This week in tech bargains, a well-known firm has considerably reduced the price of its portable gaming device, cutting costs by as much as 20 percent, which matches the lowest

Cloudfare Protection

Unbreakable: Cloudflare One Data Protection Suite

Recently, Cloudflare introduced its One Data Protection Suite, an extensive collection of sophisticated security tools designed to protect data in various environments, including web, private, and SaaS applications. The suite

Drone Revolution

Cool Drone Tech Unveiled at London Event

At the DSEI defense event in London, Israeli defense firms exhibited cutting-edge drone technology featuring vertical-takeoff-and-landing (VTOL) abilities while launching two innovative systems that have already been acquired by clients.

2D Semiconductor Revolution

Disrupting Electronics with 2D Semiconductors

The rapid development in electronic devices has created an increasing demand for advanced semiconductors. While silicon has traditionally been the go-to material for such applications, it suffers from certain limitations.

Cisco Growth

Cisco Cuts Jobs To Optimize Growth

Tech giant Cisco Systems Inc. recently unveiled plans to reduce its workforce in two Californian cities, with the goal of optimizing the company’s cost structure. The company has decided to

FAA Authorization

FAA Approves Drone Deliveries

In a significant development for the US drone industry, drone delivery company Zipline has gained Federal Aviation Administration (FAA) authorization, permitting them to operate drones beyond the visual line of

Mortgage Rate Challenges

Prop-Tech Firms Face Mortgage Rate Challenges

The surge in mortgage rates and a subsequent decrease in home buying have presented challenges for prop-tech firms like Divvy Homes, a rent-to-own start-up company. With a previous valuation of

Lighthouse Updates

Microsoft 365 Lighthouse: Powerful Updates

Microsoft has introduced a new update to Microsoft 365 Lighthouse, which includes support for alerts and notifications. This update is designed to give Managed Service Providers (MSPs) increased control and

Website Lock

Mysterious Website Blockage Sparks Concern

Recently, visitors of a well-known resource website encountered a message blocking their access, resulting in disappointment and frustration among its users. While the reason for this limitation remains uncertain, specialists

AI Tool

Unleashing AI Power with Microsoft 365 Copilot

Microsoft has recently unveiled the initial list of Australian clients who will benefit from Microsoft 365 (M365) Copilot through the exclusive invitation-only global Early Access Program. Prominent organizations participating in

Microsoft Egnyte Collaboration

Microsoft and Egnyte Collaboration

Microsoft has revealed a collaboration with Egnyte, a prominent platform for content cooperation and governance, with the goal of improving real-time collaboration features within Microsoft 365 and Microsoft Teams. This

Best Laptops

Top Programming Laptops of 2023

In 2023, many developers prioritize finding the best laptop for programming, whether at home, in the workplace, or on the go. A high-performing, portable, and user-friendly laptop could significantly influence

Renaissance Gaming Magic

AI Unleashes A Gaming Renaissance

In recent times, artificial intelligence has achieved remarkable progress, with resources like ChatGPT becoming more sophisticated and readily available. Pietro Schirano, the design lead at Brex, has explored the capabilities

New Apple Watch

The New Apple Watch Ultra 2 is Awesome

Apple is making waves in the smartwatch market with the introduction of the highly anticipated Apple Watch Ultra 2. This revolutionary device promises exceptional performance, robust design, and a myriad

Truth Unveiling

Unveiling Truths in Bowen’s SMR Controversy

Tony Wood from the Grattan Institute has voiced his concerns over Climate and Energy Minister Chris Bowen’s critique of the Coalition’s support for small modular nuclear reactors (SMRs). Wood points

Avoiding Crisis

Racing to Defy Looming Financial Crisis

Chinese property developer Country Garden is facing a liquidity challenge as it approaches a deadline to pay $15 million in interest associated with an offshore bond. With a 30-day grace

Open-Source Development

Open-Source Software Development is King

The increasingly digital world has led to the emergence of open-source software as a critical factor in modern software development, with more than 70% of the infrastructure, products, and services

Home Savings

Sensational Savings on Smart Home Security

For a limited time only, Amazon is offering massive discounts on a variety of intelligent home devices, including products from its Ring security range. Running until October 2 or while

Apple Unleashed

A Deep Dive into the iPhone 15 Pro Max

Apple recently unveiled its groundbreaking iPhone 15 Pro and iPhone 15 Pro Max models, featuring a revolutionary design, extraordinary display technology, and unrivaled performance. These new models are the first