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
83d95dca
authored
Mar 30, 2016
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
working on serial/login activity refactorization (vi)
parent
ebde1051
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
183 deletions
android/Pictogram/app/src/main/java/com/yottacode/pictogram/dao/Device.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/LoginActivity.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/SerialActivity.java
android/Pictogram/app/src/main/java/com/yottacode/pictogram/dao/Device.java
View file @
83d95dca
...
...
@@ -348,31 +348,24 @@ public class Device extends SQLiteOpenHelper {
*/
public
void
synchronizeUsers
(
Vector
<
User
>
users
,
iImgDownloaderListener
imgListener
)
throws
JSONException
{
Vector
<
User
>
prev
_users
=
getUsers
();
Vector
<
User
>
current
_users
=
getUsers
();
Vector
<
Img
>
imgs
=
new
Vector
<
Img
>(
users
.
size
()
*
2
);
SQLiteDatabase
db
=
this
.
getWritableDatabase
();
for
(
User
user
:
users
)
{
if
(
prev
_users
.
contains
(
user
))
{
if
(
current
_users
.
contains
(
user
))
{
updateUser
(
user
,
db
);
prev_users
.
remove
(
user
);
}
else
insertUser
(
user
,
db
);
if
(!
imgs
.
contains
(
user
.
get_Img_stu
()))
imgs
.
add
(
user
.
get_Img_stu
());
if
(!
imgs
.
contains
(
user
.
get_Img_sup
()))
imgs
.
add
(
user
.
get_Img_sup
());
}
for
(
User
user
:
prev_users
)
db
.
delete
(
"users_detail"
,
"id_stu=? AND id_sup=?"
,
new
String
[]{
Integer
.
toString
(
user
.
get_id_stu
()),
Integer
.
toString
(
user
.
get_id_sup
())});
db
.
close
();
ImgDownloader
downloader
=
new
ImgDownloader
(
this
.
context
,
imgListener
,
ImgDownloader
.
tsource
.
remote
);
downloader
.
executeOnExecutor
(
AsyncTask
.
THREAD_POOL_EXECUTOR
,
imgs
);
db
.
close
();
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/LoginActivity.java
View file @
83d95dca
...
...
@@ -5,6 +5,7 @@ import android.app.AlertDialog;
import
android.app.ProgressDialog
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.os.AsyncTask
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.support.v4.app.FragmentActivity
;
...
...
@@ -18,6 +19,7 @@ import com.yottacode.pictogram.R;
import
com.yottacode.net.iRestapiListener
;
import
com.yottacode.net.SSLDummyContext
;
import
com.yottacode.net.RestapiWrapper
;
import
com.yottacode.pictogram.net.ImgDownloader
;
import
com.yottacode.pictogram.tools.Img
;
import
com.yottacode.pictogram.tools.PCBcontext
;
import
com.yottacode.pictogram.net.iImgDownloaderListener
;
...
...
@@ -37,7 +39,7 @@ import java.util.Vector;
* @version 1.0
*/
public
class
LoginActivity
extends
FragmentActivity
implements
iRestapiListener
{
public
class
LoginActivity
extends
FragmentActivity
{
private
static
final
String
TAG_ID
=
"id"
;
private
static
final
String
TAG_NAME
=
"name"
;
...
...
@@ -62,6 +64,9 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
private
String
username
=
null
;
private
String
password
=
null
;
private
choose_student
(
Vector
<
User
>
students
)
{
downloader
.
executeOnExecutor
(
AsyncTask
.
THREAD_POOL_EXECUTOR
,
imgs
);
}
private
void
show_login_failed
(
int
msg
)
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
LoginActivity
.
this
);
...
...
@@ -75,25 +80,7 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
alert
.
show
();
}
private
void
load_offline_supervisor
(
String
username
,
String
password
)
{
}
/**
* If there is Internet connection it calls the WS to recover the pairs student-supervisor
* @param savedInstanceState
*/
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
Intent
intent
=
getIntent
();
Boolean
offline
=
intent
.
getBooleanExtra
(
"offline"
,
false
);
if
(
offline
){
username
=
intent
.
getStringExtra
(
"username"
);
password
=
intent
.
getStringExtra
(
"password"
);
private
void
manage_offline_supervisor
(
String
username
,
String
password
)
{
try
{
Log
.
d
(
LOG_TAG
,
"username utilizado:"
+
username
);
Log
.
d
(
LOG_TAG
,
"password utilizado:"
+
password
);
...
...
@@ -102,29 +89,10 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
// Si sólo hay 1 estudiante, cargo el st_id
if
(
localUsers
.
size
()
==
1
){
PCBcontext
.
set_user
(
localUsers
.
elementAt
(
0
),
null
,
null
);
Intent
pictogramActivity
=
new
Intent
(
this
,
PictogramActivity
.
class
);
startActivity
(
pictogramActivity
);
}
else
{
User
student
=
null
;
try
{
student
=
new
User
(-
1
,
"nickname_stu"
,
"pwd_stu"
,
""
,
""
,
""
,
"M"
,
"es-es"
,
""
,
sup_id
,
"nickname_sup"
,
"pwd_sup"
,
""
,
""
,
""
,
"M"
,
"es-es"
,
""
);
PCBcontext
.
set_user
(
student
,
token
,
new
iImgDownloaderListener
()
{
@Override
public
void
loadComplete
()
{
//close the progress dialog
//progressDialog.dismiss();
//setContentView(R.layout.activity_login);
}
@Override
public
void
loadImg
(
Img
image
)
{
//close the progress dialog
//progressDialog.dismiss();
//setContentView(R.layout.activity_login);
}
});
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
getIntent
().
putExtra
(
"sup_id"
,
localUsers
.
elementAt
(
0
).
get_id_sup
());
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
...
...
@@ -133,24 +101,35 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
:
e
.
no_students
()
?
R
.
string
.
noStudentsError
:
R
.
string
.
userErrorMsg
);
}
}
else
{
}
/**
* If there is Internet connection it calls the WS to recover the pairs student-supervisor
* @param savedInstanceState
*/
@TargetApi
(
Build
.
VERSION_CODES
.
LOLLIPOP
)
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
final
Intent
intent
=
getIntent
();
Boolean
offline
=
intent
.
getBooleanExtra
(
"offline"
,
false
);
if
(
offline
)
manage_offline_supervisor
(
intent
.
getStringExtra
(
"username"
),
intent
.
getStringExtra
(
"password"
));
else
{
// Modo ONLINE
sup_id
=
getIntent
().
getExtras
().
getInt
(
"sup_id"
);
token
=
getIntent
().
getExtras
().
getString
(
"token"
);
RestapiWrapper
wrapper
=
new
RestapiWrapper
(
getApplicationContext
().
getResources
().
getString
(
R
.
string
.
server
),
token
);
String
operation
=
"sup/"
+
sup_id
+
"/students"
;
// SEGUIR
getApplicationContext
().
getResources
().
getString
(
R
.
string
.
server
),
token
);
String
operation
=
"sup/"
+
sup_id
+
"/students"
;
Log
.
d
(
LOG_TAG
,
"operation:"
+
operation
);
//Este método es el que lanza la peticion asincrona
wrapper
.
ask
(
operation
,
this
);
}
//setContentView(R.layout.activity_login);
}
wrapper
.
ask
(
operation
,
new
iRestapiListener
()
{
@Override
public
void
error
(
Exception
e
)
{
...
...
@@ -158,150 +137,82 @@ 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
);
public
void
preExecute
()
{
progressDialog
=
ProgressDialog
.
show
(
LoginActivity
.
this
,
getString
(
R
.
string
.
userLoadingTxt
)
,
getString
(
R
.
string
.
userLoadingTxt
)
,
false
,
false
);
}
@Override
public
void
result
(
JSONArray
students_supervisors
)
{
try
{
// Saco los pares estudiante-supervisor
Vector
<
User
>
users
=
new
Vector
<
User
>(
students_supervisors
.
length
());
if
(
students_supervisors
.
length
()
==
0
){
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
LoginActivity
.
this
);
builder
.
setMessage
(
getString
(
R
.
string
.
loginNoUsers
))
.
setCancelable
(
false
)
.
setPositiveButton
(
"Entendido y salir"
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
}
});
AlertDialog
alert
=
builder
.
create
();
alert
.
show
();
}
final
Vector
<
User
>
users
=
new
Vector
<>(
students_supervisors
.
length
());
Vector
<
Img
>
imgs
=
new
Vector
<>(
users
.
size
());
if
(
students_supervisors
.
length
()
==
0
)
show_login_failed
(
R
.
string
.
noStudentsError
);
User
student
=
null
;
for
(
int
i
=
0
;
i
<
students_supervisors
.
length
();
i
++)
{
//Log.e("onPostExecute", "i vale:" + i);
JSONObject
st
=
students_supervisors
.
getJSONObject
(
i
);
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
);
Integer
st_supervision
=
st
.
getInt
(
TAG_SUPERVISION
);
//Log.d(LOG_TAG, "student pic:" + st_pic);
// Añado un par <student-supervisor>
int
st_id_int
=
st_id
.
intValue
();
int
st_supervision_int
=
st_supervision
.
intValue
();
// Si es terapeuta lo añado directamente
if
(
st_supervision_int
==
2
){
student
=
new
User
(
st_id_int
,
"nickname_stu"
,
"pwd_stu"
,
st_name
,
st_surname
,
st_pic
,
st_gender
,
st_lang
,
st_attributes
,
sup_id
,
username
,
password
,
""
,
""
,
""
,
"M"
,
"es-es"
,
""
);
student
=
new
User
(
st_id_int
,
""
,
""
,
st_name
,
st_surname
,
st_pic
,
st_gender
,
st_lang
,
st_attributes
,
sup_id
,
username
,
password
,
intent
.
getStringExtra
(
"name"
),
intent
.
getStringExtra
(
"surname"
),
intent
.
getStringExtra
(
"pic"
),
intent
.
getStringExtra
(
"gender"
),
intent
.
getStringExtra
(
"lang"
),
""
);
users
.
add
(
student
);
}
}
Log
.
d
(
LOG_TAG
,
"users size:"
+
users
.
size
());
Img
img
=
new
Img
(
st_id
,
st_pic
,
Img
.
STUDENT
);
if
(!
imgs
.
contains
(
img
))
imgs
.
add
(
img
);
//it's required to download student's images
}
//for
// Si sólo hay 1 estudiante, cargo el st_id
if
(
users
.
size
()
==
1
){
//User student = PCBcontext.getDevice().findUser(st_id_int, sup_id);
PCBcontext
.
set_user
(
student
,
token
,
null
);
// no hay que hacer nada cuando termine
}
else
{
student
=
new
User
(-
1
,
"nickname_stu"
,
"pwd_stu"
,
""
,
""
,
""
,
"M"
,
"es-es"
,
""
,
sup_id
,
username
,
password
,
""
,
""
,
""
,
"M"
,
"es-es"
,
""
);
PCBcontext
.
set_user
(
student
,
token
,
new
iImgDownloaderListener
()
{
ImgDownloader
downloader
=
new
ImgDownloader
(
LoginActivity
.
this
,
new
iImgDownloaderListener
()
{
@Override
public
void
loadComplete
()
{
//close the progress dialog
//progressDialog.dismiss();
//setContentView(R.layout.activity_login);
}
@Override
public
void
loadImg
(
Img
image
)
{
//close the progress dialog
//progressDialog.dismiss();
//setContentView(R.layout.activity_login);
}
});
}
//Device device = new Device(getApplicationContext(), null, 1);
if
(
users
.
size
()
>
0
){
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"HH:mm:ss"
);
String
currentDateandTime
=
sdf
.
format
(
new
Date
());
//Log.d(LOG_TAG, "Entro en synchronizeUsers en " + currentDateandTime);
PCBcontext
.
getDevice
().
synchronizeUsers
(
users
,
new
iImgDownloaderListener
()
{
@Override
public
void
loadComplete
()
{
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"HH:mm:ss"
);
String
currentDateandTime
=
sdf
.
format
(
new
Date
());
//Log.d(LOG_TAG, "LoadComplete en " + currentDateandTime);
Vector
<
User
>
users
=
null
;
try
{
users
=
PCBcontext
.
getDevice
().
getUsers
();
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
if
(
users
.
size
()
>
1
)
{
//close the progress dialog
progressDialog
.
dismiss
();
if
(
users
.
size
()
>
1
)
setContentView
(
R
.
layout
.
activity_login
);
}
}
@Override
public
void
loadImg
(
Img
image
)
{
}
});
// Si sólo hay 1 estudiante paso a Pictogram
if
(
users
.
size
()
==
1
){
//close the progress dialog
progressDialog
.
dismiss
();
},
ImgDownloader
.
tsource
.
remote
);
downloader
.
executeOnExecutor
(
AsyncTask
.
THREAD_POOL_EXECUTOR
,
imgs
);
Intent
pictogramActivity
=
new
Intent
(
this
,
PictogramActivity
.
class
);
pictogramActivity
.
putExtra
(
"isSupervisor"
,
true
);
// Si sólo hay 1 estudiante paso a Pictogram
if
(
users
.
size
()
==
1
)
{
Intent
pictogramActivity
=
new
Intent
(
LoginActivity
.
this
,
PictogramActivity
.
class
);
startActivity
(
pictogramActivity
);
}
}
else
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setMessage
(
"No se encontraron alumnos asociados. Consulte con el administrador de su gabinete o asociación."
)
.
setTitle
(
"Información"
)
.
setPositiveButton
(
"OK"
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
dialog
.
cancel
();
}
});
builder
.
create
();
}
//Log.d("LoginActivity:result", "Serial:" + pcb.getDevice().getSerial() + " dev. id:" + pcb.getDevice().getDeviceID() + " token:" + pcb.getDevice().getToken());
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
@Override
public
void
result
(
JSONObject
result
)
{
}
@Override
protected
void
onResume
()
{
}
});
}
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
Toast
.
makeText
(
this
,
"onResume"
,
Toast
.
LENGTH_SHORT
).
show
();
}
...
...
android/Pictogram/app/src/main/java/com/yottacode/pictogram/gui/SerialActivity.java
View file @
83d95dca
...
...
@@ -57,11 +57,11 @@ public class SerialActivity extends Activity {
public
static
final
String
PREFS_NAME
=
"MyPrefsFile"
;
private
void
manageSupervisorLogin
(
String
username
,
String
password
,
boolean
online
)
{
private
void
manageSupervisorLogin
(
final
String
username
,
final
String
password
,
boolean
online
)
{
final
Intent
loginActivity
=
new
Intent
(
SerialActivity
.
this
,
LoginActivity
.
class
);
if
(
online
)
{
final
ProgressDialog
progressDialog
=
ProgressDialog
.
show
(
SerialActivity
.
this
,
SerialActivity
.
this
.
getBaseContext
().
getString
(
R
.
string
.
userLoading
Msg
),
final
ProgressDialog
progressDialog
=
ProgressDialog
.
show
(
SerialActivity
.
this
,
SerialActivity
.
this
.
getBaseContext
().
getString
(
R
.
string
.
userLoading
Txt
),
SerialActivity
.
this
.
getBaseContext
().
getString
(
R
.
string
.
userLoadingTxt
),
false
,
false
);
final
String
operation
=
"sup/login"
;
Hashtable
<
String
,
String
>
postDataParams
=
new
Hashtable
<
String
,
String
>();
...
...
@@ -99,9 +99,18 @@ public class SerialActivity extends Activity {
try
{
Integer
su_id
=
user
.
getInt
(
TAG_ID
);
int
su_id_int
=
su_id
.
intValue
();
;
loginActivity
.
putExtra
(
"offline"
,
false
);
loginActivity
.
putExtra
(
"sup_id"
,
su_id_int
);
loginActivity
.
putExtra
(
"token"
,
jsonToken
);
loginActivity
.
putExtra
(
"username"
,
username
);
loginActivity
.
putExtra
(
"password"
,
password
);
loginActivity
.
putExtra
(
"name"
,
user
.
getString
(
TAG_NAME
));
loginActivity
.
putExtra
(
"surname"
,
user
.
getString
(
TAG_SURNAME
));
loginActivity
.
putExtra
(
"pic"
,
user
.
getString
(
TAG_PIC
));
loginActivity
.
putExtra
(
"gender"
,
user
.
getString
(
TAG_GENDER
));
loginActivity
.
putExtra
(
"lang"
,
user
.
getString
(
TAG_LANG
));
startActivity
(
loginActivity
);
}
catch
(
JSONException
e
)
{
...
...
@@ -209,23 +218,7 @@ public class SerialActivity extends Activity {
}
private
void
set_student_oline
(
User
student
,
String
token
,
final
Intent
pictogramActivity
)
{
final
ProgressDialog
progressDialog
=
ProgressDialog
.
show
(
this
,
getString
(
R
.
string
.
userLoadingTxt
),
getString
(
R
.
string
.
loadingGrammar
));
Vector
<
User
>
vstudent
=
new
Vector
<>(
1
);
vstudent
.
add
(
student
);
try
{
PCBcontext
.
getDevice
().
synchronizeUsers
(
vstudent
,
new
iImgDownloaderListener
()
{
@Override
public
void
loadComplete
()
{
}
@Override
public
void
loadImg
(
Img
image
)
{
Log
.
d
(
LOG_TAG
,
"Load a single image with ID: "
+
image
.
get_id
());
}
});
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
PCBcontext
.
set_user
(
student
,
token
,
new
iImgDownloaderListener
()
{
@Override
public
void
loadComplete
()
{
...
...
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