This is Part III of my notes on what I’ve learned on Android programming. See Part I and Part II here.

Plotting Package

Options

Intuition tells me that people have already developed plotting packages so that I do not have to reinvent the wheel. A quick Google search gives me Android GraphView and AndroidPlot. The latter seemed a little more feature rich and turned out to be very easy to use.

AndroidPlot

I have only experimented with the XYPlot of AndroidPlot, and the official tutorial is easy to understand and follow. Based on this, I managed to created custom XYPlot for my plotting purposes.

The steps for using an XYPlot are as follows.

  1. Subclass the XYSeries class.
  2. Override the getTitle(), size(), getX(int index), and getY(int index) methods.
  3. At index, the values of getX(index) and getY(index) represent a pair of coordinates of a single data point. The rest of the steps are the same as on the official tutorial page.
  4. Define a style file indicating how the plot would be plotted, as seen in the res/xml/line_point_formatter_with_plf1.xml file on the the official tutorial page.
  5. Draw the plot using the following statements.
     plot = (XYPlot) findViewById(R.id.simpleXYPlot);
     LineAndPointFormatter sf = new LineAndPointFormatter();
     sf.setPointLabelFormatter(new PointLabelFormatter());
     sf.configure(getApplicationContext(), getStyleResId(R.xml.line_point_formatter_with_plf1));
     plot.addSeries(myXYPlotObject, sf);
     plot.setTicksPerDomainLabel(3);
     plot.getGraphWidget().setDomainLabelOrientation(-45);
    

Here, the plot variable is a XYPlot object defined as a layout provided by the AndroidPlot project. A sample definition is the res/layout/simple_xy_plot_example.xml file on the official tutorial page.

Testing Apps and Misc

Testing on Samsung Galaxy Tab 10.1

I purchased a Samsung Galaxy Tab 10.1 long time ago, and did not make very good use of it. Then Apple and Samsung fought in court and Apple managed to ban the sale of my model in US. Ergo, I cannot even resell the tablet in US. Luckily Samsung still provides support so I recently upgraded the OS to Android 4.1.

Running applications on an Android tablet is way faster than with the emulator. Only one thing to note here is that, while debugging my program in Eclipse, the device would display a message that is not a typical ANR (application not responsive) message. It just says that it is waiting for the debugger to connect. Just wait, and do not click OK (in which case the debugging would be canceled).

Using ADB

With a real device, I do not usually need to use the ADB utility that often. However there are a lot of things that adb can do conveniently, for example pushing and pulling a file to and from the device, respectively.

Using Genymotion as a Testbed

Genymotion is another option for Android application simulation. A major benefit that people recommend Genymotion as opposed to Android emulator is the speed. From my experience, it is indeed very fast–not a bit, but a lot faster than the Android emulator.

The reason that I use it is for experimenting possible options since I can already use my tablet as a better option for testing. Nonetheless Genymotion has not diappointed me.

A few things to note when using Genymotion are the following:

  1. It requires a relatively new version of VirutalBox.
  2. It requires registration of a Genymotion account in order to get a virtual device image.
  3. The free version has limitations, as compared on this page. If some of the premium features are what you must have, then it may cost a fortune.

Running Multiple Instances of Eclipse in MacOSX

By default if you click the icon of Eclipse on the Dock the system will bring up an existing instance of Eclipse, not starting a new one. What I needed in my project was that some business logic is being developed in one Eclipse workspace, while the UI and some other logic is being developed in another. The trick to start another instance of Eclipse in MacOSX is to do it in a command line with the open command with a -n option. For my case, it is open /Applications/eclipse/Eclipse.app -n.