ENTRIES TAGGED "apps"
Turning Hello World into something useful
When we last left our application, it was running on the emulator, but didn’t do much. This week, we’ll add some more controls to our activity and wire up some functionality.
As a reminder, activities are roughly equivalent to view controllers in iOS. Right now, there’s not much in our activity, because all we have is a single label in our activity. As iOS developers, we’re used to never looking at our XIB files in the raw, because they’re pretty much human-unreadable. By contrast Android layout files (which end up in the
res/layout folder in a standard Eclipse project) are both readable and intended to be edited. At the moment, here’s what ours looks like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>
Effectively combine characteristics and qualifiers for optimum layouts
DisplayMetrics Red Flag
A search of GitHub returns more than 42,000 hits for the class name
DisplayMetrics. This is a red flag. Although there are safe and valuable uses for this information, a quick look at the code using this class reveals that most programs query it to determine screen dimensions, using code like this:
DisplayMetrics displaymetrics = new DisplayMetrics(); ((WindowManager)context.getSystemService("window")).getDefaultDisplay().getMetrics(displaymetrics); int i = Math.max(displaymetrics.heightPixels, displaymetrics.widthPixels); sScreenNailSize = i / 2; sThumbNailSize = i / 5;
The programs then make decisions about how the program should present its user interface. This is dangerous, because it tempts the programmer to make decisions with awful long-range consequences, when these decisions should be left up to the Android run-time.
How to Break Lots of Apps in One Easy Step
How dangerous is it? Pull up a random app on your Android device, go to the Settings and select Font Size, then select Huge.
Now see how many apps break:
- How many have fixed-size views in their layouts where text overflows its bounds?
- How many “fixed” that bug by setting the font size, and ignoring your preferences?
- How many make incorrect layout decisions where objects don’t quite fit?
- How many lock the app’s UI to a landscape or portrait orientation?
When you make your own decisions, based on screen dimension and other parameters, about how to present the user interface, you enter a danger zone that spawns bugs that can easily escape detection in both automated and manual testing. If bugs are caught late in the game, they create pressure to implement lame fixes.
The Only Way To Win Is Not To Play the Game
Aren’t you forced to make decisions about presentation? The answer is “No.” You should not be asking “How high, how wide, how dense, what font,” etc.
You should let Android ask the questions and make decisions about presentation. The only question, then, is how many answers you need to provide. Using multiple layouts for different configurations, and avoiding fixed values in layouts, you can make a system of layouts and let Android choose which layouts to use for different screen sizes and orientations.
Tech events you don't want to miss
Each Monday, we round up upcoming event highlights from the programming and technology spaces. Have an event to share? Send us a note.
Modern Web Applications Utilizing HTML5 APIs webcast: Ido Green covers techniques and tools for building great “modern” web apps, including tips on Chrome DevTools, HTML5 power tools, and modern web app design techniques. Register for this free webcast.
Date: 10 a.m. PT, May 30 Location: Online webcast
TechEd North America: This is Microsoft’s main conference for IT professionals and enterprise developers. Get hands-on experience with more than 200 self-paced labs. If you need to convince your boss to let you go, there’s even a guide to help. For more information and to register, visit the TechEd website.
Date: June 3–6 Location: New Orleans, LA
Three new battles to watch as the mobile hardware gap closes.
The iPhone 5 may or may not be the most beautiful handheld device, but it barely matters anymore. Competitors have rendered its beauty and craftsmanship irrelevant. Amazon has received the message and responded with its latest set of tablets, and Google has responded with the Motorola Droids and the Nexus 7. These devices now have sufficient quality in their materials, specs, and base operating systems so that they can make any consumer happy. So if hardware is a toss up, where will the next battles be fought?
The answer: developers, integration, and discovery.
First, the very best developers will build apps that tap key trends: improved camera quality is making real-world text and face recognition more possible, geofencing data stores are making proximity–based apps more possible, and despite Steve Jobs’ assertion that God gave us 10 styli, there’s clearly a host of applications that are benefiting from pressure-sensitivity and pens. The level to which Apple and Google embrace these new technologies and extend the current state of the art in voice and gesture recognition will factor heavily into the quality and emergence of new applications. In addition, the extent to which Apple and Google can expose these new technologies — like NFC or always-on Glass cameras in Google’s case — will provide an advantage to developers.
Joshua Bixby on mobile speed, platform optimization and KPIs.
Mobile used to carry built-in caveats around speed and design, but those excuses are now wearing thin. In this interview, Strangeloop's Joshua Bixby discusses the evolution of mobile expectations and how companies should adapt.
Marko Gargenta on investing in Android tablet development.
"Programming Honeycomb" author Marko Gargenta discusses the state of Android 3.x, the technical hurdles of Honeycomb, and why the slow adoption pattern of Android tablets may soon change.
Dan and Tracey Pilone on iOS apps and the iPad's influence.
Dan and Tracey Pilone, authors of "Head First iPhone and iPad Development," discuss the maturation of the iOS world, how the iPad has changed development patterns, and what they hope to see in iOS down the road.
Flurry's Sean Byrnes on the challenges of mobile analytics.
Flurry's Sean Byrnes talks about the intricacies of mobile analytics, the metrics app developers care about most, and the problems that stem from Android fragmentation.
"Programming HTML5 Applications" author Zachary Kessin discusses the tools, technologies, and knowledge that help developers build HTML5 apps. Plus: Learn the most common app development mistakes and how to avoid them.
Netflix's Matt McCarthy on building apps that work across platforms.
Matt McCarthy explains how WebKit and A/B testing play important roles on Netflix's many apps. Plus: Platform lessons Netflix has learned that apply to other developers and companies.