Skip to content

Commit e03bb85

Browse files
committed
Merge branch 'master' of github.com:borisdb/TodoDetector
2 parents 8efc1f7 + 141fcc8 commit e03bb85

File tree

16 files changed

+304
-60
lines changed

16 files changed

+304
-60
lines changed

RESTserver/TodoServer/src/main/java/com/androidmontreal/tododetector/server/domain/TodoList.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,31 @@ public class TodoList {
2121
@GeneratedValue(strategy = GenerationType.AUTO)
2222
private Long id;
2323

24+
private String name ;
25+
2426
@OneToMany
2527
private List<Todo> todos = new ArrayList<Todo>();
2628

2729
public Long getId() {
2830
return id;
2931
}
3032

31-
public void setId(Long id) {
32-
this.id = id;
33+
public String getName() {
34+
return name;
3335
}
3436

3537
public List<Todo> getTodos() {
3638
return todos;
3739
}
3840

41+
public void setId(Long id) {
42+
this.id = id;
43+
}
44+
45+
public void setName(String name) {
46+
this.name = name;
47+
}
48+
3949
public void setTodos(List<Todo> todos) {
4050
this.todos = todos;
4151
}

RESTserver/TodoServer/src/main/java/com/androidmontreal/tododetector/server/service/TodoService.java

Lines changed: 129 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package com.androidmontreal.tododetector.server.service;
22

3+
import java.awt.Image;
4+
import java.io.ByteArrayInputStream;
5+
import java.io.ByteArrayOutputStream;
6+
import java.io.IOException;
7+
import java.io.InputStream;
38
import java.io.Serializable;
9+
import java.util.ArrayList;
410
import java.util.List;
511

612
import javax.ws.rs.Consumes;
@@ -11,17 +17,82 @@
1117
import javax.ws.rs.PathParam;
1218
import javax.ws.rs.Produces;
1319
import javax.ws.rs.core.MediaType;
20+
import javax.ws.rs.core.Response;
21+
import javax.xml.bind.annotation.XmlRootElement;
1422

1523
import org.hibernate.Session;
1624

1725
import com.androidmontreal.tododetector.server.domain.Todo;
1826
import com.androidmontreal.tododetector.server.domain.TodoList;
27+
import com.androidmontreal.tododetector.server.service.TodoService.TodoListDTO;
1928
import com.kanawish.hibernate.HibernateUtil;
2029
import com.kanawish.hibernate.Transactionnal;
2130

2231
@Path("todo")
2332
public class TodoService {
2433

34+
@XmlRootElement
35+
static public class TodoListDTO {
36+
long id;
37+
String name;
38+
List<TodoDTO> todos = new ArrayList<TodoDTO>();
39+
40+
public long getId() {
41+
return id;
42+
}
43+
44+
public void setId(long id) {
45+
this.id = id;
46+
}
47+
48+
public String getName() {
49+
return name;
50+
}
51+
52+
public void setName(String name) {
53+
this.name = name;
54+
}
55+
56+
public List<TodoDTO> getTodos() {
57+
return todos;
58+
}
59+
60+
public void setTodos(List<TodoDTO> todos) {
61+
this.todos = todos;
62+
}
63+
}
64+
65+
@XmlRootElement
66+
static public class TodoDTO {
67+
Long id;
68+
Boolean checked;
69+
String imageUrl;
70+
71+
public Long getId() {
72+
return id;
73+
}
74+
75+
public void setId(Long id) {
76+
this.id = id;
77+
}
78+
79+
public Boolean getChecked() {
80+
return checked;
81+
}
82+
83+
public void setChecked(Boolean checked) {
84+
this.checked = checked;
85+
}
86+
87+
public String getImageUrl() {
88+
return imageUrl;
89+
}
90+
91+
public void setImageUrl(String imageUrl) {
92+
this.imageUrl = imageUrl;
93+
}
94+
}
95+
2596
@Transactionnal
2697
List<TodoList> dbGetLists() {
2798
List<TodoList> list =
@@ -32,33 +103,56 @@ List<TodoList> dbGetLists() {
32103
@Path("/lists")
33104
@GET
34105
@Produces(MediaType.APPLICATION_JSON)
35-
public List<TodoList> getLists() {
36-
return dbGetLists() ;
106+
public List<TodoListDTO> getLists() {
107+
List<TodoList> lists = dbGetLists();
108+
ArrayList<TodoListDTO> dtos = new ArrayList<TodoListDTO>();
109+
for( TodoList current : lists ) {
110+
TodoListDTO dto = new TodoListDTO();
111+
dto.setId(current.getId());
112+
dto.setName(current.getName());
113+
dtos.add(dto);
114+
}
115+
116+
return dtos ;
37117
}
38118

39119
@Transactionnal
40-
TodoList dbGetList(Long id) {
41-
return (TodoList) HibernateUtil.getCurrentSession().get(TodoList.class, id);
120+
TodoList dbGetList(Long id) {
121+
TodoList todoList = (TodoList) HibernateUtil.getCurrentSession().load(TodoList.class, id);
122+
return todoList;
42123
}
43124

44125
@Path("/lists/{id}")
45126
@GET
46127
@Produces(MediaType.APPLICATION_JSON)
47-
public TodoList getList(@PathParam("id") long id) {
48-
return dbGetList(id);
128+
public TodoListDTO getList(@PathParam("id") long id) {
129+
TodoList list = dbGetList(id);
130+
TodoListDTO dto = new TodoListDTO();
131+
dto.setId(list.getId());
132+
dto.setName(list.getName());
133+
for( Todo current : list.getTodos() ) {
134+
TodoDTO todoDTO = new TodoDTO();
135+
todoDTO.setId(current.getId());
136+
todoDTO.setChecked(current.isChecked());
137+
todoDTO.setImageUrl("http://winniecooper.net/sam/2011/12/img/MIAWINNIE.jpg"); // TODO: Implement
138+
dto.getTodos().add(todoDTO);
139+
}
140+
141+
return dto;
49142
}
50143

51144
@Transactionnal
52-
private long dbCreateList() {
145+
private long dbCreateList( String name ) {
53146
TodoList list = new TodoList();
147+
list.setName(name);
54148
HibernateUtil.getCurrentSession().saveOrUpdate(list);
55149
return list.getId();
56150
}
57151

58-
@Path("/lists")
152+
@Path("/lists/{name}")
59153
@PUT
60-
public long createList( ) {
61-
return dbCreateList() ;
154+
public long createList( @PathParam("name") String name ) {
155+
return dbCreateList(name) ;
62156
}
63157

64158
// TODO: Delete list
@@ -97,6 +191,31 @@ public long addNewTodo( @PathParam("id") long listId, byte[] data ) {
97191
return dbAddNewTodo(listId, data);
98192
}
99193

194+
@Transactionnal
195+
public byte[] dbGetImageData() {
196+
// TODO Auto-generated method stub
197+
return null;
198+
}
199+
200+
@GET
201+
@Path("/lists/{id}/item/{itemId}/img")
202+
@Produces("image/*")
203+
public Response getImage(@PathParam(value = "id") long id, @PathParam(value = "itemId") long itemId ) {
204+
205+
//TODO: Implement the db get
206+
byte[] imgData = dbGetImageData();
207+
208+
// Test this return method.
209+
if (imgData != null) {
210+
// final ByteArrayOutputStream out = new ByteArrayOutputStream();
211+
final InputStream bigInputStream = new ByteArrayInputStream(imgData);
212+
//.cacheControl(getCacheControl(true))
213+
return Response.ok(bigInputStream).build();
214+
}
215+
216+
return Response.noContent().build();
217+
}
218+
100219
@Transactionnal
101220
void dbCheckItem(Long todoId) {
102221
Session session = HibernateUtil.getCurrentSession();

RESTserver/TodoServer/src/main/java/com/androidmontreal/tododetector/server/web/LauncherTodo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public static void main(String[] args) throws Exception {
6060
// Start the server
6161
server.start();
6262
server.join();
63+
64+
6365
}
6466

6567
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
3+
import org.hibernate.Session;
4+
5+
import com.androidmontreal.tododetector.server.domain.Todo;
6+
import com.androidmontreal.tododetector.server.domain.TodoList;
7+
import com.kanawish.hibernate.HibernateUtil;
8+
9+
10+
public class HibernateTest {
11+
12+
public static void main(String[] args) {
13+
HibernateTest mgr = new HibernateTest();
14+
mgr.createAndStoreEvent();
15+
16+
HibernateUtil.getSessionFactory().close();
17+
}
18+
19+
private void createAndStoreEvent() {
20+
HibernateUtil.initSessionFactory("hibernate.todo.cfg.xml");
21+
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
22+
session.beginTransaction();
23+
24+
for( int i = 0 ; i < 4 ; i++ )
25+
{
26+
TodoList todoList1 = new TodoList();
27+
28+
Todo t1 = new Todo();
29+
t1.setChecked(false);
30+
Todo t2 = new Todo();
31+
t2.setChecked(false);
32+
33+
todoList1.setName("Mock"+i);
34+
todoList1.getTodos().add(t1);
35+
todoList1.getTodos().add(t2);
36+
37+
session.save(t2);
38+
session.save(t1);
39+
40+
session.save(todoList1);
41+
}
42+
session.getTransaction().commit();
43+
}
44+
45+
}

android/jni/imagefuncs.cpp

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ vector<vector<Point> > findAllRectangles(Mat& mbgra) {
9393

9494

9595
findDivisionBasedOnWhiteSpace(checkboxes, mbgra);
96-
96+
getCropOfToDoLines(checkboxes, mbgra);
97+
9798
return checkboxes;
9899
}
99100

@@ -107,10 +108,47 @@ Find the vertical divide line where most of the rectangles are on one side of th
107108
*/
108109
vector<vector<Point> > findDivisionBasedOnWhiteSpace(vector<vector<Point> > potentialCheckboxes, Mat& mbgra)
109110
{
110-
111111
return potentialCheckboxes;
112112
}
113+
/*
114+
Crop the lines
115+
*/
116+
vector<vector<Point> > getCropOfToDoLines(vector<vector<Point> > checkboxes, Mat& mbgra)
117+
{
118+
for (int i = 0; i < checkboxes.size(); i++) {
119+
Rect rect = boundingRect(checkboxes[i]);
120+
int margin = 5;
121+
122+
int a = rect.x - margin ;
123+
int b = rect.y - margin -80;
124+
int c = rect.width + margin * 2 ;
125+
int d = rect.height + margin * 2 +40;
126+
127+
128+
// Draw rectangle
129+
rectangle(
130+
mbgra,
131+
Rect(a,
132+
b,
133+
c,
134+
d), Scalar(200, 200, 0, 255), 2);
135+
//Mat imgroi = image(Rect(a, b, c, d));
136+
//imwrite("/sdcard/Todos/afilename.png", imgroi);
137+
113138

139+
}
140+
return checkboxes;
141+
}
142+
/*
143+
e <= jni_part.cpp
144+
Compile++ thumb : native_sample <= imagefuncs.cpp
145+
jni/imagefuncs.h: In function 'std::vector<std::vector<cv::Point_<int> > > findAllRectangles(cv::Mat&)':
146+
jni/imagefuncs.h:12: error: too few arguments to function 'std::vector<std::vector<cv::Point_<int> > > getCropOfToDoLines(std::vector<std::vector<cv::Point_<int> > >, cv::Mat&)'
147+
jni/imagefuncs.cpp:95: error: at this point in file
148+
jni/imagefuncs.cpp: In function 'std::vector<std::vector<cv::Point_<int> > > getCropOfToDoLines(std::vector<std::vector<cv::Point_<int> > >, cv::Mat&)':
149+
jni/imagefuncs.cpp:118: error: 'contours' was not declared in this scope
150+
make: *** [obj/local/armeabi/objs/native_sample/imagefuncs.o] Error 1
151+
*/
114152

115153

116154
//TODO : don't use the biggest area as reference to avoid bug if a big square exist

android/jni/imagefuncs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ double calcCircularity(std::vector<cv::Point> contour);
99
std::vector<cv::Point> findCircle(cv::Mat& mbgra);
1010
std::vector<std::vector<cv::Point> > findAllRectangles(cv::Mat& mbgra);
1111
std::vector<std::vector<cv::Point> > findDivisionBasedOnWhiteSpace(std::vector<std::vector<cv::Point> > potentialCheckboxes, cv::Mat& mbgra);
12-
cv::Mat imHist(cv::Mat hist, float scaleX=1, float scaleY=1);
12+
std::vector<std::vector<cv::Point> > getCropOfToDoLines(std::vector<std::vector<cv::Point> > potentialCheckboxes, cv::Mat& mbgra);
1313
std::vector<std::vector<cv::Point> > filterSquareByArea(std::vector<std::vector<cv::Point> > checkboxes);
1414
std::vector<std::vector<cv::Point> > filterSquareByCoordinates(std::vector<std::vector<cv::Point> > checkboxes, cv::Mat& mbgra);
1515
bool sortByY(cv::Rect , cv::Rect);

android/res/layout/galleryitem.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
<ImageView
1313
android:id="@+id/elementImage"
14+
android:contentDescription="Loading..."
1415
android:layout_width="fill_parent"
1516
android:layout_height="wrap_content" />
1617

android/res/layout/onelist.xml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
<LinearLayout
88
android:id="@+id/lytButtonContainer"
99
android:layout_width="match_parent"
10-
android:layout_height="fill_parent"
10+
android:layout_height="wrap_content"
1111
android:orientation="horizontal"
1212
android:weightSum="1">
13+
1314
<Button
1415
android:id="@+id/btnAction"
1516
android:layout_width="fill_parent"
1617
android:layout_height="wrap_content"
17-
android:text="Save/Refresh/blabla"
18+
android:text="Save"
1819
android:layout_weight="0.5"/>
1920
<Button
2021
android:id="@+id/btnServer"
@@ -28,7 +29,7 @@
2829
<LinearLayout
2930
android:id="@+id/lytListContainer"
3031
android:layout_width="match_parent"
31-
android:layout_height="fill_parent" >
32+
android:layout_height="fill_parent">
3233
</LinearLayout>
3334

3435
</LinearLayout>

0 commit comments

Comments
 (0)