Running Your Android App on a Device

By Donn on Jun 29 2009 | 0 Comments

androidlogo I’m impressed with the Android Dev Guide. It’s fairly comprehensive guide, however, I can say from personal experience that the Dev Guide is not complete in all areas.

One key example is the section on developing on a device. I followed the instructions exactly. The last couple of lines state the following:

You can verify that your device is connected by executing adb devices from your SDK tools/ directory. If connected, you'll see the device name listed as a "device."

If using Eclipse, select run or debug as usual. You will be presented with a Device Chooser dialog that lists the available emulator(s) and connected device(s). Select the device to install and run the application there.

So, I do exactly that:

As you can see, my device was found. image

I use Eclipse for my Android development so I hit Run and I got this window:

image

No where in there do I see my device. The docs state you’ll see a “Device Chooser”. Unfortunately I did not. I got a “Run As” Dialog.

 

The Issue

Being that I’m not a day to day Eclipse/Android developer I was at a loss for what to do now. After a few hours of poking fumbling around I traced the problem back to a Run Configuration in Eclipse.

Here’s how to fix it. Open the Run Configurations:

image

Once this Window Opens, click on the Target Tab. Then select the “manual” option and then click run (as shown below).

(Click for larger image). 

image

 

Now click “RUN” and you’ll get a device chooser like this:

(click for larger image)

image 

Select this device and click “Ok”. You’re app will now be installed on your device.

Now you’re back to testing, this time on a real device, not on an emulator.

 

Final Notes

You’re going to want to test your app on an actual device.

For my current personal project I’m using the G1’s built in accelerometer. I’ve found some simulators out there for the accelerometer and they have worked great, but I still need to see what the app will do on an actual device. Installing it on an actual device detailed a couple of critical issues that the emulator did not illustrate. I’d say, from personal experience, the emulator is the perfect example of the Pareto principle as it fulfills the 80/20 rule. 80'% of the features you’ll use in the G1 can be effectively simulated in the emulator. The other 20%, you’ll need to test on an actual device as well as on the emulator (as the emulator makes development super easy).

I will always test my app on an actual device to see what the user experience is going to be like, I advise you do the same.

Post info

Tags:
Categories: Mobile

Could Not Import Contacts Into G1 From CSV…

By Donn on Jun 26 2009 | 0 Comments

This is one of those blog posts that simply exist for the simple reason that if I run into this issue again I can find it later (and hopefully someone else will find it and it will help them too).

I recently got a new G1 and I exported my contacts into CSV from my old phone. The G1 syncs its contacts with the Google account that its linked to. You can log into the contact manager via Gmail (click on contacts on the left hand side). From there you can import a csv file. Their docs say something like this: We will import almost any csv file. The system will figure out the fields and place them into the appropriate area.

However, this isn't quite true. If you try this, you’ll see that the names and email addresses come over fine, but the Phone field shows up in the “notes”. This isn't so helpful on a G1. I cant use the notes field to SMS or call someone. After a few  hours of trying to figure out why my phone numbers were not coming over as “Phone” or “mobile” or anything. I found this post (which I’m copying and pasting the good stuff below just in case this help goes away) which outlines the reason. Read below to see how to fix this issue.

----------------------- Original Post----------------------------

The list of fields are below at Note #1. But, in my experimentation to make this structure work, I found some strange and annoying quirks.
1) The two Description fields (Section 1 - Description, Section 2 - Description) must be populated with the word Personal (initial cap counts!) on each and every row if you want the data in the 10 fields that follow to be included in your Import. If you have no data in the Section 1 - Description field, then the data in that row following will not be imported AND the data in the fields following Section 2 - Description will be imported instead if the Section 2 - Description field is populated with Personal. If you put another word in, rather than Personal, the data will import, but each field in the row will be appended with that word. So, if you use the word Business, your data for the Google Contact for that row will be included, but renamed (i.e., (213) 555-1212 Business / mobile). As a result of this, when iPhone tries to upload this field, it will not be recognized as a phone number and will be left out or included in the Note section.
2) If you remove any fields (columns) from this format, the Google will only look for and populate: name, email addresses and notes.
3) Most contacts CSV formats separate First Name and Last Name. Not Google's. You have to concatenate (just learned this function) the two fields into one, first. (See below Note B.)
4) If you are importing a lot of contacts (I have >2500), it takes Google a while to update the Contact Manager screen. Even though it says it's done, there is nothing there. In my case, I figured 2500 was too much, so I tried importing again with a new CSV file with only 400 records. The import of the 400, five minutes later, was rejected because, it turns out, the 2500 were there all the time.
That's what I learned so far. Good luck to everyone.
--------------------------
Note A:
Name, E-mail, Notes, Section 1 - Description, Section 1 - Email, Section 1 - IM, Section 1 - Phone, Section 1 - Mobile, Section 1 - Pager, Section 1 - Fax, Section 1 - Company, Section 1 - Title, Section 1 - Other, Section 1 - Address, Section 2 - Description, Section 2 - Email, Section 2 - IM, Section 2 - Phone, Section 2 - Mobile, Section 2 - Pager, Section 2 - Fax, Section 2 - Company, Section 2 - Title, Section 2 - Other, Section 2 - Address
Note B:
I found this on Dave Jeyes blog (http://theregoesdave.com/

2008/10/17/importing-contacts-into-gmail-guide-to-google-contact-csv-fields/)

Once you open the CSV file in Excel, you can write a formula to combine the first and last name then paste them into the correct column in this spreadsheet.

First create a column in your Outlook Export for the combined fields. Then write a function that looks something like this:

=CONCATENATE(F1, ” “, L1)

F1 should be whatever field the first name is in and L1 should be whatever field the last name is in. The part in the middle with a space between the question marks will add a space between the two. Then you can copy this field and paste it down the rest of the column to perform the same function on the rest of your contacts. Now copy this entire column and then right click on the column in my template under the Name column and select ‘Paste Special’ then ‘Values’ and it should automate it for you.

 

---------------------------End-------------------------------------

 

Simply put, make sure you have Section 1 Description set properly and things will work out fine for you. They did for me once I populated this field.

 

Google should fix their help. I consider myself to be a fairly technical person, but this took way too much time. If my mother was doing this she’d be lost. Big UX fail there.

Post info

Tags:
Categories: Mobile

Twin Cities Pragmatic/ALT.NET Beer Tomorrow

By Donn on Jun 24 2009 | 1 Comments

Tomorrow we have another Twin Cities Pragmatic Beer event at the Herkimer in Minneapolis (Uptown). Another name for this same event is the Twin Cities ALT.NET Beers. For more information on where the Herkimer is and what time things are going to get going, see the site here.

See you there.

Post info

Tags:
Categories: Events

LINQ: Single() vs First()

By Donn on Jun 23 2009 | 2 Comments

Continuing on my path to LINQ greatness, I want to cover another topic that some people get confused over: LINQ’s First() vs. Single(). Both perform a particular task for us, but just by looking at the name you’d never know which one performed the action that you expected.

  • First() returns the first element in a sequence …
  • Single() returns the _only_ occurrence of the element in the sequence …

 

… Beware: They Throw Exceptions

One _very_important_ thing to be aware of is that these two functions throw exceptions if they do not find what they are looking for. First() will throw if it cannot find the first matching value, Single() will throw if it cannot find the value and if there are more than one matching element in the input sequence. Therefore they have sister functions called FirstOrDefault() and SingleOrDefault().

The FirstOrDefault() method will search for an element in the sequence and if the first requested element is not found (that matches the functor) the function will return the default value (usually null if a reference type).

The SingleOrDefault() method will search for a single occurrence of the requested element that matches the functor. If the element is not found it will return the default value (usually null if a reference type), OR if the method finds more than 1 result matching the functor this method will throw an InvalidOperationException. The reason this method will throw is because the input sequence contains more than one matching element. Single follows the  “one” and “only one” return mechanism. If more than one element matches your predicate, this method will throw.

All the combinations of throw/success can get kind of confusing and is best illustrated with a simple table.

 

First vs Default Success/Throw Matrix

Method Success When … Throws When …
First() 1..* – elements match 0 elements match
FirstOrDefault() 0..* – elements match (does not throw)
Single() 1..1 – one element matches 0 | >1 - elements match
SingleOrDefault() 0..1 – Elements match >1 – elements match


Conclusion

The end goal here is to be aware of what you’re doing with LINQ. All in all, be careful.

If you use “First” be aware that it WILL thrown an exception if the element is not found. This can be a simple mistake. Example - while unit testing you may set up a List<Orders> to use for testing. You ensure your code works for valid orders but perhaps you forgot to test the code with an empty list. Doing this would have caught your error because the First() method would have told you right away by throwing exception.

Think about how you want to handle your use cases. With a null, or an exception handling routine? It’s up to you as null/exception handling is a different debate all together. I hope this helped some of you out there.

Post info

Tags:
Categories: .NET

LINQ: Any() vs. Count()

By Donn on Jun 22 2009 | 4 Comments

In most code that you find that uses lists you will find something like this: 

if(products.Count() > 0)
            {
                // Do stuff
            }

Personally, I’ve seen this literally thousands of times. While this works and gets the job done, there is one issue with this method. It enumerates the entire enumerable collection. What if you have 10,000 items in your collection? What if that collection has a bunch  of other nested LINQ queries that must be executed prior to the actual count can be evaluated?

A simpler way to identify if the sequence contains any elements is to use the .Any() method. From the .Any() MSDN article:

Determines whether a sequence contains any elements.”

Later in the article it states:

“The enumeration of source (the source enumeration) is stopped as soon as the result can be determined.”

In English .. the Any() method  stops enumerating the enumeration as soon as it finds the first element. This is the same for the overload of the function as well.

Therefore you could do this:

var products = productService().GetProducts();
            if(products.Any())
            {
                // Do Stuff
            }

… and you would get the same effect as Count() without the overhead of processing the entire enumeration.

Post info

Tags:
Categories: .NET , Productivity

Beginning Google Android Development

By Donn on Jun 19 2009 | 0 Comments

AndroidPhone My wife and good friend have a G1 and I’m absolutely in love with the damn thing. I plan on getting one soon, however I’ve read a lot and some people are saying to wait for the MyTouch. However, this does not prevent me from getting my hands dirty with some Android development.

Since I’m a .NET guy I thought it would be fun to see what the experience would be like to develop a simple app. A few things that I wanted accomplish during this little project:

 

  • Use Eclipse
  • Use the ADT for Eclipse
  • Test with an Emulator (Android SDK provides one for free, emulator.exe)
  • Use the Accelerometer in Android

The fun part being the Accelerometer stuff. If you don’t know what one is, here’s a Wikipedia snippet from the accelerometer article:

An accelerometer measures the acceleration it experiences relative to freefall. This is equivalent to inertial acceleration minus the local gravitational acceleration, where inertial acceleration is understood in the Newtonian sense of acceleration with respect to a fixed reference frame, which the Earth is often considered to approximate.

Cool, huh? Basically, I want to move the phone and events should fire when certain velocities and inertias are achieved. This should be a good math based challenge for me. Calculating positive and negative accelerations, gravity, etc. Getting this to work is something I plan on doing over the next few days.

So far after playing with it a bit I’ve found that the best place to start is truly with the Android SDK’s Hello World. I’m impressed with the documentation and how to information in the Hello World. It has really helped. Check it out here.

If you’re interested in following along my Android journey, I’ll probably be posting my in depth findings here and my snippets/comments on the experience on my twitter.

Post info

Tags:
Categories: Mobile

Hangin’ in the Lounge

By Donn on Jun 18 2009 | 2 Comments

LoungeLogo I’ve death with numerous different advertisers and such over the few years I’ve had my blog. Just recently I spoke with the guys over at the Lounge and we decided to work together. I needed a low maintenance advertising system that could help with the monthly costs of the blog, they needed another person to join their Small Publishers network (because lets face it… I’m no hanselborg, yet).  :) Therefore we decided to join up and make the Lounge my exclusive graphical advertiser.

From the famous words of SLC Punk.

“I didn’t sell out, son. I bought in.”

I personally feel that these ads are much more respectable and are a huge improvement compared to the huge banners that I’ve previously had (as they did all sorts of non-sense, IMO). Hopefully this makes the reading experience less like a 1987 ad party rave with candy necklaces. Enjoy

Post info

Tags:
Categories: Misc

New DimeCast: Exploring Expressions with Spark

By Donn on Jun 18 2009 | 0 Comments

I have another DimeCast that went live this morning. This one is entitled “Exploring Expressions with Spark.”.

Here’s what we cover:

We are going to take a look at the various different ways you can use Expressions with the Spark View engine. We are going to review simply scenarios such as math based expressions and move up to looking at nested if-then-else statements.

Click here to watch the episode

Post info

Tags: ,
Categories: MVC , ASP.NET , ALT.NET

ASP.NET MVC without Installing the MVC Bits

By Donn on Jun 15 2009 | 4 Comments

I was recently was helping out a collague with an ASP.NET MVC problem and I was given a link to a solution. I opened it and got this message:

image

Which ends up giving you the following in the solution explorer.

image

The reason I’m getting this is because I never installed the ASP.NET MVC bits, well, actually that's a lie. I have them, but I never installed the full ASP.NET MVC package. I unzipped the MSI with the following command prompt:

#> msiexec –a PathToMsi.msi

This will drop the MSI contents your output to your C:\ drive. Here’s the help window for the msiexec (app click for larger):

image

If you’re like me, and have the bits local, then this can be a pain. Again, the underlying reason is I did not install the MSI which contains a project template which this project is using. Its actually using a particular ProjectTypeGuid in the csproj file. This guid is:

603c0e0b-db56-11dc-be95-000d561079b0

This tells Visual Studio that this project is an ASP.NET MVC file. To open this project in Visual Studio, remove this guid.

Change the project file from this:

{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}

…to this…

{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}

Now re-open and you’ll see the project loaded successfully.

image

 

The only thing you’ll have to do is fix your references in your project as they will probably be broken. Point the references back to the ASP.NET MVC binaries stored locally on your machine.

Post info

Tags:
Categories: ASP.NET , ALT.NET

New DimeCast: Exploring how to use Global Vars & View Data in Spark

By Donn on Jun 11 2009 | 0 Comments

I have a new DimeCast up! The title is above. In this DimeCast I cover …  how to utilize both global variables and local variables. We will also take a look at how to create and use both strongly typed viewdata and weakly typed view data.

To view the episode, click here.

Post info

Tags: ,
Categories: MVC , ALT.NET , ASP.NET