Few weeks ago I wrote my first Android Jelly Bean App named ColorChanger. Since then I wanted to integrate it with Arduino and Control a physical RGB LED Light from the ColorChanger Android App. I finally managed to get it done using the following Items.
Arduino Mega 2560 Rev 3
DFRobot USB Host Shield
Arduino IDE 0023
ADK Library
1 RGB LED
1 1k Resistor
Few Jumper Cables
One USB to Micro USB Cable
Few things changed from the original ColorChanger App starting from the AndroidManifest.xml where I had to allow my MainActivity to listen for USB_ACCESSORY_ATTACHED intent action and when my Accessory connects open the ColorChanger App.
jqgrid plugin is one of the most famous jquery plugins to display tables in web pages which enables searching, sorting and filtering etc.
I wanted to integrate jqgrid with Struts2 but there was little to no proper documentation on how to do it. I wanted to use JSON format and no website has clearly mentioned (or atleast I didn't find any) the format of the JSON and how it needs to be created using Struts2. So after some trial and error I managed to get this to work.
There are two Actions getUserList which will return the JSON result and ListUsers which will render the JSON into the jqgrid.
Following is the source code for GetUsersListAction and since this object is directly used to serialize the result into JSON it needs to have the instance variable names as it is with getters and setters.
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.Action;
import com.shazin.struts2hello.model.User;
import com.shazin.struts2hello.service.UserService;
import com.shazin.struts2hello.service.impl.UserServiceImpl;
public class GetUsersListAction {
private String page;
private Double total;
private String records;
private List rows;
public String execute() {
page = "1";
total = 1.0;
UserService userService = new UserServiceImpl();
List<User> usersList = userService.getAllUsers(); // Retrieves users from database
records = usersList.size()+"";
rows = new ArrayList();
int id = 1;
for(User u:usersList) {
rows.add(new Row(String.valueOf(id),
new String[] { String.valueOf(id), u.getFirstName() , u.getLastName(), u.getUsername(), u.getEmail() }));
id++;
}
return Action.SUCCESS;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public Double getTotal() {
return total;
}
public void setTotal(Double total) {
this.total = total;
}
public String getRecords() {
return records;
}
public void setRecords(String records) {
this.records = records;
}
public List getRows() {
return rows;
}
public void setRows(List rows) {
this.rows = rows;
}
public class Row implements Serializable {
private String id;
private String[] cell;
public Row() {
}
public Row(String id, String[] cell) {
setId(id);
setCell(cell);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String[] getCell() {
return cell;
}
public void setCell(String[] cell) {
this.cell = cell;
}
}
}
The JSON output will be like this and it should be in this format to work with jqgrid.
If you develop Android applications which has multiple locales, you might face an error similar to the below one
"<Value Name>" is not translated in <Locales> ...
This is because some names which you don't want to be translated are also taken as translatable names. The easiest fix for this is to mark the error cause name tag as
<string name="myname" translatable="false">
<string-array name="myname" translatable="false">
in string, string-array element.
Or you can define all your non-translatable strings in a resource file called donottranslate.xml. Or, you can ignore the issue with a tools:ignore="MissingTranslation" attribute.
I have been wanting to learn Android App development for sometime now and I wanted to start from the basics and progress. So I read the documentations and some tutorials and wrote my first app using Eclipse Helios with ADT Plugin.
I must tell Eclipse ADT Plugin 20.x has come a long way from its predecessors and now has the capability to perform many tasks directly from the plugin from development to signed package deployment.
The App I wrote is named Color Changer and as the name suggests it just changes color of the App based on some user input. This is really basic but enabled me to understand a lot about Android App structure.
There is a main AndroidManifest.xml where the Application is defined.