Skip to content

Firefox vs Chrome and then IE

October 12, 2011

This little gem was found on the Webmater Talk Forums and I just had to share this.

Chrome vs Firefox and well there's IE too

Advertisements

Different Ways to Implement Buttons in Android: Listeners

September 27, 2011

So you want to use a Button in your Android App to do something. One would think that this would be an easy process and yes, it is, but there are different ways of writing and implementing the Java for this. For the beginner Android developer, it can be a rather confusing on which one to use.

First I’ll start with a “popular” one, which is very straight forward but not very flexible.
This example is going to give the user two buttons on a page and each button is going to launch a new window/screen (called an Intent) once a button is clicked.

Here is the main.java file:

package com.hockey.fenimore;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class HockeyActivity extends Activity {
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);
        
	Button newGoalie = (Button)findViewById(R.id.newGoalie);
	newGoalie.setOnClickListener(new OnClickListener() {
	@Override
	public void onClick(View arg0) {
		Intent myIntent = new Intent(arg0.getContext(), Newgoalie.class);
		startActivityForResult(myIntent, 0);
	}
     });


     Button editGoalie = (Button)findViewById(R.id.editGoalie);
     editGoalie.setOnClickListener(new OnClickListener() {
	@Override
	public void onClick(View arg1) {
		Intent myIntent = new Intent(arg1.getContext(), Editgoalie.class);
		startActivityForResult(myIntent, 0);
	}
     });
  }
}

The breakdown:
Button newGoalie = (Button)findViewById(R.id.newGoalie);
If you tried to read the above line in plain words, you’re telling the application that you are creating a “Button” call newGoalie and this (Button) is being associated or will be triggered by an button object on the page which you will find (findViewById) and has an ID called newGoalie. This newGoalie needs to been defined and already created in your main.xml file.

newGoalie.setOnClickListener(new OnClickListener()
The button called newGoalie is going to be listening for a click and when it is clicked, we are going to create a new OnClickListener().

Inside the onClick:
Intent myIntent = new Intent(arg1.getContext(), Editgoalie.class);
You are creating an “Intent” call myIntent (You “intend” to do something when the button is clicked). I am going to get the views context and I wish to launch a new screen/page in my android application called EditGoalie.class

startActivityForResult(myIntent, 0);
Now that you are going to be leaving the screen and moving to the next one, I want to start the activity and wait for the results because I need to return to this page.

Notes:
This example is assuming that you have already created two button in your main.xml file. Here is a sample of what they can look like.

<Button android:id="@+id/newGoalie"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/button_stick"
     android:textColor="#FFFFFF"
     android:text="@string/newGoalie"
     android:paddingTop="46dp"
     android:layout_marginTop="75dp"
     android:textSize="18px"
     android:textStyle="bold">
</Button>
    
<Button android:id="@+id/editGoalie"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:background="@drawable/button_stick"
     android:textColor="#FFFFFF"
     android:text="@string/editGoalie"
     android:paddingTop="46dp"
     android:textSize="18px"
     android:textStyle="bold">
</Button>

When you start your application there is only one .java file under the src folder. If you are going to have a button launch a new screen you will need to create a new .java file (class) for each new screen. So in this example there are three .java files:
HockeyActivity.java (Main Starting Screen)
Newgoalie.java (Seen in the code as: Intent myIntent = new Intent(arg1.getContext(), Newgoalie.class);)
Editgoalie.java

When you launch either of the new screens, remember that you will need to return to your main screen by sending a valid Intent back. There are two kinds of results you will want to send back although there are actually more in the android documentation under Summary. Android Result Values.
1) setResult(RESULT_OK, okIntent);
2) setResult(RESULT_CANCELED, cancelIntent);

Setting up an Android Virtual Device (AVD)

September 19, 2011

In my recent post on How to Set-up your System to Run Android I covered the basic steps to get your system (MAC) up and running with the Android SDK. Now that you have Java, Eclipse and all the necessary files from Google installed, you’re now ready to start programming. The only problem remaining is you need an emulator, or Virtual Device, that can simulate an Android phone.

The good news, you have this already installed as part of setting up your system to run Android. All you need to do is configure the AVD.

Steps to get the AVD up and running:

  1. Start Eclipse
  2. Under the menu “Window” select “Android SDK and AVD Manager”
  3. When the window opens you will see “Virtual Devices” in the left pane
  4. Click on the “New…” button
Android Virtual Device AVD

Window -> Android SDK and AVD Manger

Creating an Android Virtual Device: Settings

  1. In the “Name:” field, give the virtual device a name. I would recommend that you start with “Android” and then the target OS they you plan on using. If you are going to build for Android devices that are 2.1 and higher call it “Android-21”.
  2. For the “Target” pick one of the “Android x.x” APIs.
  3. For “SD Card” you can type in 512 Mib which is a safe and standard size.
  4. Under “Skin:” As a good practice you can go with HVGA as this is a standard 320 x 480 screen resolution for most android devices
AVD Screen

The Android Virtual Device Screen (AVD)

Notes:
What I like about the Android Virtual Device is you can create multiple virtual devices. This is why I recommend that you put the OS version in the name, such as “Android-15” (Version 1.5) or “Android-23” (Version 2.3). If you are going to be releasing your application out into the real world you’ll need to make sure it works on as MANY devices as possible otherwise you may get a bad review from an unhappy customer. I’ve have read that we, as programmers, should target Android devices all the way down to 1.5 and a lot of books out on the market say the same thing.

While I’m all for this, if you look at Google’s breakdown on Android OS market share, users are predominantly on 2.1 and up. This accounts for 97% of the market! Therefor I think that targeting versions 1.5 is a little drastic these days and it’s only going to get smaller and smaller as time goes on.

Now that you have a Virtual Device set up you can start programming and seeing what your application will look like. To run the AVD simply click on the green play button (for lack of better words) in the icon bar found in Eclipse.

Run AVDWhere to run the Android Virtual Device

Where to run the Android Virtual Device

What the Android Virtual Device Looks Like

Android Virtual Device

The Android Virtual Device

Prepare your system to run Android

September 16, 2011
Android Installation

So you’re ready to start building Android Applications. What do you need on your computer you ask? It’s not as complicated as you thing. Since I’m on a MAC, the instructions below focus on how to install Eclipse and the Androids SDK for the MAC OS. Windows isn’t too much different and although this will come across as biased, I actually believe that if you are going to be developing mobile applications, having a MAC is to your advantage because it would allow you to program for BOTH platforms, Apple’s iPhone and Google’s Android.

Mac & Window Users:

  • You need Java installed and running on the Machine. (Mac’s come with this pre-installed.)
  • A Graphical User Interface (GUI) called Eclipse. Free and easy to download
  • The android SDK which is the most time consuming.

The whole process from start to finish will take about 1 hour. The real time kill is downloading the Android SDK and running updates. Downloading the complete framework takes about 30-40 minutes so watch some TV or play Angry Birds but this time, trying to get 3-stars on each level.

If You Need Java:

First, MAC’s already have this pre-installed but if you’re curious to see what version of Java you have, here’s how you do it. Launch your Terminal application. This can be found if you open your Hard Drive, go into your Applications folder and and then go into the Utilities folder. Inside the Utilities folder you will see the Terminal application.

Another quick way of getting there is under the Mac menu bar. Make sure you are not in any programs, meaning you need to be in your “Desktop/Finder View”. Your MAC’s nav should have a “Go” menu. Click on it and there will be a “Go to Folder”. When the screen asks what folder you want to open, enter “/Applications/Utilities”

Now you can drop in the follow line of text into the terminal window: java -version

You should get something similar to this:

Using Terminal to find your version of Java

While in the Terminal, for MACs, type "java -version" to see what version you have

If you have 1.6.0_(another number) this is fine. Basically you have Java and no need to worry. If you absolutely have to have the most recent version of Java, you can go here: http://www.oracle.com/technetwork/java/javase/downloads/index.html

At the time of writing, JDK 7 has just come out. For Android development, you can install JAVA SE which stands for Java (Standard Edition) If you really want to go crazy you can go the rout of JAVA EE (Enterprise Edition) but that it just overkill at this point. Remember your building for a mobile app. The Enterprise Edition of Java is like buying a Mobile Home with everything in it! Including the kitchen sink. If you’re a hard core developer and you must have everything then enjoy, go for it. For the rest of us, stick with JAVA SE. You’ll have more than enough to figure out.

Getting and Installing Eclipse

You must have Java installed and on the machine before you install Eclipse. Eclipse has gone through some rapid updates itself due to Android becoming so popular. Here is a list of the last three releases, in order from oldest to newest:

  • Old: Galileo (Version 3.5)
  • Newer: Helios (Version 3.6)
  • Current: Indigo (Version 3.7)

What’s nice about the download site http://www.eclipse.org/downloads/ is that it should automatically detect your machine and give you the proper list of files to download. When I first went here, it can be very confusing. There are a ton on version you can download but the one that works best and is recommend is Eclipse IDE for Java Developers.

EclipseDownload

Eclipse download URL: http://www.eclipse.org/downloads/ will auto-detect your operating system

Again you can go with the EE (Enterprise) version but it’s overkill. The regular version of Eclipse is filled with tons of options and I still don’t know what everything does, meaning, it is NOT short on functionality and features.

To determine if you need to download the 64-bit or 32 bit version . . . check your MAC’s system by going:
About This Mac -> More Info -> Software
64-bit Kernel and Extensions: No (Use 32-bit)
64-bit Kernel and Extensions: Yes (Use 64-bit)

MaBits

64-bit Kernel and Extensions will be set to "Yes" or "No"

Installing the Android SDK

Now for the final part of the installation. Getting the Android SDK and downloading all the goodies into Eclipse. The Android SDK is a collection of files and utilities that work together in the Eclipse IDE so you can create your Android Applications. Here is the location for the Android SDK: http://developer.android.com/sdk/index.html

Once you have the file downloaded you’ll need to unZip the file. This is where the fun starts. The extracted files will be in a folder called “android-sdk-windows” or “android-sdk-mac” depending on your OS. Since this will be accessed by Eclipse it’s up to YOU on where to keep the folder. Some people put it in the root of their hard drive while I’ve seen others put it inside their eclipse folders so it will all be “together”. While it doesn’t matter where you put it on your hard drive I seem to prefer that it is within your existing eclipse folder so you will know exactly where it is.

Now lets bring the two together (Eclipse with Android SDK).

Launch Eclipse. From the Eclipse menu go to Help -> Install New Software:

Android SDK Installation into Eclipse

Android SDK Installation into Eclipse

Click on the Add… button and then you will need to enter a Name and Location. The name can be anything you want but make it meaningful such as “Android Plugins”. For the Location field you can enter in:
https://dl-ssl.google.com/android/eclipse
or
http://dl-ssl.google.com/android/eclipse

Adding Android Plugins to Eclipse

Adding the Android Plugins to Eclipse

From here you can Click OK. After a few moments you’ll see a list of Developer Tools which will be checked. Go ahead and click Next>. You will probably get asked to accept the terms of agreement so go ahead and click OK. Once the installation has gone thorough it’s steps, you will have to restart Eclipse.

Great! Now that Eclipse has been restarted let tell it where the Android SDK is. For MAC users it’s under Eclipse -> Preferences and then selecting “Android” in the Left column. Windows users should get the same thing under Windows -> Preferences

Linking the SDK in Eclipse

For MAC, Eclipse -> Preferences, select Android, browse to SDK folder, hit OK

When you click the “browse” button, go to the folder where YOU saved the SDK. Do not use what I have in the screen shot. Once you click OK, you have just linked up Eclipse with the Android SDK.

Not so bad right? But wait, as will any technology, it gets old fast. It’s no different with the Adroid SDK and although you are jsut about done there is one FINAL highly recommended step. Updating the Android SDK which takes, well, a long time.

Updating the Android SDK

As a safety precaution, while in Eclipse, go under Help -> Check for Updates. This will ensure that you have the latest SDK update from Android which you just downloaded a little while ago. There should be no update here as you just downloaded and installed the SDK. It’s also a good reference to know where this is because unlike windows and MAC’s automated updates . . . you WILL NOT get notification and reminders about updating your SDK.

The second thing you need to do is go under “Window” -> Android SDK and AVD Manager from the Eclipse menu.

Updatign the Android SDK

Windows -> Android ADK and AVD Manager

Once you are in the Android SDK and AVD you can look at your Installed packages. Below is a screen shot of everything that is in my system. You’re should have a lot less because you didn’t install the “Available Packages” yet.

Android SDK AVD Manager

The Android SDK AVD Manager Screen within Eclipse

Once you click on Available packages you should just simply select everything and click “Install” on the bottom. Like before, you will have to accept some user agreements so go ahead and Accept. Sit back, relax and now is the time to go do something else. This WILL TAKE TIME to download.

Basically, from here on, you have completed the installation of Android and Eclipse onto your system. You will most likely be asked to restart Android when the downloads are complete.

Some side notes:
You do not have to download some of the crazy packages that are there especially if you are not going to be developing for them. There are things like dual screen that I know I’ll never develop for but you get the idea. Quickly look over them and install as much as you can but not every single one is necessary. They will be there if you ever need in the future.

Next post will cover Setting up the Android Emulator.

Learning Android

September 15, 2011
Powered by Android

As any new developer starting out in Android, the biggest challenge is learning all that the Android framework has to offer. Online references are usually a disaster when perusing through a Google search result. Sometimes, the examples never give you what you want or they leave out key parts of code that you need in order to understand what is being talked about. Better yet, some examples are so old and written just horribly that people don’t realize the good from the bad.

Considering I have banged my head a few times on the keyboard and let out an occasional profanity only to be followed by moments of happiness and joy at solving a problem (a few hours later), I’d like to bring some trials and tribulations to some of you who hopefully can find some help and answers in this blog post that I have started. Feedback and questions gladly accepted.

Move along, nothing to see here

May 17, 2011

The title basically describes the events of today. It’s another wet, damp and rainy day. Uneventful with little to no excitement. The one thing to look forward to tonight are the Stanly Cup Playoffs between Boston and Tampa Bay. Since “Roli” the goalie is an ex-Islander, I’m rooting for Tampa as they have a good mix of young and veteran players that are totally focused and play as a team. Boston? I don’t like their style of play and at the end of game 1, when they were loosing 5-2 they turned into a bunch of goons. You aren’t going to get respect by literally punching 2 Tampa players in the face; even as the referees are looking right at you. Stupid. Tampa Bay is gonna laugh their way to a championship if Boston thinks that’s a winning way to play hockey.

The Menagerie

May 16, 2011

Now it’s my turn to tell a tale. [For those of you who don’t know Star Trek, the titles of the posts are in someway related to the days events. With only 79 episodes, this will come to an end eventually]. So here I am, a typical New Yorker looking to get his morning breakfast to start the day. I walk into the corner Europa Cafe and decide on a toasted corn muffin w/ butter which I hadn’t had in years. I start to get a little reminiscent about my Healthology days as this was a popular breakfast treat that I ordered often from the PAX located across the street. Don’t misunderstand me, I’ve had muffins throughout the years but never a nice and toasty warm corn muffin. It’s rare to get this done right in New York as the places I’ve gone to hate to toast them. It either messes up their grill or creates a mess for the person preparing it as it crumbles apart when they butter it.

The prized "Toasted Corn Muffin"

So where is this all leading too, have patience I’m getting to it. So, on this rainy morning I dart into the Europa Cafe and set my sights on a corn muffin. As I’m waiting to place my order with the grill chef, one of the women from the cash register come over and ask if my order was taken, This strikes me as rather strange as the grill and cash registers are not close to each other. Regardless, I order a corn muffin and she replies, “You want it toasted with butter?” Amazing, she knows exactly what I wanted. This is great! Finally a place that is willing to heat up my muffins! It’s been ages.

Now as I approach the register with my muffin she rings me up and then hits me with something that totally catches me off guard. She says “I remember you. You are from my old store downtown.” My mind is trying to piece this together as fast as possible. Remember, it’s the morning, I’m on an empty stomach, it’s wet and miserable outside and I have a cashier telling me that they remember me. What is happening!? I’m not ready for this. What do I do? To be safe, I give the polite “Wow, that’s amazing you have a good memory.” She then gives me a reply “As soon as you came in I recognized you it’s been a long time. Here you are. Have good day.”

Dazed and confused I walk out of the store and try to piece together what just happened. I’m happy to say and it’s evident through this long blog post that I have finally figured it all out! While at Healthology from 2001-2005 I used to go to PAX and order my muffins. This is the same woman that used to work at that store and take my order over 6 years ago. To put this into perspective, there are literally millions of people in Manhattan and there are hundreds of people going in and out of a PAX store every day in minutes! Six years has passed and the cashier remembers me and the breakfast I order? I’m speechless and flabbergasted but obviously it’s worth writing about.

Blue 9 Burger on 9th Ave & 53rd

Now for lunch. The name of the place is Blue 9 Burger. It may not look fancy from the outside but the burgers tasted great. Originally the guys at the office wanted to order from bearburger.com which serves ostrich burgers but due to them being over 20 blocks away from us and over 5 avenues, they didn’t want to deliveries to us. Thank goodness because the place we chose as out backup was probably just a good and a heck of a lot cheaper. For $7 you get two fresh, moist beef patties that actually had flavor. Real lettuce, tomatoes, onions and french fries that are extra crispy. This would blow away any McDonald’s or Burger King. The one thing that annoys we with BK and McD, is that what they SHOW you in all their pictures and menu-boards is NOT what you get. You see these beautiful delicious burgers in the photos but what you really get is mass produced, tasteless food the is crushed and looks nothing like their photos.

To describe what a Blue 9 burger looks and tastes like would be taking those BK and McD photos and actually putting the real thing on your plate to eat. Another thumbs up for today’s lunch. The mystery for what lies ahead tonight is diner as my wife is not home (and will not be for quiet a few days due to her trip to Norway) The problem is, I’ve become very dependent on her cooking diner for me so it’s going to be interesting the next few days. Wish me luck.