trying to build a better android application (part 1)

The circumference of Earth, in miles, which is the product of pi (3.1415926) times Earth’s diameter (7,918 miles).
Samsung Galaxy S4 running Android 5.0.2

Since sometime around 2011 I have dabbled with Android programming, starting with Android Honeycomb. My reasons for targeting Android 3.0 in were:

  1. Honeycomb was explicitly for tablets and I was very interested in the tablet form,
  2. Just about any device could become a developer target device without having to register with Google (unlike Apple),
  3. It had become “interesting” with its new additions in support of tablets,
  4. The Eclipse tooling seemed mature enough, and
  5. I had grandiose ambitions about writing the Next Great App.

That last point included the idle idea of making heaps of money, but that was quashed quickly and rather brutally by the harsh reality of the Android app marketplace.

That didn’t stop me from continuing to tinker with Android over the past few years. My hard drive is now littered with dozens and dozens of toy applications (toy in the sense that they were never launched into the marketplace). Then, one day quite recently, Google saw fit to update my two Nexus 7 2013 models with Android Lollipop 5.1 and 5.1.1 (and I have no idea why one is a point release higher than the other). I even have a Nexus 7 2012 with Lollipop 5.1.1, for all the good that older tablet can use it effectively. A Nexus 7 2012 with Android 5.1.1 is the very definition of molasses-in-January slow. A Nexus 7 2013 with Android 5.1/5.1.1 is at least usable.

Along the way to getting my Nexus 7s upgraded, AT&T upgraded my Samsung Galaxy S4 to their version of Lollipop 5.0.2. That’s what I’ll be using to test my app, rather than the larger Nexus 7 tablet. The S4’s size is about the same physical size as the HP32sII.

With the Nexus Lollipop updates came a built-in calculator app that I quickly came to loath. I don’t know who wrote it, but whomever it was has no concept of what a calculator truly is, especially regarding operational usability. Rather than merely complain about it I decided this was a golden opportunity to dig in and write my own, going by the old adage that if you think you can do better then do so.

Historical Background

I was an incoming electrical engineering freshman at Georgia Tech when the Ga Tech bookstore started to carry the Hewlett Packard HP-35 for $395. As a Georgia resident, that was about how much my tuition and books cost at the time. On my limited budget there was no way I could justify trading in my slide rule (yes, I had one of those) for the HP. But brother, I sure wanted one in the worst way.

The next spring after the HP-35 release I purchased the less expensive Texas Instruments SR-10 model 2 for $90. That lasted me for about two years until I upgraded to another wedge-shaped calculator, the SR-16. I loved those wedgies because they were built like bricks and took a lot of use and abuse. Two years after the SR-16 I advanced to the TI-58, followed rather quickly by the TI-59. After those TI models, when it came time to replace them due to heavy use, my calculator allegiance switched from TI to HP because TI had so cheapened their calculator construction in the interim. I still have working calculators from that period here at the house, but they’re an HP-16C (which I used for digital design work) and an HP-32sii (for general engineering). I have an old TI-95 Procalc I picked up at a heavy discount some point in the distant past. I bought it more for sentimental reasons at the time. It now sits in a drawer, totally unused.

The General Design

I decided to write my own calculator app, based on my experiences with both HP and TI. I did not set out to build an emulator of any particular model. What I wanted was something that fit the ethos of those calculators, especially the HP-67/HP-41C and TI-58/59 calculators. Those machines were their respective companies best of breed calculators. None before or since have quite measured up. It was one of my goals in writing my app to borrow from, but not slavishly re-create, their best ideas.

My app is based on the algebraic notation that TI also used, that is, typing in an arbitrary formula from left to right using parentheses for precedence control and ending the formula with the equals key. That’s why you’ll see those keys on my initial design. It’s a harder design as apposed to reverse Polish notation (RPN), the method used by HP. I won’t get pulled into the age-old argument as to which is better. I just decided for personal reasons to go with algebraic.

Preparatory

The application provided an opportunity to move up to writing idiomatic Lollipop applications using Google’s Material design rules. That meant moving from Eclipse to Android Studio. It also meant having to drop a lot of old coding practices. I’ve been using Android Studio since its beta releases, having created a series of (again) toy applications based on every type of starting template that Android Studio provides. For example my calculator was started with the Blank Activity template, an absolute minimal project, the Android equivalent to “Hello, World.”

I want to note that I will not be going through a step-by-step initial setup for this project. I will be talking about the issues of building this project, and what I’ve discovered along the way with using Android Studio v1.2 and Material Design, both good and bad, primarily good.

Current Functionality

The app can perform all four basic functions; add, subtract, multiple and divide. That means all the data entry keys (all numeric, decimal point), the change sign key, and the equals key work as expected. Clear (C) and clear entry (CE) keys work as expected. The Inverse (INV) and LNX (loge(x)) keys work. The keys that do not work are the Exponent Entry (EE) and the left and right parenthesis keys. You thus can’t perform full algebraic calculations nor can you enter a very large number in scientific notation, such as Avogadro’s number, 6.0221413 × 1023. I may implement that functionality while writing these posts, but that’s the current state of the app right now after several weeks of on-and-off work (mostly off).

What’s Next

The next entry in this series will begin with a general outline of the files in the application, how the app evolved from its initial creation until now, and the problems I encountered along the way with their solutions.

adding java and java-supported development tools to os x yosemite

I’ve been adding capabilities to my Mac Mini since powering it up the middle of this past week. After performing all the necessary OS updates, I installed Xcode 6.2.2. Xcode comes with a series of tools, one of which will be shown later in this article.The installation of Xcode is important to the clean installation of two Java-based tools later on in this post, Android Studio and IntelliJ IDE 14.

System Specifics

  • Mac mini Server (Late 2012)
  • Processor 2.3 GHz Intel Core i7
  • Memory 4GB
  • Two, 2 TB HDD

Preconditions

  • Mac OS X Yosemite Version 10.10.1 (update free from App Store)
  • Mac Server 4.0.3 (update free from App Store)
  • Xcode 6.2.2 (installed free from App Store)
  • Apple’s Java (Java 6) is not installed

Software Installed

Installation of Latest Java

Download the latest version from the Oracle Technology Network. You should be able to find the latest under New Downloads in the upper right corner of the web page. For this example I’m installing the 64-bit Java 8 update 31 (jdk-8u31-macosx-x64.dmg). After download start the installation by clicking or double clicking, depending on where you find the dmg file, to launch the installer.
Simply follow the directions and double click the icon (the transparent yellow square in the open box) to start the installation of Java. The first screen presented to you will be an introduction. There’s very little there, so click through.

When you click to install, it will ask you for your login account password, so type it in to continue.
The installation is a simple progress bar. When it reaches the end all the software will be installed on your system. The last dialog is the summary with a close button. Once installed you can add a JAVA_HOME variable if you like with an “export JAVA_HOME=$(/usr/libexec/java_home)” in your .profile, but I don’t believe it’s necessary. You certainly don’t need to edit $PATH, as there are links to java, javac, and jar in /usr/bin.

You can, if you also wish, download from the Oracle site the Java 8 demo examples. They’re all in a zip file. Once unzipped you’ll find all the demo and example applications that were once bundled with Java. Also included in this collection are example JavaFX applications which are well work looking at. JavaFX is so much better for UI development than the older and much worse looking Swing.

Android Studio and IntelliJ 14 IDE Pre-Installation Preparation

The installation for both is very similar, which they should be, considering that Android Studio is based on IntelliJ IDE. For both download their respective dmg files, double click them to open them in Finder, then drag them into the Application folder. Once in the Application folder you need to make a change to their respective plist files. Find the applications in the Application folder, and right click on them. Select Show Package Contents from the menu.

When the Contents folder appears, click through to the contents where info.plist is located. Double clock on info.plist.When Xcode opens up the plist (you did install Xcode, did you not?) open up JVMOptions, then select JVMVersion and clock on the string to edit it. The string, as shipped, is “1.6*”. Note the asterisk. If the string is left this way you will be prompted by both applications to install Apple’s much older Java 6. Changing the string to “1.6+”, with a “+” replacing “*”, tells the application to use the version of Java installed on the machine. Save this file and then double click the application to finish installation configuration.

For Android Studio I chose to download the separate Android SDK and install it (for my purposes) under $HOME/Java. The SDK comes as a zip file, so unzipping it under $HOME/Java produces $HOME/Java/android-sdk-macosx.

Installing Android Studio 1.0.1

With everything properly prepared, we’re ready to finish Android Studio’s installation (and IntelliJ if you’re so inclined). I’m only going to show Android Studio because it’s the more complex due to the Android SDK, but other than that they’re nearly identical.Make sure you open both top-level menu items and agree to their licensing.You’ll go through several minutes (or longer) of watching Android Studio download any Android SDK files it thinks it needs. This is just a typical capture of this process, and towards the end.We’re finally done!And ready to start development. The installation of IntelliJ is essentially the same but shorter. I’ll spare you the details.

Notes to The Gentle Reader

  • If you think this is overly complicated, it’s not. It’s no worse (and some might argue even simpler) than installation on Linux and Windows. The only obscure piece I had to go looking for was the plist adjustment. This information is missing on both Google’s Android Studio and Jetbrain’s IntelliJ IDEA websites. You’re welcome.
  • This is an initial install. I have no idea what will happen when I update Java, and I will update Java as each version is released. You update for the bug fixes. Failure to update any software is an invitation to grief, which is so easy to avoid. If any problems crop up when an update occurs then I’ll post an update about it here.