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
552c23ab
authored
Jan 26, 2016
by
Miguel Ángel García Cumbreras
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Integrado el nuevo sistema del PCBContext. Añadido popup de Cargando datos.
parent
60ea3ee3
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
219 additions
and
305 deletions
android/Pictogrammar/app/build.gradle
android/Pictogrammar/app/src/main/java/com/yottacode/net/RestapiWrapper.java
android/Pictogrammar/app/src/main/java/com/yottacode/net/iRestapiListener.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/action/ActionLog.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/grammar/Vocabulary.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/gui/LoginActivity.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/gui/PictogramActivity.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/gui/SerialActivity.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/gui/StudentFragmentGrid.java
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/net/NetService.java
android/Pictogrammar/app/src/main/res/layout/activity_login.xml
android/Pictogrammar/app/src/main/res/layout/activity_pictogram.xml
android/Pictogrammar/app/src/main/res/values-en/strings.xml
android/Pictogrammar/app/src/main/res/values-es/strings.xml
android/Pictogrammar/app/build.gradle
View file @
552c23ab
...
...
@@ -21,7 +21,7 @@ android {
resValue
"bool"
,
"force_img_download"
,
"false"
resValue
"integer"
,
"netservice_timing"
,
"20"
resValue
"integer"
,
"rows"
,
"5"
resValue
"integer"
,
"columns"
,
"
10
"
resValue
"integer"
,
"columns"
,
"
8
"
}
debug
{
...
...
@@ -31,7 +31,7 @@ android {
resValue
"bool"
,
"force_img_download"
,
"false"
resValue
"integer"
,
"netservice_timing"
,
"20"
resValue
"integer"
,
"rows"
,
"5"
resValue
"integer"
,
"columns"
,
"
10
"
resValue
"integer"
,
"columns"
,
"
8
"
}
}
productFlavors
{
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/net/RestapiWrapper.java
View file @
552c23ab
...
...
@@ -32,6 +32,11 @@ package com.yottacode.net;
*
* @author dofer
*/
/**
* Modificado por: magc
* LastUpdate: 22 de enero de 2016
*/
public
class
RestapiWrapper
{
String
server
;
String
token
;
...
...
@@ -53,6 +58,8 @@ public class RestapiWrapper {
}
public
void
ask
(
String
operation
,
Hashtable
<
String
,
String
>
params
,
String
postOrGet
,
iRestapiListener
listener
)
{
// call preExecute listener to show loading window
listener
.
preExecute
();
// call AsynTask to perform network operation on separate thread
if
(
this
.
token
!=
null
)
{
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/net/iRestapiListener.java
View file @
552c23ab
...
...
@@ -12,6 +12,7 @@ import org.json.JSONObject;
* @author dofer
*/
public
interface
iRestapiListener
{
public
void
preExecute
();
public
void
result
(
JSONArray
result
);
public
void
result
(
JSONObject
result
);
public
void
error
(
Exception
e
);
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/action/ActionLog.java
View file @
552c23ab
...
...
@@ -61,6 +61,11 @@ public class ActionLog implements iRestapiListener {
}
@Override
public
void
preExecute
()
{
}
@Override
public
void
result
(
JSONArray
result
)
{
}
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/grammar/Vocabulary.java
View file @
552c23ab
...
...
@@ -134,12 +134,17 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
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
(
"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
preExecute
()
{
}
@Override
public
void
result
(
JSONArray
result
)
{
}
...
...
@@ -291,6 +296,11 @@ public class Vocabulary implements Iterable<Picto>, iRestapiListener, iVocabular
}
@Override
public
void
preExecute
()
{
}
@Override
public
void
result
(
JSONArray
result
)
{
if
(
result
!=
null
)
{
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/gui/LoginActivity.java
View file @
552c23ab
...
...
@@ -3,6 +3,7 @@ package com.yottacode.pictogram.gui;
import
android.annotation.TargetApi
;
import
android.app.AlertDialog
;
import
android.app.FragmentTransaction
;
import
android.app.ProgressDialog
;
import
android.app.admin.DevicePolicyManager
;
import
android.content.ComponentName
;
import
android.content.Context
;
...
...
@@ -43,14 +44,23 @@ import java.util.Vector;
public
class
LoginActivity
extends
FragmentActivity
implements
iRestapiListener
,
iImgDownloaderListener
{
private
static
final
String
TAG_STUDENT
=
"student"
;
private
static
final
String
TAG_ID
=
"id"
;
private
static
final
String
TAG_NAME
=
"name"
;
private
static
final
String
TAG_SURNAME
=
"surname"
;
private
static
final
String
TAG_GENDER
=
"gender"
;
private
static
final
String
TAG_PIC
=
"pic"
;
private
static
final
String
TAG_LANG
=
"lang"
;
private
static
final
String
TAG_ATTRIBUTES
=
"attributes"
;
private
static
final
String
TAG_SUPERVISOR
=
"supervisor"
;
private
int
sup_id
;
// String constant for logs
private
final
String
LOG_TAG
=
this
.
getClass
().
getSimpleName
();
// Or .getCanonicalName()
//PCBcontext pcb;
//A ProgressDialog object
private
ProgressDialog
progressDialog
;
private
String
token
=
null
;
/**
* If there is Internet connection it calls the WS to recover the pairs student-supervisor
...
...
@@ -91,15 +101,11 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
//startLockTask();
// FIN del modo Kiosko
// Singleton getInstance
//pcb = PCBcontext.getInstance();
//NetService service= PCBcontext.getNetService();
// Llamo al WS para coger los usuarios y los supervisores de este dispositivo
SSLDummyContext
.
init
(
getResources
().
getBoolean
(
R
.
bool
.
ssl_connect
));
PCBcontext
.
init
(
this
);
// Compruebo si tengo acceso a internet
//if (!PCBcontext.getRestapiWrapper().ping("/server/ping", this)) {
// Compruebo si tengo acceso a internet
if
(!
RestapiWrapper
.
ping
(
getResources
().
getString
(
R
.
string
.
server
),
"server/ping"
,
this
))
{
// No puedo comprobar si el serial es válido. Muestro un alertdialog de error, y cierro la aplicación
AlertDialog
alertDialog
=
new
AlertDialog
.
Builder
(
...
...
@@ -114,19 +120,16 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
});
alertDialog
.
show
();
}
else
{
// QUITAR LUEGO !!!!
// Esto lo hago porque la reinstalar la app cada vez que lo pruebo, borra la bbdd y no deja guardados los datos de deviceID y token
//PCBcontext.getDevice().setDeviceID("85");
//PCBcontext.getDevice().setToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkZXNjIjoiU00tVDMzMCIsImlkIjoxNzYsImlkRmlybXdhcmUiOiJwcnVlYmFfMTIzNSIsImlhdCI6MTQ0NDM5MDQ5M30.SRJSMWxdenCwecsHIshqh4QEYqFCytI_aHajeVHTT20");
// NUEVO
sup_id
=
getIntent
().
getExtras
().
getInt
(
"sup_id"
);
token
=
getIntent
().
getExtras
().
getString
(
"token"
);
//String deviceID = PCBcontext.getDevice().getDeviceID();
RestapiWrapper
wrapper
=
new
RestapiWrapper
(
getApplicationContext
().
getResources
().
getString
(
R
.
string
.
server
),
token
);
String
operation
=
"sup/"
+
sup_id
+
"/students"
;
// SEGUIR
RestapiWrapper
wrapper
=
PCBcontext
.
getRestapiWrapper
();
//String operation = "/dev/" + deviceID + "/users";
String
operation
=
""
;
// SEGUIR
Log
.
d
(
"LoginActivity onCreate"
,
"operation:"
+
operation
);
Log
.
d
(
LOG_TAG
,
"operation:"
+
operation
);
//Este método es el que lanza la peticion asincrona
wrapper
.
ask
(
operation
,
this
);
...
...
@@ -141,10 +144,16 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
}
@Override
public
void
preExecute
(){
progressDialog
=
ProgressDialog
.
show
(
LoginActivity
.
this
,
"Cargando..."
,
"Cargando datos de los alumnos, espere por favor..."
,
false
,
false
);
}
@Override
public
void
result
(
JSONArray
students_supervisors
)
{
//FERNANDO
try
{
// Saco los pares estudiante-supervisor
Log
.
d
(
"LoginActivity:result"
,
"students_supervisors size:"
+
students_supervisors
.
length
());
Log
.
d
(
LOG_TAG
,
"students_supervisors size:"
+
students_supervisors
.
length
());
// looping through All Students
Vector
<
User
>
users
=
new
Vector
<
User
>(
students_supervisors
.
length
());
...
...
@@ -165,52 +174,53 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
alert
.
show
();
}
User
student
=
null
;
for
(
int
i
=
0
;
i
<
students_supervisors
.
length
();
i
++)
{
//Log.e("onPostExecute", "i vale:" + i);
JSONObject
st
=
students_supervisors
.
getJSONObject
(
i
);
/*
JSONObject student = st.getJSONObject(TAG_STUDENT);
Integer st_id = student.getInt(TAG_ID);
String st_name = student.getString(TAG_NAME);
String st_surname = student.getString(TAG_SURNAME);
String st_pic = student.getString(TAG_PIC);
String st_gender = student.getString(TAG_GENDER);
String st_lang = student.getString(TAG_LANG);
st_lang = "es-es";
String st_attributes = student.getString(TAG_ATTRIBUTES);
Log.d("LoginActivity:result", "student pic:" + st_pic);
// ESTA PARTE DE SUPERVISORES SE PUEDE ELIMINAR
JSONObject supervisor = st.getJSONObject(TAG_SUPERVISOR);
Integer su_id = supervisor.getInt(TAG_ID);
String su_name = supervisor.getString(TAG_NAME);
String su_surname = supervisor.getString(TAG_SURNAME);
String su_pic = supervisor.getString(TAG_PIC);
String su_gender = supervisor.getString(TAG_GENDER);
String su_lang = supervisor.getString(TAG_LANG);
//if (su_lang.equals("es"))
su_lang = "es-es"; // QUITAR Y DESCOMENTAR LO ANTERIOR
String su_tts_engine_sup = supervisor.getString(TAG_TTSENGINE);
Integer
st_id
=
st
.
getInt
(
TAG_ID
);
String
st_name
=
st
.
getString
(
TAG_NAME
);
String
st_surname
=
st
.
getString
(
TAG_SURNAME
);
String
st_pic
=
st
.
getString
(
TAG_PIC
);
String
st_gender
=
st
.
getString
(
TAG_GENDER
);
String
st_lang
=
st
.
getString
(
TAG_LANG
);
//st_lang = "es-es";
String
st_attributes
=
st
.
getString
(
TAG_ATTRIBUTES
);
//Log.d(LOG_TAG, "student pic:" + st_pic);
// Añado un par <student-supervisor>
int
st_id_int
=
st_id
.
intValue
();
int su_id_int = su_id.intValue();
// NOTA !!!! Esta parte se puede optimizar porque sólo debe salir un supervisor a partir del registro
student
=
new
User
(
st_id_int
,
st_name
,
st_surname
,
st_pic
,
st_gender
,
st_lang
,
st_attributes
,
sup_id
,
""
,
""
,
""
,
"M"
,
"es-es"
,
""
);
users
.
add
(
student
);
}
users.add(new User(st_id_int, st_name, st_surname, st_pic, st_gender, st_lang, st_attributes,
su_id_int, su_name, su_surname, su_pic, su_gender, su_lang, su_tts_engine_sup));
*/
// Si sólo hay 1 estudiante, cargo el st_id
if
(
students_supervisors
.
length
()
==
1
){
//User student = PCBcontext.getDevice().findUser(st_id_int, sup_id);
PCBcontext
.
set_user
(
student
,
token
,
this
);
}
else
{
student
=
new
User
(-
1
,
""
,
""
,
""
,
"M"
,
"es-es"
,
""
,
sup_id
,
""
,
""
,
""
,
"M"
,
"es-es"
,
""
);
PCBcontext
.
set_user
(
student
,
token
,
this
);
}
//Device device = new Device(getApplicationContext(), null, 1);
if
(
students_supervisors
.
length
()
>
0
){
if
(
users
.
size
()
>
0
){
PCBcontext
.
getDevice
().
synchronizeUsers
(
users
,
this
);
PCBcontext
.
getDevice
().
deleteDeprecatedImgs
();
// Si sólo hay 1 estudiante paso a Pictogram
if
(
users
.
size
()
==
1
){
//close the progress dialog
progressDialog
.
dismiss
();
Intent
pictogramActivity
=
new
Intent
(
this
,
PictogramActivity
.
class
);
startActivity
(
pictogramActivity
);
}
}
else
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
...
...
@@ -236,7 +246,6 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
@Override
public
void
result
(
JSONObject
result
)
{
}
@Override
...
...
@@ -248,19 +257,10 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
Vector
<
User
>
users
=
PCBcontext
.
getDevice
().
getUsers
();
if
(
users
.
size
()>
1
){
setContentView
(
R
.
layout
.
activity_login
);
}
else
{
// SEGUIR. Sólo tengo 1 usuario, así que no hace falta que cargue Login
//close the progress dialog
progressDialog
.
dismiss
();
PCBcontext
.
getDevice
().
setLastStuId
(
users
.
elementAt
(
0
).
get_id_stu
());
// Si tiene SupID se saca del registro
//PCBcontext.getDevice().setSupId(-1);
//Log.d(LOG_TAG, "SET id_alumno:" + students_ids.elementAt(pos) + " /id_supervisor:-1");
Intent
pictogramActivity
=
new
Intent
(
this
,
PictogramActivity
.
class
);
startActivity
(
pictogramActivity
);
setContentView
(
R
.
layout
.
activity_login
);
}
}
catch
(
NullPointerException
e
){
e
.
printStackTrace
();
...
...
@@ -275,8 +275,17 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener,
@Override
public
void
loadImg
(
Img
img
)
{
Log
.
d
(
LOG_TAG
,
"Load a single image with ID: "
+
img
.
get_id
());
// Aquí filtro si sólo tiene un único usuario o varios
Vector
<
User
>
users
=
null
;
try
{
users
=
PCBcontext
.
getDevice
().
getUsers
();
if
(
users
.
size
()>
1
){
setContentView
(
R
.
layout
.
activity_login
);
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/gui/PictogramActivity.java
View file @
552c23ab
...
...
@@ -58,21 +58,16 @@ import java.util.Locale;
import
android.provider.Settings.Secure
;
public
class
PictogramActivity
extends
Activity
implements
iVocabularyListener
,
iImgDownloaderListener
,
TextToSpeech
.
OnInitListener
{
public
class
PictogramActivity
extends
Activity
implements
iVocabularyListener
,
TextToSpeech
.
OnInitListener
{
PanelAdapter
panelAdapter
;
TapeAdapter
tapeAdapter
;
//PCBDBHelper pcbdb;
//Device device;
//Room room;
Vocabulary
vocabulary
;
User
student
;
Context
context
;
//PCBcontext pcb;
Picto
actualCategory
;
TextToSpeech
tts
;
...
...
@@ -98,31 +93,32 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
Log
.
d
(
LOG_TAG
,
"1) Opening PCB"
);
SSLDummyContext
.
init
(
getResources
().
getBoolean
(
R
.
bool
.
ssl_connect
));
PCBcontext
.
init
(
this
);
Log
.
d
(
LOG_TAG
,
"PCBcontext iniciado"
);
// Redundante, pero lo hago para forzarlo
/*
student = PCBcontext.getPcbdb().getCurrentUser();
String jsonToken = PCBcontext.getRestapiWrapper().getToken();
Log.d(LOG_TAG, "student name:" + student.get_name_stu());
PCBcontext.set_user(student,jsonToken, this);
*/
// Cargo los datos del alumno y el supervisor seleccionado
//Log.d(LOG_TAG, "student name:" + student.get_name_stu());
// Create user. QUITAR cuando cargue bien el student con find_user
//student = new User(73, "Alumno", "Con Pictogramas", "http://www4.ujaen.es/~dofer/pictures/student/rosa.jpg", "M", "es-es", "");
// QUITAR cuando esté funcionando, porque debe coger de antes estos valores
//PCBcontext.getDevice().setToken("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJkZXNjIjoiTlZpZGlhIFNoaWVsZCIsImlkIjoxNjUsImlkRmlybXdhcmUiOiJBTkRST0lEXzMyIiwiaWF0IjoxNDQyOTAzMzY3fQ.m-jbcEBQceWLZKda6fKMow_dg_fAwK9Nys00QA-gNwY");
//PCBcontext.getDevice().setSerial("serial1");
//PCBcontext.getDevice().setDeviceID("deviceID");
//Log.d(LOG_TAG, "2) OnCreate - Serial:" + pcb.getDevice().getSerial() + " dev. id:" + pcb.getDevice().getDeviceID() + " token:" + pcb.getDevice().getToken());
// Init PCB DB
// 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
());
LinkedList
<
Picto
>
ll
;
if
(
actualCategory
!=
null
)
ll
=
order
(
vocabulary
.
next
(
actualCategory
));
else
ll
=
order
(
vocabulary
.
startSentence
());
panelAdapter
.
clear
();
panelAdapter
.
addAll
(
ll
);
}
// Open websocket connection
vocabulary
.
listen
(
PCBcontext
.
getRoom
(),
this
);
// Connect the views
final
GridView
tapeGridView
=
(
GridView
)
findViewById
(
R
.
id
.
tape_grid_view
);
// Cojo el tamaño de la pantalla para poner el ancho dinámico
...
...
@@ -144,8 +140,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
if
(
pictogramSize
==
0
)
panelGridView
.
setNumColumns
(
10
);
else
if
(
pictogramSize
==
1
)
panelGridView
.
setNumColumns
(
4
);
// Adapter for grid
panelAdapter
=
new
PanelAdapter
(
new
LinkedList
<
Picto
>());
panelGridView
.
setAdapter
(
panelAdapter
);
// Adapter for tape
...
...
@@ -377,7 +371,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
/**
* Load pictos. Asociado a botón provisional para cargar el vocabulario en el adapter
* @param v
* BORRAR. Ya funciona la carga asíncrona del vocabulario
*/
public
void
load_pictos
(
View
v
)
{
if
(
vocabulary
!=
null
)
...
...
@@ -397,26 +390,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
}
/**
* Go back. Asociado al botón "volver" carga los pictos anteriores al actual del vocabulario
* @param v
* TODO ¿Quitar? ¿O asociar a otro evento?
*/
public
void
go_back
(
View
v
)
{
try
{
actualCategory
=
null
;
LinkedList
<
Picto
>
ll
=
order
(
vocabulary
.
startSentence
());
panelAdapter
.
clear
();
panelAdapter
.
addAll
(
ll
);
}
catch
(
NullPointerException
e
){
Log
.
d
(
LOG_TAG
,
"El vocabulario todavía no se ha cargado"
);
}
}
/**
* Order a linked list of pictos with "blank spaces" between them
* @param list
* @return
...
...
@@ -527,31 +500,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
}
}
// De la interfaz iImgDownloaderListener
@Override
public
void
loadComplete
()
{
Log
.
d
(
LOG_TAG
,
"Load images complete"
);
try
{
vocabulary
=
PCBcontext
.
getVocabulary
();
LinkedList
<
Picto
>
ll
;
if
(
actualCategory
!=
null
)
ll
=
order
(
vocabulary
.
next
(
actualCategory
));
else
ll
=
order
(
vocabulary
.
startSentence
());
panelAdapter
.
clear
();
panelAdapter
.
addAll
(
ll
);
}
catch
(
NullPointerException
e
){
Log
.
d
(
LOG_TAG
,
"El vocabulario todavía no se ha cargado"
);
}
}
// De la interfaz iImgDownloaderListener
@Override
public
void
loadImg
(
Img
img
)
{
Log
.
d
(
LOG_TAG
,
"Load a single image with ID: "
+
img
.
get_id
());
}
// Disable Back Button --> Kiosk mode
@Override
public
void
onBackPressed
()
{
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/gui/SerialActivity.java
View file @
552c23ab
...
...
@@ -2,6 +2,7 @@ package com.yottacode.pictogram.gui;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.app.ProgressDialog
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
...
...
@@ -61,13 +62,10 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
Context
context
;
//String s_serial = new String();
//String _ANDROIDID = new String();
private
static
final
String
TAG_USER
=
"user"
;
private
static
final
String
TAG_ISSTUDENT
=
"isStudent"
;
private
static
final
String
TAG_TOKEN
=
"token"
;
private
static
final
String
TAG_ID
=
"id"
;
private
static
final
String
TAG_USERNAME
=
"username"
;
private
static
final
String
TAG_NAME
=
"name"
;
private
static
final
String
TAG_SURNAME
=
"surname"
;
private
static
final
String
TAG_GENDER
=
"gender"
;
...
...
@@ -76,11 +74,16 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
private
static
final
String
TAG_ATTRIBUTES
=
"attributes"
;
//private static final String TAG_TTSENGINE = "ttsEngine";
Integer
st_id
=-
1
,
su
_id
=-
1
;
private
Integer
st
_id
=-
1
;
// String constant for logs
private
final
String
LOG_TAG
=
this
.
getClass
().
getSimpleName
();
// Or .getCanonicalName()
private
String
username
=
null
;
//A ProgressDialog object
private
ProgressDialog
progressDialog
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -123,31 +126,20 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
mEntrarButton
.
setOnClickListener
(
new
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
// No necesita token
//String token = "0";
/* QUITAR
String username = mSerialViewMail.getText().toString();
username
=
mSerialViewMail
.
getText
().
toString
();
String
password
=
mSerialViewPass
.
getText
().
toString
();
*/
// DE PRUEBA
/
*
String
username = "faf0001";
String
password = "faf0001";
*/
String
username
=
"dofer@ujaen.es"
;
String
password
=
"dofer"
;
/
/ Alumno
//
username = "faf0001";
//
password = "faf0001";
// Supervisor
username
=
"dofer@ujaen.es"
;
password
=
"dofer"
;
RestapiWrapper
wrapper
=
PCBcontext
.
getRestapiWrapper
();
//String serial = mSerialView.getText().toString();
//String serial = "0yhHcxMUcm"; // QUITAR
if
(
username
.
contains
(
"@"
)){
// Es un supervisor
String
operation
=
"sup/login"
;
//s_serial = serial;
//String _ANDROIDID = Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);
//SecureRandom random = new SecureRandom();
//Log.d("SerialActivity onCreate", "ANDROID ID:" + _ANDROIDID);
//String _MODEL = android.os.Build.MODEL;
Hashtable
<
String
,
String
>
postDataParams
=
new
Hashtable
<
String
,
String
>();
postDataParams
.
put
(
"email"
,
username
);
...
...
@@ -161,11 +153,6 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
}
else
{
// Es un estudiante
String
operation
=
"stu/login"
;
//s_serial = serial;
//String _ANDROIDID = Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);
//SecureRandom random = new SecureRandom();
//Log.d("SerialActivity onCreate", "ANDROID ID:" + _ANDROIDID);
//String _MODEL = android.os.Build.MODEL;
Hashtable
<
String
,
String
>
postDataParams
=
new
Hashtable
<
String
,
String
>();
postDataParams
.
put
(
"username"
,
username
);
...
...
@@ -179,45 +166,14 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
}
}
});
/*
Button mOmitirButton = (Button) findViewById(R.id.omitir_button);
mOmitirButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// Al pulsar aquí no es un tablet Yotta y no se registra como tal. Muestro una ventana informativa con el ANDROID ID
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
builder.setMessage(getString(R.string.tabletNoYotta) + ": " + _ANDROIDID)
.setCancelable(false)
.setPositiveButton("Entendido", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//do things
// No necesita token
String token = "0";
RestapiWrapper wrapper = new RestapiWrapper(
getApplicationContext().getResources().getString(R.string.server),token);
String serial = "";
s_serial = serial;
String operation = "/dev/register";
//String _ANDROIDID = Settings.Secure.getString(getContentResolver(),Settings.Secure.ANDROID_ID);
//SecureRandom random = new SecureRandom();
Log.d("SerialActivity onCreate", "ANDROID ID:" + _ANDROIDID);
String _MODEL = android.os.Build.MODEL;
Hashtable<String, String> postDataParams = new Hashtable<String, String>();
postDataParams.put("idFirmware", _ANDROIDID);
postDataParams.put("desc", _MODEL);
postDataParams.put("serial", serial);
wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context);
}
});
AlertDialog alert = builder.create();
alert.show();
}
});
*/
@Override
public
void
preExecute
(){
if
(!
username
.
contains
(
"@"
)){
progressDialog
=
ProgressDialog
.
show
(
SerialActivity
.
this
,
"Cargando..."
,
"Cargando datos, espere por favor..."
,
false
,
false
);
}
}
...
...
@@ -236,6 +192,11 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
String
jsonToken
=
result
.
getString
(
TAG_TOKEN
);
JSONObject
user
=
result
.
getJSONObject
(
TAG_USER
);
try
{
Boolean
is_student
=
user
.
has
(
TAG_ISSTUDENT
);
if
(
is_student
)
{
// Es un estudiante
st_id
=
user
.
getInt
(
TAG_ID
);
int
st_id_int
=
st_id
.
intValue
();
String
st_name
=
user
.
getString
(
TAG_NAME
);
...
...
@@ -243,27 +204,38 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
String
st_pic
=
user
.
getString
(
TAG_PIC
);
String
st_gender
=
user
.
getString
(
TAG_GENDER
);
String
st_lang
=
user
.
getString
(
TAG_LANG
);
//String st_attributes = user.getString(TAG_ATTRIBUTES);
String
st_attributes
=
""
;
// COMPROBAR CONSTRAINT PORQUE FALLA
String
st_attributes
=
user
.
getString
(
TAG_ATTRIBUTES
);
users
.
add
(
new
User
(
st_id_int
,
st_name
,
st_surname
,
st_pic
,
st_gender
,
st_lang
,
st_attributes
,
-
1
,
""
,
""
,
""
,
"M"
,
"es-es"
,
""
));
Log
.
d
(
LOG_TAG
,
"jsonToken válido:"
+
jsonToken
);
User
student
=
PCBcontext
.
getDevice
().
findUser
(
st_id
,
-
1
);
PCBcontext
.
set_user
(
student
,
jsonToken
,
null
);
PCBcontext
.
getDevice
().
synchronizeUsers
(
users
,
this
);
PCBcontext
.
getDevice
().
deleteDeprecatedImgs
();
//JSONObject jDevice = result.getJSONObject("device");
//Object jsonId = jDevice.get("id");
//String jsonIdString = jsonId.toString();
}
else
{
// Es un Supervisor
Log
.
d
(
LOG_TAG
,
"Es un SUPERVISOR. Sigo..."
);
Log
.
d
(
LOG_TAG
,
"jsonToken válido:"
+
jsonToken
);
//Log.d(LOG_TAG, "jsonIdString:" + jsonIdString);
// Guardo el deviceID, token y serial en la bbdd
//PCBcontext.getDevice().setDeviceID(jsonIdString);
User
student
=
PCBcontext
.
getDevice
().
findUser
(
st_id
,
su_id
);
PCBcontext
.
set_user
(
student
,
jsonToken
,
this
);
Integer
su_id
=
user
.
getInt
(
TAG_ID
);
int
su_id_int
=
su_id
.
intValue
();
//close the progress dialog
if
(!
username
.
contains
(
"@"
)){
progressDialog
.
dismiss
();
}
// Llamo a LoginActivity
Intent
loginActivity
=
new
Intent
(
this
,
LoginActivity
.
class
);
loginActivity
.
putExtra
(
"token"
,
jsonToken
);
loginActivity
.
putExtra
(
"sup_id"
,
su_id_int
);
startActivity
(
loginActivity
);
}
}
catch
(
JSONException
ex
){
ex
.
printStackTrace
();
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
...
...
@@ -276,7 +248,7 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
Log
.
e
(
this
.
getClass
().
getName
(),
" Server restapi error: "
+
e
.
getLocalizedMessage
());
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
SerialActivity
.
this
);
builder
.
setMessage
(
getString
(
R
.
string
.
ser
ialRepeated
)+
":"
+
e
.
getLocalizedMessage
())
builder
.
setMessage
(
getString
(
R
.
string
.
ser
verError
)+
":"
+
e
.
getLocalizedMessage
())
.
setCancelable
(
false
)
.
setPositiveButton
(
"Entendido"
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
...
...
@@ -290,7 +262,9 @@ public class SerialActivity extends Activity implements iRestapiListener, iImgDo
@Override
public
void
loadComplete
()
{
Log
.
d
(
LOG_TAG
,
"Load images complete"
);
//close the progress dialog
progressDialog
.
dismiss
();
// Entro directamente a Pictogram con ese alumno
Intent
pictogramActivity
=
new
Intent
(
this
,
PictogramActivity
.
class
);
startActivity
(
pictogramActivity
);
}
...
...
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/gui/StudentFragmentGrid.java
View file @
552c23ab
...
...
@@ -11,9 +11,11 @@ import java.util.Vector;
import
android.app.Fragment
;
import
android.app.FragmentTransaction
;
import
android.app.ProgressDialog
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
...
...
@@ -23,6 +25,9 @@ import android.widget.Toast;
import
com.yottacode.pictogram.R
;
import
com.yottacode.pictogram.dao.User
;
import
com.yottacode.pictogram.grammar.Vocabulary
;
import
com.yottacode.pictogram.net.iImgDownloaderListener
;
import
com.yottacode.pictogram.tools.Img
;
import
com.yottacode.pictogram.tools.PCBcontext
;
import
org.json.JSONException
;
...
...
@@ -42,7 +47,7 @@ public class StudentFragmentGrid extends Fragment{
Map<String, Bitmap> map_supervisor_pictures = new TreeMap<String, Bitmap>();
Vector<Bitmap> imageStudents = new Vector<Bitmap>();
*/
Boolean
modoSupervisor
;
//
Boolean modoSupervisor;
// NEW
Map
<
Integer
,
Vector
<
Integer
>>
ids_stu_sup
=
new
TreeMap
<
Integer
,
Vector
<
Integer
>>();
...
...
@@ -54,26 +59,19 @@ public class StudentFragmentGrid extends Fragment{
// String constant for logs
private
final
String
LOG_TAG
=
this
.
getClass
().
getSimpleName
();
// Or .getCanonicalName()
//A ProgressDialog object
private
ProgressDialog
progressDialog
;
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setRetainInstance
(
true
);
// Singleton getInstance
//pcb = PCBcontext.getInstance();
/*
Set<String> s_students;
List<String> l_supervisors = new ArrayList<String>();
students_ids = new Vector<Integer>();
supervisor_ids = new Vector<Integer>();
*/
modoSupervisor
=
false
;
try
{
// Cargo los datos de los estudiantes
Vector
<
User
>
users
=
PCBcontext
.
getDevice
().
getUsers
();
if
(
users
!=
null
){
Log
.
d
(
LOG_TAG
,
"Cargo "
+
users
.
size
()
+
" alumnos"
);
// Recorro el vector para sacar los nombres de estudiantes y las imágenes
for
(
int
i
=
0
;
i
<
users
.
size
()
;
i
++
){
int
st_id
=
users
.
elementAt
(
i
).
get_id_stu
();
...
...
@@ -91,40 +89,7 @@ public class StudentFragmentGrid extends Fragment{
ids_stu_sup
.
put
(
st_id
,
sups
);
}
}
/*
String st_name = users.elementAt(i).get_name_stu();
String st_surname = users.elementAt(i).get_surname_stu();
Bitmap st_picture = users.elementAt(i).get_bitmap_stu(getActivity());
String su_name = users.elementAt(i).get_name_sup();
String su_surname = users.elementAt(i).get_surname_sup();
Bitmap su_picture = users.elementAt(i).get_bitmap_sup(getActivity());
if (!map_students.containsKey(st_name + " " + st_surname)){
// Creo un nuevo supervisor y lo añado
if (su_id!=-1){
l_supervisors = new ArrayList<String>();
l_supervisors.add(su_name + " " + su_surname);
map_supervisor_pictures.put(su_name + " " + su_surname, su_picture);
supervisor_ids.add(su_id);
}
imageStudents.add(st_picture);
map_students.put(st_name + " " + st_surname, l_supervisors);
students_ids.add(st_id);
} else{
// Saco los supervisores, añado uno más y grabo
if (su_id!=-1){
l_supervisors = map_students.get(st_name + " " + st_surname);
l_supervisors.add(su_name + " " + su_surname);
supervisor_ids.add(su_id);
}
map_students.put(st_name + " " + st_surname, l_supervisors);
}
*/
}
// Saco los estudiantes
/*
s_students = map_students.keySet();
students = s_students.toArray(new String[s_students.size()]);
*/
}
else
{
// TRATO EL ERROR. COMO ?????
}
...
...
@@ -144,11 +109,12 @@ public class StudentFragmentGrid extends Fragment{
try
{
List
<
String
>
l_students_name
=
new
ArrayList
<
String
>();
Vector
<
Bitmap
>
imageStudents
=
new
Vector
<
Bitmap
>();
int
id_sup
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_id_sup
();
students_ids
=
new
Vector
<
Integer
>();
for
(
Map
.
Entry
<
Integer
,
Vector
<
Integer
>>
entry
:
ids_stu_sup
.
entrySet
())
{
Integer
id_stu
=
entry
.
getKey
();
students_ids
.
add
(
id_stu
);
User
currentUser
=
PCBcontext
.
getDevice
().
findUser
(
id_stu
,
-
1
);
User
currentUser
=
PCBcontext
.
getDevice
().
findUser
(
id_stu
,
id_sup
);
String
st_name
=
currentUser
.
get_name_stu
();
Bitmap
st_picture
=
currentUser
.
get_bitmap_stu
(
getActivity
());
l_students_name
.
add
(
st_name
);
...
...
@@ -161,30 +127,33 @@ public class StudentFragmentGrid extends Fragment{
@Override
public
void
onItemClick
(
AdapterView
<?>
arg0
,
View
arg1
,
int
pos
,
long
arg3
)
{
//Log.d("onitemclick", " " + pos + " pulsado");
/*
if (modoSupervisor){
// Llamo al fragment de Supervisores para cargarlos en la misma ventana
Toast.makeText(getActivity().getBaseContext(), "Modo Supervisor activado", Toast.LENGTH_SHORT).show();
PCBcontext.getDevice().setStuId(students_ids.elementAt(pos));
// Llamo al fragment de los supervisores para cargar sus datos
SupervisorFragmentGrid supervisores = (SupervisorFragmentGrid)getFragmentManager().findFragmentById(R.id.supervisores);
// Cojo el nombre y apellidos de ese estudiante
//String name_surname_st = students[pos];
supervisores.change(ids_stu_sup, pos);
} else{
*/
// Entro en pictogram con ese valor de alumno y con supervisor a null
Toast
.
makeText
(
getActivity
().
getBaseContext
(),
"Modo Supervisor desactivado"
,
Toast
.
LENGTH_SHORT
).
show
();
PCBcontext
.
getDevice
().
setLastStuId
(
students_ids
.
elementAt
(
pos
));
PCBcontext
.
getDevice
().
setLastSupId
(-
1
);
int
id_sup
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_id_sup
();
User
student
=
null
;
try
{
student
=
PCBcontext
.
getDevice
().
findUser
(
students_ids
.
elementAt
(
pos
),
id_sup
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
String
jsonToken
=
PCBcontext
.
getRestapiWrapper
().
getToken
();
//Log.d(LOG_TAG, "SET id_alumno:" + students_ids.elementAt(pos) + " /id_supervisor:-1");
progressDialog
=
ProgressDialog
.
show
(
getActivity
(),
"Cargando..."
,
"Cargando datos del alumno seleccionado, espere por favor..."
,
false
,
false
);
PCBcontext
.
set_user
(
student
,
jsonToken
,
new
iImgDownloaderListener
()
{
@Override
public
void
loadComplete
()
{
//Vocabulary vocabulary = PCBcontext.getVocabulary();
//Log.d(LOG_TAG, "Vocabulario de tam:" + vocabulary.size());
progressDialog
.
dismiss
();
Intent
pictogramActivity
=
new
Intent
(
getActivity
(),
PictogramActivity
.
class
);
startActivity
(
pictogramActivity
);
//}
}
@Override
public
void
loadImg
(
Img
image
)
{
}
});
}
});
}
catch
(
JSONException
e
)
{
...
...
@@ -197,20 +166,4 @@ public class StudentFragmentGrid extends Fragment{
}
return
v
;
}
/*
public void changeSupervisorMode(boolean value){
modoSupervisor = value;
Toast.makeText(getActivity().getBaseContext(), "Modo Supervisor " + value, Toast.LENGTH_SHORT).show();
SupervisorFragmentGrid supervisores = (SupervisorFragmentGrid)getFragmentManager().findFragmentById(R.id.supervisores);
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
if (supervisores.isHidden()) {
ft.show(supervisores);
} else {
ft.hide(supervisores);
}
ft.commit();
}
*/
}
android/Pictogrammar/app/src/main/java/com/yottacode/pictogram/net/NetService.java
View file @
552c23ab
...
...
@@ -51,6 +51,11 @@ public class NetService implements Runnable, iRestapiListener {
}
@Override
public
void
preExecute
()
{
}
@Override
public
void
result
(
JSONArray
result
)
{
}
...
...
android/Pictogrammar/app/src/main/res/layout/activity_login.xml
View file @
552c23ab
...
...
@@ -18,7 +18,7 @@
<fragment
android:layout_width=
"fill_parent"
android:layout_height=
"
3
00px"
android:layout_height=
"
6
00px"
class=
"com.yottacode.pictogram.gui.StudentFragmentGrid"
android:id=
"@+id/alumnos"
android:layout_below=
"@+id/logintitle"
/>
...
...
android/Pictogrammar/app/src/main/res/layout/activity_pictogram.xml
View file @
552c23ab
...
...
@@ -15,7 +15,7 @@
<GridView
android:id=
"@+id/tape_grid_view"
android:layout_width=
"
8
60dp"
android:layout_width=
"
5
60dp"
android:layout_height=
"85dp"
android:gravity=
"center"
android:numColumns=
"@integer/columns"
...
...
@@ -44,8 +44,8 @@
android:src=
"@drawable/ic_action"
android:background=
"@null"
android:id=
"@+id/button_delete"
android:layout_
below=
"@+id/button_tts
"
android:layout_
toRightOf=
"@+id/tape_grid_view
"
/>
android:layout_
toRightOf=
"@+id/tape_grid_view
"
android:layout_
alignParentTop=
"true
"
/>
<GridView
android:id=
"@+id/panel_grid_view"
...
...
android/Pictogrammar/app/src/main/res/values-en/strings.xml
View file @
552c23ab
...
...
@@ -37,5 +37,6 @@
<string
name=
"systemMessage"
>
System message
</string>
<string
name=
"noInternetConnection"
>
There is no Internet connection. Try again later
</string>
<string
name=
"exitingApp"
>
Exiting the app
</string>
<string
name=
"serverError"
>
There is a server error. Try again later
</string>
</resources>
android/Pictogrammar/app/src/main/res/values-es/strings.xml
View file @
552c23ab
...
...
@@ -41,6 +41,7 @@
<string
name=
"systemMessage"
>
Mensaje del sistema
</string>
<string
name=
"noInternetConnection"
>
No hay conexión a internet. Inténtelo más tarde
</string>
<string
name=
"exitingApp"
>
Saliendo de la aplicación
</string>
<string
name=
"serverError"
>
Error en el servidor de datos. Inténtelo más tarde
</string>
<item
type=
"integer"
name=
"maxInTape"
>
8
</item>
...
...
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