Hour 1. Introducing Android 4


What You’ll Learn in This Hour

• New features in Android 4

History of the platform

Android hardware specifications

• Dev system requirements


The first four hours are very hands-on with step-by-step tutorials on setting up the Android SDK using two development environments: NetBeans and Eclipse. We will go over the steps to configure either Eclipse or NetBeans (your choice) for Android development.

This hour begins our exploration of game programming on Google’s new smartphone platform, Android 4. There are two versions currently in circulation at the time of this writing: 4.0 (Ice Cream Sandwich) and 4.1 (Jelly Bean) with additional sub-versions expected in the coming year. Android 4 feels like a whole new platform, not just an upgrade of 3.2. One exciting thing about making games for Android is the excellent software development kit and development tools. We’ll discuss the devices, feature set, and specifications in this hour, and we’ll dig into the development tools right away. I assume you already know how to use your Android phone and want to get started writing code as soon as possible. You’ll be up and running with Android code in no time! This hour is intended to help you choose an appropriate target for your game because there are so many Android devices. We’ll look at the most common phones and tablets and compare their hardware specifications to see what types of games most devices will run.

Hello, Android 4

The most surprising thing about Android is that it has fully matured as a competitor in the smartphone market in only three years! From concept to the present version in three years is a remarkable feat. But there’s a reason: Android is based on Linux core 3.0. Yes, it is essentially a derivative of the Linux operating system.

That Android competes successfully with Apple’s powerhouse iPhone is significant given that Android was late entering the market, after Apple had a two-year head start. Microsoft continues to take market share away from both Google and Apple with its Windows Phone platform, which has seen similar fast-track improvements in the past year. As a result of the pacing, Google’s Android SDK and OS developers tend to rely on creativity to get through challenges that normally require more time (see Figure 1.1).

Image

Figure 1.1. Android 4.0, Ice Cream Sandwich. Image courtesy of Google.

Figure 1.2 shows the home screen for an Android 4 smartphone in portrait orientation. Note the simple layout of the interface. At the bottom are three soft buttons: Return, Home, and Tasks. The Return button is a generic Back button. The Home button returns to this screen.

Image

Figure 1.2. The Android 4 home screen. Image courtesy of Google.

The Tasks button brings up the screen shown in Figure 1.3, which shows running apps (including games) for quick task switching (also called Recent Apps). At the top is the Google search field with voice recognition.

Image

Figure 1.3. Browsing the running apps using the Tasks (Recent Apps) button. Image courtesy of Google.

Before learning all about Java SE 7, source code projects, compiler configurations, Android Market, and other great things that will interest a game developer, we need to first understand this new platform. Android is an operating system for smartphone devices. Android is also non proprietary, meaning that licensing the OS from Google is free. The source code for Android is open source. In contrast, Microsoft and Apple have a tight grip on the source code for their operating systems: Windows Mobile and iOS, respectively. These companies strictly regulate the release of their OS.

Microsoft licenses the Windows Mobile OS, aka “Windows Phone,” to manufacturers, who then use the OS on their devices. This is a middle position on licensing: not as wide open as Google, not as restrictive as Apple.

Apple maintains its proprietary control over both the OS and hardware, fine-tuning both exceptionally well. Although Apple iOS devices do not enjoy the broad offerings and versatility of Android, they do offer a more refined and consistent experience because one company designs both the hardware and software to work together.

Figure 1.4 shows the Apps installed on an Android 4 smartphone.

Image

Figure 1.4. The Android 4 Apps screen. Image courtesy of Google.

There is a price to pay for open source, though. Releasing the source code for the OS does not automatically mean Android will dominate the market. On the contrary, one challenge for Android game developers is the large number of nonlicensed hardware manufacturers building Android phones and tablets without “permission” from Google. These manufacturers follow a guideline or “hardware API” for their devices to ensure broad compatibility among devices, but there are exceptions. Some Android phones and tablets use a different CPU, so they will not run some apps and games!


Did You Know

If you’re planning to port your smartphone games to other platforms, see my other recent book from Sams, titled Teach Yourself Windows Phone 7 Game Programming in 24 Hours.


There was a time not too many years ago when just having a PC was enough to do your work: programming, software engineering, computer-aided design (CAD), word processing, accounting. Even in the 1980s it was rare for every employee to have a PC at his or her desk, and even more rare for families to have a PC in their homes. A lot of kids might have had a Nintendo Entertainment System (NES), a Sega Master System (SMS), or the older Atari 2600, all of which used cartridge-based games. A step up from these video game systems were the true PCs of the time, such as the Apple II, Commodore 64, Amiga, Atari 400/800, Atari ST.

No computer enthusiasts at the time used an IBM PC at home! MS-DOS was a terrible operating system compared to the other, more user-friendly ones. If you wanted to do programming, you would naturally gravitate to the consumer PCs, not the business-oriented IBM PCs. At the time, the Apple Macintosh was pretty expensive, and the ordinary kid would prefer an Apple II, but that was the start of the Mac back in the 1980s (although it has been completely redesigned several times before reaching the modern OS X).

Today the world is a different place. Even if we ignore how powerful computers are today, just look at all the handheld systems. The Nintendo DS family and the Sony PSP family are the two leading competitors of handheld video game systems, and they can do almost anything that their big brothers (Nintendo Wii and Sony PS3) can do, including online play. These things are everywhere! You can’t walk through a store or a mall without seeing kids carrying some sort of mobile video game system with them, not to mention smartphones. And it’s not just kids, but adults have their toys, too, like iPhone, iPad, Windows Phone, and Android devices.

One of my favorites is Plants vs. Zombies by PopCap Games. This game has been ported to most systems, including Xbox 360, Mac OS X, Windows, Nintendo DSi, iPhone, Android, and dozens of other systems. And you know what? Some of the higher-profile games are starting to come out for Android 4 already, ported from other systems like Windows, Xbox 360, and iPhone.

So what is Android 4 all about? Obviously, because you’re reading this book, you are interested in programming games for the device. But what is development for this platform really like? What’s it all about? We have to ask ourselves these questions because developing a game that you want to be taken seriously requires a pretty big investment of time, if not money. Most likely, anyone looking at Android 4 for game development is already experienced with Java SE 7. If you have never used this development tool, the next two hours will be really important because we’ll be creating projects and working with both NetBeans and Eclipse quite a bit. I’ll assume that you might not have any experience with the development tools.

About the Android SDK

The Android SDK is based on the Java language. Java programs are compiled with the Java Development Kit (JDK). All apps and games are written in Java and run on Android devices using the Java Runtime Environment (JRE). A Java program has an extension of .class, and the source code file has an extension of .java. Programs built with the Android SDK are compiled into a package that can run on the Android platform. There are two primary development environments for Java: Eclipse and NetBeans. Both have strong points and weak points, and neither is really superior to the other—it’s more a matter of preference. Instructions on installing and configuring the Android SDK are coming in the next two hours.

If you are a beginner to both Java and the Android SDK, you should still be able to follow the instructions and get started writing Android code. But, if you have never programmed in a language like Java before (such as C#, C++, or Lua), you may find the code difficult to understand. A programming novice may want to read a primer on basic Java programming before continuing on with the Android SDK. Because many concepts are shared among all programming languages, it is helpful to know at least one of these languages. Some programming experience is really important to feel confident with the code in this book because we don’t go over basic programming concepts—there’s just too much to cover!

If you are already an experienced Java developer, you will still want to peruse the information over the next two hours to get a handle on the installation and structure of the Android SDK and development tools.

About the Android NDK

The Android NDK (which differs from the SDK) lets you write components of an app or game in native C++ code instead of Java. The NDK is a separate tool installed after the Android SDK is already installed. The NDK does not allow you to write an entire app or game in C++. Rather, it is used to supplement the SDK with support for C++ code and libraries and is meant to operate as a bridge to many hardware devices for which no Java library is available. We can use the NDK to optimize our game code. In addition to many C++ libraries, the NDK also supports OpenGL ES 2.0 for 3D rendering, OpenSL ES for audio, and pixel buffer access. The Android developers do not recommend using the NDK for most apps and games, but a game developer always looks for every edge!

Android Dev System Requirements

The Android SDK supports these operating systems:

• Windows XP, Vista, 7 (32- or 64-bit);

• Mac OS X 10.4.8 or later (x86 only)

• Linux (32- or 64-bit); any dist with GLibc 2.7 or later

We will be using the Windows version of NetBeans and Eclipse, giving you the choice of which IDE to use. The installation and configuration of both IDEs and the Android SDK is covered in the next two hours.

History of the Platform

Android 4 follows a very short history, dating to the first Android SDK in 2008. Android competes directly with Apple’s iOS, which includes iPhone, iPod, and iPad devices. Although Microsoft’s Windows Phone 7 follows in market share, it is also a worthy competitor.

Interestingly enough, I would not consider Apple’s iPhone an evolutionary leap beyond Palm Pilot (the first “PDA”). The iPhone does not follow in the lineage of “mobile computer” dating back to the Palm Pilot and Pocket PC; instead, iPhone (that is, iOS) was derived from Apple’s iPod. The iPod might have been invented by Sony, the company responsible for the Walkman generation of portable music players. Everyone in the 1980s or 1990s had at least heard of a Walkman at one time or another.

You have surely heard the term podcast. The term is rather generalized today to mean digital audio streamed for playback on the Web or on a portable player. The concept was invented by Apple for the iPod and iTunes, which now support video as well. While many of us were caught up in the Napster lawsuits over music sharing, Apple was busy developing iTunes and began selling music in a revolutionary new way: per track instead of per album.

Have you ever heard a catchy new song on the radio and wanted to buy it for your iPod, Android music player, or similar media device? In the past decade, you would buy the whole CD and then rip the tracks into MP3 with software such as Windows Media Player or Winamp. This point is debatable, but I would argue that Apple iTunes proved that digital music sales can be a commercial success, highly profitable both for the recording artists and for the service provider. Amazon has also shown that digital media is a successful industry.

iPod was so successful that it evolved into the iPhone and iPad, and competing companies have been trying to keep up with Apple in both of these markets now for several years. The iOS operating system works great. It does what users want, rather than what software engineers think users want—that’s a key difference. Although Android is derivative of iOS, it offers its own innovations, such as being based on a grounded, established core in Linux.

What did customers want? Not a do-everything poorly device, but a do-the-most-useful-thing great device. In contrast, many companies hire “experts” to conduct consumer studies and then spend millions trying to convince customers that they really want and need that product. This might be one good way to break into a relatively unknown market or to adjust the feature set of a product according to consumer interest. The situation Apple found itself in back in 2007 with the release of iPhone was enviable, and with that came emulation.

Where Google has placed its mark is in licensing to attract hardware manufacturers. Most of Google’s awesome web services—Earth, Maps, Picasa, and Documents (known as Google Drive for Android users)—are available for Android as free apps. The free licensing is compelling to device manufacturers, which has allowed Android to claim over a third of the market share in the smartphone and tablet markets.


By the Way

Android OS 1.0 was released in September of 2008. That is a very quick-to-market time considering the maturity and stability of the OS in its current form.


Table 1.1 charts the very brief history of this awesome OS.

Table 1.1. History of Android OS

Image

Android Hardware Specifications

Android OS is used on many types of devices, not just smartphones, although that is the largest market by far. Figure 1.5 shows a Samsung Galaxy Nexus smartphone. As you can see in Figure 1.6, the design of the tablet is very similar in the Samsung Galaxy Tab. This is by no means an endorsement of any one brand; it is simply meant to show a comparison between a smartphone and tablet from the same manufacturer.

Image

Figure 1.5. The Samsung Galaxy Nexus (Android phone). Image courtesy of Samsung.

Image

Figure 1.6. The Samsung Galaxy Tab (Android tablet). Image courtesy of Samsung.

Table 1.2 shows the common hardware specifications among the most popular Android models available at the time of this writing. The most notable thing about the specifications is that they now follow a basic standard across all manufacturers. Apple has demonstrated that too much openness and flexibility are not always desirable traits in mobile hardware. One of the difficulties facing Android developers today is the need to support many different hardware devices in a single code base. We will address this problem when covering the Android display system.

Table 1.2. Android 4 Hardware Comparison

Image

The Android OS has rapidly become a leading contender to Apple iOS with nearly 40% market share. We’ll be seeing a lot more of the friendly Android logo (Figure 1.7) in the years to come. This is definitely a strong platform, a worthy investment of your time.

Image

Figure 1.7. The Android OS logo. Image courtesy of Google.

Summary

The Android operating system has matured very quickly in only three years. The latest version, Android 4, is fully capable of competing with iPhone and Windows Phone. You will be using the Java language and the Android SDK to program games on this platform.

Q&A

Q. Android OS was developed and released rapidly in a very short time and quickly gobbled up market share from Apple’s iOS. What possible ramifications will there be long term because of this rapid development?

A. Answers will vary.

Q. Because the Android OS is open source software, the source code for the OS is freely available. Is this a strength or a weakness? Explain your reasons.

A. Answers will vary.

Workshop

Quiz

1. What language do you use to program with the Android SDK?

2. What is the nickname of Android OS 3.0?

3. Which version of the Android OS has the nickname of Ice Cream Sandwich?

Answers

1. Java

2. Honeycomb

3. 4.0

Activities

Go online to Google and search for the Android SDK. Look up version 4.0 or 4.1 and note the URL to the documentation page. Bookmark this page for future reference—you’ll need it!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.22.23