The Sex and Cash Theory for Programmers

Draw a Circle Graphic with ESRI Android SDK

14. November 2011 12:56 by Scott in Development, ESRI  //  Tags: , , ,   //   Comments (3)

I wrote this code a while back.  The requirement was to have a user draw a circle with the ESRI Android SDK.  Well, their Android SDK doesn't currently support drawing circles.  It draws all other types of polygons except for the circle.  So what does a Software Engineer do, we come up with our own implementation.

So for the world to see, here it is:

First we capture the OnMotionEvent and the comments are in line.

Hope this helps someone.

    public boolean onDragPointerMove(MotionEvent from, MotionEvent to) {

        if (tempCircleGraphic != null)

        // creates a new polygon to be drawn.
        _circleTemp = new Polygon();

        Point point = _map.toMapPoint(to.getX(), to.getY());

        // If the starting point is null, create a polyline and start a
        // path.
        if (_startPoint == null) {
            _startPoint = _map.toMapPoint(from.getX(), from.getY());
            // creates a polyline so we can measure the radius of the
            // person
            // drawing the circle.
            _polylineTemp = new Polyline();
            // starts the poly line
            _polylineTemp.startPath(_startPoint.getX(), _startPoint.getY());
        // continues the draw of the poly line
        _polylineTemp.lineTo((float) point.getX(), (float) point.getY());

        // calculates the circle when getting ready to be drawn.
        int pointsAroundCircle = 50; // N
        double radius = _polylineTemp.calculateLength2D(); // radius
        for (int i = 0; i < pointsAroundCircle; i++) {
            double fi = 2 * Math.PI * i / pointsAroundCircle;
            double x = radius * Math.sin(fi + Math.PI) + _startPoint.getX();
            double y = radius * Math.cos(fi + Math.PI) + _startPoint.getY();
            if (i == 0) // starts the drawing of the circle. if
                        // beginning
                        // the for loop
                _circleTemp.startPath(x, y);
            else if (i == pointsAroundCircle - 1) // ends the circle
                                                    // when at
                                                    // the end of the
                // for loop.
                // continues drawing the cirlce while it iterates
                _circleTemp.lineTo(x, y);
        // creates a new graphic and sets the geometry to a polygon.
        Graphic graphic = new Graphic();

        int drawColor = getDrawColor();
        int transparentColor = Color.argb(POLYGON_ALPHA,,
        SimpleFillSymbol fillSymbol = new SimpleFillSymbol(transparentColor);
        tempCircleGraphic = graphic;
        // add the updated graphic to graphics layer

        // Refresh the graphics layer
        return true;


java.lang.RuntimeException: Stub! On With JUnit and Android

2. November 2011 10:35 by Scott in Development, Android  //  Tags: , , ,   //   Comments (34)

Running into another Error I figured I would blog about.

So im getting a Stub Error while trying to JUnit test a library I built with some Android code inside of it.  The Error is as follows:

java.lang.RuntimeException: Stub!
    at com.irad.conversion.gml.GmlConverter.GetAttributesFromGml(
    at com.irad.conversion.gml.GmlConverter.ConvertGmlPolygonToGraphic(
    at com.irad.conversion.gml.GmlConverter.ConvertGmlToEsriGraphic(
    at com.irad.conversion.gml.test.GmlConverterTest.ConvertGmlToEsriPolygonRingsGraphicTest(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(
    at org.junit.internal.runners.statements.RunBefores.evaluate(
    at org.junit.internal.runners.statements.RunAfters.evaluate(
    at org.junit.runners.ParentRunner.runLeaf(
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(
    at org.junit.runners.ParentRunner$
    at org.junit.runners.ParentRunner$1.schedule(
    at org.junit.runners.ParentRunner.runChildren(
    at org.junit.runners.ParentRunner.access$000(
    at org.junit.runners.ParentRunner$2.evaluate(
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

While, I couldn't figure out what was going on, I kept getting a message of Stub while running some Android API code.  Keep in mind I was testing with JUnit outside of the official Android Test Project.  And in that lies the problem.


In order to run Android API code, you MUST run it on the emulator.  Which to me stinks and for something as easy as converting colors like I was feels needless, but I guess I must now convert all my JUnit tests to the Android JUnit Project Sadly.

Pushing Large Files to Android Using Eclipse Tip

10. March 2011 17:12 by Scott in   //  Tags: ,   //   Comments (0)

I was pushing large files to the Android Emulator lately.  We are talking above 100mbs a piece or more.  When I uploaded them in Eclipse, they would break and not upload about half way through.  It took me a few hours to keep trying till I got frustrated.

So I found a tool inside the Android SDK Folder under the platform tools folder.  Its call adb and it needs to be run with the command line.  This tool actually worked and I was able to watch it work via the Eclipse DDMS view.

So if you need to upload large files for any reason and eclipse is failing you, use the adb tool.


C:\Program Files (x86)\eclipse\android-sdk-windows\platform-tools>adb push C:\UsersAndroidCs2\Map.db /mnt/sdcard/mapdata/Cycle_Map.db

One Error I received before I found this tool:

[2011-03-10 16:10:17] Failed to push the items
[2011-03-10 16:10:17] (null)

Android Unit Test Tip

3. March 2011 12:56 by Scott in   //  Tags: ,   //   Comments (0)

Something I had to learn the hard way when unit testing in Android.

When using this tutorial for testing in Android:

Something that they don’t tell you is to you must declare that the methods are tests.  Well since I was also used to adding attributes to C# tests in Visual Studio.  You don’t have attributes in java.  Sadly.

So whats the next step in declaring that your method is a test?

public void testAssertions(){}

You must declare it in the syntax.  By preceding the method name with the word “test” like the method above, you declare that it is a test.  I know, this sounds stupid and the darn tutorial doesn’t even explain that this is required, but it is.  This little problem took me a day to figure out.

Some errors I received because of this little problem are below:

Test run failed: Test run incomplete. Expected 1 tests, received 0.

Mobile Device Maps Need a Zoom Out Button

18. February 2011 16:23 by Scott in   //  Tags: , , ,   //   Comments (9)

To All Developers of a Mobile Mapping Tool,

Will you please build into the map a button to zoom out? 

Let me give you all a scenario I find my self in all the time.  I am walking down the road and I have a mobile device in one hand, while carrying a bag of something in the other.  I am trying to find out where I exactly need to go.  I look at my mobile map and it has the directions on it.  I click on the map with my ‘opposable thumb’ to zoom into the location, But oh wait, I zoomed in to see what corner its on and now I need to zoom back out to watch where I am walking. 

Can you please tell me how to do this efficiently without pulling up my other hand to use two fingers to zoom out?  I can’t even use my ‘efficiently nature given opposable thumb’.  I have to use two fingers to zoom out.  Did someone expect me to zoom in with my thumb, but never wanting to zoom back out?  The hand held device should be capable of being used with just one hand.  The Zooming on maps does not allow this ability.

This scenario can happen anywhere and bite you in the butt. 

  1. Walking with groceries.
  2. Driving with GPS.
  3. Its cold out side and I have gloves on.  Why would I want to remove both pairs?
  4. I am a War veteran and I lost my arm in battle.  Not to mention if I just lost my hand.
  5. I have a Beer in one hand and walking down some downtown street at a festival and I need to find my friends.  I would never put my beer down.  That’s just disrespectful to the beer.

This is a PLEA.  Please implement a ZOOM OUT button by default or just enabling it in settings.  I personally develop for Android and WM7 and make sure I put that Zoom out button on the same screen as the map.  Zoom in is a totally different scenario since I can just click on the map to zoom in.

Please, Just think about it!