<?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>Simon&#039;s Wonder World</title>
	<atom:link href="http://blog.simonstahl.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.simonstahl.com</link>
	<description>Just another European geek in Silicon Valley</description>
	<lastBuildDate>Tue, 19 Apr 2011 22:01:51 +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>Parallel Image loading performance in Android</title>
		<link>http://blog.simonstahl.com/2011/03/22/parallel-image-loading-performance-in-android/</link>
		<comments>http://blog.simonstahl.com/2011/03/22/parallel-image-loading-performance-in-android/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 09:25:35 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[AsyncTask]]></category>
		<category><![CDATA[image download]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=166</guid>
		<description><![CDATA[I just ran into the problem that I have to load a whole bunch of images in an Android application, so I wondered about the performance of parallel image loading and how many images can be loaded simultaneously. Therefore I wrote a small benchmark app that loads about 100 images (each between 4 and 7 KB) from [...]]]></description>
			<content:encoded><![CDATA[<p>I just ran into the problem that I have to load a whole bunch of images in an Android application, so I wondered about the performance of parallel image loading and how many images can be loaded simultaneously. Therefore I wrote a small benchmark app that loads about 100 images (each between 4 and 7 KB) from a webpage. I admit, the app could be written better, but for my purpose it should be fine.</p>
<p>I measured the time in seconds that it took to load all images <strong>without </strong>displaying them in a View. 0 Threads means that all images were loaded in a sequence. A Thread count above 0 means that I created a new AsyncTask for each image and ran n of them at the same time.</p>
<p><a href="http://blog.simonstahl.com/wp-content/uploads/2011/03/ImageLoading.png"><img class="aligncenter size-full wp-image-167" title="Parallel image loading performance" src="http://blog.simonstahl.com/wp-content/uploads/2011/03/ImageLoading.png" alt="" width="516" height="387" /><span id="more-166"></span></a></p>
<h3>Emulator Eclair 2.1</h3>
<p>Eclair did well in the emulator between around 3 and 40 simultaneous downloads. It became pretty critical above 50 though. When i tried 100 downloads at the same time, it just stopped to work. The app did not crash, but the downloads seemed to stop completely and no progress was visible anymore.</p>
<h3>Emulator Gingerbread 2.3</h3>
<p>Interestingly, the emulator with Gingerbread did way worse then Eclair, but it was OK until around 30 parallel downloads. Gingerbread even had problems to create the AsyncTasks. Even when I tried 100 parallel downloads, I could never create and run more than 75 AsyncTasks at the same time. At least the app ran until the end, but the used time for 100 parallel downloads is just beyond the acceptable.</p>
<h3>Nexus One Gingerbread 2.3.3 (T-Mobile)</h3>
<p>Well, the difference from the emulator to my Nexus One was impressive. I got the best result with 20 simultaneous downloads in 7 seconds, but the whole range from 3 to 50 parallel downloads was fine and never over 11 seconds. I think that is a pretty good time.</p>
<p>At the end I would suggest not to go over around 20 or 30 simultaneous downloads. In that way it&#8217;s still tolerable in the emulator as well as on phones with slower download rates.</p>
<p>It would be interesting though to see similar performance tests with other phones and carriers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2011/03/22/parallel-image-loading-performance-in-android/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login to the Foursquare API v2 from Android with OAuth</title>
		<link>http://blog.simonstahl.com/2011/03/16/login-with-oauth-to-the-foursquare-api-v2-from-android/</link>
		<comments>http://blog.simonstahl.com/2011/03/16/login-with-oauth-to-the-foursquare-api-v2-from-android/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 07:50:42 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Social]]></category>
		<category><![CDATA[Foursquare]]></category>
		<category><![CDATA[OAuth]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=147</guid>
		<description><![CDATA[Once you figured out how OAuth works, you might ask yourself how this principle works from within a native Android app. It&#8217;s actually easier then expected at first. There exist some libraries that can make our life somehow easier, but I decided not to use any of them and to do everything from scratch. This [...]]]></description>
			<content:encoded><![CDATA[<p>Once you figured out how OAuth works, you might ask yourself how this principle works from within a native Android app. It&#8217;s actually easier then expected at first. There exist some libraries that can make our life somehow easier, but I decided not to use any of them and to do everything from scratch.</p>
<p><strong>This is the OAuth workflow for Foursquare:</strong></p>
<ul>
<li>A call to the Foursquare server is made with the client id and a redirect URL (has to be in a browser)</li>
<li>The user accepts the access request of the application</li>
<li>Foursquare calls the redirect URL with special code as parameter</li>
<li>The Foursquare server has to be called again with the client id, client secret, the code and the redirect URL (not in the browser anymore)</li>
<li>Foursquare returns now the access token which has to be saved by the app</li>
<li>Further calls to the Foursquare API can be made with the token</li>
</ul>
<p><span id="more-147"></span>The only problem in this workflow is how we can make the first call in the browser and then return to our app.</p>
<p>OK, we&#8217;re going to register out app first as an OAuth Consumer at Foursquare. Define the Callback URL as &#8220;simontest-android-app://&#8221;. You can do so <a title="Foursquare OAuth Consumer registration" href="https://foursquare.com/oauth/">here</a>.</p>
<p>Now, we create a new Android project and <strong>give it the INTERNET permission</strong>.</p>
<p>Then open the Manifest file and add the following filter to the &lt;application&gt; tag:</p>
<pre class="brush:xml">&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
	&lt;activity android:name=".LoginTest" android:label="@string/app_name"&gt;
		&lt;intent-filter&gt;
			&lt;action android:name="android.intent.action.MAIN" /&gt;
			&lt;category android:name="android.intent.category.LAUNCHER" /&gt;
		&lt;/intent-filter&gt;

		&lt;!-- Add this filter --&gt;
		&lt;intent-filter&gt;
 			&lt;action android:name="android.intent.action.VIEW" /&gt;
 			&lt;category android:name="android.intent.category.DEFAULT" /&gt;
 			&lt;category android:name="android.intent.category.BROWSABLE" /&gt;
 			&lt;data android:scheme="simontest-android-app" /&gt;
 		&lt;/intent-filter&gt;

 	&lt;/activity&gt;
&lt;/application&gt;</pre>
<p>This maps the schema &#8220;simontest-android-app&#8221; to this activity.</p>
<p>Now it&#8217;s time to start the coding. Add a button or something to your UI and add a click listener to it, which calls this method:</p>
<pre class="brush:java">private void loginToForsquare() {
	// Call the webbrowser with the Foursquare OAuth login URL
	Intent intent = new Intent(Intent.ACTION_VIEW);
	intent.setData(
	      Uri.parse(
	    		  "https://foursquare.com/oauth2/authenticate" +
	    		  "?client_id=" +CLIENT_ID +
	    		  "&amp;response_type=code" +
	    		  "&amp;redirect_uri=simontest-android-app://"));
	startActivity(intent);
}</pre>
<p>This will open the browser where the user can accept or deny our app to access his Foursquare data. After that the browser will automatically be redirected to the Callback URL &#8220;simontest-android-app://&#8221; which we have previously mapped to our activity. The activity will be called and we can check for the expected parameter in the onResume() method:</p>
<pre class="brush:java">public void onResume() {
	super.onResume();

    // extract the OAUTH access token if it exists
    Uri uri = this.getIntent().getData();
    if(uri != null) {
    	String code = null;

    	// Check if ther is a parameter called "code"
    	if((code = uri.getQueryParameter("code")) != null){

			try {
				// Call Foursquare again to get the access token
				JSONObject tokenJson = executeHttpGet(
						"https://foursquare.com/oauth2/access_token" +
						"?client_id=" + CLIENT_ID +
						"&amp;client_secret=" + CLIENT_SECRET +
						"&amp;grant_type=authorization_code" +
						"&amp;redirect_uri=simontest-android-app://" +
						"&amp;code=" + code);

				String token = tokenJson.getString("access_token");

				// TODO save token

				// Get userdata of myself
				JSONObject userJson = executeHttpGet(
						"https://api.foursquare.com/v2/" +
						"users/self" +
						"?oauth_token=" +token);

				// Get return code
				int returnCode = Integer.parseInt(userJson.getJSONObject("meta").getString("code"));

				// 200 = OK
				if(returnCode == 200){
					// output data
					Log.i("LoginTest", userJson.getJSONObject("response").getJSONObject("user").toString());
				}else{
					Toast.makeText(this, "Wrong return code: " +code, Toast.LENGTH_SHORT).show();
				}
			} catch (Exception exp) {
				Log.e("LoginTest", "Login to Foursquare failed", exp);
			}
    	}else if((code = uri.getQueryParameter("error")) != null){
    		Toast.makeText(this, code, Toast.LENGTH_SHORT).show();
    	}else{
    		Toast.makeText(this, "Unknown login error", Toast.LENGTH_SHORT).show();
    	}
    }
}

// Calls a URI and returns the answer as a JSON object
private JSONObject executeHttpGet(String uri) throws Exception{
	HttpGet req = new HttpGet(uri);

	HttpClient client = new DefaultHttpClient();
	HttpResponse resLogin = client.execute(req);
	BufferedReader r = new BufferedReader(
			new InputStreamReader(resLogin.getEntity()
					.getContent()));
	StringBuilder sb = new StringBuilder();
	String s = null;
	while ((s = r.readLine()) != null) {
		sb.append(s);
	}

	return new JSONObject(sb.toString());
}</pre>
<p>And that is already everything. You just might wanna save the token after you&#8217;ve got it so you don&#8217;t have to login to Foursquare the next time the user starts your app.</p>
<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2011/03/16/login-with-oauth-to-the-foursquare-api-v2-from-android/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Geek and non-geek places to see in and around Silicon Valley</title>
		<link>http://blog.simonstahl.com/2011/01/03/geek-and-non-geek-places-to-see-in-and-around-silicon-valley/</link>
		<comments>http://blog.simonstahl.com/2011/01/03/geek-and-non-geek-places-to-see-in-and-around-silicon-valley/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 03:32:17 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[A European in California]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[places]]></category>
		<category><![CDATA[silicon valley]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=108</guid>
		<description><![CDATA[I&#8217;m already for a while in the Silicon Valley now, so I thought it would be time to publish a list of places in this area that I like. Some of them might be just interesting for Tech Geeks, others for everyone.  The list is of course not complete and I will amend it as [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m already for a while in the Silicon Valley now, so I thought it would be time to publish a list of places in this area that I like. Some of them might be just interesting for Tech Geeks, others for everyone.  The list is of course not complete and I will amend it as I&#8217;ll explore new places.</p>
<ul>
<li><a title="Googleplex" href="#googleplex" target="_self">Googleplex</a></li>
<li><a title="Tech Museum of Innovation" href="#thetech" target="_self">San Jose Tech Museum of Innovation</a></li>
<li><a title="Mountain View Downtown" href="#mv_downtown" target="_self">Mountain View Downtown</a></li>
<li><a title="Computer History Museum" href="#computer_history_museum">Computer History Museum</a></li>
<li><a title="Lake Tahoe" href="#tahoe" target="_self">Lake Tahoe</a></li>
<li><a title="Apple Mothership" href="#apple" target="_self">Apple Mothership</a></li>
<li><a title="Berkley University" href="#berkley" target="_self">Berkley University</a></li>
<li><a title="Santa Cruz" href="#santa_cruz" target="_self">Santa Cruz</a></li>
<li><a title="The Castro" href="#the_castro" target="_self">San Francisco Castro District</a><span id="more-108"></span></li>
</ul>
<h2 id="googleplex">Googleplex</h2>
<div id="attachment_133" class="wp-caption alignright" style="width: 160px"><img class="size-thumbnail wp-image-133" title="Biggest Nexus One @ Googleplex" src="http://blog.simonstahl.com/wp-content/uploads/2011/01/P1020284-150x150.jpg" alt="Biggest Nexus One @ Googleplex" width="150" height="150" /><p class="wp-caption-text">Biggest Nexus One @ Googleplex</p></div>
<p>OK, this is a tricky one. You can of course just drive to the Google HQ which is located at 1600 Amphitheatre Parkway in Mountain View, but you won&#8217;t be able to see a lot before you get kicked out by the security guards. According to them are you not even allowed to park your car in the huge parking lots there. Also the Google HQ is a closed campus and does not offer any tours through the buildings.</p>
<p>I found my way in by signing up for the <a title="SV Google Technology User Group" href="http://www.meetup.com/sv-gtug/" target="_blank">Silicon Valley Google Technology User Group</a> on <a title="meetup.com" href="http://www.meetup.com/" target="_blank">meetup.com</a>. Participation is free and they normally organize one meetup per month about Google technologies. Of course that is not comparable to a real tour, but at least it&#8217;s a way to see one of the buildings from the inside.</p>
<h2 id="thetech">San Jose Tech Museum of Innovation</h2>
<p>The <a title="Tech Museum of Innovation" href="http://www.thetech.org/" target="_blank">Tech Museum of Innovation</a> in San Jose is actually more made for kids then for grown ups, but lets be honest; who is already so grown up that he/she does not like to explore scientific base principles in a playful and fun way anymore? Well, I&#8217;m not! And I&#8217;m sure that everyone can still learn one thing or another there.</p>
<h2 id="mv_downtown">Mountain View Downtown</h2>
<p>Mountain View has a nice Downtown area which is basically located left and right of the Castro Street between Central Expressway and Church Street. It&#8217;s nice to stroll around there on a warm summer evening, have dinner in one of the Restaurants or just drink a Beer in the English Pub.</p>
<h2 id="computer_history_museum">Computer History Museum</h2>
<p>A must for every Computer Geek! The <a title="Computer History Museum" href="http://www.computerhistory.org/" target="_blank">Computer History Museum</a> in Mountain View exhibits literally the last 2,000 years of computer history. From the first wooden calculation engines to the newest smart phones, you can find everything there.</p>
<h2 id="tahoe">Lake Tahoe</h2>
<div id="attachment_118" class="wp-caption alignleft" style="width: 100px"><img class="size-thumbnail wp-image-118  " title="Tahoe View" src="http://blog.simonstahl.com/wp-content/uploads/2011/01/Tahoe-030-150x150.jpg" alt="View over South Lake Tahoe" width="90" height="90" /><p class="wp-caption-text">Tahoe</p></div>
<p><span style="color: #bbbbbb; font-size: 12px; line-height: 19px; font-weight: normal;">Lake Tahoe is about a 4 hour drive away from the Silicon Valley. Therefore, I would not recommend to go there for just one day. I&#8217;ve never been there in the Summertime so far, but in the Wintertime you can Ski and Snowboard there. More information about Tahoe can be found <a title="A Europian View on Lake Tahoe" href="http://blog.simonstahl.com/?p=105" target="_self">here</a>.</span></p>
<p>&nbsp;</p>
<h2 id="apple">Apple Mothership</h2>
<p>The Apple HQ is a must for every Tech fan. Just the address itself is worth the visit: 1 Infinite Loop, Cupertino. Basically there&#8217;s not so much to do and see, it&#8217;s just about the feeling to be at the place where it all happens. And don&#8217;t forget to buy a &#8220;I visited the Mothership&#8221; T-Shirt at the Apple store there.</p>
<h2 id="berkley">Berkley University</h2>
<div id="attachment_135" class="wp-caption alignright" style="width: 160px"><img class="size-thumbnail wp-image-135" title="Berkley" src="http://blog.simonstahl.com/wp-content/uploads/2011/01/IMAG0014-150x150.jpg" alt="Berkley" width="150" height="150" /><p class="wp-caption-text">Berkley</p></div>
<p>A nice University city where you can see the elite of the next generation at work. You can easily spend a whole day there hanging around, relaxing in the grass or just drinking a coffee in one of the many coffee shops around the campus.</p>
<p>&nbsp;</p>
<h2 id="santa_cruz">Santa Cruz</h2>
<p>Santa Cruz is the Beach and Surfer spot of the Silicon Valley. On hot summer weekend days it seems almost as if everyone rushed there for a place in the sun. The Santa Cruz city beach is therefore mostly totally crowded. Right next to the beach is the Boardwalk with a lot of attractions.</p>
<p>If you like it more quiet, you can just head a bit more to the south. There are plenty of public beaches coming up like the Sunset State Beach. Unfortunately you have to pay there to drive with your car to the parking.</p>
<h2 id="the_castro">San Francisco Castro District</h2>
<p>The Castro district in San Francisco is famous for it&#8217;s gay community. Nevertheless, also straight people can have lots of fun there on a Friday or Saturday Night. There are plenty of Bars and Restaurants around, so everyone should be able do find something that he/she likes. What else is there to say about the Castro? Be open minded and most important: <strong>Have Fun!!</strong> <img src='http://blog.simonstahl.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2011/01/03/geek-and-non-geek-places-to-see-in-and-around-silicon-valley/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A European view on Lake Tahoe</title>
		<link>http://blog.simonstahl.com/2011/01/03/a-european-view-on-lake-tahoe/</link>
		<comments>http://blog.simonstahl.com/2011/01/03/a-european-view-on-lake-tahoe/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 06:48:40 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[A European in California]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[great view]]></category>
		<category><![CDATA[lake takoe]]></category>
		<category><![CDATA[skiing]]></category>
		<category><![CDATA[snowboaring]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=105</guid>
		<description><![CDATA[I&#8217;ve heard a lot about Lake Tahoe since I&#8217;m here in the US and because I&#8217;m snowboarding for many years already, I thought it was time to check it out myself. From San Jose, where I live, you can reach Lake Tahoe in under 4 hours. In the wintertime, you better go with a 4WD [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve heard a lot about Lake Tahoe since I&#8217;m here in the US and because I&#8217;m snowboarding for many years already, I thought it was time to check it out myself. From San Jose, where I live, you can reach Lake Tahoe in under 4 hours. In the wintertime, you better go with a 4WD or at least with the snow chains because the US50 can be heavily snow covered. Also the streets in the Village, we stayed in South Lake Tahoe, can be snow and ice covered.<span id="more-105"></span></p>
<h2>Hotel</h2>
<p>We were in Tahoe just one week before the main season started. Nevertheless, the Hotel prices were surprisingly low. We got a decent Hotel for under $40 and there are many more in this price range all over the place. Just try to get one close to the Gondola, so you don&#8217;t have to use your car to go there.</p>
<h2>Heavenly Ski Resort</h2>
<p>The worst right at the beginning: this is the most expensive Ski Resort that I&#8217;ve ever been to! I&#8217;m from Switzerland so I&#8217;m actually used to high prices, but that was just too much. I expected high prices because I looked them up on their <a title="http://www.skiheavenly.com/" href="http://www.skiheavenly.com/" target="_blank">Homepage</a> before we went there, but when we bought the tickets there, they were even more expensive than the published ones. <strong>At the end we payed more than $250 for a 3 day pass.</strong> And that&#8217;s not all, if you decide to go by car and park there, you pay another $25 a day for that! Tip from me: just park at the Harrah&#8217;s Casino, that is right next to the gondola and parking is free there.</p>
<div id="attachment_118" class="wp-caption alignright" style="width: 310px"><img class="size-medium wp-image-118   " title="Tahoe View" src="http://blog.simonstahl.com/wp-content/uploads/2011/01/Tahoe-030-300x225.jpg" alt="View over the Ski runs and the Lake" width="300" height="225" /><p class="wp-caption-text">View over the Ski runs and the Lake</p></div>
<p>Except of the price, the Resort is very nice. There are enough lifts available so the waiting time is never too long. When I was there, the snow was just amazing and the view from almost every place on the mountain is astonishing! On one side of the mountain you can see over the Californian part of the Lake and on the other side of the mountain it almost feels as you could see over whole Nevada.</p>
<p>If you are a Snowboard or Ski beginner, there is a lift just for you that is especially slow and the staff takes care about you and slows it even more down if you have problems getting in or out. The ski run there is so flat that really everyone can try their first turns there.</p>
<p>If you&#8217;re a more advanced rider, there are double black runs for you. I tried them and I have to say that they are really challenging, even if you have several years of experience already.</p>
<h2>South Lake Tahoe</h2>
<p>South Lake Tahoe is a very nice village. There are some sport shops where you can rent a Snowboard or Skis, some Bars, many Restaurants and there are a couple of Casinos located on the Nevada side of the Village. The big problem, like everywhere in the US: everything is just too far away from the other places. A few Bars and Restaurant as well as the Casinos are in walking distance from the Gondola, but if you want to explore more places you have to drive with the car.</p>
<h2>Apres Ski</h2>
<div id="attachment_119" class="wp-caption alignleft" style="width: 235px"><img class="size-medium wp-image-119 " title="Mc P's Irish Pub &amp; Grill" src="http://blog.simonstahl.com/wp-content/uploads/2011/01/Tahoe-004-225x300.jpg" alt="Mc P's Irish Pub &amp; Grill" width="225" height="300" /><p class="wp-caption-text">Mc P&#39;s Irish Pub &amp; Grill</p></div>
<p>OK, as I wrote earlier, I&#8217;m from Switzerland which is not really known as a big Apres Ski place, but you can normally find at least one or two Bars where you can party after a day at the mountain. <strong>Don&#8217;t expect that in South Lake Tahoe!</strong> There is a nice Bar, the <a title="Mc P's Irish Pub &amp; Grill" href="http://www.mcpspubtahoe.com/welcome.htm" target="_blank">Mc P&#8217;s Irish Pub &amp; Grill</a>, right next to the bottom station of the Gondola. They even have a Fireplace outside where you can get warm in cold nights. But here we go: no one is there! I have no idea where all the people go after the lifts are getting closed. It&#8217;s just sure that they don&#8217;t go partying&#8230;</p>
<p>OK, Apres Ski: minus 10 points!! <img src='http://blog.simonstahl.com/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> </p>
<h2>Overall Experience</h2>
<p>Overall, I had a great time in Tahoe! I give some minus points for the lift ticket prices and the missing Apres Ski Parties. On the plus side is certainly the great view from the top of the mountain and the cheap accommodation. And at the end keep in mind that if you go with some good friends, you will have fun everywhere! In this sense: <strong>Enjoy your time in Tahoe!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2011/01/03/a-european-view-on-lake-tahoe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A European view on California</title>
		<link>http://blog.simonstahl.com/2010/12/30/a-european-view-on-california/</link>
		<comments>http://blog.simonstahl.com/2010/12/30/a-european-view-on-california/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 05:08:22 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[A European in California]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[California]]></category>
		<category><![CDATA[european]]></category>
		<category><![CDATA[weird]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=78</guid>
		<description><![CDATA[It&#8217;s now about 9 month ago that I moved from Switzerland to San Jose, CA and I thought it is now time to start a series about my thoughts and experiences that I make here. Don&#8217;t get me wrong, I love it here, but there are just some things here that I don&#8217;t understand or [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s now about 9 month ago that I moved from Switzerland to San Jose, CA and I thought it is now time to start a series about my thoughts and experiences that I make here. Don&#8217;t get me wrong, I love it here, but there are just some things here that I don&#8217;t understand or that seem stupid to me.<span id="more-78"></span></p>
<p>This list here is not complete and will become larger as I work on on it.</p>
<ul>
<li><a title="Clubs" href="http://blog.simonstahl.com/?p=81" target="_self">Clubs</a></li>
<li><a title="Lake Tahoe" href="http://blog.simonstahl.com/?p=105" target="_self">Lake Tahoe</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2010/12/30/a-european-view-on-california/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A European view on Californian Clubs and Bars</title>
		<link>http://blog.simonstahl.com/2010/12/30/a-european-view-on-californian-clubs-and-bars/</link>
		<comments>http://blog.simonstahl.com/2010/12/30/a-european-view-on-californian-clubs-and-bars/#comments</comments>
		<pubDate>Thu, 30 Dec 2010 05:05:36 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[A European in California]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Bar]]></category>
		<category><![CDATA[Bouncer]]></category>
		<category><![CDATA[California]]></category>
		<category><![CDATA[Club]]></category>
		<category><![CDATA[USA]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=81</guid>
		<description><![CDATA[One thing that I just can not understand here in California is how people are treated in Bars and Clubs. It seems to me that the Club Bouncers are some kind of a private army that can do to you whatever they like. Entering the Club It all starts when you try to go into [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that I just can not understand here in California is how people are treated in Bars and Clubs. It seems to me that the Club Bouncers are some kind of a private army that can do to you whatever they like.</p>
<h2>Entering the Club</h2>
<p>It all starts when you try to go into the Club. First of all you have to stand in the waiting line. Even if the Club is almost empty, you <strong>HAVE </strong>to wait outside. It almost looks like they want that there is a line in front of the Club so it seems like there&#8217;s a big crowd inside. If you&#8217;re a group of just girls, chances are good that you get picked by the Bouncer to skip the line and go straight in. That can also happen if you are in a mixed group. However, if you&#8217;re just guys, you&#8217;re doomed and have to wait.<span id="more-81"></span></p>
<h2>Being in the Club</h2>
<p>Once you&#8217;re in it just starts to get more weird. There are Bouncers that are just here to annoy you with their flashlights. They will blink around with them as soon as you stand in a spot where they don&#8217;t like you to stay.</p>
<h2>Leaving the Club</h2>
<p>OK, this is the weirdest part. I understand that the Californian law says that the Clubs have to close at 2am. What I don&#8217;t understand is why you get kicked out already at 1:30am or sometimes even at 1:20am. Wouldn&#8217;t the Clubs make more money if the guests could stay a bit longer? And they are damn strict with kicking you out. Don&#8217;t even try to argue with them. They don&#8217;t care if your friend is still in the restroom and you&#8217;d like to wait for him/her or anything else. They will just annoy you as long until you finally leave the place.</p>
<p>So, you&#8217;re out of the Club now and you think you finally escaped the Bouncers? Wrong! They will follow you and even kick you off the street in front of the Club. I once bought some food and sat down on a bench in front of the club to eat. As the Bouncer told me I have to leave, I explained to him that I just wanted to eat my food and that I would leave as soon as I finished that. Well, he didn&#8217;t care, got very aggressive and annoyed me with his flashlight for 2 or 3 minutes. Finally a cop came and told me very clear that I had to leave <strong>RIGHT NOW</strong>. Well, I don&#8217;t wanna mess with the cops, since everyone know what they can do to you, so I left. But until this day I wonder what exactly the legal basis is for this action. Am I really not allowed to sit peacefully there on public ground and eat something?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2010/12/30/a-european-view-on-californian-clubs-and-bars/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Login to Foursquare with an Android App using OAuth</title>
		<link>http://blog.simonstahl.com/2010/05/15/login-to-foursquare-with-an-android-app-using-oauth/</link>
		<comments>http://blog.simonstahl.com/2010/05/15/login-to-foursquare-with-an-android-app-using-oauth/#comments</comments>
		<pubDate>Sat, 15 May 2010 20:10:15 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Foursquare]]></category>
		<category><![CDATA[OAuth]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=69</guid>
		<description><![CDATA[Note: This tutorial is for the Foursquare API V1. A version for v2 can be found here. Although the Foursquare login process is pretty easy, it took me some time to figure out how this could be done from an Android application. The problem here is, that I don&#8217;t want a Popup window for the OAuth [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Note: This tutorial is for the Foursquare API V1. A version for v2 can be found <a title="Login with OAuth to the Foursquare API v2 from Android" href="http://blog.simonstahl.com/2011/03/16/login-with-oauth-to-the-foursquare-api-v2-from-android/">here</a>.</strong></p>
<p>Although the Foursquare login process is pretty easy, it took me some time to figure out how this could be done from an Android application. The problem here is, that I don&#8217;t want a Popup window for the OAuth login. There&#8217;s a different requirement for the whole login process.</p>
<p>A standard OAuth login process consists of this flow:</p>
<ul>
<li>Create consumer with application token and secret</li>
<li>Get login URL from service</li>
<li>Redirect the user to the login URL</li>
<li>User grant or deny access to service</li>
<li>Get the access token and secret</li>
</ul>
<p>But in a mobile application, without a URL redirection, what we actually want is something like this:</p>
<ul>
<li>Create consumer with application token and secret</li>
<li>Login to service</li>
<li>Get the access token and secret<span id="more-69"></span></li>
</ul>
<p>OK, first we need an OAuth library. In this example I&#8217;m going to user the Signpost lib. You can get it from here: <a href="http://code.google.com/p/oauth-signpost/">http://code.google.com/p/oauth-signpost/</a></p>
<p>There are 3 available libraries, but for this example we need only the <strong>core </strong>and the <strong>commonshttp4 </strong>part. Then, it&#8217;s actually pretty easy to login. We can to this in just one step with the user <strong>Email-address</strong> and his <strong>password</strong>.</p>
<pre class="brush:java">// Build URL and create GET request
String url = "http://api.foursquare.com/v1/authexchange" +
				"?fs_username=" +
				EMAIL +
				"&amp;fs_password=" +
				PW;
HttpGet reqLogin = new HttpGet(url);

// Instantiate consumer with application key and secret
OAuthConsumer consumer = new CommonsHttpOAuthConsumer(
		CONSUMER_KEY,
		CONSUMER_SECRET);
consumer.sign(reqLogin);

// Login
HttpClient httpClient = new DefaultHttpClient();
HttpResponse resLogin = httpClient.execute(reqLogin);
if (resLogin.getEntity() == null) {
	throw new Exception("Could not login");
}

// Parse response
Document document =
	DocumentBuilderFactory
		.newInstance()
			.newDocumentBuilder()
				.parse(resLogin.getEntity().getContent());

// Get access token
Element eOAuthToken =
	(Element)document.getElementsByTagName("oauth_token").item(0);
Node e = eOAuthToken.getFirstChild();
String sOAuthToken =  e.getNodeValue();
System.out.println("token: " +sOAuthToken);

// Get access secret
Element eOAuthTokenSecret =
	(Element)document.getElementsByTagName("oauth_token_secret").item(0);
e = eOAuthTokenSecret.getFirstChild();
String sOAuthTokenSecret =  e.getNodeValue();
System.out.println("Secret: " +sOAuthTokenSecret);

// Set access token and secret for further requests
consumer.setTokenWithSecret(sOAuthToken, sOAuthTokenSecret);

// Get user information
HttpGet requestVenue = new HttpGet("http://api.foursquare.com/v1/user");
consumer.sign(requestVenue);
HttpResponse resVenue = httpClient.execute(requestVenue);
if (resVenue.getEntity() == null) {
	throw new Exception("Could not get user information");
}

InputStream is = resVenue.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null; 

while ((line = reader.readLine()) != null) {
    sb.append(line + "\n");
}

System.out.println(sb.toString());</pre>
<p>Of course, this login process has to be done just once. We just need to store the access token and the secret somewhere for further use.</p>
<p>That&#8217;s it. Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2010/05/15/login-to-foursquare-with-an-android-app-using-oauth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Does Social Networking changes our view of privacy?</title>
		<link>http://blog.simonstahl.com/2010/05/15/does-social-networking-changes-our-view-of-privacy/</link>
		<comments>http://blog.simonstahl.com/2010/05/15/does-social-networking-changes-our-view-of-privacy/#comments</comments>
		<pubDate>Sat, 15 May 2010 19:04:25 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Social]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Privacy]]></category>
		<category><![CDATA[Social Networking]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=65</guid>
		<description><![CDATA[Social Networking: How Social Networking changes our view of privacy As Social Networking Sites (SNS) in the Internet are faced with an exponential growth, it gets more and more important what kind of personal data users are willing to disclose to get a fully satisfying user-experience in return. These days, many users expect a SNS [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">Social Networking:</p>
<p style="text-align: center;">How Social Networking changes our view of privacy</p>
<p>As Social Networking Sites (SNS) in the Internet are faced with an exponential growth, it gets more and more important what kind of personal data users are willing to disclose to get a fully satisfying user-experience in return. These days, many users expect a SNS to allow them to broadcast their thoughts and doings in realtime to all their friends. But that was not always the case; when Mark Zuckerberg, the founder of Facebook which has currently over 400 million active users (Facebook, 2010), in 2004 invented the status field that allowed the users to make their thoughts public, many people asked him &#8220;What is that good for?&#8221; and &#8220;Why would I like to post my thoughts to the Internet?&#8221;. Since then, posting status messages has become normal for Facebook users and most of them would certainly miss that feature. These status messages are in fact nothing else then highly personal data. It is possible to know a person quite well just by reading this persons Facebook wall. But what does it mean when millions of people feel the demand to disclose their personal data to their friends and often to the whole world? Does this mean that they are less concerned about their privacy than people were previously? My research actually shows exactly the opposite of that; Even if people are sharing quite a lot of their private data, it seems that they care rather more about their privacy then in the early days.<span id="more-65"></span></p>
<p>The Term SNS is widely used these days and it may be hard to distinguish where it really applies and where not, so first of all it is important to clarify what exactly a SNS is. Boyd and Ellison (2007) defined it as</p>
<p style="padding-left: 30px;">web-based services that allow individuals to (1) construct a public or semi-public profile within a bounded system, (2) articulate a list of other users with whom they share a connection, and (3) view and traverse their list of connections and those made by others within the system. The nature and nomenclature of these connections may vary from site to site.</p>
<p>Facebook is a perfect example of a SNS. It allows users to create a profile which they can share with their friends as an closed profile (closed to the public) or to the whole world as an open profile (open to the public). It contains a privacy settings page, which allows users to define exactly which information they want to be public and which private. Furthermore, Facebook allows users to connect their profile to a social graph consisting of their friends and family. And finally users can browse the social graph of their friends to see with whom they are friend. And of course everyone can post status messages which can, depending on the privacy settings, be seen by either just their friends or by everyone who looks at their profile.</p>
<p>An important point, however, is that all users have the guarantied right by law to decide themselves who can access their data. Schaefer and Birkland (2007) distinguished between four guaranteed privacy rights that are guaranteed by law: informational, physical, decision and propriety privacy. Regarding SNS the applicable one is that of informational privacy, which includes the control of personal data. With Facebook this means that all users can control who can see their personal data like name, address, Email address and also their status messages and the comments they made. Facebook does indeed provide the possibility of defining exactly who can access which information about a person. However, these are opt-out settings, which means the default is that every information is shared with everyone. If the users want their data to be private, they have to find the proper setting and change it accordingly.</p>
<p>Even if this privacy rights are guaranteed by law, there are exceptions that allows the FBI for example to see all information submitted through the Internet. The FBI has had the right to observe the digital data of suspects on the Internet for a long time. If they previously had a suspicion that a person did something illegal, they could request this persons data and look over it. But Batra (2008) pointed out that as reaction to the 9/11 attacks, the Patriot Act was released which now gave the FBI the right to store and even automatically analyze information gathered in the Internet. This means they do not even need a suspicion anymore to analyze someone’s data. Everybody‘s data is now automatically checked by a bunch of algorithms to see if it contains content that may be dangerous for the public. If someone, for example, writes an Email to a friend in which he complains about the government and where he writes that he would like to kill the president, the FBIs algorithms would recognize this message as potential dangerous and may alert an agent. This can lead to further observations of this person and in extreme cases even to a black listing so this person is not allowed anymore to enter the US or to fly over US territory.</p>
<p>Thought not just the FBI can see personal information from SNS; because of the opt-out mechanism that defines information as public by default, almost everyone with a computer can gather a lot of information about a person via a SNS. One statistic released by Lampe, Ellison and Steinfield (2008) demonstrated that about one third of the SNS users think that their profile has been watched by possible future employers and even total strangers. Of course, it brings some discomfort to know that people at the company where I just applied for a job can see the party pictures I made last weekend.</p>
<p>As a logical consequence of the assumption that strangers watch their profile and the fact that most SNS users know pretty well that the Internet is everything but anonymous and private, some users have started to obscure their real identity. Quan-Haase and Young (2009) showed that many users try to hide their real identity by providing some fake data or by excluding important information from their profile. The hope of this users is that by doing this, their profile won’t be that easy to find anymore or not relatable to them as person at all.</p>
<p>Although it’s just a minority that try to hide their identity in such a way, most of the SNS users provide their real data and do not even make use of the available privacy settings to hide their information from unknown people. Schrammel, Köffel and Tscheligi (2009) discovered that more then half of the SNS users disclose their real name as well as their picture to the public. A bit less, but still more then one third also share their date of birth and their friend connections with the world. Their profiles can therefore pretty easily be found and their data can be used or misused by anybody.</p>
<p>With the further evolution of SNS and the invention of Photo-services people have been faced with even more possibilities of data disclosure. Ahern, Eckles, Good, King, Naaman and Nair (2007) showed that 28% of photos that show people and were uploaded to a photo-service in the Internet were publicly accessible. Even a larger amount of non-person pictures were public; for example 64% of pictures showing activities were accessibly by everybody. They also found out that just a minority of the people are concerned about the location tagging of the pictures. With this technique, it is possible to see on a map where the users were at the moment when they took the picture. This information can, of course, easily be misused for example by a stalker to physically meet the person that took the picture.</p>
<p>The fact that SNS users disclose their data in such a liberal way does not mean, that they do not care about their privacy. In fact, most are very concerned about their privacy. Kasper (2005) found that 79% of adults think it is &#8220;extremity important&#8221; to be in control of their personal data. This shows the difference between the concerns of the users and what they actually do to protect their personal data. On one side, they are very concerned about their privacy but on the other side are they sharing their information quite freely.</p>
<p>This willingness to provide personal information despite the concern about privacy might have its roots in the unlimited confidence that especially the younger users have in the Internet. While evaluating the search behavior of people on the Internet, Conti and Sobiesk (2007) came across the interesting fact that younger people are much more likely to search for sensitive keywords, that they do not want their employer to know about, than older users. This indicates that older Internet users do not fully trust in the shallow web-anonymity while the younger ones are much more trustworthy. It also exhibits the different mentality of the users that grew up with the Internet and others that also know the time before it.</p>
<p>As younger users are willing to trust the Internet more and more, some of the elder people might argue that SNS and the Internet in general mislead younger generations to disclose too much private data about themselves. While the elder ones in fact just may not know how to handle these new technologis. It may be true, that younger users are willing to share more information on the internet than elders, but as showed before they are well aware that this information can be watched by other people and will therefore mostly not share any sensitive information.</p>
<p>This fear, that new technologies lead to a reduction in privacy, could already be seen several times in latest history. People were also very concerned about their privacy after the invention of photography, the telephone and especially in the late 1960s after the computer was invented (Kasper, 2005). As we know now, however, our privacy rights do still exist even after these inventions.</p>
<p>Even if the disclosing of private data in SNS can be a serious problem, we can not deny the benefits we get in response. Ferrell, Nowak and Phelps (2000) found that people actually expect personalized Marketing and that they would be upset if they lost it. This expectation can just be fulfilled if the users continue to provide some amount of private data.</p>
<p style="text-align: center;">References</p>
<p><em>Facebook Statistics </em>(2010). Retrieved April 13, 2010 from <a href="http://www.facebook.com/press/info.php?statistics">http://www.facebook.com/press/info.php?statistics</a></p>
<p>Boyd, D.M., &amp; Ellison, N.B. (2007, October). Social network sites: Definition, history, and scholarship. <em>Journal of Computer-Mediated Communication,</em> 13, Article 11. Retrieved April 13, 2010, from <a href="http://jcmc.indiana.edu/vol13/issue1/boyd.ellison.html">http://jcmc.indiana.edu/vol13/issue1/boyd.ellison.html</a></p>
<p>Birkland, T.A., &amp; Schaefer, T.M. (2007). <em>Encyclopedia of media and politics</em>. Washington, D.C.: CQ Press. Batra, N. D. (2008). <em>Digital freedom: how much can you handle? </em>Lanham, Rowman &amp; Littlefield.</p>
<p>Ellison, N. B., Lampe, C., &amp; Steinfield, C. (2008). Changes in use and perception of Facebook. <em>Computer Supported Cooperative Work</em> (pp. 721-730). San Diego, CA: ACM. Retrieved April 13, 2010, from <a href="http://portal.acm.org.libaccess.sjlibrary.org/citation.cfm?doid=1460563.1460675">http://portal.acm.org.libaccess.sjlibrary.org/citation.cfm?doid=1460563.1460675</a></p>
<p>Quan-Haase, A., Young, &amp; A.L. (2009). Information revelation and Internet privacy concerns on social network sites: a case study of facebook. <em>Communities and Technologies </em>(pp. 265-274). University Park, PA: ACM. Retrieved April 13, 2010, from <a href="http://portal.acm.org.libaccess.sjlibrary.org/citation.cfm?id=1556460.1556499">http://portal.acm.org.libaccess.sjlibrary.org/citation.cfm?id=1556460.1556499</a></p>
<p>Köffel, C., Schrammel, J., &amp; Tscheligi, M. (2009). Personality traits, usage patterns and information disclosure in online communities. <em>British Computer Society Conference on </em><em>Human-Computer Interaction</em> (pp. 169-174). Cambridge, UK: British Computer Society. Retrieved April 13, 2010, from <a href="http://portal.acm.org.libaccess.sjlibrary.org/citation.cfm?id=1671031">http://portal.acm.org.libaccess.sjlibrary.org/citation.cfm?id=1671031</a></p>
<p>Ahern, S., Eckles, D., Good, N.S., King, S., Naaman, M., &amp; Nair, R. (2007). Over-exposed?: privacy patterns and considerations in online and mobile photo sharing. <em>Conference on </em><em>Human Factors in Computing Systems</em> (pp. 357-366). San Jose, CA: ACM. Retrieved April 13, 2010, from <a href="http://portal.acm.org.libaccess.sjlibrary.org/citation.cfm?id=1240624.1240683">http://portal.acm.org.libaccess.sjlibrary.org/citation.cfm?id=1240624.1240683</a></p>
<p>Kasper, D.V.S. (2005) The Evolution (Or Devolution) of Privacy. Sociological Forum, 20, 69-92. Retrieved April 13, 2010, from <a href="http://www.jstor.org/pss/4540882">http://www.jstor.org/pss/4540882</a></p>
<p>Conti, G., &amp; Sobiesk, E. (2007). An honest man has nothing to fear: user perceptions on web-based information disclosure. <em>ACM International Conference Proceeding Series</em> (pp. 112-121). Pittsburgh, PA: ACM. Retrieved April 13, 2010, from <a href="http://portal.acm.org.libaccess.sjlibrary.org/citation.cfm?id=1280680.1280695">http://portal.acm.org.libaccess.sjlibrary.org/citation.cfm?id=1280680.1280695</a></p>
<p>Phelps, J., Nowak, G., Ferrell, E. (2000). Privacy Concerns and Consumer Willingness to Provide Personal Information. <em>Journal of Public Policy &amp; Marketing</em>, 19, 27-41. Retrieved April 13, 2010, from <a href="http://www.jstor.org/stable/30000485">http://www.jstor.org/stable/30000485</a></p>
<p><em> </em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2010/05/15/does-social-networking-changes-our-view-of-privacy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Define some items in a ListBox as unselectable</title>
		<link>http://blog.simonstahl.com/2010/01/11/define-some-items-in-a-listbox-as-unselectable/</link>
		<comments>http://blog.simonstahl.com/2010/01/11/define-some-items-in-a-listbox-as-unselectable/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 23:48:47 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[XAML]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[disable]]></category>
		<category><![CDATA[item]]></category>
		<category><![CDATA[listbox]]></category>
		<category><![CDATA[listboxitem]]></category>
		<category><![CDATA[unselectable]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=51</guid>
		<description><![CDATA[It seems to be a quite common problem that one does not know how to set one or more items in a ListBox to unselectable or disabled. The same principle as described here can also be user for similar problems like setting a different background color for some items. First we&#8217;re going to create a [...]]]></description>
			<content:encoded><![CDATA[<p>It seems to be a quite common problem that one does not know how to set one or more items in a <strong>ListBox </strong>to <strong>unselectable</strong> or <strong>disabled</strong>.</p>
<p>The same principle as described here can also be user for similar problems like setting a different background color for some items.</p>
<p>First we&#8217;re going to create a simple domain class with a property that describes if the item should be selectable or not.</p>
<pre class="brush:c#">public class MyDataObject {
    public string Name { get; set; }
    public bool IsSelectable { get; set; }
}</pre>
<p><span id="more-51"></span>Next we create a <strong>XAML</strong> Window that contains a ListBox. In this ListBox we define a custom <strong>ItemContainerStyle </strong>with a Style that defines if the Item will be selected or not. And finally we bind this Style to the <strong>IsSelectable </strong>property from our data object.</p>
<pre class="brush:xml">

            <!--
                <Setter Property="Focusable" Value="{Binding IsSelectable}" />

--></pre>
<p>And now we just have to fill the <strong>ItemsSource</strong> from the ListBox and we can run the example.</p>
<pre class="brush:c#">public partial class MainWindow : Window {
    public MainWindow() {
        InitializeComponent();

        myListBox.ItemsSource =
            from i in Enumerable.Range(0, 10)
            select new MyDataObject() { Name = string.Format("Object {0}", i), IsSelectable = i % 3 != 0 };
    }
}</pre>
<p>That&#8217;s all. Easy, isn&#8217;t it?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2010/01/11/define-some-items-in-a-listbox-as-unselectable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An easy way to revert changes in Object data</title>
		<link>http://blog.simonstahl.com/2009/12/14/an-easy-way-to-revert-changes-in-object-data/</link>
		<comments>http://blog.simonstahl.com/2009/12/14/an-easy-way-to-revert-changes-in-object-data/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 23:43:53 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Clone]]></category>
		<category><![CDATA[DataBinding]]></category>
		<category><![CDATA[DataContext]]></category>
		<category><![CDATA[INotifyPropertyChanged]]></category>
		<category><![CDATA[Model View Control]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[PropertyChangedEventHandler]]></category>
		<category><![CDATA[Serializable]]></category>
		<category><![CDATA[SerializationException]]></category>

		<guid isPermaLink="false">http://blog.simonstahl.com/?p=42</guid>
		<description><![CDATA[A quite common problem in an MVC GUI is the need to revert changes in the model made by the user. Let&#8217;s say you create a UI where the user can modify some fields that are bound to a model object. After the user already did some changes, he recognizes that he entered some wrong [...]]]></description>
			<content:encoded><![CDATA[<p>A quite common problem in an <strong>MVC </strong>GUI is the need to revert changes in the model made by the user. Let&#8217;s say you create a UI where the user can modify some fields that are bound to a model object. After the user already did some changes, he recognizes that he entered some wrong data and wants to cancel the editing. So what now? The data is already written into the model.</p>
<p>The easiest way to revert this changes is obviously to let the user work with a copy of the real data object. So let&#8217;s add a clone method to the model and mark it as Serializable.<span id="more-42"></span></p>
<h2>Model with Clone() method</h2>
<pre class="brush:c#">[Serializable]
public abstract class PersonModel {

    public string Name { get; set; }
    public string FirstName { get; set; }
    public int Age { get; set; }

    public PersonModel Clone() {
        IFormatter formatter = new BinaryFormatter();
        Stream stream = new MemoryStream();
        using (stream) {
            formatter.Serialize(stream, this);
            stream.Seek(0, SeekOrigin.Begin);
            return (PersonModel)formatter.Deserialize(stream);
        }
    }
}</pre>
<p>We now just bind the copy of the object to the view:</p>
<pre class="brush:c#">myView.DataContext = person.Clone();</pre>
<p>This copy can easily be dropped in case the user cancels the editing. In case he saves the<br />
changes, you can just replace the original object with the copy.</p>
<p>One problem I ran in it was, that I normally implement the <strong>INotifyPropertyChanged </strong>interfaces to my models to inform the view about changes in the model. Unfortunately the <strong>PropertyChangedEventHandler </strong>contained in this interface causes a nasty SerializationException because the Class PropertyChangedEventManager is not marked as Serializable.</p>
<p><em><strong>System.Runtime.Serialization.SerializationException was caught</strong><br />
Message=&#8221;Type &#8216;System.ComponentModel.PropertyChangedEventManager&#8217; in Assembly &#8216;WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&#8242; is not marked as serializable.&#8221;</em></p>
<p>The easiest way to work around this problem is to just exclude the <strong>PropertyChangedEventHandler </strong>from the serialization.</p>
<h2>Clonable Model that implements INotifyPropertyChanged</h2>
<pre class="brush:c#">[Serializable]
public abstract class PersonModel : INotifyPropertyChanged {
    [field: NonSerialized]
    public event PropertyChangedEventHandler PropertyChanged;

    private string name;
    private string firstName;
    private int age;

    public string Name {
        get { return name; }
        set { name = value; OnPropertyChange(); }
    }
    public string FirstName {
        get { return firstName; }
        set { firstName = value; OnPropertyChange(); }
    }
    public int Age {
        get { return age; }
        set { age = value; OnPropertyChange(); }
    }

    public PersonModel Clone() {
        IFormatter formatter = new BinaryFormatter();
        Stream stream = new MemoryStream();
        using (stream) {
            formatter.Serialize(stream, this);
            stream.Seek(0, SeekOrigin.Begin);
            return (PersonModel)formatter.Deserialize(stream);
        }
    }

    protected void OnPropertyChange() {
        string propName = new StackFrame(1).GetMethod().Name.Replace("set_", "");
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(propName));
    }
}</pre>
<p>In this way everything works fine and you have hopefully one problem less to care about&#8230;</p>
<p>Happy DataBinding <img src='http://blog.simonstahl.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.simonstahl.com/2009/12/14/an-easy-way-to-revert-changes-in-object-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

