Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
60ea3ee3
authored
Jan 26, 2016
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Implementando subida de archivos pcb->server
parent
9cf71f79
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
63 additions
and
15 deletions
android/Pictogrammar/app/src/main/java/com/yottacode/net/RestapiWrapper.java
android/Pictogrammar/app/src/main/java/com/yottacode/net/SailsSocketsIO.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/action/ActionLog.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/action/PictoAction.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/action/Room.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/grammar/Vocabulary.java
android/Pictogrammar/app/src/main/java/com/yottacode/net/RestapiWrapper.java
View file @
60ea3ee3
...
...
@@ -132,7 +132,6 @@ public class RestapiWrapper {
// convert inputstream to string
if
(
inputStream
!=
null
)
result
=
convertInputStreamToString
(
inputStream
);
}
catch
(
IOException
e
)
{
Log
.
e
(
RestapiWrapper
.
class
.
getName
(),
e
.
getLocalizedMessage
());
if
(
listener
!=
null
)
listener
.
error
(
e
);
result
=
e
.
getMessage
();
}
...
...
@@ -233,13 +232,15 @@ public class RestapiWrapper {
}
else
if
(
jsonResult
instanceof
JSONArray
)
{
// The result is an array
params
.
listener
.
result
((
JSONArray
)
jsonResult
);
}
else
params
.
listener
.
result
((
JSONObject
)
null
);
}
else
params
.
listener
.
result
((
JSONObject
)
null
);
}
else
{
params
.
listener
.
result
((
JSONObject
)
null
);
}
}
catch
(
JSONException
e
)
{
params
.
listener
.
error
(
e
);
}
params
.
url_params
.
clear
();
}
}
}
\ No newline at end of file
android/Pictogrammar/app/src/main/java/com/yottacode/net/SailsSocketsIO.java
View file @
60ea3ee3
...
...
@@ -117,7 +117,6 @@ public class SailsSocketsIO {
Log
.
d
(
this
.
getClass
().
getName
(),
"Emitted messsage:"
+
obj
);
socket
.
emit
(
this
.
EMIT_METHOD
,
obj
,
ack
);
}
public
void
destroy
()
{
this
.
socket
.
disconnect
();
this
.
socket
.
off
();
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/action/ActionLog.java
View file @
60ea3ee3
...
...
@@ -24,7 +24,6 @@ public class ActionLog implements iRestapiListener {
public
ActionLog
()
{
actions_buffer
=
PCBcontext
.
getPcbdb
().
loadActions
();
actions_buffer
=
new
Vector
<>();
//TODO BORRAR
if
(
PCBcontext
.
getNetService
().
online
())
batch
();
}
// String constant for logs
...
...
@@ -49,7 +48,7 @@ public class ActionLog implements iRestapiListener {
public
void
batch
()
{
if
(!
actions_buffer
.
isEmpty
())
{
Hashtable
<
String
,
String
>
params
=
new
Hashtable
<>(
1
);
Hashtable
<
String
,
String
>
params
=
new
Hashtable
<>(
1
);
String
url
=
"stu/actions_batch"
;
String
actions
=
""
;
for
(
JSONObject
action:
actions_buffer
)
...
...
@@ -58,7 +57,6 @@ public class ActionLog implements iRestapiListener {
params
.
put
(
"actions"
,
actions
);
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
" Sending batch actions: "
+
url
+
": "
+
actions
);
PCBcontext
.
getRestapiWrapper
().
ask
(
url
,
params
,
"post"
,
this
);
params
.
clear
();
}
}
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/action/PictoAction.java
View file @
60ea3ee3
...
...
@@ -61,6 +61,9 @@ public class PictoAction extends Action {
public
JSONObject
get_json_picto
()
throws
JSONException
{
final
String
param_id_json
=
"id"
;
final
String
param_picto
=
"picto"
;
final
String
param_expression
=
"expression"
;
final
String
param_expr_lang
=
"lang"
;
final
String
param_expr_text
=
"text"
;
final
String
param_attrs
=
"attributes"
;
final
String
param_picto_id
=
"id"
;
final
String
param_picto_uri
=
"uri"
;
...
...
@@ -69,8 +72,11 @@ public class PictoAction extends Action {
.
put
(
param_picto_uri
,
picto
.
get_url
())
.
put
(
param_picto_cat
,
picto
.
get_category
());
JSONObject
attributes
=
new
JSONObject
(
picto
.
get_json_attrs
());
JSONObject
expression
=
new
JSONObject
().
put
(
param_expr_lang
,
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_lang_stu
())
.
put
(
param_expr_text
,
picto
.
get_translation
());
JSONObject
subPicto
=
new
JSONObject
().
put
(
param_id_json
,
1470
)
.
put
(
param_picto
,
subsubPicto
)
.
put
(
param_expression
,
expression
)
.
put
(
param_attrs
,
attributes
);
return
subPicto
;
}
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/action/Room.java
View file @
60ea3ee3
...
...
@@ -34,9 +34,10 @@ import java.util.LinkedList;
*/
public
class
Room
{
protected
SailsSocketsIO
socket
=
null
;
protected
boolean
inRoom
=
false
;
public
Room
(
)
{
protected
SailsSocketsIO
socket
=
null
;
protected
boolean
inRoom
=
false
;
public
Room
(
)
{
reconnect
();
}
...
...
@@ -52,7 +53,8 @@ public class Room {
this
.
socket
.
emit
(
url
,
this
.
common_data
(
action
.
get_type
(),
action
.
get_json
()),
new
Ack
()
{
@Override
public
void
call
(
Object
...
args
)
{
Log
.
d
(
this
.
getClass
().
getCanonicalName
(),
"Action ack received"
);
for
(
Object
arg
:
args
)
Log
.
d
(
this
.
getClass
().
getName
(),
"Ack messsage:"
+
arg
);
}
});
}
catch
(
JSONException
e
)
{
...
...
@@ -66,7 +68,8 @@ public class Room {
this
.
socket
.
emit
(
url
,
this
.
common_data
(
action
.
get_type
(),
action
.
get_json
()).
put
(
token_param
,
token
),
new
Ack
()
{
@Override
public
void
call
(
Object
...
args
)
{
Log
.
d
(
this
.
getClass
().
getCanonicalName
(),
"Action ack received"
);
for
(
Object
arg
:
args
)
Log
.
d
(
this
.
getClass
().
getName
(),
"Ack messsage:"
+
arg
);
}
});
}
catch
(
JSONException
e
)
{
...
...
@@ -82,13 +85,14 @@ public class Room {
this
.
socket
=
new
SailsSocketsIO
(
PCBcontext
.
getRestapiWrapper
().
getServer
(),
transport
,
new
Emitter
.
Listener
()
{
@Override
public
void
call
(
Object
...
args
)
{
Log
.
i
(
this
.
getClass
().
getName
(),
"Reconnect successful"
);
subscribe
();
inRoom
=
true
;
}
},
new
Emitter
.
Listener
()
{
@Override
public
void
call
(
Object
...
args
)
{
Log
.
i
(
this
.
getClass
().
getName
(),
"
Error sending Action
: "
+
args
[
0
]);
Log
.
i
(
this
.
getClass
().
getName
(),
"
Room exit
: "
+
args
[
0
]);
if
(
args
.
length
>
0
&&
args
[
0
].
toString
().
equals
(
"transport error"
)
)
{
inRoom
=
false
;
}
...
...
@@ -99,9 +103,6 @@ public class Room {
public
void
listen
(
String
msg
,
Emitter
.
Listener
listener
)
{
this
.
socket
.
registerMessage
(
msg
,
listener
);
}
void
subscribe
()
{
final
String
url
=
"/stu/subscribe"
;
final
String
action
=
"subscribe"
;
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/grammar/Vocabulary.java
View file @
60ea3ee3
package
com
.
yottacode
.
pictogram
.
grammar
;
import
android.os.Environment
;
import
android.util.Log
;
import
com.yottacode.pictogram.dao.Picto
;
...
...
@@ -14,6 +15,10 @@ import org.json.JSONArray;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.Hashtable
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
...
...
@@ -119,6 +124,43 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
PCBcontext
.
getPcbdb
().
addPicto
(
pic
);
}
/**
*TODO: to be finished and tried
*/
public
void
uploadPicto
(
String
path
,
String
name
,
String
exp
,
int
cat
,
int
coord_x
,
int
coord_y
)
throws
IOException
{
File
file
=
new
File
(
path
);
FileInputStream
imageInFile
=
new
FileInputStream
(
file
);
byte
imageData
[]
=
new
byte
[(
int
)
file
.
length
()];
imageInFile
.
read
(
imageData
);
Hashtable
<
String
,
String
>
params
=
new
Hashtable
<>(
3
);
params
.
put
(
"filename"
,
name
);
params
.
put
(
"folder"
,
"custompictos"
);
params
.
put
(
"id"
,
String
.
valueOf
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_id_stu
()));
params
.
put
(
"file"
,
String
.
valueOf
(
imageData
));
PCBcontext
.
getRestapiWrapper
().
ask
(
"upload"
,
params
,
"post"
,
new
iRestapiListener
()
{
@Override
public
void
result
(
JSONArray
result
)
{
}
@Override
public
void
result
(
JSONObject
result
)
{
}
@Override
public
void
error
(
Exception
e
)
{
}
});
}
/**
*
* @param pic_cat
* @return
*/
private
boolean
empty_category
(
int
pic_cat
)
{
return
this
.
pictos
.
get
(
pic_cat
)==
null
;}
private
int
find_picto_index
(
int
pic_cat
,
int
pic_id
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment