<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>josecgomez.com &#187; Programming</title>
	<atom:link href="http://www.josecgomez.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.josecgomez.com</link>
	<description>The random thoughts of an IT professional.</description>
	<lastBuildDate>Wed, 18 Jan 2012 13:40:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sleeping Sort (the algorithm)</title>
		<link>http://www.josecgomez.com/2011/07/19/sleeping-sorting-algorithm/</link>
		<comments>http://www.josecgomez.com/2011/07/19/sleeping-sorting-algorithm/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 14:56:28 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Views]]></category>
		<category><![CDATA[Algorithms]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[Sorting]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=685</guid>
		<description><![CDATA[Credit where credit is due, I ran across this elsewhere a while ago and figured i&#8217;d give it a shot in C#, sadly I don&#8217;t remember where I saw  it, but either way I present to you a new awesome sorting algorithm. If all the stars align and your list is short enough this will sort properly! [...]]]></description>
			<content:encoded><![CDATA[<p>Credit where credit is due, I ran across this elsewhere a while ago and figured i&#8217;d give it a shot in C#, sadly I don&#8217;t remember where I saw  it, but either way I present to you a new awesome sorting algorithm.</p>
<pre class="brush: csharp; title: ; notranslate">
private static void Sort(List&lt;int&gt; integers)
        {
            foreach (int i in integers)
            {
                Thread t = new Thread(new ParameterizedThreadStart(display));
                t.Start(i);
            }
        }

        private static void display(object x)
        {
            int i = (int)x;
            Thread.Sleep(i * 100);
            Console.WriteLine(i);
        }
</pre>
<p>If all the stars align and your list is short enough this will sort properly!</p>
<p>*SHEERS*</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2011/07/19/sleeping-sorting-algorithm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Evernote Sticky Note</title>
		<link>http://www.josecgomez.com/2011/05/23/evernote-sticky-note/</link>
		<comments>http://www.josecgomez.com/2011/05/23/evernote-sticky-note/#comments</comments>
		<pubDate>Mon, 23 May 2011 17:52:18 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Evernote]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Evernote Sticky]]></category>
		<category><![CDATA[Sticky Note]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=656</guid>
		<description><![CDATA[Update 6/6/2011:New Version Released Minor Bug Fixes Update 6/2/2011:  New Version Released Application will automatically update next time it is launched. Added ability to create a new note from an active note by using Ctrl N Added ability to force Sync an active note by pressing Ctrl S Fixed a bug on the location Sync, [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 6/6/2011:New Version Released<br />
</strong></p>
<blockquote>
<ul>
<li><span style="font-weight: normal;">Minor Bug Fixes</span></li>
</ul>
</blockquote>
<hr />
<p><strong>Update 6/2/2011:  New Version Released<br />
Application will automatically update next time it is launched. </strong></p>
<blockquote>
<ul>
<li>Added ability to create a new note from an active note by using Ctrl N</li>
<li>Added ability to force Sync an active note by pressing Ctrl S</li>
<li>Fixed a bug on the location Sync, now it syncs based on percentage , not pixels, so it should look right in all computers</li>
<li>Added the ability to change font size by using Ctrl (Mouse Wheel)</li>
</ul>
</blockquote>
<hr />
<p>For quite a while new I have been a fan of <a href="http://evernote.com/">Evernote</a> its an awesome platform for creating and maintaining notes of all types that synchronize among all of your devices/platforms. The only thing that Evernote lacked in my opinion was the option of having a sticky note (See window 7 built in sticky note functionality below). This application is very usefull when you need to keep things fresh in your mind since they sit there on your desktop as a constant reminder. But it has the major downside that the notes reside only on your local desktop.</p>
<p><a href="http://www.youtube.com/watch?v=LCMMR154xy8">www.youtube.com/watch?v=LCMMR154xy8</a></p>
<p>It occurred to me that Evernote was uniquely qualified to implement a similar application but with the added advantage of ubiquitous synchronization across platforms / desktops.</p>
<p>Evernote Sticky is an application I wrote which takes advantage of the Evernote open API to allow you to have the same functionality of the Microsoft Sticky Notes with the above mentioned advantage of synchronization across platforms and desktops. It synchronizes not only the notes content, but color, font and screen position. Making having sticky notes a great tool.</p>
<p><a href="http://www.youtube.com/watch?v=SQPeWEjby5Q">www.youtube.com/watch?v=SQPeWEjby5Q</a></p>
<p>Features:</p>
<ul>
<li>Synchronizes across desktops and platforms.</li>
<li>Creates individual notebook for all the sticky notes</li>
<li>Synchronizes colors and fonts</li>
<li>Automatically launches new notes when they are created in a different location</li>
<li>Delivered to Click Once Install from Microsoft ensures that the application is always up to date.</li>
<li>Takes advantage of the Windows 7 Task Bar for application Interaction</li>
<li>Written in .NET 4.0 using C# and WPF</li>
<li>Create a new note from an active note by pressing Ctrl N</li>
<li>Force sync an active note by pressing Ctrl S</li>
<li>Change the font size by using Ctrl (Mouse Wheel)</li>
<li>Install it using <a href="http://www.josecgomez.com/apps/EverSticky/index.html">Click Once</a><sup>*</sup></li>
<li>Install it using <a href="http://www.josecgomez.com/wordpress/wp-content/uploads/2011/06/EvernoteSticky.zip">Setup.exe</a><sup>*</sup></li>
</ul>
<p><sup>*Both methods are maintained and  automatically updated when a new version is available.</sup></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2011/05/23/evernote-sticky-note/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>GOlang System Programming</title>
		<link>http://www.josecgomez.com/2010/09/08/go-system-programming/</link>
		<comments>http://www.josecgomez.com/2010/09/08/go-system-programming/#comments</comments>
		<pubDate>Wed, 08 Sep 2010 19:13:37 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[GO!]]></category>
		<category><![CDATA[Golang]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[System Language]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=575</guid>
		<description><![CDATA[GOlang takes a fresh spin at something we are all familiar with, it does it class and performance. I have recently had the chance to delve into the intricacies of GO and I have decided to dedicated part of my blog to it as a resource for future programmers.]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">Last year Google introduced Golang (GO) a system programming language.</p>
<p style="text-align: left;">&#8220;No major systems language has emerged in over a decade, but over that time the computing landscape has changed tremendously&#8221;</p>
<p style="text-align: left;">GOlang takes a fresh spin at something we are all familiar with, it does it with class and performance. I have recently had the chance to delve into the intricacies of GO for class and decided to dedicated part of my blog to it as a resource for future programmers.</p>
<p style="text-align: left;">I have acquired the ONLY GO Programming book available and will be posting a review shortly. I will also start to develop a library of simple examples to help everyone out!</p>
<p style="text-align: left;">GO&#8217;s official site is located at <a href="http://golang.org/">http://golang.org</a></p>
<p style="text-align: left;">The book which has been facilitated to me can be found at <a href="http://www.goprogrammingbook.com/">http://www.goprogrammingbook.com/</a></p>
<p style="text-align: left;"><a href="http://www.goprogrammingbook.com/"></a><img title="GO Lang" src="http://golang.org/doc/logo-153x55.png" alt="GO Lang" width="153" height="55" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2010/09/08/go-system-programming/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Instead of Insert Trigger</title>
		<link>http://www.josecgomez.com/2010/05/11/instead-of-insert-trigger/</link>
		<comments>http://www.josecgomez.com/2010/05/11/instead-of-insert-trigger/#comments</comments>
		<pubDate>Tue, 11 May 2010 14:16:03 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[triggers]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=501</guid>
		<description><![CDATA[Ever wanted to have an easy way to get the most recent entry for any given key on a massive database? I ran into this problem a few days ago at work and I wanted to attempt to explain how I solved it. We have a large database that contains the lifetime history of our [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to have an easy way to get the most recent entry for any given key on a massive database? I ran into this problem a few days ago at work and I wanted to attempt to explain how I solved it.</p>
<p>We have a large database that contains the lifetime history of our trucks GPS locations. The data in these tables is entered once every 10 seconds per truck, given the fact that we have about 30 trucks on average there are about 31536000 entries into this table per year and we have been running this program for several years now. We need a quick way to get the most recent location for every truck on the fleet regardless of whether it was last reported 10 seconds ago or 10 days ago.</p>
<p>For a while we had created a simple SQL query that returned the MAX(date) record for each given truck and this seemed to work all right. That is until yesterday evening, at that time the query that I just mentioned was taking somewhere in the realm of 10-15 minutes to execute, just long enough for our program to time out. Our table now contains somewhere in the realm of two billion records and this query is just not efficient enough. We attempted to optimize the query and gained some performance but not nearly enough to make a sustainable difference in the future.</p>
<p>The program that relies on this query is a real time monitoring system and we cannot sit there and wait for this to process during several minutes. An idea I had was to intercept the incoming stream and tag it as &#8220;most-recent&#8221; before insertion thus allowing a simple query such as &#8220;SELECT * FROM TABLE WHERE MOST-RECENT=true&#8221; would work. The challenge with this approach was, the interception of the data. We knew that we could write a simple database trigger, but had no idea if  would allow us to modify the incoming data stream.</p>
<p>Most of the database triggers happen after insertion, or update so this may have posed a problem. However it appears that Microsoft had thought about this for us and gave us &#8220;Instead of Insert&#8221; triggers. This triggers take the incoming data and allow you to do something with it other than actually inserting it into the database. We decided to take the incoming data, update the table to clear the &#8220;most-current&#8221; flag and then insert the data while updating the current records most-current flag. See the implementation below, we went from a 10 minute query to a milliseconds long query. And the overhead placed on the insert hasn&#8217;t posed a problem for the amount of data we receive.</p>
<pre class="brush: sql; title: ; notranslate">
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		Jose C Gomez
-- Create date: 5/10/2010
-- Description:	Trigger that allows us to keep track of the Vehicles most recent location
-- =============================================
CREATE TRIGGER InsteadofInsert
   ON  dbo.current_location
   INSTEAD OF INSERT
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for trigger here
--CLEAR THE OLDER MOST-RECENT FLAG
UPDATE current_location
SET most_current=0
WHERE most_current =1 AND  Device_ID in (SELECT Device_ID from Inserted);

--INSERT THE RECORD WITH THE MOST-RECENT FLAF SET TO TRUE (1)
INSERT INTO current_location
	SELECT Device_ID, Lat, Lon, date, ip_address, direction, speed ,1
	FROM Inserted

END
GO
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2010/05/11/instead-of-insert-trigger/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Android accessing RESTFull JSON Services Library</title>
		<link>http://www.josecgomez.com/2010/05/04/android-accessing-restfull-json-services-library/</link>
		<comments>http://www.josecgomez.com/2010/05/04/android-accessing-restfull-json-services-library/#comments</comments>
		<pubDate>Tue, 04 May 2010 15:22:43 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[RESTFull]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=428</guid>
		<description><![CDATA[As a follow up to my earlier post, I would like to make a jar library available that should allow you to access any RESTFull service that uses JSON. Simply import this jar file into your project and you should be good to go. Please note that the attached jar file contains a compiled copy [...]]]></description>
			<content:encoded><![CDATA[<p>As a follow up to my earlier post, I would like to make a jar library available that should allow you to access any RESTFull service that uses JSON. Simply import this jar file into your project and you should be good to go.</p>
<p>Please note that the attached jar file contains a compiled copy of the GSON library available at <a href="http://code.google.com/p/google-gson/">http://code.google.com/p/google-gson/</a>.</p>
<p>Click <a href="http://www.josecgomez.com/wordpress/wp-content/uploads/2010/05/josecgomez.com.android.webservices.json.jar">here</a> to download the jar file.</p>
<p>Once you have downloaded the above file and added it to your project you may use the following code to access a JSON web service.</p>
<p>The example shown here returns a collection of JSON objects in the form </p>
<pre class="brush: css; title: ; notranslate">
[
{&quot;alertid&quot;:&quot;1&quot;,&quot;alerttext&quot;:&quot;This is test&quot;,&quot;alertdate&quot;:&quot;2010-02-11 09:03:40&quot;},
{&quot;alertid&quot;:&quot;2&quot;,&quot;alerttext&quot;:&quot;Another alert&quot;,&quot;alertdate&quot;:&quot;2010-02-11 09:11:04&quot;},
{&quot;alertid&quot;:&quot;3&quot;,&quot;alerttext&quot;:&quot;This is third test&quot;,&quot;alertdate&quot;:&quot;2010-02-11 11:00:57&quot;},
{&quot;alertid&quot;:&quot;4&quot;,&quot;alerttext&quot;:&quot;message from starbucks&quot;,&quot;alertdate&quot;:&quot;2010-02-11 18:00:22&quot;}]
</pre>
<p> The class I implemented to hold these object is as follows </p>
<pre class="brush: java; title: ; notranslate">
public class alerts {

	public int alertid;
	public String alerttext;
	public String alertdate;

	@Override
	public String toString()
	{
		return &quot;Alert ID: &quot;+alertid+ &quot; Alert Text: &quot;+alerttext+ &quot; Alert Date: &quot;+alertdate;

	}
}
</pre>
<p>With the above class implemented, we can used the provided library to access the web-service available at http://www.sumasoftware.com/alerts/GetAlerts.php and parse its JSON repose back into our above mentioned java class.</p>
<pre class="brush: java; title: ; notranslate">
import josecgomez.com.android.webservices.json.WebService;
//Instantiate your web service call
WebService webService = new WebService(&quot;http://www.sumasoftware.com/alerts/GetAlerts.php&quot;);

//Pass the parameters needed to the service
Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
params.put(&quot;var&quot;,&quot;&quot;);
//Please note that this service doesn't have any required parameters and I am only passing these as an example
params.put(&quot;firstName&quot;, &quot;yName&quot;);
params.put(&quot;isActive&quot;, false);
//If you need to pass a JSON object as a parameter you may do so as follows
params.put(&quot;requiredObject&quot;, WebService.Object(myObject));

//Using GET
String response = webService.webGet(&quot;&quot;, params);
//You may pass it a method name if there is one as such
//String response = webService.webGet(&quot;METHODNAME&quot;, params);

//To retrieve an collection of objects
Type collectionType = new TypeToken&lt;List&lt;alerts&gt;&gt;(){}.getType();
List&lt;alerts&gt; lst= new Gson().fromJson(response, collectionType);

//Note that the above object alerts has to match the structure of our JSON object, please see the beginning of the post for an example. 

//To retrieve a single item instead of a collection
alerts alert = new Gson().fromJson(response, alerts.class);

//To use POST instead of get
webService.webInvoke(&quot;&quot;, params);
</pre>
<p> I hope this helps, feel free to use this library anywhere you want, the source code for it is available in an earlier post so if you&#8217;d like to modify it feel free to do so.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2010/05/04/android-accessing-restfull-json-services-library/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Android Putting Custom Objects in ListView</title>
		<link>http://www.josecgomez.com/2010/05/03/android-putting-custom-objects-in-listview/</link>
		<comments>http://www.josecgomez.com/2010/05/03/android-putting-custom-objects-in-listview/#comments</comments>
		<pubDate>Mon, 03 May 2010 13:50:02 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[ListView]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=394</guid>
		<description><![CDATA[Following up to my last post, I would like to show you in detail how to get our custom List to be shown in a ListView follow along. The first thing we need to do is create out layout files, I have for this example created two layout files, one called main and one called [...]]]></description>
			<content:encoded><![CDATA[<p>Following up to my last post, I would like to show you in detail how to get our custom List to be shown in a ListView follow along.</p>
<p>The first thing we need to do is create out layout files, I have for this example created two layout files, one called main and one called listitems the code is below.</p>
<p>main.xml</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
    android:orientation=&quot;vertical&quot;
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    &gt;
&lt;ListView
    android:layout_width=&quot;fill_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:id=&quot;@+id/lstText&quot;
    /&gt;
&lt;/LinearLayout&gt;
</pre>
<p>listitems.xml</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
	android:layout_width=&quot;fill_parent&quot; android:layout_height=&quot;fill_parent&quot;&gt;
	&lt;LinearLayout
	android:orientation=&quot;vertical&quot;
	android:layout_width=&quot;0dip&quot; android:layout_weight=&quot;1&quot;
	android:layout_height=&quot;fill_parent&quot;&gt;
		&lt;TextView
		android:layout_width=&quot;fill_parent&quot;
		android:layout_height=&quot;wrap_content&quot;
		android:id=&quot;@+id/txtAlertText&quot; /&gt;
		&lt;TextView
		android:layout_width=&quot;fill_parent&quot;
		android:layout_height=&quot;wrap_content&quot;
		android:id=&quot;@+id/txtAlertDate&quot; /&gt;
	&lt;/LinearLayout&gt;
&lt;/LinearLayout&gt;
</pre>
<p>Once you&#8217;ve done this you need to create an new ArrayAdapter class specific to your object as such</p>
<pre class="brush: java; title: ; notranslate">
package josecgomez.com.android.dev.webservice;

import java.util.List;

import josecgomez.com.android.dev.webservice.objects.alerts;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class AlertsAdapter extends ArrayAdapter&lt;alerts&gt; {

	int resource;
	String response;
	Context context;
	//Initialize adapter
	public AlertsAdapter(Context context, int resource, List&lt;alerts&gt; items) {
		super(context, resource, items);
		this.resource=resource;

	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		LinearLayout alertView;
		//Get the current alert object
		alerts al = getItem(position);

		//Inflate the view
		if(convertView==null)
		{
			alertView = new LinearLayout(getContext());
			String inflater = Context.LAYOUT_INFLATER_SERVICE;
			LayoutInflater vi;
			vi = (LayoutInflater)getContext().getSystemService(inflater);
			vi.inflate(resource, alertView, true);
		}
		else
		{
			alertView = (LinearLayout) convertView;
		}
		//Get the text boxes from the listitem.xml file
		TextView alertText =(TextView)alertView.findViewById(R.id.txtAlertText);
		TextView alertDate =(TextView)alertView.findViewById(R.id.txtAlertDate);

		//Assign the appropriate data from our alert object above
		alertText.setText(al.alerttext);
		alertDate.setText(al.alertdate);

		return alertView;
	}

}
</pre>
<p>Then on your main activity you may add this items to the list as shown below. Please keep in mind that this tutorial assumes you&#8217;ve correctly implemented my web service calls in a previous post.</p>
<pre class="brush: java; title: ; notranslate">
package josecgomez.com.android.dev.webservice;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import josecgomez.com.android.dev.webservice.objects.alerts;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

public class main extends Activity {
    /** Called when the activity is first created. */
	//ListView that will hold our items references back to main.xml
	ListView lstTest;
	//Array Adapter that will hold our ArrayList and display the items on the ListView
	AlertsAdapter arrayAdapter;

	//List that will  host our items and allow us to modify that array adapter
	ArrayList&lt;alerts&gt; alrts=null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //Initialize ListView
        lstTest= (ListView)findViewById(R.id.lstText);

         //Initialize our ArrayList
        alrts = new ArrayList&lt;alerts&gt;();
        //Initialize our array adapter notice how it references the listitems.xml layout
        arrayAdapter = new AlertsAdapter(main.this, R.layout.listitems,alrts);

        //Set the above adapter as the adapter of choice for our list
        lstTest.setAdapter(arrayAdapter);

        //Instantiate the Web Service Class with he URL of the web service not that you must pass
        WebService webService = new WebService(&quot;http://www.sumasoftware.com/alerts/GetAlerts.php&quot;);

        //Pass the parameters if needed , if not then pass dummy one as follows
		Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
		params.put(&quot;var&quot;, &quot;&quot;);

		//Get JSON response from server the &quot;&quot; are where the method name would normally go if needed example
		// webService.webGet(&quot;getMoreAllerts&quot;, params);
		String response = webService.webGet(&quot;&quot;, params);

		try
		{
			//Parse Response into our object
			Type collectionType = new TypeToken&lt;ArrayList&lt;alerts&gt;&gt;(){}.getType();

			//JSON expects an list so can't use our ArrayList from the lstart
			List&lt;alerts&gt; lst= new Gson().fromJson(response, collectionType);

			//Now that we have that list lets add it to the ArrayList which will hold our items.
			for(alerts l : lst)
			{
				alrts.add(l);
			}

			//Since we've modified the arrayList we now need to notify the adapter that
			//its data has changed so that it updates the UI
			arrayAdapter.notifyDataSetChanged();
		}
		catch(Exception e)
		{
			Log.d(&quot;Error: &quot;, e.getMessage());
		}
    }
}
 </pre>
<p>I hope this helps</p>
<p><a href="http://www.josecgomez.com/wordpress/wp-content/uploads/2010/05/emulator.png"><img src="http://www.josecgomez.com/wordpress/wp-content/uploads/2010/05/emulator-300x212.png" alt="" title="emulator" width="300" height="212" class="aligncenter size-medium wp-image-422" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2010/05/03/android-putting-custom-objects-in-listview/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>Android accessing RESTFull Web Services using JSON</title>
		<link>http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/</link>
		<comments>http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 13:31:05 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[Gson]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=379</guid>
		<description><![CDATA[I just finished a huge project for school using the Google Android OS. The biggest hurdle I had to jump through we getting android to successfully talk to web services. I have put together a set of classes and procedures to do so that make it easy and reliable. I have taken some code from [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished a huge project for school using the Google Android OS. The biggest hurdle I had to jump through we getting android to successfully talk to web services. I have put together a set of classes and procedures to do so that make it easy and reliable. I have taken some code from here and there and adapted my own. It was a while ago so I don&#8217;t recall where I found it all. For this example I am going to be using the web service  <a href="http://www.sumasoftware.com/alerts/GetAlerts.php">http://www.sumasoftware.com/alerts/GetAlerts.php</a> to read the alerts.</p>
<p>The first thing you&#8217;ll need to download and add to your project is the google GSON library <a href="http://code.google.com/p/google-gson/issues/list">http://code.google.com/p/google-gson/downloads/list</a></p>
<p><a href="http://code.google.com/p/google-gson/issues/list"></a>Add the jar file to your android project as an external jar</p>
<p>Download the following WebService.java class in order to interact with the web service and add it to your project</p>
<p>
<pre class="brush: java; title: ; notranslate">
package josecgomez.com.android.dev.webservice;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.client.params.CookiePolicy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.google.gson.Gson;

public class WebService{

    DefaultHttpClient httpClient;
    HttpContext localContext;
    private String ret;

    HttpResponse response = null;
    HttpPost httpPost = null;
    HttpGet httpGet = null;
    String webServiceUrl;

    //The serviceName should be the name of the Service you are going to be using.
    public WebService(String serviceName){
        HttpParams myParams = new BasicHttpParams();

        HttpConnectionParams.setConnectionTimeout(myParams, 10000);
        HttpConnectionParams.setSoTimeout(myParams, 10000);
        httpClient = new DefaultHttpClient(myParams);
        localContext = new BasicHttpContext();
        webServiceUrl = serviceName;

    }

    //Use this method to do a HttpPost\WebInvoke on a Web Service
    public String webInvoke(String methodName, Map&lt;String, Object&gt; params) {

    	JSONObject jsonObject = new JSONObject();

    	for (Map.Entry&lt;String, Object&gt; param : params.entrySet()){
    		try {
    			jsonObject.put(param.getKey(), param.getValue());
			}
    		catch (JSONException e) {
    			Log.e(&quot;Groshie&quot;, &quot;JSONException : &quot;+e);
			}
    	}
        return webInvoke(methodName,  jsonObject.toString(), &quot;application/json&quot;);
    }

    private String webInvoke(String methodName, String data, String contentType) {
        ret = null;

        httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);

        httpPost = new HttpPost(webServiceUrl + methodName);
        response = null;

        StringEntity tmp = null;        

        //httpPost.setHeader(&quot;User-Agent&quot;, &quot;SET YOUR USER AGENT STRING HERE&quot;);
        httpPost.setHeader(&quot;Accept&quot;,
&quot;text/html,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5&quot;);

        if (contentType != null) {
            httpPost.setHeader(&quot;Content-Type&quot;, contentType);
        } else {
            httpPost.setHeader(&quot;Content-Type&quot;, &quot;application/x-www-form-urlencoded&quot;);
        }

        try {
            tmp = new StringEntity(data,&quot;UTF-8&quot;);
        } catch (UnsupportedEncodingException e) {
            Log.e(&quot;Groshie&quot;, &quot;HttpUtils : UnsupportedEncodingException : &quot;+e);
        }

        httpPost.setEntity(tmp);

        Log.d(&quot;Groshie&quot;, webServiceUrl + &quot;?&quot; + data);

        try {
            response = httpClient.execute(httpPost,localContext);

            if (response != null) {
                ret = EntityUtils.toString(response.getEntity());
            }
        } catch (Exception e) {
            Log.e(&quot;Groshie&quot;, &quot;HttpUtils: &quot; + e);
        }

        return ret;
    }

    //Use this method to do a HttpGet/WebGet on the web service
    public String webGet(String methodName, Map&lt;String, String&gt; params) {
    	String getUrl = webServiceUrl + methodName;

    	int i = 0;
    	for (Map.Entry&lt;String, String&gt; param : params.entrySet())
    	{
    		if(i == 0){
    			getUrl += &quot;?&quot;;
    		}
    		else{
    			getUrl += &quot;&amp;&quot;;
    		}

    		try {
				getUrl += param.getKey() + &quot;=&quot; + URLEncoder.encode(param.getValue(),&quot;UTF-8&quot;);
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

    		i++;
    	}

        httpGet = new HttpGet(getUrl);
        Log.e(&quot;WebGetURL: &quot;,getUrl);

        try {
            response = httpClient.execute(httpGet);
        } catch (Exception e) {
            Log.e(&quot;Groshie:&quot;, e.getMessage());
        }

        // we assume that the response body contains the error message
        try {
            ret = EntityUtils.toString(response.getEntity());
        } catch (IOException e) {
            Log.e(&quot;Groshie:&quot;, e.getMessage());
        }

        return ret;
    }

    public static JSONObject Object(Object o){
    	try {
			return new JSONObject(new Gson().toJson(o));
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
    }

    public InputStream getHttpStream(String urlString) throws IOException {
        InputStream in = null;
        int response = -1;

        URL url = new URL(urlString);
        URLConnection conn = url.openConnection();

        if (!(conn instanceof HttpURLConnection))
            throw new IOException(&quot;Not an HTTP connection&quot;);

        try{
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setAllowUserInteraction(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod(&quot;GET&quot;);
            httpConn.connect(); 

            response = httpConn.getResponseCode();                 

            if (response == HttpURLConnection.HTTP_OK) {
                in = httpConn.getInputStream();
            }
        } catch (Exception e) {
            throw new IOException(&quot;Error connecting&quot;);
        } // end try-catch

        return in;
    }

    public void clearCookies() {
        httpClient.getCookieStore().clear();
    }

    public void abort() {
        try {
            if (httpClient != null) {
                System.out.println(&quot;Abort.&quot;);
                httpPost.abort();
            }
        } catch (Exception e) {
            System.out.println(&quot;Your App Name Here&quot; + e);
        }
    }
}
</pre>
</p>
<p>Based on the structure of your JSON file develop a class in your project to support the structure. For example for the above mentioned service I developed this class. </p>
<p>The JSON returned has this structure {&#8220;alertid&#8221;:&#8221;1&#8243;,&#8221;alerttext&#8221;:&#8221;This is test&#8221;,&#8221;alertdate&#8221;:&#8221;2010-02-11 09:03:40&#8243;}</p>
<p>
<pre class="brush: java; title: ; notranslate">
package josecgomez.com.android.dev.webservice.objects;

public class alerts {

	public int alertid;
	public String alerttext;
	public String alertdate;

	@Override
	public String toString()
	{
		return &quot;Alert ID: &quot;+alertid+ &quot; Alert Text: &quot;+alerttext+ &quot; Alert Date: &quot;+alertdate;

	}
}
</pre>
<p>Once you&#8217;ve done this in your android activity you may execute the following code to access the web service</p>
<p>
<pre class="brush: java; title: ; notranslate">
 // Instantiate the Web Service Class with he URL of the web service not that you must pass

        WebService webService = new WebService(&quot;http://www.sumasoftware.com/alerts/GetAlerts.php&quot;);

        //Pass the parameters if needed , if not then pass dummy one as follows
		Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
		params.put(&quot;var&quot;, &quot;&quot;);

		//Get JSON response from server the &quot;&quot; are where the method name would normally go if needed example
		// webService.webGet(&quot;getMoreAllerts&quot;, params);
		String response = webService.webGet(&quot;&quot;, params);

		try
		{
			//Parse Response into our object
			Type collectionType = new TypeToken&lt;List&lt;alerts&gt;&gt;(){}.getType();
			List&lt;alerts&gt; alrt = new Gson().fromJson(response, collectionType);

		}
		catch(Exception e)
		{
			Log.d(&quot;Error: &quot;, e.getMessage());
		}
</pre>
</p>
<p>Please note that the above code is for accessing collection of items, if you are attempting to access a single item there should be a slight modification to the code as follows</p>
<p>
<pre class="brush: java; title: ; notranslate">
/* Replace
Type collectionType = new TypeToken&lt;List&lt;alerts&gt;&gt;(){}.getType();
List&lt;alerts&gt; alrt = new Gson().fromJson(response, collectionType);
with
*/
alerts alert = new Gson().fromJson(response, alerts.class);
</pre>
</p>
<p>The above method uses GET if you need to INVOKE POST there should be a slight modification to the above code as follows. I hope this helps.</p>
<p>
<pre class="brush: java; title: ; notranslate">
/* Replace
String response = webService.webGet(&quot;&quot;, params);
with
*/
webService.webInvoke(&quot;&quot;, params);
</pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2010/04/30/android-accessing-restfull-web-services-using-json/feed/</wfw:commentRss>
		<slash:comments>57</slash:comments>
		</item>
		<item>
		<title>VS 2008 C# WYSIWYG HTML Editor</title>
		<link>http://www.josecgomez.com/2009/09/21/vs-2008-c-wysiwyg-html-editor/</link>
		<comments>http://www.josecgomez.com/2009/09/21/vs-2008-c-wysiwyg-html-editor/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 19:46:55 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=331</guid>
		<description><![CDATA[I&#8217;ve been busy at work lately one of the projects assigned to me is to create an application to redact and edit emails that will be sent to customers. This provided a great opportunity for me to get familiar with creating a custom control in C#. I needed a way to create rich content and although C# has the rich text control it [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been busy at work lately one of the projects assigned to me is to create an application to redact and edit emails that will be sent to customers. This provided a great opportunity for me to get familiar with creating a custom control in C#. I needed a way to create rich content and although C# has the rich text control it provides everything in RTF which is difficult to work with and hard to embed. So I got to work on my very own WYSIWYG control that produces HTML. So I am making it open source and available to anyone have fun and enjoy if you make any cool modifications to it let me know. I would love to include spell check ability but I don&#8217;t have much time to work on it right now.</p>
<p style="text-align: center;">Download Here <a href="http://www.josecgomez.com/wordpress/wp-content/uploads/2009/09/HTMLWYSIWYG.zip">HTMLWYSIWYG</a><br />
 <img class="aligncenter size-full wp-image-332" title="wysiwyg" src="http://www.josecgomez.com/wordpress/wp-content/uploads/2009/09/wysiwyg.png" alt="wysiwyg" width="510" height="500" /></p>
<p style="text-align: left;">Sample Uses</p>
<pre class="brush: csharp; title: ; notranslate">
 private void button1_Click_1(object sender, EventArgs e)
 {
 //Gets the HTML Code generated by the control
 Console.WriteLine( htmlwysiwyg1.getHTML())
 //Getts the PLain Tex code generated by the control.
 Console.WriteLine(htmlwysiwyg1.getPlainText());
 }
 </pre>
<pre class="brush: csharp; title: ; notranslate">
 private void frm_main_Load(object sender, EventArgs e)
 {
 //Sets the control to allow edits
 htmlwysiwyg1.allowEdit(true)
 //Loads the HTML into the control
 htmlwysiwyg1.setHTML(&quot;&lt;B&gt;BOLD&lt;/B&gt;&quot;);
 //Loads aditional fonts into the control
 htmlwysiwyg1.addFont(&quot;Cambria&quot;);
 }
 </pre>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2009/09/21/vs-2008-c-wysiwyg-html-editor/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>XML Config no more</title>
		<link>http://www.josecgomez.com/2009/03/26/xml-config-no-more/</link>
		<comments>http://www.josecgomez.com/2009/03/26/xml-config-no-more/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 19:33:56 +0000</pubDate>
		<dc:creator>Jose C Gomez</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Views]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[object oriented]]></category>
		<category><![CDATA[serialization]]></category>
		<category><![CDATA[wikipedia]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.josecgomez.com/?p=262</guid>
		<description><![CDATA[This may make me sound like I am antiquated and behind the times, and in this aspect you are probably right. Since I started messing with programming quite a few years ago, I&#8217;ve tried to make the programs I write as user friendly and as easy to maintain as possible. Recently I have adopted a few [...]]]></description>
			<content:encoded><![CDATA[<p>This may make me sound like I am antiquated and behind the times, and in this aspect you are probably right. Since I started messing with programming quite a few years ago, I&#8217;ve tried to make the programs I write as user friendly and as easy to maintain as possible. Recently I have adopted a few things I&#8217;ve picked up from others like making the methods in my programs accessible through web services when it has merit and things of the sort.</p>
<p>One of the things I have always done is provide extensive config files in XML format in order to alleviate having to modify the code when simple things change such as passwords, database names, host addresses etc. This has in my opinion always been a great venue to ensure maintainability and stability. But the big issue always was XML..</p>
<blockquote><p>XML (Extensible Markup Language) is a general-purpose specification for creating custom markup languages.[1] It is classified as an extensible language, because it allows the user to define the mark-up elements. XML&#8217;s purpose is to aid information systems in sharing structured data, especially via the Internet, [2] to encode documents, and to serialize data; in the last context, it compares with text-based serialization languages such as JSON, YAML and S-Expressions. [3] <br />
<a href="http://en.wikipedia.org/wiki/XML" target="_blank">more&#8230;</a></p>
</blockquote>
<p><br class="spacer_" />The problem I&#8217;ve always had with XML is parsing the file; although the support for it and the built in tools have improved greatly over the past few years it still requires considerable amount of code in order to gather the data in some languages (C#), and another considerable amount of code in order to update or change the data in the file. When I was learning Object Oriented programming a while back we were introduced to the concept of Serialization</p>
<blockquote><p>In computer science, in the context of data storage and transmission, serialization is the process of converting an object into a sequence of bits so that it can be stored on a storage medium (such as a file, or a memory buffer) or transmitted across a network connection link. When the resulting series of bits is reread according to the serialization format, it can be used to create a semantically identical clone of the original object. For many complex objects, such as those that make extensive use of references, this process is not straightforward.<br />
<a href="http://en.wikipedia.org/wiki/Serialization" target="_blank">more&#8230;</a></p>
</blockquote>
<p>But like the Wikipedia definition above says &#8220;this process is not straightforward&#8221;, you used to have to define Interfaces and formats and if your object had any kind of list or array in it, you couldn&#8217;t use it unless you wanted to spend a considerable amount of time making it work.</p>
<p>While I was working on the practice projects I grew to hate Serialization and had not used it since. Yesterday in a fit of rage, because my XML config file was being stubborn I stumbled across an implementation that used a Serialized object for storing configuration. I was baffled by the ease in which this was accomplished and I immediately implemented it. Now it its extremely easy to add and remove config parameters from my program and at the same time I don&#8217;t have to worry about someone deleting or changing the config file since it is stored in binary and gets re-created if deleted.</p>
<p>In order to serialize an object your class must be declared as <span style="font-size: x-small;">[</span><span style="font-size: x-small; color: #2b91af;">Serializable</span><span style="font-size: x-small;">] . After you have done this, the below example will take care of the serialization for you.</span></p>
<p><span style="font-size: x-small;"><span style="font-size: x-small; color: #008000;">//Serialize an Object<br />
</span><span style="font-size: x-small; color: #2b91af;">FileStream</span><span style="font-size: x-small;">fs = </span><span style="font-size: x-small; color: #0000ff;">new</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #2b91af;">FileStream</span><span style="font-size: x-small;">(</span><span style="font-size: x-small; color: #a31515;">@&#8221;prog.conf&#8221;</span><span style="font-size: x-small;">, </span><span style="font-size: x-small; color: #2b91af;">FileMode</span><span style="font-size: x-small;">.Create); <span style="color: #008000;">//Create new File where the object will live</span><br />
</span><span style="font-size: x-small; color: #2b91af;">BinaryFormatter</span><span style="font-size: x-small;"> bf = </span><span style="font-size: x-small; color: #0000ff;">new</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #2b91af;">BinaryFormatter</span><span style="font-size: x-small;">(); <span style="color: #008000;">//Create new BinaryFormatter to Serilize Object</span><br />
bf.Serialize(fs, YOUROBJECT); <span style="color: #008000;">//Serialize Object</span><br />
fs.Close(); <span style="color: #008000;">//Close File</span><br />
</span></span></p>
<p><span style="color: #008000;">//Deserialize<br />
</span><span style="color: #2b91af;">FileStream</span>fs = <span style="color: #0000ff;">new</span><span style="color: #2b91af;">FileStream</span>(<span style="color: #a31515;">@&#8221;prog.conf&#8221;</span>,<span style="font-size: x-small; color: #2b91af;">FileMode</span><span style="font-size: x-small;">.Open);  <span style="color: #008000;">//Open File Containing Serialized Object</span><br />
</span><span style="font-size: x-small;"><span style="color: #2b91af;">YOUROBJECT</span> obj = (<span style="color: #2b91af;">YOUROBJECT</span></span><span style="font-size: x-small;">) (</span><span style="font-size: x-small; color: #0000ff;">new</span><span style="font-size: x-small;"> </span><span style="font-size: x-small; color: #2b91af;">BinaryFormatter</span><span style="font-size: x-small;">().Deserialize(fs));<br />
fs.Close(); <span style="color: #008000;">//Close File</span></span></p>
<p>Remember to include the System.IO and System.Runtime.Serialization.Formatters.Binary libraries.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.josecgomez.com/2009/03/26/xml-config-no-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

