For the purposes of the Tutorial, we will instantiate the FatFractal class as a singleton in a new Hoodyoodoo class which is a subclass of Application.
First, add a new class to com.hoodyoodoo.droidapp called Hoodyoodoo that subclasses Application. This class will do a couple of things for us:
First, enter the following package and import statements:
package com.hoodyoodoo.droidapp;
import android.app.AlertDialog;
import android.app.Application;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import com.fatfractal.ffef.FFException;
import com.fatfractal.ffef.FatFractal;
import com.fatfractal.ffef.impl.FatFractalHttpImpl;
import com.fatfractal.ffef.json.FFObjectMapper;
import com.hoodyoodoo.droidapp.model.Celebrity;
import java.net.URI;
import java.net.URISyntaxException;
Here, we define the Hoodyoodoo class itself:
public class Hoodyoodoo extends Application {
}
The rest of this section will be filling in the definition of the Hoodyoodoo class. We first define a static FatFractal data member:
public static FatFractal ff = null;
Next, define a getFF method that initializes the FatFractal class, sets the URL configuration for which API it will use, and registers the Celebrity Class:
public static FatFractal getFF() {
if (ff == null) {
String baseUrl = "http://acme.fatfractal.com/hoodyoodoo";
String sslUrl = "https://acme.fatfractal.com/hoodyoodoo";
try {
ff = FatFractal.getInstance(new URI(baseUrl), new URI(sslUrl));
FatFractalHttpImpl.addTrustedHost("acme.fatfractal.com");
FFObjectMapper.registerClassNameForClazz(Celebrity.class.getName(), "Celebrity");
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
return ff;
}
We call getFF in the standard onCreate() method for Application:
public void onCreate() {
super.onCreate();
if (ff == null) {
ff = Hoodyoodoo.getFF();
}
}
In the next section, we finish the Hoodyoodoo class by making a layout for a login dialog, and adding a method to show it and perform the login.
NEXT: Create a Login Dialog