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
3c9d879a
authored
Mar 04, 2016
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Vocabulary management from PCB, upload images, implemented
parent
fa93884b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
30 deletions
android/Pictogram/app/build.gradle
android/Pictogram/app/src/main/java/com/yottacode/net/RestapiWrapper.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/PictogramActivity.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/net/PictoUploader.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/tools/Img.java
android/Pictogram/app/build.gradle
View file @
3c9d879a
...
...
@@ -37,7 +37,7 @@ android {
debug
{
resValue
"string"
,
"db_name"
,
"PCB.db"
resValue
"bool"
,
"force_db_create"
,
"
tru
e"
resValue
"bool"
,
"force_db_create"
,
"
fals
e"
resValue
"bool"
,
"ssl_connect"
,
"false"
resValue
"bool"
,
"force_img_download"
,
"false"
resValue
"integer"
,
"netservice_timing"
,
"20"
...
...
android/Pictogram/app/src/main/java/com/yottacode/net/RestapiWrapper.java
View file @
3c9d879a
...
...
@@ -23,6 +23,9 @@ package com.yottacode.net;
import
android.os.StrictMode
;
import
android.util.Log
;
import
com.google.gson.JsonParser
;
import
com.koushikdutta.async.parser.JSONObjectParser
;
import
javax.net.ssl.HttpsURLConnection
;
...
...
@@ -59,6 +62,9 @@ public class RestapiWrapper {
}
public
void
ask
(
String
operation
,
Hashtable
<
String
,
String
>
params
,
String
postOrGet
,
iRestapiListener
listener
)
{
ask
(
operation
,
params
,
postOrGet
,
false
,
listener
);
}
public
void
ask
(
String
operation
,
Hashtable
<
String
,
String
>
params
,
String
postOrGet
,
boolean
json
,
iRestapiListener
listener
)
{
// call preExecute listener to show loading window
listener
.
preExecute
();
// call AsynTask to perform network operation on separate thread
...
...
@@ -74,6 +80,8 @@ public class RestapiWrapper {
httpAsyncTaskParams
.
listener
=
listener
;
httpAsyncTaskParams
.
url_params
=
params
;
httpAsyncTaskParams
.
url
=
this
.
server
+
'/'
+
operation
;
httpAsyncTaskParams
.
json_params
=
json
;
new
HttpAsyncTask
().
executeOnExecutor
(
HttpAsyncTask
.
THREAD_POOL_EXECUTOR
,
httpAsyncTaskParams
);
}
...
...
@@ -145,20 +153,14 @@ public class RestapiWrapper {
}
return
result
;
}
public
String
POST
(
String
surl
,
String
request_method
,
Hashtable
<
String
,
String
>
params
)
{
public
String
POST
(
String
surl
,
String
request_method
,
Hashtable
<
String
,
String
>
params
,
boolean
json_params
)
{
URL
url
=
null
;
String
response
=
""
;
try
{
url
=
new
URL
(
surl
);
String
sparams
=
""
;
for
(
String
param
:
params
.
keySet
())
{
String
value
=
params
.
get
(
param
);
sparams
+=
param
+
'='
+
value
+
'&'
;
}
if
(
sparams
.
length
()>
0
)
sparams
=
sparams
.
substring
(
0
,
sparams
.
length
()-
1
);
Log
.
d
(
LOG_TAG
,
"POST url:"
+
surl
+
" params:"
+
sparams
);
HttpURLConnection
urlConnection
=
null
;
urlConnection
=
(
HttpsURLConnection
)
url
.
openConnection
();
urlConnection
.
setReadTimeout
(
60000
);
...
...
@@ -166,6 +168,26 @@ public class RestapiWrapper {
urlConnection
.
setRequestMethod
(
request_method
);
urlConnection
.
setDoInput
(
true
);
urlConnection
.
setDoOutput
(
true
);
if
(
json_params
)
{
urlConnection
.
setRequestProperty
(
"Content-Type"
,
"application/json;charset=utf-8"
);
urlConnection
.
setRequestProperty
(
"Accept"
,
"application/json, text/plain, */*"
);
}
String
sparams
;
if
(
json_params
)
{
sparams
=
params
.
get
(
"json"
);
params
.
remove
(
"json"
);
}
else
sparams
=
""
;
for
(
String
param
:
params
.
keySet
())
{
String
value
=
params
.
get
(
param
);
if
(
param
.
equals
(
"token"
))
urlConnection
.
setRequestProperty
(
"Authorization"
,
"Bearer "
+
value
);
else
{
if
(
sparams
.
length
()
>
0
)
sparams
+=
'&'
;
sparams
+=
param
+
'='
+
value
;
}
}
//Send request
DataOutputStream
wr
=
new
DataOutputStream
(
...
...
@@ -178,8 +200,6 @@ public class RestapiWrapper {
os
.
close
();
int
responseCode
=
urlConnection
.
getResponseCode
();
Log
.
d
(
LOG_TAG
,
"RESPONSECODE: "
+
responseCode
);
String
line
;
BufferedReader
br
=
new
BufferedReader
(
new
InputStreamReader
(
responseCode
==
HttpsURLConnection
.
HTTP_OK
?
urlConnection
.
getInputStream
()
...
...
@@ -191,6 +211,7 @@ public class RestapiWrapper {
Log
.
e
(
com
.
yottacode
.
net
.
RestapiWrapper
.
class
.
getName
(),
"Error:"
+
e
.
getLocalizedMessage
()
+
" when asking for "
+
surl
);
response
=
e
.
getMessage
();
}
return
response
;
}
...
...
@@ -210,6 +231,7 @@ public class RestapiWrapper {
protected
String
request_method
;
protected
String
url
;
protected
Hashtable
<
String
,
String
>
url_params
;
protected
boolean
json_params
;
protected
iRestapiListener
listener
;
protected
String
result
;
}
...
...
@@ -221,7 +243,7 @@ public class RestapiWrapper {
protected
HttpAsyncTaskParams
doInBackground
(
HttpAsyncTaskParams
...
params
)
{
params
[
0
].
result
=
params
[
0
].
request_method
.
equalsIgnoreCase
(
"GET"
)
?
GET
(
params
[
0
].
url
,
params
[
0
].
url_params
,
null
)
:
POST
(
params
[
0
].
url
,
params
[
0
].
request_method
,
params
[
0
].
url_params
);
:
POST
(
params
[
0
].
url
,
params
[
0
].
request_method
,
params
[
0
].
url_params
,
params
[
0
].
json_params
);
return
params
[
0
];
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/PictogramActivity.java
View file @
3c9d879a
...
...
@@ -425,9 +425,9 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
public
boolean
onLongClick
(
View
v
)
{
Log
.
d
(
LOG_TAG
,
"DELETE LONGCLICK..."
);
count_deletelong
++;
Log
.
i
(
"FERNANDO BORRAR"
,
"SAVE LOCAL PICTO 1"
);
Picto
picto
=
PCBcontext
.
getVocabulary
().
saveLocalPicto
(
"/sdcard/DCIM/camera/javo.jpg"
,
"javier"
,
7515
,
2
,
2
);
Log
.
i
(
"FERNANDO BORRAR"
,
"SAVE LOCAL PICTO 2:"
+
picto
.
get_id
());
//
Picto picto=PCBcontext.getVocabulary().saveLocalPicto("/sdcard/DCIM/camera/javo.jpg", "javier", 7515, 2, 2);
if
(
count_deletelong
>=
3
){
//Log.d(LOG_TAG, "SALTO A LOGIN");
// Paso un parámetro a la SerialActivity, para controlar de dónde viene
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/net/PictoUploader.java
View file @
3c9d879a
...
...
@@ -110,7 +110,7 @@ public class PictoUploader {
(
response
==
null
?
-
1
:
response
.
getHeaders
().
code
()));
img_id
=-
1
;
}
ion
.
dump
();
//
ion.dump();
return
img_id
;
}
...
...
@@ -123,13 +123,16 @@ public class PictoUploader {
final
int
id_stupicto
[]=
new
int
[
1
];
Hashtable
<
String
,
String
>
params
=
new
Hashtable
<
String
,
String
>(
4
);
try
{
params
.
put
(
"attributes"
,
new
JSONObject
().
put
(
"id_cat"
,
Integer
.
toString
(
picto
.
get_category
()))
.
put
(
"coord_x"
,
Integer
.
toString
(
picto
.
get_column
()))
.
put
(
"coord_y"
,
Integer
.
toString
(
picto
.
get_row
())).
toString
());
params
.
put
(
"json"
,
new
JSONObject
().
put
(
"attributes"
,
(
new
JSONObject
().
put
(
"id_cat"
,
picto
.
get_category
())
.
put
(
"coord_x"
,
picto
.
get_column
())
.
put
(
"coord_y"
,
picto
.
get_row
())
.
put
(
"status"
,
picto
.
get_status
()))).
toString
());
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
this
.
getClass
().
getCanonicalName
(),
" Error: "
+
e
.
getLocalizedMessage
());
}
PCBcontext
.
getRestapiWrapper
().
ask
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_restapi_operation_stu
()
+
"/picto/"
+
id_picto
,
params
,
"post"
,
new
iRestapiListener
()
{
PCBcontext
.
getRestapiWrapper
().
ask
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_restapi_operation_stu
()
+
"/picto/"
+
id_picto
,
params
,
"post"
,
true
,
new
iRestapiListener
()
{
@Override
public
void
preExecute
()
{
}
...
...
@@ -141,18 +144,19 @@ public class PictoUploader {
@Override
public
void
result
(
JSONObject
result
)
{
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Attributes uploaded: "
+
result
.
toString
());
try
{
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"
Attributes uploaded: "
+
result
.
toString
());
/*
try {
id_stupicto[0]=result.getJSONObject("picto").getInt("id");
} catch (JSONException e) {
e.printStackTrace();
}
Log.e(this.getClass().getCanonicalName(), "Error: " + e.getLocalizedMessage());
}*/
}
@Override
public
void
error
(
Exception
e
)
{
Log
.
e
(
this
.
getClass
().
getCanonicalName
(),
"Error uploading attributes: "
+
e
.
getLocalizedMessage
());
Log
.
e
(
this
.
getClass
().
getCanonicalName
(),
"
Error uploading attributes: "
+
e
.
getLocalizedMessage
());
id_stupicto
[
0
]=-
1
;
}
});
...
...
@@ -162,10 +166,10 @@ public class PictoUploader {
/**
* if the a picto was included from the PCB, the translation is uploaded to the server
*/
private
void
uploadTranslation
(
int
id_
stu
picto
)
{
private
void
uploadTranslation
(
int
id_picto
)
{
Hashtable
<
String
,
String
>
params
=
new
Hashtable
<
String
,
String
>(
3
);
params
.
put
(
"picto"
,
Integer
.
toString
(
id_
stu
picto
));
params
.
put
(
"picto"
,
Integer
.
toString
(
id_picto
));
params
.
put
(
"lang"
,
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_lang_stu
());
params
.
put
(
"text"
,
picto
.
get_translation
());
PCBcontext
.
getRestapiWrapper
().
ask
(
"picto/exp"
,
params
,
"post"
,
new
iRestapiListener
()
{
...
...
@@ -195,8 +199,8 @@ public class PictoUploader {
public
void
upload
()
throws
IOException
{
int
img_id
=
uploadImg
(
this
.
picto
);
if
(
img_id
>
0
)
{
int
stupicto_id
=
uploadAttributes
(
img_id
);
uploadTranslation
(
stupicto
_id
);
uploadAttributes
(
img_id
);
uploadTranslation
(
img
_id
);
}
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/tools/Img.java
View file @
3c9d879a
...
...
@@ -126,7 +126,7 @@ public class Img {
Log
.
e
(
Img
.
class
.
getCanonicalName
(),
"Out of memory when decoding "
+
this
.
get_url
());
}
ByteArrayOutputStream
outstream
=
new
ByteArrayOutputStream
();
ls
-
l
this
.
bitmap
.
setHasAlpha
(
true
);
this
.
bitmap
.
setHasAlpha
(
true
);
this
.
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
100
,
outstream
);
byte
[]
byteArray
=
outstream
.
toByteArray
();
os
.
write
(
byteArray
);
...
...
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