Developer Reference

Developing for Android platform

You should have a zip file like that when you download the code from CloudyRec.

Downloaded source
Fig 1.1: Downloaded source code for Android

1. Creating a new Android project in Eclipse

Extract the downloaded zip file to your workspace. As we can see in the following figure, it has all the necessary files to start an Android project development.

Directory contents
Fig 1.2: Android source directory contents

So in Eclipse, we can create a new Android project from existing source by selecting the source code folder you just downloaded from CloudyRec. Take note that the downloaded Android project folder also contains the main activity java class as well. So if we already have an existing project we’re working on, we can just import the “src” folder from the downloaded folder.

Eclipse new project
Fig 1.3: New Android Project

Create project from existing source
Fig 1.4: Create project from existing source

CloudyRec requires Android API level at least 10 which is Android 2.3.3.

Android API version
Fig 1.5: Android API version

Your project folder will look something like this.

Eclipse project directory
Fig 1.6: Eclipse project directory

2. Using resource methods

CloudyRec generates each resource we defined as an individual class with OOP designs in mind. That means if we define 2 resources as user and blog_post, we’ll get 2 classes with their respective names. In the following code examples we’ll use the ‘user’ resource we created previously as an example.

For demo purpose, we’ll omit the steps like exception handling, importing header files and packages. We can use Eclipse’s features like ‘Quick Fix’ to easily add necessary exception handling and import required packages. You are also encouraged to explore the resource classes being generated.

2.1. Creating data

Creating a new record can be done in multiple ways. The simplest way is to pass all the required attribute values to the constructor when creating a new resource object. Then call the save method to upload the data to CloudyRec.


User user = new User("user id", "secret pwd");
user.save();

2.2. Authenticating an existing user

If a resource is being checked as “is authenticable” during resource creation, we can use the generated authenticate method to login with a user id and password.


User user = new User();
Boolean isSuccess = user.authenticate("user id", "secret pwd");

2.3. Retrieving data

To retrieve the records from CloudyRec servers, you can use the list method. This method accepts a parameter to specify selection filters. If you pass null, it’ll return all the records from that resource.

Selecting all users:


User user = new User();
List<User> l = user.list(null);

Iterating through the list:


ListIterator<User> li = l.listIterator();
while(li.hasNext()) {
	User curUser = (User)li.next();
	Log.v(ACCOUNT_SERVICE, curUser.getUname());
}

Selecting a particular user:


User user = new User();
List<User> l = user.list("_uname=user id");

2.4. Updating data

In order to edit and update a record, we first need to get the record ID that we want to edit. Then update its properties through getter/setter methods and call the save method again.

Updating all users:


User user = new User();
List<User> l = user.list(null);
ListIterator<User> li = l.listIterator();
while(li.hasNext()) {
	User curUser = (User)li.next();
	curUser.setEmail("new_email@cloudyrec.com");
	curUser.save();
}

Updating a particular user:


T.B.A

2.5. Deleting data

Deleting a record is similar to updating a record. We first get the record ID we want to delete and the call the delete method. Let’s delete all the records from our user resource.

Deleting all users:


User user = new User();
List<User> l = user.list(null);
ListIterator<User> li = l.listIterator();
while(li.hasNext()) {
	User curUser = (User)li.next();
	curUser.delete();
}

Deleting a particular user:


T.B.A