Adding Android support to Trident

November 27th, 2009 | 2 Comments »

The main goal of Trident project is to provide a general purpose animation library for Java applications. Animations are a natural fit for modern client applications, and Trident has special built-in support for Java based UI toolkits such as Swing and SWT. The latest 1.2dev drop of Trident provides first support for Android, Google’s software stack for mobile devices.

First, a video that illustrates Trident looping timeline that animates the foreground color of an Android button running in an emulator:

And here is the code of the main activity behind this screen:

public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	Button button = new Button(this);
	button.setText("Hello, Android");
	setContentView(button);
 
	button.setTextColor(Color.BLUE);
	button.setTextSize(30);
	Timeline timeline = new Timeline();
	timeline.addPropertyToInterpolate(Timeline. property(
		"textColor").from(Color.BLUE).to(Color.RED).interpolatedWith(
		AndroidPropertyInterpolators.COLOR_INTERPOLATOR));
	timeline.setDuration(500);
	timeline.playLoop(RepeatBehavior.REVERSE);
}

Those of you who are familiar with the Trident APIs can see that it is the same exact approach as with Swing and SWT. The only difference for Android is the explicit usage of the color interpolator, since the Android APIs use integers for colors – and the built-in mechanism for auto-discovering the matching property interpolator cannot handle this case without explicit coding in either the app code or future Android code base.

Apart from the explicit usage of property interpolator, the application code does not need to handle the UI threading issues (making sure that the TextView.setTextColor is called on the matching UI thread).

If you’re interesting in using Trident in your Android apps, take the latest Trident 1.2dev (code named Cookie Jar) and add it to your Android project. The project documentation describes the basic terminology of Trident, and will provide more Android-specific examples in the next few weeks.


Related posts:

  1. Trident part 2 – interpolating fields Over the course of the next few days i’m going to talk about different concepts...
  2. Trident 1.1 – custom property interpolators Trident animation library for Java applications is nearing release 1.1 (code-named Bogeyman), and it’s time...
  3. Trident part 6 – simple Swing / SWT examples Over the course of the next few days i’m going to talk about different concepts...
  4. Trident part 10 – extending the core with plugins Over the course of this week i’m talking about different concepts in the Trident animation...


2 Comments on “Adding Android support to Trident”

  1. 1 Reinier Kip said at 4:45 am on November 28th, 2009:

    I didn’t see that coming, but I guess it’s only logical as Android is entirely Java-based. Runs quite smoothly, even in the emulator! Might use this in the future.

  2. 2 Manuel Kaess said at 6:02 am on December 1st, 2009:

    Great work Kirill!

    It’s nice to see that you are not focusing on Swing only and build a library that is ready to use for a variety of systems.
    One doubt though: I haven’t played around with it a lot yet but isn’t there already good animation support in Android itself? What are the benefits of using an additional library instead of using Androids build-in animation capabilities?

    Cheers,
    Manuel