Tuesday, November 16, 2010

Symja Computer Algebra System

I have begun incorporating the Symja CAS into the Calculus Tools application.  This should make the application much more powerful, stable and bring some great features like symbolic integration to the application.  Unfortunately, this will be rather time-consuming, and updates for Calculus Tools will probably be far off.  It should prove to be well worth the wait though.

Progress may be tracked through at http://code.google.com/p/android-symja/.  Expect the first code check-in this weekend.

Thursday, November 4, 2010

Cupcake and Donut Compatibility Part I (The Invisible View Conundrum)

Android 1.5 (Cupcake) is a total nightmare to design for.  1.6 (Donut) is not a whole lot of fun either.  Fortunately, Cupcake has dropped to about 8% of the current Android population, and Donut is at 16%.  Unfortunately, to target Eclair, one is losing out on nearly a quarter of the possible users on the market.  Furthermore, since these users have almost no one releasing apps for them, they are more likely to use your app because it is their only option.

In Part I of the Compatibility series, I will demonstrate a work around for a disaster that happens one sets a View of a RelativeLayout invisible in Android 1.5

Now, suppose you three views in a RelativeLayout.  For example:


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
android:id="@+id/TextView1"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="TextView1"
    />
<TextView  
android:id="@+id/TextView2"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="TextView2"
    android:layout_below="@id/TextView1"
    />
<TextView  
android:id="@+id/TextView3"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="TextView3"
    android:layout_below="@id/TextView2"
    />
</RelativeLayout>

This should look like




Now, suppose you want to set TextView2's visibility to View.GONE with

findViewById(R.id.TextView2).setVisibility(View.GONE);

Cupcake will give you this wonderful view:



Now, in subsequent versions of Android, this will show up like this:



The trick to get this sort of implementation in Cupcake is to wrap TextView2 in a descendant of ViewGroup, (AbsoluteLayout, LinearLayout, RelativeLayout, etc.).  The code below uses LinearLayout  to serve as a wrapper for the invisible TextView2.


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
android:id="@+id/TextView1"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="TextView1"
    />
<LinearLayout
android:id="@+id/ViewGroup1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/TextView1">
<TextView  
android:id="@+id/TextView2"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="TextView2"
    />
</LinearLayout>
<TextView  
android:id="@+id/TextView3"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="TextView3"
    android:layout_below="@id/ViewGroup1"
    />
</RelativeLayout>

The problem exists because in Android 1.5, when TextView 2 is removed from the view, TextView3 is now asking the RelativeLayout to put it below a view that doesn't exist.  Thus, RelativeLayout, instead of crashing puts it in the default top-left corner.  In the code directly above, there is no view that references TextView2 to find it's layout.  ViewGroup1's height is set to wrap_content so when TextView2 disappears, ViewGroup1 no longer has any elements.  Thus, it collapses to 0px in height and TextView3 lies directly below TextView1.

This issue was corrected in Android 1.6.

Application Install to SD Card

As many of you know, a great feature included with Android 2.2 is the ability to install apps to the SD card.  Most Android phones have a limited amount of ROM, which is used for system files, text messages, emails, applications, etc.  All applications that do not implement services, Fortunately, this is an extremely easy feature to implement in an application, and it done while being compatible with previous versions of Android.

In the manifest tag of the Android Manifest, simply add the attribute
android:installLocation="auto"
to the Manifest tag.  Now, in order for this to compile you must use the Android 2.2 SDK.  In order to ensure backwards compatibility, make sure to set your minimum SDK requirement to whichever SDK the rest of your application will work for.  When the application is loaded on an older version of Android than Froyo, this tag will simply be overlooked.

Now, some may be hesitant to constantly compile their application against a newer version because they may accidentally overlook the use of a newer API that may crash the application at runtime.  This can be circumvented by loading all your class and resource files into a separate library project which compiles against the older SDK and importing it into your main project.  In your main project, all that is needed is a manifest.

If you already have Android library files, this should not be an issue as with the recent SDK tools (r7), Android libraries may now import Android library themselves.

Tuesday, November 2, 2010

Calculus Tools 1.2

Sorry for the late change-log.

New additions in 1.2:

Support for piece-wise functions (see help section for details)
Experimental 3D graph controls
Plenty more Bug Fixes and Bugs