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
8b01ca8d
authored
Mar 14, 2016
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merge branch 'fernando_branch' of
http://scm.ujaen.es/softuno/pictogram
parents
8ed0bb6e
38597dd9
Show whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
355 additions
and
264 deletions
android/Pictogram/app/build.gradle
android/Pictogram/app/src/fernandoFlavor/java/com/yottacode/pictogrammar/Translate.java
android/Pictogram/app/src/main/AndroidManifest.xml
android/Pictogram/app/src/main/java/com/yottacode/pictogram/action/ActionLog.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/dao/Device.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/dao/PCBDBHelper.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/dao/Picto.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/dao/User.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/grammar/Vocabulary.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/grammar/VocabularyTalk.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/grammar/iVocabularyListener.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/LoginActivity.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/PanelAdapter.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/PictogramActivity.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/SerialActivity.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/net/ImgDownloader.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/src/main/java/com/yottacode/tools/FileTools.java
android/Pictogram/app/src/main/res/values-en/strings.xml
android/Pictogram/app/src/main/res/values-es/strings.xml
android/Pictogram/app/src/main/res/values/strings.xml
android/Pictogram/app/build.gradle
View file @
8b01ca8d
...
...
@@ -26,17 +26,17 @@ android {
resValue
"bool"
,
"force_img_download"
,
"false"
resValue
"integer"
,
"netservice_timing"
,
"20"
resValue
"integer"
,
"rows"
,
"5"
resValue
"integer"
,
"columns"
,
"
8
"
resValue
"integer"
,
"columns"
,
"
10
"
}
debug
{
resValue
"string"
,
"db_name"
,
"PCB.db"
resValue
"bool"
,
"force_db_create"
,
"
fals
e"
resValue
"bool"
,
"force_db_create"
,
"
tru
e"
resValue
"bool"
,
"ssl_connect"
,
"false"
resValue
"bool"
,
"force_img_download"
,
"false"
resValue
"integer"
,
"netservice_timing"
,
"20"
resValue
"integer"
,
"rows"
,
"5"
resValue
"integer"
,
"columns"
,
"
8
"
resValue
"integer"
,
"columns"
,
"
10
"
}
}
productFlavors
{
...
...
android/Pictogram/app/src/fernandoFlavor/java/com/yottacode/pictogrammar/Translate.java
View file @
8b01ca8d
...
...
@@ -83,7 +83,7 @@ public class Translate extends Activity implements iVocabularyListener, iImgDown
PCBcontext
.
init
(
this
);
PCBcontext
.
getDevice
().
setSerial
(
"serial1"
);
PCBcontext
.
getDevice
().
setDeviceID
(
"deviceID"
);
PCBcontext
.
getDevice
().
deleteDeprecatedImgs
();
PCBcontext
.
set_user
(
alumno_picto
,
TOKEN
,
this
);
Log
.
i
(
LOG_TAG
,
"2) OnCreate - Serial:"
+
PCBcontext
.
getDevice
().
getSerial
()
+
" dev. id:"
+
PCBcontext
.
getDevice
().
getDeviceID
()
+
" token:"
+
TOKEN
);
...
...
android/Pictogram/app/src/main/AndroidManifest.xml
View file @
8b01ca8d
...
...
@@ -17,6 +17,13 @@
<android:uses-permission
android:name=
"android.permission.READ_PHONE_STATE"
/>
<android:uses-permission
android:name=
"android.permission.READ_EXTERNAL_STORAGE"
/>
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission
android:name=
"android.permission.GET_ACCOUNTS"
/>
<uses-permission
android:name=
"android.permission.READ_PROFILE"
/>
<uses-permission
android:name=
"android.permission.READ_CONTACTS"
/>
<android:uses-permission
android:name=
"android.permission.READ_CALL_LOG"
/>
<application
android:name=
".kiosk.AppContext"
android:allowBackup=
"true"
...
...
@@ -36,24 +43,22 @@
<activity
android:name=
".gui.MainActivity"
android:label=
"@string/app_name"
android:screenOrientation=
"landscape"
>
</activity>
android:screenOrientation=
"landscape"
/>
<activity
android:name=
".gui.SerialActivity"
android:label=
"@string/title_activity_serial"
android:screenOrientation=
"landscape"
>
</activity>
android:screenOrientation=
"landscape"
/>
<activity
android:name=
".gui.LoginActivity"
android:exported=
"true"
android:label=
"@string/title_activity_login_activity_fragments"
android:screenOrientation=
"landscape"
/>
android:screenOrientation=
"landscape"
/>
<activity
android:name=
".gui.PictogramActivity"
android:exported=
"true"
android:label=
"@string/app_name"
android:launchMode=
"singleTop"
android:screenOrientation=
"landscape"
/>
android:screenOrientation=
"landscape"
/>
<!-- Intent Filter to run the app when the boot is completed -->
<receiver
android:name=
".kiosk.BootReceiver"
>
<intent-filter>
...
...
@@ -66,7 +71,16 @@
android:exported=
"false"
/>
<service
android:name=
".net.NetService"
android:exported=
"false"
/>
android:exported=
"false"
/>
<activity
android:name=
".ImgLabelActivity"
android:label=
"@string/title_activity_img_label"
android:parentActivityName=
".gui.PictogramActivity"
>
<meta-data
android:name=
"android.support.PARENT_ACTIVITY"
android:value=
"com.yottacode.pictogram.gui.PictogramActivity"
/>
</activity>
</application>
</manifest>
android/Pictogram/app/src/main/java/com/yottacode/pictogram/action/ActionLog.java
View file @
8b01ca8d
...
...
@@ -35,11 +35,10 @@ public class ActionLog implements iRestapiListener {
*/
public
void
log
(
Action
action
)
{
if
(
PCBcontext
.
getRoom
().
inRoom
())
// PCBcontext.getRoom().emit(action.get_action(), action);
PCBcontext
.
getRoom
().
emit
(
action
);
else
{
// If there is no room, the action is stored in local DB
// If there is no room, the action is stored in
to the
local DB
PCBcontext
.
getPcbdb
().
insertAction
(
action
);
actions_buffer
.
add
(
action
.
getDescription
());
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
" Batch action included: "
+
action
.
getDescription
());
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/dao/Device.java
View file @
8b01ca8d
...
...
@@ -317,13 +317,17 @@ public class Device extends SQLiteOpenHelper {
/**
* delete the list of images (students, supervisors, pictograms) which are no longer used
*/
public
void
deleteDeprecatedImgs
()
throws
IOException
{
public
void
deleteDeprecatedImgs
()
{
SQLiteDatabase
db
=
this
.
getWritableDatabase
();
Cursor
cursor
=
db
.
query
(
"deprecated_images"
,
null
,
null
,
null
,
null
,
null
,
null
);
while
(
cursor
.
moveToNext
())
{
String
type
=
cursor
.
getString
(
1
);
String
folder
=
type
.
equals
(
"stu"
)
?
Img
.
STUDENT
:
type
.
equals
(
"sup"
)
?
Img
.
SUPERVISOR
:
Img
.
VOCABULARY
;
try
{
(
new
Img
(
cursor
.
getInt
(
0
),
null
,
folder
)).
delete_bitmap
(
this
.
context
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Image file "
+
cursor
.
getString
(
1
)
+
"."
+
cursor
.
getInt
(
0
)
+
" deleted"
);
}
cursor
.
close
();
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/dao/PCBDBHelper.java
View file @
8b01ca8d
...
...
@@ -203,10 +203,14 @@ public class PCBDBHelper extends SQLiteOpenHelper {
SQLiteDatabase
db
=
this
.
getWritableDatabase
();
int
id_stu
=
this
.
getCurrentUser
().
get_id_stu
();
int
seconds1
=
Calendar
.
getInstance
().
get
(
Calendar
.
SECOND
);
db
.
delete
(
"collection"
,
"id_stu=?"
,
new
String
[]
{
String
.
valueOf
(
id_stu
)});
db
.
delete
(
"collection"
,
"id_stu="
+
id_stu
,
null
);
int
newsize
=
0
;
ContentValues
values
=
new
ContentValues
(
5
);
values
.
put
(
"id_stu"
,
id_stu
);
for
(
Picto
picto
:
vocabulary
)
{
newsize
++;
values
.
put
(
"id_picto"
,
picto
.
get_id
());
values
.
put
(
"url"
,
picto
.
get_url
());
values
.
put
(
"translation"
,
picto
.
get_translation
());
...
...
@@ -215,7 +219,8 @@ public class PCBDBHelper extends SQLiteOpenHelper {
}
int
seconds2
=
Calendar
.
getInstance
().
get
(
Calendar
.
SECOND
);
Log
.
i
(
this
.
getClass
().
getName
(),
" Local student vocabulary updated, id:"
+
id_stu
+
", cats: "
+
vocabulary
.
size
()
+
" time:"
+(
seconds2
-
seconds1
));
Log
.
i
(
this
.
getClass
().
getName
(),
" Local student vocabulary updated, id:"
+
id_stu
+
", cats: "
+
vocabulary
.
size
()
+
" time:"
+
(
seconds2
-
seconds1
)
+
" secs. Size: "
+
newsize
+
" read only?"
+
db
.
isReadOnly
());
db
.
close
();
}
...
...
@@ -248,11 +253,11 @@ public class PCBDBHelper extends SQLiteOpenHelper {
int
id_stu
=
this
.
getCurrentUser
().
get_id_stu
();
SQLiteDatabase
db
=
this
.
getWritableDatabase
();
db
.
delete
(
"collection"
,
"id_stu=? AND id_
sup=? AND id_
picto=?"
,
db
.
delete
(
"collection"
,
"id_stu=? AND id_picto=?"
,
new
String
[]{
Integer
.
toString
(
this
.
currentUser
.
get_id_stu
()),
Integer
.
toString
(
this
.
currentUser
.
get_id_sup
()),
Integer
.
toString
(
picto_id
)});
db
.
close
();
PCBcontext
.
getDevice
().
deleteDeprecatedImgs
();
}
/**
* Update a picto of the current collection's student.
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/dao/Picto.java
View file @
8b01ca8d
...
...
@@ -23,14 +23,14 @@ public class Picto extends Img {
private
final
String
LOG_TAG
=
this
.
getClass
().
getSimpleName
();
// Or .getCanonicalName()
public
final
static
class
JSON_ATTTRS
{
static
String
CATEGORY
=
"id_cat"
;
static
String
ROW
=
"coord_x"
;
static
String
COLUMN
=
"coord_y"
;
static
String
MAGNIFY
=
"magnify"
;
static
String
HIGHLIGHT
=
"highlight"
;
static
String
STATUS
=
"status"
;
static
String
COLOR
=
"color"
;
static
String
PCB_STATUS_MODIFICATION
=
"pcb_status_modification"
;
public
static
String
CATEGORY
=
"id_cat"
;
public
static
String
COLUMN
=
"coord_x"
;
public
static
String
ROW
=
"coord_y"
;
public
static
String
MAGNIFY
=
"magnify"
;
public
static
String
HIGHLIGHT
=
"highlight"
;
public
static
String
STATUS
=
"status"
;
public
static
String
COLOR
=
"color"
;
public
static
String
PCB_STATUS_MODIFICATION
=
"pcb_status_modification"
;
}
public
final
static
class
JSON_ATTTR_STATUS_VALUES
{
...
...
@@ -46,7 +46,7 @@ public class Picto extends Img {
private
JSONObject
attributes
;
private
String
translation
;
public
Picto
(
int
id
,
String
url
,
String
translation
,
int
cat
,
int
column
,
int
row
)
throws
JSONException
{
public
Picto
(
int
id
,
String
url
,
String
translation
,
int
cat
,
int
row
,
int
column
)
throws
JSONException
{
this
(
id
,
url
,
translation
,
new
JSONObject
()
.
put
(
JSON_ATTTRS
.
CATEGORY
,
cat
)
.
put
(
JSON_ATTTRS
.
COLUMN
,
column
)
...
...
@@ -175,7 +175,8 @@ public class Picto extends Img {
*/
public
boolean
is_invisible
()
{
try
{
return
this
.
attributes
.
getString
(
JSON_ATTTRS
.
STATUS
).
equals
(
JSON_ATTTR_STATUS_VALUES
.
INVISIBLE
);
return
this
.
attributes
.
getString
(
JSON_ATTTRS
.
STATUS
).
equals
(
JSON_ATTTR_STATUS_VALUES
.
INVISIBLE
)
||
(
this
.
is_category
()
&&
!
PCBcontext
.
getVocabulary
().
isVisibleCategory
(
this
.
get_id
()));
}
catch
(
JSONException
e
)
{
return
false
;
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/dao/User.java
View file @
8b01ca8d
...
...
@@ -246,16 +246,9 @@ public class User {
}
}
/**
*
* @return the id of the real user: stu or sup
public int get_id() {
return this.get_name_sup() == null ? this.get_id_stu() : this.get_id_sup();
public
boolean
is_supervisor
()
{
return
get_id_sup
()!=
User
.
NO_SUPERVISOR
;
}
*/
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/grammar/Vocabulary.java
View file @
8b01ca8d
...
...
@@ -47,11 +47,9 @@ public class Vocabulary implements Iterable<Picto> {
this
.
pictos
=
new
Hashtable
<>(
Vocabulary
.
DEFAULT_VOCABULARY_SIZE
);
this
.
imgListener
=
listener
;
if
(
PCBcontext
.
getNetService
().
online
())
{
Log
.
i
(
this
.
getClass
().
getName
(),
"FERNANDO Downloading vocabulary"
);
synchronize
();
}
else
try
{
Log
.
i
(
this
.
getClass
().
getName
(),
"FERNANDO Local vocabulary"
);
PCBcontext
.
getPcbdb
().
getStudentVocabulary
(
this
);
listener
.
loadComplete
();
}
catch
(
JSONException
e
)
{
...
...
@@ -121,6 +119,7 @@ public class Vocabulary implements Iterable<Picto> {
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
this
.
getClass
().
getName
(),
" Picto json error from server: "
+
picto
.
toString
());
}
}
}
...
...
@@ -217,9 +216,6 @@ public class Vocabulary implements Iterable<Picto> {
Log
.
d
(
this
.
getClass
().
getName
(),
"Vocabulary size: "
+
updated_collection
.
length
);
ImgDownloader
downloader
=
new
ImgDownloader
(
PCBcontext
.
getContext
(),
imgListener
,
ImgDownloader
.
tsource
.
remote
);
downloader
.
executeOnExecutor
(
AsyncTask
.
THREAD_POOL_EXECUTOR
,
imgs
);
PCBcontext
.
getPcbdb
().
setStudentVocabulary
(
this
);
}
public
int
size
()
{
return
this
.
pictos
.
size
();}
...
...
@@ -228,6 +224,9 @@ public class Vocabulary implements Iterable<Picto> {
* @param pic
*/
public
void
addPicto
(
Picto
pic
,
ImgDownloader
.
tsource
source
){
addPicto
(
pic
,
source
,
this
.
imgListener
);
}
public
void
addPicto
(
Picto
pic
,
ImgDownloader
.
tsource
source
,
iImgDownloaderListener
imgListener
){
Vector
<
Img
>
imgs
=
new
Vector
<
Img
>(
1
);
imgs
.
add
(
new
Img
(
pic
.
get_id
(),
pic
.
get_url
(),
Img
.
VOCABULARY
));
...
...
@@ -311,14 +310,7 @@ public class Vocabulary implements Iterable<Picto> {
* @return list of pictos which should be selectable at the beginning of a sentence. Empty categories are removed
*/
public
LinkedList
<
Picto
>
startSentence
(){
Iterator
<
Picto
>
pictos
=
this
.
pictos
.
get
(
new
Integer
(
Picto
.
NO_CATEGORY
)).
iterator
();
LinkedList
<
Picto
>
filteredPictos
=
new
LinkedList
<
Picto
>();
while
(
pictos
.
hasNext
())
{
Picto
picto
=
pictos
.
next
();
if
(!
picto
.
is_category
()
||
isVisibleCategory
(
picto
.
get_id
()))
filteredPictos
.
add
(
picto
);
}
return
filteredPictos
;
return
this
.
pictos
.
get
(
new
Integer
(
Picto
.
NO_CATEGORY
));
}
/**
...
...
@@ -326,13 +318,13 @@ public class Vocabulary implements Iterable<Picto> {
* @param id
* @return
*/
p
rivate
boolean
isVisibleCategory
(
int
id
)
{
p
ublic
boolean
isVisibleCategory
(
int
id
)
{
if
(
empty_category
(
id
))
return
false
;
boolean
visible
=
false
;
for
(
Picto
picto
:
this
.
pictos
.
get
(
id
))
{
visible
=
picto
.
is_enabled
();
visible
=
!
picto
.
is_invisible
();
if
(
visible
)
break
;
}
return
visible
;
...
...
@@ -342,19 +334,32 @@ public class Vocabulary implements Iterable<Picto> {
*/
public
Picto
saveLocalPicto
(
String
url
,
String
exp
,
int
cat
,
int
coord_x
,
int
coord_y
)
{
int
id
=
PCBcontext
.
getDevice
().
getNextLocalPictoID
();
Picto
picto
;
final
Picto
picto
[]=
new
Picto
[
1
];
try
{
picto
[
0
]
=
new
Picto
(
id
,
url
,
exp
,
cat
,
coord_x
,
coord_y
);
addPicto
(
picto
[
0
],
ImgDownloader
.
tsource
.
local
,
new
iImgDownloaderListener
()
{
@Override
public
void
loadComplete
()
{
try
{
picto
=
new
Picto
(
id
,
url
,
exp
,
cat
,
coord_x
,
coord_y
);
new
PictoUploader
(
picto
[
0
]).
upload
();
//id<0 iif it is a local id
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
@Override
public
void
loadImg
(
Img
image
)
{
}
});
addPicto
(
picto
,
ImgDownloader
.
tsource
.
local
);
new
PictoUploader
(
picto
).
upload
();
//id<0 iif it is a local id
}
catch
(
Exception
e
)
{
picto
=
null
;
picto
[
0
]
=
null
;
e
.
printStackTrace
();
Log
.
e
(
Vocabulary
.
class
.
getCanonicalName
(),
e
.
getMessage
());
}
PCBcontext
.
getActionLog
().
log
(
new
VocabularyAction
(
VocabularyAction
.
ADD
,
picto
));
return
picto
;
PCBcontext
.
getActionLog
().
log
(
new
VocabularyAction
(
VocabularyAction
.
ADD
,
picto
[
0
]
));
return
picto
[
0
]
;
}
/**
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/grammar/VocabularyTalk.java
View file @
8b01ca8d
package
com
.
yottacode
.
pictogram
.
grammar
;
import
android.util.Log
;
import
com.github.nkzawa.emitter.Emitter
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
com.yottacode.pictogram.dao.Picto
;
import
com.yottacode.pictogram.action.Room
;
/** * Websocket Vocabulary Room based on Room * @author Fernando Martinez Santiago * @version 1.0 */
public
class
VocabularyTalk
implements
Emitter
.
Listener
{
private
static
final
String
URL
=
"vocabulary"
;
private
Room
room
;
iVocabularyListener
listeners
[];
public
VocabularyTalk
(
Room
room
,
iVocabularyListener
listeners
[])
{
this
.
room
=
room
;
this
.
room
.
listen
(
URL
,
this
);
this
.
listeners
=
listeners
;
}
@Override
public
void
call
(
Object
...
args
)
{
final
String
param_action
=
"action"
;
final
String
param_attributes
=
"attributes"
;
final
String
param_picto
=
"picto"
;
final
String
param_picto_cat
=
"id_cat"
;
final
String
action_update
=
"update"
;
final
String
action_add
=
"add"
;
final
String
action_delete
=
"delete"
;
JSONObject
msg
=
(
JSONObject
)
args
[
0
];
try
{
String
action
=
msg
.
getString
(
param_action
).
toLowerCase
();
JSONObject
picto
=
msg
.
getJSONObject
(
param_attributes
).
getJSONObject
(
param_picto
);
JSONObject
attrs_picto
=
picto
.
getJSONObject
(
param_attributes
);
int
picto_id
=
picto
.
getInt
(
param_picto
);
int
picto_cat
=
attrs_picto
.
optInt
(
param_picto_cat
,
Picto
.
NO_CATEGORY
);
Log
.
d
(
this
.
getClass
().
getName
(),
"Received message '"
+
action
+
"' for picto "
+
picto_id
+
" (cat "
+
picto_cat
+
", attrs: "
+
attrs_picto
);
for
(
iVocabularyListener
listener:
this
.
listeners
)
listener
.
change
(
action
.
equals
(
action_update
)
?
iVocabularyListener
.
action
.
update
:
action
.
equals
(
action_add
)
?
iVocabularyListener
.
action
.
add
:
iVocabularyListener
.
action
.
delete
,
picto_cat
,
picto_id
,
attrs_picto
);
}
catch
(
JSONException
e
)
{
Log
.
e
(
this
.
getClass
().
getCanonicalName
(),
e
.
getClass
().
getCanonicalName
()
+
"--"
+
e
);
}
}
}
\ No newline at end of file
package
com
.
yottacode
.
pictogram
.
grammar
;
import
android.util.Log
;
import
com.github.nkzawa.emitter.Emitter
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
com.yottacode.pictogram.dao.Picto
;
import
com.yottacode.pictogram.action.Room
;
/** * Websocket Vocabulary Room based on Room * @author Fernando Martinez Santiago * @version 1.0 */
public
class
VocabularyTalk
implements
Emitter
.
Listener
{
private
static
final
String
URL
=
"vocabulary"
;
private
Room
room
;
iVocabularyListener
listeners
[];
public
VocabularyTalk
(
Room
room
,
iVocabularyListener
listeners
[])
{
this
.
room
=
room
;
this
.
room
.
listen
(
URL
,
this
);
this
.
listeners
=
listeners
;
}
@Override
public
void
call
(
Object
...
args
)
{
final
String
param_action
=
"action"
;
final
String
param_attributes
=
"attributes"
;
final
String
param_picto
=
"picto"
;
final
String
param_picto_id
=
"id"
;
final
String
param_picto_cat
=
"id_cat"
;
final
String
action_update
=
"update"
;
final
String
action_add
=
"add"
;
final
String
action_delete
=
"delete"
;
JSONObject
msg
=
(
JSONObject
)
args
[
0
];
try
{
String
action
=
msg
.
getString
(
param_action
).
toLowerCase
();
JSONObject
picto
=
msg
.
getJSONObject
(
param_attributes
).
getJSONObject
(
param_picto
);
JSONObject
attrs_picto
=
picto
.
getJSONObject
(
param_attributes
);
int
picto_id
=
picto
.
getInt
(
param_picto_id
);
int
picto_cat
=
attrs_picto
.
optInt
(
param_picto_cat
,
Picto
.
NO_CATEGORY
);
Log
.
d
(
this
.
getClass
().
getName
(),
"Received message '"
+
action
+
"' for picto "
+
picto_id
+
" (cat "
+
picto_cat
+
", attrs: "
+
attrs_picto
);
for
(
iVocabularyListener
listener:
this
.
listeners
)
listener
.
change
(
action
.
equals
(
action_update
)
?
iVocabularyListener
.
action
.
update
:
action
.
equals
(
action_add
)
?
iVocabularyListener
.
action
.
add
:
iVocabularyListener
.
action
.
delete
,
picto_cat
,
picto_id
,
attrs_picto
);
}
catch
(
JSONException
e
)
{
Log
.
e
(
this
.
getClass
().
getCanonicalName
(),
e
.
getClass
().
getCanonicalName
()
+
"--"
+
e
);
}
}
}
\ No newline at end of file
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/grammar/iVocabularyListener.java
View file @
8b01ca8d
...
...
@@ -16,6 +16,5 @@ import java.util.LinkedList;
*/
public
interface
iVocabularyListener
{
public
enum
action
{
delete
,
add
,
update
}
public
enum
arg
{
attributes
,
expression
,
url
}
public
void
change
(
iVocabularyListener
.
action
action
,
int
picto_cat
,
int
picto_id
,
JSONObject
args
);
}
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/LoginActivity.java
View file @
8b01ca8d
...
...
@@ -261,7 +261,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
}
});
PCBcontext
.
getDevice
().
deleteDeprecatedImgs
();
// Si sólo hay 1 estudiante paso a Pictogram
if
(
users
.
size
()
==
1
){
//close the progress dialog
...
...
@@ -289,8 +288,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/PanelAdapter.java
View file @
8b01ca8d
...
...
@@ -2,6 +2,7 @@ package com.yottacode.pictogram.gui;
import
android.annotation.TargetApi
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.Canvas
;
...
...
@@ -23,7 +24,9 @@ import android.widget.GridView;
import
android.widget.ImageView
;
import
com.yottacode.pictogram.R
;
import
com.yottacode.pictogram.dao.PCBDBHelper
;
import
com.yottacode.pictogram.dao.Picto
;
import
com.yottacode.pictogram.dao.User
;
import
com.yottacode.pictogram.grammar.iVocabularyListener
;
import
com.yottacode.pictogram.tools.PCBcontext
;
...
...
@@ -146,7 +149,8 @@ public class PanelAdapter extends ArrayAdapter {
// Es un hueco en blanco
imageView
.
setImageAlpha
(
0
);
}
else
{
Bitmap
bmp1
=
lPictos
.
get
(
position
).
get_bitmap
(
PCBcontext
.
getContext
());
Picto
picto
=
lPictos
.
get
(
position
);
Bitmap
bmp1
=
picto
.
get_bitmap
(
PCBcontext
.
getContext
());
if
(
bmp1
!=
null
){
// Magnify
if
(
lPictos
.
get
(
position
).
is_magnify
()){
...
...
@@ -157,14 +161,14 @@ public class PanelAdapter extends ArrayAdapter {
imageView
.
setScaleY
(
1
f
);
}
// Estado de los pictos: enabled | disabled | invisible
String
status
=
lPictos
.
get
(
position
).
get_status
();
if
(
status
.
equalsIgnoreCase
(
"invisible"
)){
imageView
.
setImageAlpha
(
0
);
Log
.
d
(
LOG_TAG
,
"POSITION:"
+
position
+
" / STATUS: "
+
status
);
if
(
picto
.
is_invisible
())
{
imageView
.
setImageAlpha
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_supervisor
()
?
50
:
0
);
imageView
.
setImageBitmap
(
bmp1
);
Log
.
d
(
LOG_TAG
,
"POSITION:"
+
position
+
" / STATUS: "
+
picto
.
get_status
());
//imageView.setImageBitmap(bmp1);
}
else
if
(
status
.
equalsIgnoreCase
(
"disabled"
)){
}
if
(
picto
.
is_disabled
()){
imageView
.
setImageAlpha
(
100
);
// Entre 0 y 255
Bitmap
bmp2
=
BitmapFactory
.
decodeResource
(
PCBcontext
.
getContext
().
getResources
(),
R
.
drawable
.
redcross3
);
Bitmap
bmOverlay
=
Bitmap
.
createBitmap
(
bmp1
.
getWidth
(),
bmp1
.
getHeight
(),
bmp1
.
getConfig
());
...
...
@@ -185,7 +189,7 @@ public class PanelAdapter extends ArrayAdapter {
canvas.drawBitmap(bmp2, boardPosX, boardPosY, null);
*/
}
else
{
if
(
picto
.
is_enabled
())
{
/* AÑADO UN BORDE */
/*
final int BORDER_WIDTH = 1;
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/PictogramActivity.java
View file @
8b01ca8d
...
...
@@ -3,7 +3,6 @@ package com.yottacode.pictogram.gui;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.content.ServiceConnection
;
import
android.database.Cursor
;
import
android.graphics.Color
;
import
android.graphics.Point
;
...
...
@@ -18,11 +17,13 @@ import android.os.Bundle;
import
android.provider.MediaStore
;
import
android.provider.Settings
;
import
android.speech.tts.TextToSpeech
;
import
android.text.InputType
;
import
android.util.Log
;
import
android.view.Display
;
import
android.view.DragEvent
;
import
android.view.KeyEvent
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.Window
;
...
...
@@ -34,24 +35,16 @@ import android.widget.ImageButton;
import
android.widget.RelativeLayout
;
import
android.widget.Toast
;
import
com.yottacode.net.SSLDummyContext
;
import
com.yottacode.pictogram.BuildConfig
;
import
com.yottacode.pictogram.R
;
import
com.yottacode.pictogram.action.Action
;
import
com.yottacode.pictogram.action.ActionLog
;
import
com.yottacode.pictogram.action.PictoAction
;
import
com.yottacode.pictogram.action.PictosAction
;
import
com.yottacode.pictogram.action.TalkAction
;
import
com.yottacode.pictogram.action.VocabularyAction
;
import
com.yottacode.pictogram.dao.Picto
;
import
com.yottacode.pictogram.dao.User
;
import
com.yottacode.pictogram.grammar.Vocabulary
;
import
com.yottacode.pictogram.grammar.iVocabularyListener
;
import
com.yottacode.pictogram.net.PictoUploader
;
import
com.yottacode.pictogram.tools.Img
;
import
com.yottacode.pictogram.tools.PCBcontext
;
import
com.yottacode.pictogram.net.iImgDownloaderListener
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.util.ArrayList
;
...
...
@@ -69,15 +62,12 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
PanelAdapter
panelAdapter
;
TapeAdapter
tapeAdapter
;
Vocabulary
vocabulary
;
User
student
;
Context
context
;
Picto
actualCategory
;
Picto
currentCategory
;
TextToSpeech
tts
;
static
final
int
SELECT_PICTURE
=
1
;
// For disabling volume button (See method at the end of the class)
private
final
List
blockedKeys
=
new
ArrayList
(
Arrays
.
asList
(
KeyEvent
.
KEYCODE_VOLUME_DOWN
,
KeyEvent
.
KEYCODE_VOLUME_UP
));
...
...
@@ -88,7 +78,8 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
private
boolean
isSupervisor
=
false
;
private
String
selectedImagePath
;
private
static
final
int
SELECT_PICTURE
=
1
;
/*
float xAxis = 0f;
...
...
@@ -104,16 +95,14 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
setContentView
(
R
.
layout
.
activity_pictogram
);
Intent
intent
=
getIntent
();
Intent
intent
=
getIntent
();
isSupervisor
=
intent
.
getBooleanExtra
(
"isSupervisor"
,
false
);
//isSupervisor = true;// QUITAR
//Log.d(LOG_TAG, "isSupervisor vale " + isSupervisor);
context
=
this
;
actualCategory
=
null
;
// this for refresh vocabulary when a websocket action arrived from the dashboard
currentCategory
=
null
;
// this for refresh vocabulary when a websocket action arrived from the dashboard
count_deletelong
=
0
;
...
...
@@ -137,17 +126,17 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// Adapter for grid
panelAdapter
=
new
PanelAdapter
(
new
LinkedList
<
Picto
>());
this
.
vocabulary
=
PCBcontext
.
getVocabulary
();
if
(
this
.
vocabulary
!=
null
&&
this
.
vocabulary
.
size
()
>
0
)
{
Log
.
d
(
LOG_TAG
,
"Vocabulario correcto de tam:"
+
this
.
vocabulary
.
size
());
Vocabulary
vocabulary
=
PCBcontext
.
getVocabulary
();
if
(
vocabulary
!=
null
&&
vocabulary
.
size
()
>
0
)
{
Log
.
d
(
LOG_TAG
,
"Vocabulario correcto de tam:"
+
vocabulary
.
size
());
LinkedList
<
Picto
>
ll
;
if
(
actualCategory
!=
null
)
ll
=
order
(
vocabulary
.
next
(
actual
Category
));
if
(
currentCategory
!=
null
)
ll
=
order
(
vocabulary
.
next
(
current
Category
));
else
ll
=
order
(
vocabulary
.
startSentence
());
panelAdapter
.
clear
();
panelAdapter
.
addAll
(
ll
);
}
// Open websocket connection
vocabulary
.
listen
(
PCBcontext
.
getRoom
(),
this
);
vocabulary
.
listen
(
PCBcontext
.
getRoom
(),
this
);
// Connect the views
final
GridView
tapeGridView
=
(
GridView
)
findViewById
(
R
.
id
.
tape_grid_view
);
...
...
@@ -200,14 +189,14 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
*/
final
GridView
panelGridView
=
(
GridView
)
findViewById
(
R
.
id
.
panel_grid_view
);
final
ImageButton
deleteButton
=
(
ImageButton
)
findViewById
(
R
.
id
.
button_delete
);
final
ImageButton
deleteButton
=
(
ImageButton
)
findViewById
(
R
.
id
.
button_delete
);
//final Button deleteAllButton = (Button) findViewById(R.id.button_delete_all);
final
ImageButton
ttsButton
=
(
ImageButton
)
findViewById
(
R
.
id
.
button_tts
);
// Si los pictogramas son grandes pongo una configuración. Si son pequeños otra...
int
pictogramSize
=
0
;
// ESTE VALOR SE COGE DE LA CONFIGURACION DEL USUARIO (0:normal; 1:large)
if
(
pictogramSize
==
0
)
panelGridView
.
setNumColumns
(
10
);
else
if
(
pictogramSize
==
1
)
panelGridView
.
setNumColumns
(
4
);
if
(
pictogramSize
==
0
)
panelGridView
.
setNumColumns
(
10
);
else
if
(
pictogramSize
==
1
)
panelGridView
.
setNumColumns
(
4
);
panelGridView
.
setAdapter
(
panelAdapter
);
...
...
@@ -236,22 +225,22 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
//rowNumberAdapter.notifyDataSetChanged();
Picto
p
=
panelAdapter
.
getItem
(
position
);
if
(
p
!=
null
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
if
(
p
!=
null
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
Log
.
d
(
LOG_TAG
,
"Clic en picto: "
+
p
.
toString
());
//Log.d(LOG_TAG, "STATUS: " + p.get_status());
//QUITAR PARA QUE HABLE panelAdapter.ttsPicto(p, tts);
// If is not the blank picto, it isn't invisible or disabled
if
(
p
.
get_id
()
!=
0
&&
if
(
p
.
get_id
()
!=
0
&&
!
p
.
get_status
().
equalsIgnoreCase
(
"invisible"
)
&&
!
p
.
get_status
().
equalsIgnoreCase
(
"disabled"
))
{
LinkedList
<
Picto
>
ll
=
order
(
vocabulary
.
next
(
p
));
LinkedList
<
Picto
>
ll
=
order
(
PCBcontext
.
getVocabulary
()
.
next
(
p
));
//LinkedList<Picto> ll = vocabulary.next(p);
Log
.
d
(
LOG_TAG
,
"Lista de pictos recuperada: "
+
ll
.
toString
());
int
maxInTape
=
getResources
().
getInteger
(
R
.
integer
.
maxInTape
);
int
maxInTape
=
getResources
().
getInteger
(
R
.
integer
.
maxInTape
);
// If the picto is a category
if
(
p
.
is_category
())
{
...
...
@@ -264,19 +253,18 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
//panelAdapter = new PanelAdapter(ll);
// Cambio el color del fondo
RelativeLayout
rl
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
pictogramLayout
);
RelativeLayout
rl
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
pictogramLayout
);
//rl.setBackgroundColor(Color.RED);
if
(
p
.
get_color
()
!=
-
1
){
if
(
p
.
get_color
()
!=
-
1
)
{
rl
.
setBackgroundColor
(
p
.
get_color
());
panelAdapter
.
setColor
(
p
.
get_darkner_color
());
}
actualCategory
=
p
;
Toast
.
makeText
(
context
,
"El picto pulsado es una categoría"
,
Toast
.
LENGTH_SHORT
).
show
();
currentCategory
=
p
;
PCBcontext
.
getActionLog
().
log
(
new
TalkAction
(
TalkAction
.
SELECT
,
p
));
}
else
if
(
tapeAdapter
.
getCount
()
<
maxInTape
)
{
}
else
if
(
tapeAdapter
.
getCount
()
<
maxInTape
)
{
// If the picto selected is not a category and the tape is not full, it is placed in tape
tapeAdapter
.
addItem
(
p
);
tapeAdapter
.
notifyDataSetChanged
();
...
...
@@ -286,7 +274,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
panelAdapter
.
addAll
(
ll
);
panelAdapter
.
setColor
(
Color
.
parseColor
(
"#AFAFAF"
));
RelativeLayout
rl
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
pictogramLayout
);
RelativeLayout
rl
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
pictogramLayout
);
rl
.
setBackgroundColor
(
Color
.
parseColor
(
"#BDBDBD"
));
// Call to static log method
...
...
@@ -294,7 +282,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// Send websocket notification
// when clicking a picto, the activity goes to the main category view
actual
Category
=
null
;
current
Category
=
null
;
}
}
}
...
...
@@ -305,33 +293,37 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
panelGridView
.
setOnItemLongClickListener
(
new
AdapterView
.
OnItemLongClickListener
()
{
@Override
public
boolean
onItemLongClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
if
(
isSupervisor
){
if
(
isSupervisor
)
{
// Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito
Picto
p
=
panelAdapter
.
getItem
(
position
);
if
(
p
==
null
){
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device
if
(
p
==
null
)
{
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if
(
PictogramActivity
.
this
.
currentCategory
!=
null
)
{
Log
.
d
(
LOG_TAG
,
"No tengo pictograma. Abro carrete..."
);
chooseImage
();
// ...
}
else
{
int
cols
=
getResources
().
getInteger
(
R
.
integer
.
columns
);
addPicto
(
position
%
cols
,
(
int
)
(
position
/
cols
));
}
else
Toast
.
makeText
(
PictogramActivity
.
this
,
PictogramActivity
.
this
.
getResources
().
getString
(
R
.
string
.
notNewCats
),
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
p
.
alter_status
();
LinkedList
<
Picto
>
ll
;
if
(
actualCategory
!=
null
)
ll
=
order
(
vocabulary
.
next
(
actual
Category
));
else
ll
=
order
(
vocabulary
.
startSentence
());
LinkedList
<
Picto
>
ll
;
if
(
currentCategory
!=
null
)
ll
=
order
(
PCBcontext
.
getVocabulary
().
next
(
current
Category
));
else
ll
=
order
(
PCBcontext
.
getVocabulary
()
.
startSentence
());
panelAdapter
.
clear
();
panelAdapter
.
addAll
(
ll
);}
panelAdapter
.
addAll
(
ll
);
}
}
else
{
}
else
{
ClipData
.
Item
item
=
new
ClipData
.
Item
(
""
+
position
);
String
[]
mimeTypes
=
{
ClipDescription
.
MIMETYPE_TEXT_PLAIN
};
ClipData
data
=
new
ClipData
(
""
+
position
,
mimeTypes
,
item
);
Picto
p
=
panelAdapter
.
getItem
(
position
);
if
(
p
!=
null
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
if
(
p
!=
null
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
// If is not the blank picto, it isn't invisible or disabled
if
(
p
.
get_id
()
!=
0
&&
if
(
p
.
get_id
()
!=
0
&&
!
p
.
get_status
().
equalsIgnoreCase
(
"invisible"
)
&&
!
p
.
get_status
().
equalsIgnoreCase
(
"disabled"
)
&&
tapeAdapter
.
getCount
()
<
8
)
{
...
...
@@ -393,7 +385,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
panelAdapter
.
setColor
(
Color
.
parseColor
(
"#AFAFAF"
));
RelativeLayout
rl
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
pictogramLayout
);
RelativeLayout
rl
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
pictogramLayout
);
rl
.
setBackgroundColor
(
Color
.
parseColor
(
"#BDBDBD"
));
// Load the categories
...
...
@@ -420,19 +412,18 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
});
// Acción para volver a la ventana de login
deleteButton
.
setOnLongClickListener
(
new
AdapterView
.
OnLongClickListener
(){
deleteButton
.
setOnLongClickListener
(
new
AdapterView
.
OnLongClickListener
()
{
@Override
public
boolean
onLongClick
(
View
v
)
{
Log
.
d
(
LOG_TAG
,
"DELETE LONGCLICK..."
);
count_deletelong
++;
//Picto picto=PCBcontext.getVocabulary().saveLocalPicto("/sdcard/DCIM/camera/javo.jpg", "javier", 7515, 2, 2);
if
(
count_deletelong
>=
3
){
if
(
count_deletelong
>=
3
)
{
//Log.d(LOG_TAG, "SALTO A LOGIN");
// Paso un parámetro a la SerialActivity, para controlar de dónde viene
Intent
serialActivity
=
new
Intent
(
getBaseContext
(),
SerialActivity
.
class
);
serialActivity
.
putExtra
(
"activity_name"
,
"PictogramActivity"
);
serialActivity
.
putExtra
(
"activity_name"
,
"PictogramActivity"
);
startActivity
(
serialActivity
);
}
...
...
@@ -441,56 +432,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
});
}
/**
* función para la selección de una foto del carrete
*/
public
void
chooseImage
(){
Intent
intent
=
new
Intent
(
Intent
.
ACTION_PICK
);
intent
.
setType
(
"image/*"
);
startActivityForResult
(
intent
,
SELECT_PICTURE
);
}
/**
* Función para la selección de una foto del carrete
* @param requestCode
* @param resultCode
* @param data
*/
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
if
(
resultCode
==
RESULT_OK
)
{
if
(
requestCode
==
SELECT_PICTURE
)
{
Uri
selectedImageUri
=
data
.
getData
();
selectedImagePath
=
getPath
(
selectedImageUri
);
Log
.
d
(
LOG_TAG
,
"selectedImagePath:"
+
selectedImagePath
);
// Ahora guardaría la imagen en la bbdd local y habría que subirla al server y sincronizar las bbdd
// ...
}
}
}
/**
* Función para la selección de una foto del carrete
* @param uri
* @return
*/
public
String
getPath
(
Uri
uri
)
{
if
(
uri
==
null
)
{
return
null
;
}
// this will only work for images selected from gallery
String
[]
projection
=
{
MediaStore
.
Images
.
Media
.
DATA
};
Cursor
cursor
=
managedQuery
(
uri
,
projection
,
null
,
null
,
null
);
if
(
cursor
!=
null
){
int
column_index
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
);
cursor
.
moveToFirst
();
return
cursor
.
getString
(
column_index
);
}
return
uri
.
getPath
();
}
@Override
public
void
onInit
(
int
status
)
{
...
...
@@ -501,7 +442,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
@Override
protected
void
onStart
()
{
super
.
onStart
();
Toast
.
makeText
(
this
,
"onStart"
,
Toast
.
LENGTH_SHORT
).
show
();
//
Toast.makeText(this, "onStart", Toast.LENGTH_SHORT).show();
}
@Override
protected
void
onResume
()
{
...
...
@@ -509,26 +450,26 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
//Toast.makeText(this, "onResume", Toast.LENGTH_SHORT).show();
String
android_id
=
Settings
.
Secure
.
getString
(
this
.
getContentResolver
(),
Secure
.
ANDROID_ID
);
//
String android_id = Settings.Secure.getString(this.getContentResolver(),
//
Secure.ANDROID_ID);
Toast
.
makeText
(
this
,
"onResume - Android ID: "
+
android_id
,
Toast
.
LENGTH_SHORT
).
show
();
//
Toast.makeText(this, "onResume - Android ID: " + android_id, Toast.LENGTH_SHORT).show();
}
@Override
protected
void
onPause
()
{
Toast
.
makeText
(
this
,
"onPause"
,
Toast
.
LENGTH_SHORT
).
show
();
//
Toast.makeText(this, "onPause", Toast.LENGTH_SHORT).show();
super
.
onPause
();
}
@Override
protected
void
onStop
()
{
super
.
onStop
();
Toast
.
makeText
(
this
,
"onStop"
,
Toast
.
LENGTH_SHORT
).
show
();
//
Toast.makeText(this, "onStop", Toast.LENGTH_SHORT).show();
}
@Override
protected
void
onRestart
()
{
super
.
onRestart
();
Toast
.
makeText
(
this
,
"onRestart"
,
Toast
.
LENGTH_SHORT
).
show
();
//
Toast.makeText(this, "onRestart", Toast.LENGTH_SHORT).show();
}
@Override
protected
void
onDestroy
()
{
...
...
@@ -536,7 +477,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
if
(
tts
!=
null
){
tts
.
shutdown
();
}
Toast
.
makeText
(
this
,
"onDestroy"
,
Toast
.
LENGTH_SHORT
).
show
();
//
Toast.makeText(this, "onDestroy", Toast.LENGTH_SHORT).show();
}
/**
...
...
@@ -544,13 +485,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
* @param v
*/
public
void
load_pictos
(
View
v
)
{
if
(
vocabulary
!=
null
)
Log
.
d
(
LOG_TAG
,
"4) Vocabulario: "
+
vocabulary
.
toString
());
if
(
PCBcontext
.
getVocabulary
()
!=
null
)
Log
.
d
(
LOG_TAG
,
"4) Vocabulario: "
+
PCBcontext
.
getVocabulary
()
.
toString
());
try
{
actual
Category
=
null
;
current
Category
=
null
;
LinkedList
<
Picto
>
ll
=
order
(
vocabulary
.
startSentence
());
LinkedList
<
Picto
>
ll
=
order
(
PCBcontext
.
getVocabulary
()
.
startSentence
());
panelAdapter
.
clear
();
panelAdapter
.
addAll
(
ll
);
...
...
@@ -571,17 +512,12 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// This is to show the pictos ordered in the 2D Array that represents the panel
int
rows
=
5
;
int
cols
=
10
;
/*
int rows = R.integer.rows;
int cols = R.integer.columns;
*/
int
rows
=
getResources
().
getInteger
(
R
.
integer
.
rows
);
int
cols
=
getResources
().
getInteger
(
R
.
integer
.
columns
);
Picto
[][]
mp
=
new
Picto
[
rows
][
cols
];
for
(
Picto
p
:
list
)
mp
[
p
.
get_
row
()][
p
.
get_column
()]
=
p
;
mp
[
p
.
get_
column
()][
p
.
get_row
()]
=
p
;
try
{
/*
...
...
@@ -612,18 +548,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
Log
.
d
(
LOG_TAG
,
"Vocabulary action listened: "
+
action
);
if
(
args
!=
null
)
Log
.
d
(
LOG_TAG
,
"args: "
+
args
.
toString
());
/*
LinkedList<Picto> ll;
if(actualCategory != null) ll = order(vocabulary.next(actualCategory));
else ll = order(vocabulary.startSentence());
panelAdapter.clear();
panelAdapter.addAll(ll);
panelAdapter.notifyDataSetChanged();
*/
// Background task that updates the ui into the main thread.
runOnUiThread
(
new
Runnable
()
{
@Override
...
...
@@ -632,8 +556,8 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
//stuff that updates ui
LinkedList
<
Picto
>
ll
;
if
(
actualCategory
!=
null
)
ll
=
order
(
vocabulary
.
next
(
actual
Category
));
else
ll
=
order
(
vocabulary
.
startSentence
());
if
(
currentCategory
!=
null
)
ll
=
order
(
PCBcontext
.
getVocabulary
().
next
(
current
Category
));
else
ll
=
order
(
PCBcontext
.
getVocabulary
()
.
startSentence
());
panelAdapter
.
clear
();
panelAdapter
.
addAll
(
ll
);
...
...
@@ -642,33 +566,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
}
});
switch
(
action
)
{
case
delete:
{
Log
.
d
(
LOG_TAG
,
"Entra en el case delete. Picto cat: "
+
picto_cat
+
" y picto_id: "
+
picto_id
);
//removePicto(picto_cat, picto_id);
break
;
}
case
update:
{
Log
.
d
(
LOG_TAG
,
"Entra en el case update. Picto cat: "
+
picto_cat
+
" y picto_id: "
+
picto_id
);
//modifyAttsPicto(picto_cat, picto_id, (JSONObject) args.get(arg.attributes));
break
;
}
case
add:
{
Log
.
d
(
LOG_TAG
,
"Entra en el case add. Picto_id: "
+
picto_id
);
/*
addPicto(new Picto(picto_id, (String) args.get(arg.url),
(String) args.get(arg.expression),
(JSONObject) args.get(arg.attributes)));
*/
break
;
}
}
}
// Disable Back Button --> Kiosk mode
...
...
@@ -695,13 +592,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
// Change the password
if
(
checkBox
.
isChecked
()){
// Show a new dialog
View
dialogChangeEscapeCode
=
View
.
inflate
(
context
,
R
.
layout
.
dialog_change_escape_code
,
null
);
View
dialogChangeEscapeCode
=
View
.
inflate
(
PCBcontext
.
getContext
()
,
R
.
layout
.
dialog_change_escape_code
,
null
);
final
EditText
input1
=
(
EditText
)
dialogChangeEscapeCode
.
findViewById
(
R
.
id
.
editText1
);
final
EditText
input2
=
(
EditText
)
dialogChangeEscapeCode
.
findViewById
(
R
.
id
.
editText2
);
// Build the AlertDialog
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
context
);
builder
.
setTitle
(
context
.
getResources
().
getString
(
R
.
string
.
newEscapeCode
));
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
PCBcontext
.
getContext
()
);
builder
.
setTitle
(
PCBcontext
.
getContext
()
.
getResources
().
getString
(
R
.
string
.
newEscapeCode
));
builder
.
setView
(
dialogChangeEscapeCode
);
// Set up the buttons
...
...
@@ -715,11 +612,11 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
if
(
m_Text1
.
equalsIgnoreCase
(
m_Text2
))
{
// Change the keyword
PCBcontext
.
getDevice
().
setKeyword
(
m_Text1
);
Toast
.
makeText
(
context
,
getResources
().
getString
(
R
.
string
.
codeModified
),
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
PCBcontext
.
getContext
()
,
getResources
().
getString
(
R
.
string
.
codeModified
),
Toast
.
LENGTH_SHORT
).
show
();
// And exit PictogramActivity
finish
();
}
else
Toast
.
makeText
(
context
,
getResources
().
getString
(
R
.
string
.
codesNotEqual
),
Toast
.
LENGTH_SHORT
).
show
();
}
else
Toast
.
makeText
(
PCBcontext
.
getContext
()
,
getResources
().
getString
(
R
.
string
.
codesNotEqual
),
Toast
.
LENGTH_SHORT
).
show
();
}
});
builder
.
setNegativeButton
(
getResources
().
getString
(
R
.
string
.
cancel
),
new
DialogInterface
.
OnClickListener
()
{
...
...
@@ -741,7 +638,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
*/
}
// Wrong code
}
else
Toast
.
makeText
(
context
,
getResources
().
getString
(
R
.
string
.
wrongCode
),
Toast
.
LENGTH_SHORT
).
show
();
}
else
Toast
.
makeText
(
PCBcontext
.
getContext
()
,
getResources
().
getString
(
R
.
string
.
wrongCode
),
Toast
.
LENGTH_SHORT
).
show
();
}
});
builder
.
setNegativeButton
(
getResources
().
getString
(
R
.
string
.
cancel
),
new
DialogInterface
.
OnClickListener
()
{
...
...
@@ -921,4 +818,105 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
return
true
;
}
}
/*
* Methods for add a new picto from pcb
*
*/
/**
* add a local picto from pcb
* @param row
* @param col
*/
public
void
addPicto
(
int
row
,
int
col
)
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_PICK
);
intent
.
setType
(
"image/*"
);
this
.
getIntent
().
putExtra
(
Picto
.
JSON_ATTTRS
.
ROW
,
row
);
this
.
getIntent
().
putExtra
(
Picto
.
JSON_ATTTRS
.
COLUMN
,
col
);
startActivityForResult
(
intent
,
SELECT_PICTURE
);
}
/**
* función para la edición de un texto asociado a una nueva imagen y guardar el nuevo picto
*/
public
void
chooseTextAndSavePicto
(
final
String
selectedImagePath
,
final
int
row
,
final
int
col
)
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setTitle
(
getResources
().
getString
(
R
.
string
.
enterImgLabel
));
// Set up the input
final
EditText
input
=
new
EditText
(
this
);
input
.
setInputType
(
InputType
.
TYPE_CLASS_TEXT
);
builder
.
setView
(
input
);
// Set up the buttons
builder
.
setPositiveButton
(
"OK"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
int
cat
=
PictogramActivity
.
this
.
currentCategory
!=
null
?
PictogramActivity
.
this
.
currentCategory
.
get_id
()
:
Picto
.
NO_CATEGORY
;
Picto
localPicto
=
PCBcontext
.
getVocabulary
().
saveLocalPicto
(
selectedImagePath
,
input
.
getText
().
toString
(),
cat
,
row
,
col
);
change
(
action
.
add
,
cat
,
localPicto
.
get_id
(),
null
);
//gui must be refresh
}
});
builder
.
show
();
}
/**
* Función para la selección de una foto del carrete
* @param requestCode
* @param resultCode
* @param data
*/
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
if
(
requestCode
==
SELECT_PICTURE
)
{
String
selectedImagePath
;
Uri
selectedImageUri
=
data
.
getData
();
selectedImagePath
=
getPath
(
selectedImageUri
);
int
row
=
this
.
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
ROW
,
-
1
);
int
col
=
this
.
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
COLUMN
,
-
1
);
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"0 Picto x y "
+
" "
+
row
+
" "
+
col
);
this
.
getIntent
().
removeExtra
(
Picto
.
JSON_ATTTRS
.
ROW
);
this
.
getIntent
().
removeExtra
(
Picto
.
JSON_ATTTRS
.
COLUMN
);
chooseTextAndSavePicto
(
selectedImagePath
,
row
,
col
);
}
}
}
/**
* Función para la selección de una foto del carrete
* @param uri
* @return
*/
static
public
String
getPath
(
Uri
uri
)
{
if
(
uri
==
null
)
{
return
null
;
}
// this will only work for images selected from gallery
String
[]
projection
=
{
MediaStore
.
Images
.
Media
.
DATA
};
Cursor
cursor
=
PCBcontext
.
getContext
().
getContentResolver
().
query
(
uri
,
projection
,
null
,
null
,
null
);
if
(
cursor
!=
null
){
int
column_index
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
);
cursor
.
moveToFirst
();
return
cursor
.
getString
(
column_index
);
}
return
uri
.
getPath
();
}
}
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/SerialActivity.java
View file @
8b01ca8d
...
...
@@ -331,7 +331,6 @@ public class SerialActivity extends Activity implements iRestapiListener {
setContentView
(
R
.
layout
.
activity_serial
);
}
});
PCBcontext
.
getDevice
().
deleteDeprecatedImgs
();
}
else
{
// Es un Supervisor
...
...
@@ -372,8 +371,6 @@ public class SerialActivity extends Activity implements iRestapiListener {
}
catch
(
JSONException
e
)
{
//Log.d(LOG_TAG, "ERROR 2");
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/net/ImgDownloader.java
View file @
8b01ca8d
...
...
@@ -8,6 +8,7 @@ import android.util.Log;
import
com.yottacode.pictogram.R
;
import
com.yottacode.pictogram.tools.Img
;
import
com.yottacode.pictogram.tools.PCBcontext
;
import
java.io.File
;
import
java.io.FileInputStream
;
...
...
@@ -68,7 +69,7 @@ public class ImgDownloader extends AsyncTask<Vector<Img>, Void, Img> {
if
(!
img
.
exists_bitmap
(
this
.
context
)
||
this
.
force_download
)
try
{
this
.
activityManager
.
getMemoryInfo
(
mi
);
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
img
.
get_url
()
+
" to be downloaded"
);
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Picto Img "
+
img
.
get_url
()
+
" to be downloaded"
);
if
(
this
.
source
==
source
.
remote
)
{
String
surl
=
context
.
getResources
().
getString
(
R
.
string
.
server
)
+
"/"
+
img
.
get_url
();
URL
url
=
new
URL
(
surl
);
...
...
@@ -113,7 +114,7 @@ public class ImgDownloader extends AsyncTask<Vector<Img>, Void, Img> {
@Override
protected
void
onPostExecute
(
Img
img
)
{
Log
.
d
(
this
.
getClass
().
getCanonicalName
(),
"Inside OnPostExecute()"
+
new
SimpleDateFormat
(
"HH:mm:ss"
)
);
PCBcontext
.
getDevice
().
deleteDeprecatedImgs
(
);
if
(
imgListener
!=
null
)
if
(
img
==
null
)
imgListener
.
loadComplete
();
else
imgListener
.
loadImg
(
img
);
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/net/PictoUploader.java
View file @
8b01ca8d
...
...
@@ -37,7 +37,11 @@ public class PictoUploader {
throw
new
UnsupportedEncodingException
(
"Extension "
+
img
.
get_filetype
()+
" is not supported. Only png files"
);
Ion
ion
=
Ion
.
getDefault
(
PCBcontext
.
getContext
());
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Uploading "
+
img
.
file_name
()
+
" from "
+
img
.
get_type
());
try
{
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Uploading Picto img"
+
img
.
file_name
()
+
" from "
+
img
.
get_type
()
+
"size:"
+
img
.
get_bitmap
(
PCBcontext
.
getContext
()).
getWidth
()
+
" "
+
img
.
get_bitmap
(
PCBcontext
.
getContext
()).
getHeight
());
}
catch
(
IOException
e
)
{
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Uploading Picto img"
+
img
.
file_name
()
+
" from "
+
img
.
get_type
());
}
File
file
=
img
.
file
(
PCBcontext
.
getContext
());
Response
<
JsonObject
>
response
=
null
;
...
...
@@ -149,15 +153,20 @@ public class PictoUploader {
}
/**
*Try to Upload local picto. It requires: i) to upload the image, ii) to upload the attributes and iii) to upload the expression
*Try to Upload local picto. It requires:
* i) to upload the image,
* ii) to upload the attributes
* iii) to upload the expression
* iv) delete the old local picto since it will be recovered from the server
**/
public
void
upload
()
throws
IOException
{
int
old_picto
=
this
.
picto
.
get_id
();
int
img_id
=
uploadImg
(
this
.
picto
);
if
(
img_id
>
0
)
{
uploadAttributes
(
img_id
);
uploadTranslation
(
img_id
);
PCBcontext
.
getRoom
().
emit
(
new
VocabularyAction
(
VocabularyAction
.
ADD
,
PictoUploader
.
this
.
picto
));
PCBcontext
.
getPcbdb
().
deletePicto
(
old_picto
);
}
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/tools/Img.java
View file @
8b01ca8d
...
...
@@ -4,8 +4,11 @@ package com.yottacode.pictogram.tools;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.Rect
;
import
android.util.Log
;
import
com.yottacode.tools.FileTools
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
...
...
@@ -15,6 +18,7 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.util.Enumeration
;
/**
* Img
* @author Fernando
...
...
@@ -26,11 +30,17 @@ public class Img {
static
public
String
SUPERVISOR
=
"supervisor"
;
public
static
final
void
mkDirs
(
Context
context
)
{
new
File
(
path
(
context
,
Img
.
VOCABULARY
)
).
mkdirs
()
;
new
File
(
path
(
context
,
Img
.
STUDENT
)
).
mkdirs
()
;
new
File
(
path
(
context
,
Img
.
SUPERVISOR
)
).
mkdirs
()
;
File
file
;
file
=
new
File
(
path
(
context
,
Img
.
VOCABULARY
));
FileTools
.
deleteDirectory
(
file
);
file
.
mkdirs
();
file
=
new
File
(
path
(
context
,
Img
.
STUDENT
));
FileTools
.
deleteDirectory
(
file
);
file
.
mkdirs
();
file
=
new
File
(
path
(
context
,
Img
.
SUPERVISOR
));
FileTools
.
deleteDirectory
(
file
);
file
.
mkdirs
();
}
protected
int
id
;
protected
String
url
;
String
type
;
...
...
@@ -121,12 +131,13 @@ public class Img {
File
file
=
file
(
context
);
FileOutputStream
os
=
new
FileOutputStream
(
file
);
try
{
this
.
bitmap
=
BitmapFactory
.
decodeStream
(
is
);
this
.
bitmap
=
BitmapFactory
.
decodeStream
(
is
,
new
Rect
(
0
,
0
,
78
,
66
),
null
);
}
catch
(
java
.
lang
.
OutOfMemoryError
err
)
{
Log
.
e
(
Img
.
class
.
getCanonicalName
(),
"Out of memory when decoding "
+
this
.
get_url
());
}
ByteArrayOutputStream
outstream
=
new
ByteArrayOutputStream
();
this
.
bitmap
.
setHasAlpha
(
true
);
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Img Uploading Picto img"
+
file_name
()
+
" from "
+
get_type
()
+
"size:"
+
get_bitmap
(
PCBcontext
.
getContext
()).
getWidth
()
+
" "
+
get_bitmap
(
PCBcontext
.
getContext
()).
getHeight
());
this
.
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
100
,
outstream
);
byte
[]
byteArray
=
outstream
.
toByteArray
();
os
.
write
(
byteArray
);
...
...
android/Pictogram/app/src/main/java/com/yottacode/tools/FileTools.java
0 → 100644
View file @
8b01ca8d
package
com
.
yottacode
.
tools
;
import
java.io.File
;
/**
* Created by Fernando on 14/03/2016.
*/
public
class
FileTools
{
public
static
boolean
deleteDirectory
(
File
path
)
{
if
(
path
.
exists
()
)
{
File
[]
files
=
path
.
listFiles
();
if
(
files
==
null
)
{
return
true
;
}
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
if
(
files
[
i
].
isDirectory
())
{
deleteDirectory
(
files
[
i
]);
}
else
{
files
[
i
].
delete
();
}
}
}
return
(
path
.
delete
()
);
}
}
android/Pictogram/app/src/main/res/values-en/strings.xml
View file @
8b01ca8d
...
...
@@ -47,4 +47,9 @@
<string
name=
"naturalgrammar"
>
SUpO_EN
</string>
<string
name=
"pictogrammar"
>
SUpO_PICTOEN
</string>
<string
name=
"nogrammar"
>
Warning: unknown language
</string>
<!--Upload local img -->
<string
name=
"enterImgLabel"
>
Enter img label
</string>
<string
name=
"notNewCats"
>
Including new categories is not allowed
</string>
</resources>
android/Pictogram/app/src/main/res/values-es/strings.xml
View file @
8b01ca8d
...
...
@@ -52,4 +52,8 @@
<item
type=
"integer"
name=
"maxInTape"
>
8
</item>
<!--Upload local img -->
<string
name=
"enterImgLabel"
>
Introduzca etiqueta de la imagen
</string>
<string
name=
"notNewCats"
>
No puede añadir nuevas categorias
</string>
</resources>
android/Pictogram/app/src/main/res/values/strings.xml
View file @
8b01ca8d
...
...
@@ -48,5 +48,23 @@
<string
name=
"grammar"
>
SUpO_EN
</string>
<string
name=
"nogrammar"
>
Warning: unknown language
</string>
<item
type=
"integer"
name=
"maxInTape"
>
8
</item>
<!--Upload local img -->
<string
name=
"enterImgLabel"
>
Introduzca etiqueta de la imagen
</string>
<string
name=
"notNewCats"
>
No puede añadir nuevas categorias
</string>
<item
name=
"maxInTape"
type=
"integer"
>
8
</item>
<string
name=
"title_activity_img_label"
>
img_label
</string>
<!-- Strings related to login -->
<string
name=
"prompt_email"
>
Email
</string>
<string
name=
"prompt_password"
>
Password (optional)
</string>
<string
name=
"action_sign_in"
>
Sign in or register
</string>
<string
name=
"action_sign_in_short"
>
Sign in
</string>
<string
name=
"error_invalid_email"
>
This email address is invalid
</string>
<string
name=
"error_invalid_password"
>
This password is too short
</string>
<string
name=
"error_incorrect_password"
>
This password is incorrect
</string>
<string
name=
"error_field_required"
>
This field is required
</string>
<string
name=
"permission_rationale"
>
"Contacts permissions are needed for providing email
completions."
</string>
</resources>
\ No newline at end of file
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