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
f35fbc40
authored
May 04, 2017
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
issues
#193
,
#194
closed
parent
2dc9f5f9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
30 deletions
android/Pictogram/commonlibrary/build.gradle
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/dao/Device.java
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/dao/PCBDBHelper.java
android/Pictogram/commonlibrary/src/main/res/raw/pcbdb_create.sql
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/login/SerialActivity.java
android/Pictogram/commonlibrary/build.gradle
View file @
f35fbc40
...
@@ -10,7 +10,7 @@ android {
...
@@ -10,7 +10,7 @@ android {
versionCode
1
versionCode
1
versionName
"1.0"
versionName
"1.0"
resValue
"string"
,
"db_name"
,
"PCB.db"
resValue
"string"
,
"db_name"
,
"PCB.db"
resValue
"integer"
,
"db_version"
,
"
4
"
resValue
"integer"
,
"db_version"
,
"
7
"
resValue
"string"
,
"app_version"
,
"1.1"
resValue
"string"
,
"app_version"
,
"1.1"
resValue
"string"
,
"core_vocabulary"
,
"core_vocabulary"
resValue
"string"
,
"core_vocabulary"
,
"core_vocabulary"
resValue
"string"
,
"apk"
,
"to_be_set_in_subproject"
resValue
"string"
,
"apk"
,
"to_be_set_in_subproject"
...
...
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/dao/Device.java
View file @
f35fbc40
...
@@ -38,12 +38,13 @@ public class Device extends SQLiteOpenHelper {
...
@@ -38,12 +38,13 @@ public class Device extends SQLiteOpenHelper {
private
static
final
String
LOG_TAG
=
SQLiteOpenHelper
.
class
.
getCanonicalName
();
private
static
final
String
LOG_TAG
=
SQLiteOpenHelper
.
class
.
getCanonicalName
();
Context
context
;
Context
context
;
public
static
final
String
PREFS_NAME
=
"MyPrefsFile"
;
final
static
class
PARAMS
{
final
static
class
PARAMS
{
static
String
keyword
=
"key"
;
static
String
keyword
=
"key
word
"
;
static
String
stu_id
=
"last__stu_id"
;
static
String
stu_id
=
"last__stu_id"
;
static
String
sup_id
=
"last__sup_id"
;
static
String
sup_id
=
"last__sup_id"
;
static
String
db_version
=
"db_version"
;
}
}
/**
/**
...
@@ -51,18 +52,14 @@ public class Device extends SQLiteOpenHelper {
...
@@ -51,18 +52,14 @@ public class Device extends SQLiteOpenHelper {
*
*
* @param context the context of the activity
* @param context the context of the activity
* @param factory null
* @param factory null
* @param version 1
*/
*/
public
Device
(
Context
context
,
CursorFactory
factory
,
int
version
)
{
public
Device
(
Context
context
,
CursorFactory
factory
,
int
version
)
{
super
(
context
,
DeviceHelper
.
getDBName
(
context
),
factory
,
context
.
getSharedPreferences
(
PREFS_NAME
,
0
).
getInt
(
PARAMS
.
db_version
,
version
));
super
(
context
,
DeviceHelper
.
getDBName
(
context
),
factory
,
version
)
;
this
.
context
=
context
;
if
(
DeviceHelper
.
force_create
(
context
))
{
if
(
DeviceHelper
.
force_create
(
context
))
{
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Forcing create new Database "
+
DeviceHelper
.
getDBName
(
context
)+
" v."
+
DeviceHelper
.
getDBVersion
(
context
));
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Forcing create new Database "
+
DeviceHelper
.
getDBName
(
context
)+
" v."
+
DeviceHelper
.
getDBVersion
(
context
));
context
.
deleteDatabase
(
DeviceHelper
.
getDBName
(
context
));
context
.
deleteDatabase
(
DeviceHelper
.
getDBName
(
context
));
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Database dropped"
);
}
}
this
.
context
=
context
;
}
}
/**
/**
...
@@ -70,7 +67,14 @@ public class Device extends SQLiteOpenHelper {
...
@@ -70,7 +67,14 @@ public class Device extends SQLiteOpenHelper {
*
*
*/
*/
private
void
setParam
(
String
param
,
String
value
)
{
private
void
setParam
(
String
param
,
String
value
)
{
SQLiteDatabase
db
=
this
.
getWritableDatabase
();
setParam
(
this
.
getWritableDatabase
(),
param
,
value
);
}
/**
* Set the value of a param.
*
*/
private
void
setParam
(
SQLiteDatabase
db
,
String
param
,
String
value
)
{
db
.
beginTransaction
();
db
.
beginTransaction
();
ContentValues
values
=
new
ContentValues
(
2
);
ContentValues
values
=
new
ContentValues
(
2
);
values
.
put
(
"key"
,
param
);
values
.
put
(
"key"
,
param
);
...
@@ -88,18 +92,19 @@ public class Device extends SQLiteOpenHelper {
...
@@ -88,18 +92,19 @@ public class Device extends SQLiteOpenHelper {
* @return value of key param
* @return value of key param
*/
*/
public
String
getParamValue
(
String
key
)
{
public
String
getParamValue
(
String
key
)
{
SQLiteDatabase
db
=
this
.
getReadableDatabase
();
SQLiteDatabase
db
=
this
.
getReadableDatabase
();
String
value
;
String
value
;
Cursor
cursor
=
db
.
query
(
"params"
,
new
String
[]{
"value"
},
"key=?"
,
new
String
[]{
key
},
null
,
null
,
null
,
null
);
Cursor
cursor
=
db
.
query
(
"params"
,
new
String
[]{
"value"
},
"key=?"
,
new
String
[]{
key
},
null
,
null
,
null
,
null
);
if
(
cursor
.
getCount
()
==
0
){
if
(
cursor
.
getCount
()
==
0
){
value
=
null
;
value
=
null
;
Log
.
e
(
this
.
getClass
().
getCanonicalName
()
,
"Error when getting param "
+
key
);
Log
.
e
(
LOG_TAG
,
"Error when getting param "
+
key
);
}
else
{
}
else
{
cursor
.
moveToFirst
();
cursor
.
moveToFirst
();
value
=
cursor
.
getString
(
0
);
value
=
cursor
.
getString
(
0
);
}
}
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
cursor
.
close
();
return
value
;
return
value
;
}
}
...
@@ -337,8 +342,7 @@ public class Device extends SQLiteOpenHelper {
...
@@ -337,8 +342,7 @@ public class Device extends SQLiteOpenHelper {
* delete the list of images (students, supervisors, pictograms) which are no longer used
* delete the list of images (students, supervisors, pictograms) which are no longer used
*/
*/
public
void
deleteDeprecatedImgs
()
{
public
void
deleteDeprecatedImgs
()
{
SQLiteDatabase
db
=
this
.
getWritableDatabase
();
Cursor
cursor
=
this
.
getWritableDatabase
().
query
(
"deprecated_images"
,
null
,
null
,
null
,
null
,
null
,
null
);
Cursor
cursor
=
db
.
query
(
"deprecated_images"
,
null
,
null
,
null
,
null
,
null
,
null
);
while
(
cursor
.
moveToNext
())
{
while
(
cursor
.
moveToNext
())
{
String
type
=
cursor
.
getString
(
1
);
String
type
=
cursor
.
getString
(
1
);
String
folder
=
type
.
equals
(
"stu"
)
?
Img
.
STUDENT
:
type
.
equals
(
"sup"
)
?
Img
.
SUPERVISOR
:
Img
.
VOCABULARY
;
String
folder
=
type
.
equals
(
"stu"
)
?
Img
.
STUDENT
:
type
.
equals
(
"sup"
)
?
Img
.
SUPERVISOR
:
Img
.
VOCABULARY
;
...
@@ -347,7 +351,7 @@ public class Device extends SQLiteOpenHelper {
...
@@ -347,7 +351,7 @@ public class Device extends SQLiteOpenHelper {
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Image file "
+
cursor
.
getString
(
1
)
+
"."
+
cursor
.
getInt
(
0
)
+
" deleted"
);
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Image file "
+
cursor
.
getString
(
1
)
+
"."
+
cursor
.
getInt
(
0
)
+
" deleted"
);
}
}
cursor
.
close
();
cursor
.
close
();
db
.
delete
(
"deprecated_images"
,
null
,
null
);
this
.
getWritableDatabase
()
.
delete
(
"deprecated_images"
,
null
,
null
);
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
//db.close(); <--no es necesario cerrar la bbdd https://groups.google.com/forum/#!msg/android-developers/NwDRpHUXt0U/jIam4Q8-cqQJ
}
}
...
@@ -356,11 +360,11 @@ public class Device extends SQLiteOpenHelper {
...
@@ -356,11 +360,11 @@ public class Device extends SQLiteOpenHelper {
* IMPORTANT: every DDL sentence has to finish with the sequence: ;--
* IMPORTANT: every DDL sentence has to finish with the sequence: ;--
*
*
* @param database picto.db helper
* @param database picto.db helper
* @param inputStream the stream where the ddl of picto.db is depicted
* @throws IOException
* @throws IOException
*/
*/
protected
static
void
executeSQLScript
(
SQLiteDatabase
database
,
InputStream
inputStream
)
protected
void
executeSQLScript
(
SQLiteDatabase
database
)
throws
IOException
{
throws
IOException
{
InputStream
inputStream
=
DeviceHelper
.
getDBScriptStream
(
this
.
context
);
Vector
<
String
>
commands
=
new
Vector
<
String
>(
50
);
Vector
<
String
>
commands
=
new
Vector
<
String
>(
50
);
BufferedReader
r
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
));
BufferedReader
r
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
));
...
@@ -377,7 +381,8 @@ public class Device extends SQLiteOpenHelper {
...
@@ -377,7 +381,8 @@ public class Device extends SQLiteOpenHelper {
r
.
close
();
r
.
close
();
for
(
String
sqlStatement
:
commands
)
for
(
String
sqlStatement
:
commands
)
database
.
execSQL
(
sqlStatement
);
database
.
execSQL
(
sqlStatement
);
Log
.
i
(
Device
.
class
.
getName
(),
"Database created"
);
setParam
(
database
,
PARAMS
.
db_version
,
Integer
.
toString
(
DeviceHelper
.
getDBVersion
(
context
)));
Log
.
i
(
Device
.
class
.
getName
(),
"Database v."
+
DeviceHelper
.
getDBVersion
(
context
)+
" created!"
);
}
}
/**
/**
...
@@ -415,7 +420,7 @@ public class Device extends SQLiteOpenHelper {
...
@@ -415,7 +420,7 @@ public class Device extends SQLiteOpenHelper {
@Override
@Override
public
void
onCreate
(
SQLiteDatabase
db
)
throws
RuntimeException
{
public
void
onCreate
(
SQLiteDatabase
db
)
throws
RuntimeException
{
try
{
try
{
executeSQLScript
(
db
,
DeviceHelper
.
getDBScriptStream
(
this
.
context
)
);
executeSQLScript
(
db
);
Img
.
mkDirs
(
this
.
context
);
Img
.
mkDirs
(
this
.
context
);
copyCoreVocabulary
();
copyCoreVocabulary
();
}
catch
(
java
.
io
.
IOException
io
)
{
}
catch
(
java
.
io
.
IOException
io
)
{
...
@@ -481,7 +486,7 @@ public class Device extends SQLiteOpenHelper {
...
@@ -481,7 +486,7 @@ public class Device extends SQLiteOpenHelper {
try
{
try
{
Log
.
i
(
LOG_TAG
,
"Upgrading db from "
+
oldVersion
+
" to "
+
newVersion
);
Log
.
i
(
LOG_TAG
,
"Upgrading db from "
+
oldVersion
+
" to "
+
newVersion
);
executeSQLScript
(
db
,
DeviceHelper
.
getDBScriptStream
(
this
.
context
)
);
executeSQLScript
(
db
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
"Update database ir cached Images error"
,
e
);
throw
new
RuntimeException
(
"Update database ir cached Images error"
,
e
);
}
}
...
...
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/dao/PCBDBHelper.java
View file @
f35fbc40
...
@@ -155,21 +155,23 @@ public class PCBDBHelper extends SQLiteOpenHelper {
...
@@ -155,21 +155,23 @@ public class PCBDBHelper extends SQLiteOpenHelper {
* "pictos": [.....] Pictos of that scene
* "pictos": [.....] Pictos of that scene
*/
*/
public
void
setActiveSceneForStudent
(
JSONObject
params
){
public
void
setActiveSceneForStudent
(
JSONObject
params
){
SQLiteDatabase
db
=
this
.
getReadableDatabase
();
try
{
try
{
db
.
rawQuery
(
"INSERT
INTO scene VALUES ("
String
sql_scene
=
"INSERT OR REPLACE
INTO scene VALUES ("
+
params
.
getInt
(
"id"
)
+
params
.
getInt
(
"id"
)
+
","
+
params
.
getInt
(
"supervisor"
)
+
","
+
params
.
getInt
(
"supervisor"
)
+
","
+
params
.
get
(
"student"
)
+
","
+
params
.
get
(
"student"
)
+
",'"
+
params
.
getString
(
"name"
)
+
",'"
+
params
.
getString
(
"name"
)
+
"','"
+
params
.
getBoolean
(
"active"
)
+
"','"
+
params
.
getBoolean
(
"active"
)
+
"','"
+
params
.
getBoolean
(
"categories"
)
+
"','"
+
params
.
getBoolean
(
"categories"
)
+
"')"
,
null
);
+
"')"
;
Log
.
i
(
LOG_TAG
,
"Scene to be inserted: "
+
sql_scene
);
getWritableDatabase
().
execSQL
(
sql_scene
);
}
catch
(
JSONException
e
)
{
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
Log
.
e
(
LOG_TAG
,
"Error setting active scene:"
+
e
.
getMessage
());
}
}
Cursor
cursor
=
db
.
rawQuery
(
"SELECT * FROM scene"
,
null
);
Cursor
cursor
=
getReadableDatabase
()
.
rawQuery
(
"SELECT * FROM scene"
,
null
);
Log
.
i
(
LOG_TAG
,
"tam scen: "
+
cursor
.
getCount
());
Log
.
i
(
LOG_TAG
,
"tam scen: "
+
cursor
.
getCount
());
cursor
.
close
();
cursor
.
close
();
}
}
...
...
android/Pictogram/commonlibrary/src/main/res/raw/pcbdb_create.sql
View file @
f35fbc40
...
@@ -5,7 +5,7 @@ DROP TABLE IF EXISTS params
...
@@ -5,7 +5,7 @@ DROP TABLE IF EXISTS params
;
--
;
--
CREATE
TABLE
params
(
CREATE
TABLE
params
(
key
TEXT
(
12
)
CHECK
(
key
in
(
'
serial'
,
'deviceID'
,
'last__stu_id'
,
'last__sup_id'
,
'token
'
,
'keyword'
))
UNIQUE
,
key
TEXT
(
12
)
CHECK
(
key
in
(
'
db_version'
,
'last__sup_id'
,
'last__stu_id
'
,
'keyword'
))
UNIQUE
,
value
TEXT
(
40
)
NOT
NULL
value
TEXT
(
40
)
NOT
NULL
)
)
;
--
;
--
...
...
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/login/SerialActivity.java
View file @
f35fbc40
...
@@ -18,6 +18,7 @@ import android.widget.LinearLayout;
...
@@ -18,6 +18,7 @@ import android.widget.LinearLayout;
import
android.widget.ListView
;
import
android.widget.ListView
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.yottacode.pictogram.dao.Device
;
import
com.yottacode.pictogram.dao.User
;
import
com.yottacode.pictogram.dao.User
;
import
com.yottacode.pictogram.dao.UserLogin
;
import
com.yottacode.pictogram.dao.UserLogin
;
import
com.yottacode.pictogram.tabletlibrary.R
;
import
com.yottacode.pictogram.tabletlibrary.R
;
...
@@ -35,7 +36,7 @@ import java.util.Vector;
...
@@ -35,7 +36,7 @@ import java.util.Vector;
*/
*/
public
class
SerialActivity
extends
Activity
{
public
class
SerialActivity
extends
Activity
{
public
static
final
String
PREFS_NAME
=
"MyPrefsFile"
;
// String constant for logs
// String constant for logs
private
final
String
LOG_TAG
=
this
.
getClass
().
getSimpleName
();
// Or .getCanonicalName()
private
final
String
LOG_TAG
=
this
.
getClass
().
getSimpleName
();
// Or .getCanonicalName()
...
@@ -56,7 +57,7 @@ public class SerialActivity extends Activity {
...
@@ -56,7 +57,7 @@ public class SerialActivity extends Activity {
String
password
=
intent
.
getStringExtra
(
"switch_pwd"
);
String
password
=
intent
.
getStringExtra
(
"switch_pwd"
);
if
(
username
==
null
||
password
==
null
)
{
if
(
username
==
null
||
password
==
null
)
{
SharedPreferences
settings
=
getSharedPreferences
(
PREFS_NAME
,
0
);
SharedPreferences
settings
=
getSharedPreferences
(
Device
.
PREFS_NAME
,
0
);
username
=
settings
.
getString
(
"username"
,
""
);
username
=
settings
.
getString
(
"username"
,
""
);
password
=
settings
.
getString
(
"password"
,
""
);
password
=
settings
.
getString
(
"password"
,
""
);
}
}
...
@@ -92,7 +93,7 @@ public class SerialActivity extends Activity {
...
@@ -92,7 +93,7 @@ public class SerialActivity extends Activity {
toast
.
show
();
toast
.
show
();
}
else
{
}
else
{
SharedPreferences
settings
=
getSharedPreferences
(
PREFS_NAME
,
0
);
SharedPreferences
settings
=
getSharedPreferences
(
Device
.
PREFS_NAME
,
0
);
SharedPreferences
.
Editor
editor
=
settings
.
edit
();
SharedPreferences
.
Editor
editor
=
settings
.
edit
();
editor
.
putString
(
"username"
,
supUsers
.
elementAt
(
position
).
get_email_sup
());
editor
.
putString
(
"username"
,
supUsers
.
elementAt
(
position
).
get_email_sup
());
editor
.
putString
(
"password"
,
supUsers
.
elementAt
(
position
).
get_pwd_sup
());
editor
.
putString
(
"password"
,
supUsers
.
elementAt
(
position
).
get_pwd_sup
());
...
@@ -126,7 +127,7 @@ public class SerialActivity extends Activity {
...
@@ -126,7 +127,7 @@ public class SerialActivity extends Activity {
listaStu
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
listaStu
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
@Override
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
SharedPreferences
settings
=
getSharedPreferences
(
PREFS_NAME
,
0
);
SharedPreferences
settings
=
getSharedPreferences
(
Device
.
PREFS_NAME
,
0
);
SharedPreferences
.
Editor
editor
=
settings
.
edit
();
SharedPreferences
.
Editor
editor
=
settings
.
edit
();
editor
.
putString
(
"username"
,
stuUsers
.
elementAt
(
position
).
get_nickname_stu
());
editor
.
putString
(
"username"
,
stuUsers
.
elementAt
(
position
).
get_nickname_stu
());
editor
.
putString
(
"password"
,
stuUsers
.
elementAt
(
position
).
get_pwd_stu
());
editor
.
putString
(
"password"
,
stuUsers
.
elementAt
(
position
).
get_pwd_stu
());
...
@@ -165,7 +166,7 @@ public class SerialActivity extends Activity {
...
@@ -165,7 +166,7 @@ public class SerialActivity extends Activity {
String
username
=
mSerialViewMail
.
getText
().
toString
();
String
username
=
mSerialViewMail
.
getText
().
toString
();
String
password
=
mSerialViewPass
.
getText
().
toString
();
String
password
=
mSerialViewPass
.
getText
().
toString
();
SharedPreferences
settings
=
getSharedPreferences
(
PREFS_NAME
,
0
);
SharedPreferences
settings
=
getSharedPreferences
(
Device
.
PREFS_NAME
,
0
);
SharedPreferences
.
Editor
editor
=
settings
.
edit
();
SharedPreferences
.
Editor
editor
=
settings
.
edit
();
editor
.
putString
(
"username"
,
username
);
editor
.
putString
(
"username"
,
username
);
editor
.
putString
(
"password"
,
password
);
editor
.
putString
(
"password"
,
password
);
...
...
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