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
fe7a35d9
authored
Jan 15, 2017
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
issues #795,#797, #798, #801, #803, #806 closed
parent
54299bdf
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
231 additions
and
143 deletions
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/net/websockets/ActionTalk.java
android/Pictogram/commonlibrary/src/main/java/com/yottacode/tools/BitmapTools.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/session/PictoAdapter.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/session/SessionActivity.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/session/SessionFragment.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/net/SessionWrapper.java
android/Pictogram/tabletlibrary/src/main/res/drawable-hdpi/session_category.png
android/Pictogram/tabletlibrary/src/main/res/drawable-hdpi/try_border.jpg
android/Pictogram/tabletlibrary/src/main/res/layout/activity_session.xml
android/Pictogram/tabletlibrary/src/main/res/layout/fragment_session.xml
android/Pictogram/tabletlibrary/src/main/res/layout/list_logsessions.xml
android/Pictogram/tabletlibrary/tabletlibrary.iml
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/net/websockets/ActionTalk.java
View file @
fe7a35d9
...
...
@@ -23,6 +23,7 @@ public class ActionTalk implements Emitter.Listener {
private
Room
room
;
Vector
<
iActionListener
>
listeners
;
private
static
final
String
LOG_TAG
=
ActionTalk
.
class
.
getCanonicalName
();
public
ActionTalk
(
Room
room
,
iActionListener
listener
)
{
this
.
room
=
room
;
...
...
@@ -41,13 +42,14 @@ public class ActionTalk implements Emitter.Listener {
final
String
param_picto_cat
=
"id_cat"
;
final
String
action_select
=
"select"
;
final
String
action_add
=
"add"
;
final
String
action_delete
=
"delete"
;
final
String
action_show
=
"show"
;
JSONObject
msg
=
(
JSONObject
)
args
[
0
];
try
{
Log
.
i
(
this
.
getClass
().
getName
(),
"Received message (raw): "
+
msg
.
toString
()+
" mirror:"
+
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_mirror_on
());
String
action
=
msg
.
getString
(
param_action
).
toLowerCase
();
if
(
action
.
equals
(
action_add
)
||
action
.
equals
(
action_select
)
||
action
.
equals
(
action_show
))
{
if
(
action
.
equals
(
action_add
)
||
action
.
equals
(
action_select
)
||
action
.
equals
(
action_show
)
||
action
.
equals
(
action_delete
))
{
int
picto_id
;
int
picto_cat
;
boolean
mirroing
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_mirror_on
();
...
...
@@ -62,14 +64,16 @@ public class ActionTalk implements Emitter.Listener {
mirroing
|=
attrs_stu_picto
.
has
(
Picto
.
JSON_ATTTRS
.
MIRROR
);
}
if
(
mirroing
)
{
Log
.
i
(
this
.
getClass
().
getName
()
,
"Received message '"
+
action
+
Log
.
i
(
LOG_TAG
,
"Received message '"
+
action
+
"' for picto "
+
picto_id
+
" (cat "
+
picto_cat
);
for
(
iActionListener
listener
:
this
.
listeners
)
listener
.
action
(
action
.
equals
(
action_add
)
?
iActionListener
.
action
.
add
:
action
.
equals
(
action_select
)
?
iActionListener
.
action
.
select
:
iActionListener
.
action
.
show
:
action
.
equals
(
action_delete
)
?
iActionListener
.
action
.
delete
:
iActionListener
.
action
.
show
,
picto_cat
,
picto_id
);
}
}
...
...
@@ -96,7 +100,7 @@ public class ActionTalk implements Emitter.Listener {
* @version 1.0
*/
public
interface
iActionListener
{
enum
action
{
add
,
select
,
show
}
enum
action
{
add
,
delete
,
select
,
show
}
void
action
(
action
action
,
int
picto_cat
,
int
picto_id
);
}
}
android/Pictogram/commonlibrary/src/main/java/com/yottacode/tools/BitmapTools.java
View file @
fe7a35d9
...
...
@@ -7,6 +7,7 @@ import android.graphics.Color;
import
android.graphics.Matrix
;
import
android.graphics.Paint
;
import
android.graphics.PorterDuff
;
import
android.graphics.drawable.BitmapDrawable
;
/**
* Created by Fernando on 15/03/2016.
...
...
@@ -157,4 +158,13 @@ public class BitmapTools {
return
this
;
}
public
void
paint
(
BitmapDrawable
drawable
,
double
factor
)
{
Canvas
canvas
=
new
Canvas
(
this
.
bitmap
);
int
w
=(
int
)(
this
.
bitmap
.
getWidth
()*
factor
);
int
h
=(
int
)(
this
.
bitmap
.
getHeight
()*
factor
);
canvas
.
drawBitmap
(
new
BitmapTools
(
drawable
.
getBitmap
()).
resize
(
w
,
h
).
get
(),
(
int
)((
this
.
bitmap
.
getWidth
()-
w
)/
2
),(
int
)((
this
.
bitmap
.
getHeight
()-
h
)/
2
),
null
);
}
}
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/session/PictoAdapter.java
View file @
fe7a35d9
...
...
@@ -14,6 +14,7 @@ import android.view.View;
import
android.view.ViewGroup
;
import
android.widget.BaseAdapter
;
import
android.widget.ImageView
;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
com.yottacode.pictogram.tabletlibrary.R
;
...
...
@@ -28,6 +29,8 @@ import java.util.Vector;
* Created by Fernando on 18/12/2016.
*/
class
PictoAdapter
extends
BaseAdapter
{
private
String
LOG_TAG
=
PictoAdapter
.
class
.
getCanonicalName
();
public
void
setCurrentMsg
(
int
currentMsg
)
{
this
.
currentMsg
=
currentMsg
;
}
...
...
@@ -36,11 +39,10 @@ class PictoAdapter extends BaseAdapter {
public
static
class
Item
{
Bitmap
img
;
String
secs
;
String
Builder
sentence
;
String
sentence
=
""
;
public
Item
(
Bitmap
img
,
String
secs
)
{
this
.
img
=
img
;
this
.
secs
=
secs
;
this
.
sentence
=
new
StringBuilder
(
""
);
}
Bitmap
getImg
()
{
return
img
;
...
...
@@ -49,9 +51,9 @@ class PictoAdapter extends BaseAdapter {
return
secs
;
}
public
String
getMsg
()
{
return
sentence
.
toString
();}
public
void
setImg
(
Bitmap
currmsg
,
String
word
)
{
public
void
setImg
(
Bitmap
currmsg
,
String
word
,
boolean
eval
)
{
this
.
img
=
currmsg
;
sentence
.
append
(
" "
+
word
)
;
if
(
eval
)
sentence
=
": "
+
word
;
}
}
Context
context
;
...
...
@@ -103,9 +105,10 @@ public long getItemId(int position) {
vi
=
inflater
.
inflate
(
R
.
layout
.
session_picto_view
,
null
);
ImageView
picto
=(
ImageView
)
vi
.
findViewById
(
R
.
id
.
session_picto
);
picto
.
setImageBitmap
(
this
.
msg
.
get
(
position
).
getImg
());
if
(
currentMsg
==
position
)
if
(
currentMsg
==
position
)
{
vi
.
setBackgroundColor
(
Color
.
LTGRAY
);
else
((
ListView
)
parent
).
smoothScrollToPosition
(
position
);
}
else
vi
.
setBackgroundColor
(
Color
.
TRANSPARENT
);
return
vi
;
}
...
...
@@ -116,7 +119,7 @@ public long getItemId(int position) {
bmp
=
set_text
(
context
,
bmp
,
getTimeDiff
(
new
Date
().
getTime
()));
Bitmap
currmsg
=
combineImages
(
oldmsg
,
bmp
);
item
.
setImg
(
currmsg
,
text
);
item
.
setImg
(
currmsg
,
text
,
false
);
}
...
...
@@ -128,34 +131,30 @@ public long getItemId(int position) {
float
height
=
context
.
getResources
().
getDimension
(
R
.
dimen
.
picto_session_height
);
bmp
=
new
BitmapTools
(
bmp
).
resize
((
int
)
width
,(
int
)
height
).
get
();
bmp
=
set_text
(
context
,
bmp
,
getTimeDiff
(
new
Date
().
getTime
()));
Bitmap
currmsg
=
this
.
currentMsg
=
=
this
.
msg
.
size
()-
1
?
combineImages
(
oldmsg
,
bmp
)
:
updateImage
(
oldmsg
,
bmp
);
item
.
setImg
(
currmsg
,
": "
+
evaluation
);
Bitmap
currmsg
=
position
>
=
this
.
msg
.
size
()-
1
?
combineImages
(
oldmsg
,
bmp
)
:
updateImage
(
oldmsg
,
bmp
);
item
.
setImg
(
currmsg
,
evaluation
,
true
);
}
public
int
newMsg
()
{
Bitmap
bmp
=
BitmapFactory
.
decodeResource
(
context
.
getResources
(),
R
.
drawable
.
application_online
);
float
width
=
context
.
getResources
().
getDimension
(
R
.
dimen
.
picto_session_width
);
float
height
=
context
.
getResources
().
getDimension
(
R
.
dimen
.
picto_session_height
);
bmp
=
new
BitmapTools
(
bmp
).
resize
((
int
)
width
,(
int
)
height
).
get
();
Calendar
calendar
=
GregorianCalendar
.
getInstance
();
// creates a new calendar instance
calendar
.
setTime
(
new
Date
());
// assigns calendar to given date
String
time
=
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
)+
":"
+
calendar
.
get
(
Calendar
.
MINUTE
)+
":"
+
calendar
.
get
(
Calendar
.
SECOND
);
bmp
=
set_text
(
context
,
bmp
,
time
);
this
.
currentMsg
=
this
.
msg
.
size
();
msg
.
add
(
new
Item
(
bmp
,
time
));
if
((
msg
.
size
()>
0
&&
msg
.
get
(
msg
.
size
()-
1
).
getImg
().
getWidth
()>
context
.
getResources
().
getDimension
(
R
.
dimen
.
picto_session_width
))
||
msg
.
size
()==
0
)
{
Calendar
calendar
=
GregorianCalendar
.
getInstance
();
// creates a new calendar instance
calendar
.
setTime
(
new
Date
());
// assigns calendar to given date
String
time
=
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
)
+
":"
+
calendar
.
get
(
Calendar
.
MINUTE
)
+
":"
+
calendar
.
get
(
Calendar
.
SECOND
);
Bitmap
bmp
=
set_trycount
(
context
,
this
.
msg
.
size
()+
1
);
this
.
currentMsg
=
this
.
msg
.
size
();
msg
.
add
(
new
Item
(
bmp
,
time
));
}
return
msg
.
size
()-
1
;
}
private
Bitmap
combineImages
(
Bitmap
c
,
Bitmap
s
)
{
Bitmap
cs
=
null
;
int
width
,
height
=
0
;
width
=
c
.
getWidth
()
+
s
.
getWidth
();
height
=
c
.
getHeight
();
cs
=
Bitmap
.
createBitmap
(
width
,
height
,
Bitmap
.
Config
.
ARGB_8888
);
Canvas
comboImage
=
new
Canvas
(
cs
);
...
...
@@ -163,31 +162,71 @@ public long getItemId(int position) {
comboImage
.
drawBitmap
(
c
,
0
f
,
0
f
,
null
);
comboImage
.
drawBitmap
(
s
,
c
.
getWidth
(),
0
f
,
null
);
return
cs
;
}
private
Bitmap
updateImage
(
Bitmap
c
,
Bitmap
s
)
{
Bitmap
cs
=
null
;
int
width
=
c
.
getWidth
(),
height
=
c
.
getHeight
();
int
cutwidth
=
c
.
getWidth
()-
s
.
getWidth
();
cs
=
Bitmap
.
createBitmap
(
width
,
height
,
Bitmap
.
Config
.
ARGB_8888
);
Canvas
comboImage
=
new
Canvas
(
cs
);
comboImage
.
drawBitmap
(
Bitmap
.
createBitmap
(
c
,
0
,
0
,
cutwidth
,
height
),
0
f
,
0
f
,
null
);
comboImage
.
drawBitmap
(
s
,
c
.
getWidth
()-
s
.
getWidth
()
,
0
f
,
null
);
comboImage
.
drawBitmap
(
s
,
c
utwidth
,
0
f
,
null
);
return
cs
;
}
static
void
set_date
(
Context
context
,
Canvas
canvas
,
String
time
)
{
TextView
textView2
=
new
TextView
(
context
);
textView2
.
layout
(
0
,
20
,
100
,
100
);
textView2
.
setPadding
(
0
,
0
,
0
,
0
);
textView2
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
13
);
textView2
.
setTextColor
(
Color
.
BLACK
);
textView2
.
setBackgroundColor
(
Color
.
LTGRAY
);
textView2
.
setWidth
(
100
);
textView2
.
setGravity
(
Gravity
.
CENTER_HORIZONTAL
);
textView2
.
setMaxLines
(
1
);
textView2
.
setText
(
time
);
textView2
.
setDrawingCacheEnabled
(
true
);
canvas
.
drawBitmap
(
textView2
.
getDrawingCache
(),
0
,
60
,
null
);
}
static
Bitmap
set_trycount
(
Context
context
,
int
pos
)
{
Bitmap
param_bitmap
=
BitmapFactory
.
decodeResource
(
context
.
getResources
(),
R
.
drawable
.
try_border
);
float
width
=
context
.
getResources
().
getDimension
(
R
.
dimen
.
picto_session_width
);
float
height
=
context
.
getResources
().
getDimension
(
R
.
dimen
.
picto_session_height
);
Bitmap
bmp
=
Bitmap
.
createScaledBitmap
(
param_bitmap
,
(
int
)
width
,
(
int
)
height
,
false
);
Canvas
canvas
=
new
Canvas
(
bmp
);
TextView
textView
=
new
TextView
(
context
);
String
texto
=(
pos
<
10
?
"0"
:
""
)+
new
Integer
(
pos
).
toString
();
textView
.
layout
(
0
,
0
,
100
,
100
);
textView
.
setPadding
(
0
,
0
,
0
,
0
);
textView
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
40
);
textView
.
setTextColor
(
Color
.
BLACK
);
textView
.
setBackgroundColor
(
Color
.
TRANSPARENT
);
textView
.
setWidth
(
100
);
textView
.
setGravity
(
Gravity
.
LEFT
);
textView
.
setMaxLines
(
1
);
textView
.
setText
(
texto
);
textView
.
setDrawingCacheEnabled
(
true
);
canvas
.
drawBitmap
(
textView
.
getDrawingCache
(),
10
,
10
,
null
);
Calendar
calendar
=
GregorianCalendar
.
getInstance
();
// creates a new calendar instance
calendar
.
setTime
(
new
Date
());
// assigns calendar to given date
String
time
=
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
)+
":"
+
calendar
.
get
(
Calendar
.
MINUTE
)+
":"
+
calendar
.
get
(
Calendar
.
SECOND
);
set_date
(
context
,
canvas
,
time
);
return
bmp
;
}
static
Bitmap
set_text
(
Context
context
,
Bitmap
param_bitmap
,
String
texto
)
{
Paint
paint
=
new
Paint
(
Paint
.
ANTI_ALIAS_FLAG
);
float
width
=
param_bitmap
.
getWidth
();
float
height
=
param_bitmap
.
getHeight
();
Paint
paint
=
new
Paint
(
Paint
.
ANTI_ALIAS_FLAG
);
float
width
=
param_bitmap
.
getWidth
();
float
height
=
param_bitmap
.
getHeight
();
android
.
graphics
.
Bitmap
.
Config
bitmapConfig
=
param_bitmap
.
getConfig
();
android
.
graphics
.
Bitmap
.
Config
bitmapConfig
=
param_bitmap
.
getConfig
();
if
(
bitmapConfig
==
null
)
{
bitmapConfig
=
android
.
graphics
.
Bitmap
.
Config
.
ARGB_8888
;
}
...
...
@@ -199,20 +238,7 @@ public long getItemId(int position) {
canvas
.
drawColor
(
Color
.
TRANSPARENT
,
PorterDuff
.
Mode
.
CLEAR
);
//Poner en blanco el bitmap original para dibujar encima
canvas
.
drawBitmap
(
bm
,
0
,
0
,
paint
);
TextView
textView
=
new
TextView
(
context
);
textView
.
layout
(
0
,
20
,
100
,
100
);
textView
.
setPadding
(
0
,
0
,
0
,
0
);
textView
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
13
);
textView
.
setTextColor
(
Color
.
BLACK
);
textView
.
setBackgroundColor
(
Color
.
LTGRAY
);
textView
.
setWidth
(
100
);
textView
.
setGravity
(
Gravity
.
CENTER_HORIZONTAL
);
textView
.
setMaxLines
(
1
);
textView
.
setText
(
texto
);
textView
.
setDrawingCacheEnabled
(
true
);
canvas
.
drawBitmap
(
textView
.
getDrawingCache
(),
0
,
60
,
null
);
set_date
(
context
,
canvas
,
texto
);
return
bitmap
;
}
...
...
@@ -223,5 +249,7 @@ public long getItemId(int position) {
public
String
getCurrentMsgText
()
{
return
this
.
getItem
(
currentMsg
).
getMsg
();
}
public
String
getMsgText
(
int
pos
)
{
return
this
.
getItem
(
pos
).
getMsg
();
}
}
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/session/SessionActivity.java
View file @
fe7a35d9
...
...
@@ -10,9 +10,11 @@ import android.util.Log;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.Window
;
import
android.widget.ArrayAdapter
;
import
android.widget.Button
;
import
android.widget.CompoundButton
;
import
android.widget.ImageView
;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
android.widget.ToggleButton
;
...
...
@@ -33,6 +35,7 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
private
static
final
String
FRAGMENT_SESSION
=
"session"
;
private
static
final
String
FRAGMENT_METHOD
=
"method"
;
private
static
final
String
LOG_TAG
=
SessionActivity
.
class
.
getCanonicalName
();
public
static
FragmentActivity
session
=
null
;
private
int
currentInstruction
;
private
int
id_session
;
...
...
@@ -44,94 +47,108 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
ListInstructionsFragment
listInstructionsFragment
=
new
ListInstructionsFragment
();
boolean
previous_mirrormode
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_mirror_on
();
private
void
addLogMsg
(
String
msg
)
{
TextView
log
=(
TextView
)
findViewById
(
R
.
id
.
session_serverlog
);
msg
=
log
.
getText
()+
new
java
.
text
.
SimpleDateFormat
(
"HH:mm:ss"
).
format
(
new
Date
())+
": "
+
msg
+
'\n'
;
log
.
setText
(
msg
);
}
@Override
public
void
newMsg
(
final
int
msg_pos
)
{
final
SessionFragment
sessionFragment
=
(
SessionFragment
)
getSupportFragmentManager
().
findFragmentByTag
(
SessionActivity
.
FRAGMENT_SESSION
);
SessionWrapper
.
newTry
(
id_session
,
new
SessionWrapper
.
iTryUpdated
()
{
@Override
public
void
update
(
int
id
)
{
private
void
addLogMsg
(
final
String
msg
)
{
int
pos_newmsg
=
sessionFragment
.
newMsg
();
msgs
.
put
(
pos_newmsg
,
id
);
addLogMsg
(
getString
(
R
.
string
.
session_log_newtry
));
}
@Override
public
void
error
(
String
error
)
{
addLogMsg
(
getString
(
R
.
string
.
session_error
));
}
});
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
ListView
log
=(
ListView
)
findViewById
(
R
.
id
.
session_serverlog
);
ArrayAdapter
adapter
=
(
ArrayAdapter
)
log
.
getAdapter
();
adapter
.
add
(
new
java
.
text
.
SimpleDateFormat
(
"HH:mm:ss"
).
format
(
new
Date
())+
": "
+
msg
+
'\n'
);
}
});
}
@Override
public
void
selectedMsg
(
int
msg_pos
)
{
}
@Override
public
void
play_msg
(
int
msg_pos
)
{
evaluateMsg
(
msg_pos
,
"DISCARDED"
,
R
.
string
.
session_eval_notevuated
,
R
.
drawable
.
session_notevaluated
);
public
void
play_msg
()
{
evaluateMsg
(
this
.
msgs
.
size
()-
1
,
null
,
R
.
string
.
session_eval_notevuated
,
R
.
drawable
.
session_notevaluated
);
}
private
void
evaluateMsg
(
final
int
msg_pos
,
final
String
evaluation_value
,
final
int
evaluation_translation
,
final
int
evaluation_bitmap
)
{
final
SessionFragment
sessionFragment
=
(
SessionFragment
)
getSupportFragmentManager
().
findFragmentByTag
(
SessionActivity
.
FRAGMENT_SESSION
);
final
int
currentMsgId
=
SessionActivity
.
this
.
msgs
.
get
(
msg_pos
);
SessionWrapper
.
evaluateTry
(
currentMsgId
,
false
,
evaluation_value
,
new
SessionWrapper
.
iTryUpdated
()
{
SessionWrapper
.
evaluateTry
(
currentMsgId
,
msg_pos
==
this
.
msgs
.
size
()-
1
,
evaluation_value
,
new
SessionWrapper
.
iTryUpdated
()
{
@Override
public
void
update
(
int
id
)
{
public
void
update
(
int
next_try_
id
)
{
Bitmap
bitmap
=
BitmapFactory
.
decodeResource
(
getResources
(),
evaluation_bitmap
);
sessionFragment
.
evaluateMsg
(
bitmap
,
getString
(
evaluation_translation
),
msg_pos
);
addLogMsg
(
sessionFragment
.
get_current_msg_text
());
addLogMsg
(
"#"
+(
msg_pos
<
9
?
"0"
:
""
)+(
msg_pos
+
1
)+
sessionFragment
.
get_msg_text
(
msg_pos
));
if
(!
msgs
.
containsValue
(
next_try_id
))
new_try
(
sessionFragment
,
next_try_id
);
if
(
evaluation_value
!=
null
&&
msg_pos
==
msgs
.
size
()-
1
){
SessionWrapper
.
newTry
(
id_session
,
new
SessionWrapper
.
iTryUpdated
()
{
@Override
public
void
update
(
int
id
)
{
int
pos_newmsg
=
sessionFragment
.
newMsg
();
msgs
.
put
(
pos_newmsg
,
id
);
addLogMsg
(
getString
(
R
.
string
.
session_log_newtry
));
}
@Override
public
void
error
(
String
error
)
{
addLogMsg
(
getString
(
R
.
string
.
session_error
));
}
});
}
}
@Override
public
void
error
(
String
error
)
{
addLogMsg
(
getString
(
R
.
string
.
session_error
)+
":"
+
error
);
Log
.
e
(
this
.
getClass
().
getCanonicalName
()
,
"server error:"
+
error
+
" when updating try "
+
currentMsgId
+
" to "
+
evaluation_value
);
Log
.
e
(
LOG_TAG
,
"server error:"
+
error
+
" when updating try "
+
currentMsgId
+
" to "
+
evaluation_value
);
}
});
}
private
void
new_try
(
SessionFragment
sessionFragment
,
int
next_try_id
)
{
int
pos_newmsg
=
sessionFragment
.
newMsg
();
msgs
.
put
(
pos_newmsg
,
next_try_id
);
addLogMsg
(
getString
(
R
.
string
.
session_log_newtry
));
}
class
TouchButtonListener
implements
View
.
OnTouchListener
{
int
button
;
String
value
;
int
translation
;
public
TouchButtonListener
(
int
button
,
String
value
,
int
translation
)
{
this
.
button
=
button
;
this
.
value
=
value
;
this
.
translation
=
translation
;
}
@Override
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
int
button
;
String
value
;
int
translation
;
Drawable
draw
=
getDrawable
(
button
);
public
TouchButtonListener
(
int
button
,
String
value
,
int
translation
)
{
this
.
button
=
button
;
this
.
value
=
value
;
this
.
translation
=
translation
;
}
v
.
setBackground
(
draw
);
@Override
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
v
.
setAlpha
(
event
.
getAction
()==
MotionEvent
.
ACTION_UP
?
(
float
)
1
:
(
float
)
0.5
);
if
(
event
.
getAction
()==
MotionEvent
.
ACTION_UP
)
{
final
SessionFragment
sessionFragment
=
(
SessionFragment
)
getSupportFragmentManager
().
findFragmentByTag
(
SessionActivity
.
FRAGMENT_SESSION
);
final
int
msg_pos
=
sessionFragment
.
get_current_msg_pos
();
evaluateMsg
(
msg_pos
,
value
,
translation
,
button
);
if
(
msg_pos
==
sessionFragment
.
get_last_msg_pos
())
newMsg
(
msg_pos
);
}
Drawable
draw
=
getDrawable
(
button
);
v
.
setBackground
(
draw
);
v
.
setAlpha
(
event
.
getAction
()
==
MotionEvent
.
ACTION_UP
?
(
float
)
1
:
(
float
)
0.5
);
return
true
;
if
(
event
.
getAction
()
==
MotionEvent
.
ACTION_UP
)
{
final
SessionFragment
sessionFragment
=
(
SessionFragment
)
getSupportFragmentManager
().
findFragmentByTag
(
SessionActivity
.
FRAGMENT_SESSION
);
final
int
msg_pos
=
sessionFragment
.
get_current_msg_pos
();
evaluateMsg
(
msg_pos
,
value
,
translation
,
button
);
if
(
msg_pos
!=
sessionFragment
.
get_last_msg_pos
())
sessionFragment
.
adapter_pictomsg
.
setCurrentMsg
(
sessionFragment
.
adapter_pictomsg
.
getCount
()-
1
);
}
return
true
;
}
}
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -150,13 +167,13 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
final
Button
failBtn
=((
Button
)
findViewById
(
R
.
id
.
btn_fail
));
final
Button
supBtn
=((
Button
)
findViewById
(
R
.
id
.
btn_supervised
));
final
Button
modBtn
=((
Button
)
findViewById
(
R
.
id
.
btn_model
));
((
ListView
)
findViewById
(
R
.
id
.
session_serverlog
)).
setAdapter
(
new
ArrayAdapter
<
String
>(
getBaseContext
(),
R
.
layout
.
list_logsessions
));
StudentFullNameView
.
setText
(
student
.
get_name_stu
()
+
" "
+
student
.
get_surname_stu
());
StudentUserNameView
.
setText
(
student
.
get_nickname_stu
());
try
{
StudentPhotoView
.
setImageBitmap
(
student
.
get_bitmap_stu
(
this
.
getBaseContext
()));
}
catch
(
IOException
e
)
{
Log
.
e
(
this
.
getClass
().
getCanonicalName
()
,
e
.
getMessage
());
Log
.
e
(
LOG_TAG
,
e
.
getMessage
());
}
okBtn
.
setOnTouchListener
(
new
TouchButtonListener
(
R
.
drawable
.
session_ok
,
"SUCCESS"
,
R
.
string
.
session_eval_success
));
failBtn
.
setOnTouchListener
(
new
TouchButtonListener
(
R
.
drawable
.
session_fail
,
"FAIL"
,
R
.
string
.
session_eval_fail
));
...
...
@@ -232,7 +249,6 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
@Override
public
void
instruction_selected
(
int
instruction
,
String
instruction_name
)
{
addLogMsg
(
instruction_name
);
Log
.
e
(
"ubs"
,
instruction_name
+
":"
+
instruction
);
this
.
currentInstruction
=
instruction
;
((
TextView
)
findViewById
(
R
.
id
.
sessionTopbarInstructionName
)).
setText
(
instruction_name
);
findViewById
(
R
.
id
.
sessionOnOffBtn
).
setEnabled
(
true
);
...
...
@@ -275,7 +291,7 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
return
super
.
dispatchTouchEvent
(
event
);
}
private
void
set_fragment_sesion
()
{
private
SessionFragment
set_fragment_sesion
()
{
final
Button
okBtn
=((
Button
)
findViewById
(
R
.
id
.
btn_correct
));
final
Button
disBtn
=((
Button
)
findViewById
(
R
.
id
.
btn_discarded
));
final
Button
spoBtn
=((
Button
)
findViewById
(
R
.
id
.
btn_spontaneous
));
...
...
@@ -290,7 +306,7 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
getSupportFragmentManager
()
.
beginTransaction
()
.
replace
(
R
.
id
.
sessions_fragment_container
,
sessionFragment
,
SessionActivity
.
FRAGMENT_SESSION
)
.
commit
()
.
commit
Now
()
;
findViewById
(
R
.
id
.
sessionPauseBtn
).
setVisibility
(
View
.
VISIBLE
);
okBtn
.
setVisibility
(
View
.
VISIBLE
);
...
...
@@ -301,6 +317,7 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
modBtn
.
setVisibility
(
View
.
VISIBLE
);
findViewById
(
R
.
id
.
sessionTopbarMethodName
).
setVisibility
(
View
.
VISIBLE
);
findViewById
(
R
.
id
.
sessionTopbarInstructionName
).
setVisibility
(
View
.
VISIBLE
);
return
sessionFragment
;
}
private
void
set_fragment_method
()
{
final
Button
okBtn
=((
Button
)
findViewById
(
R
.
id
.
btn_correct
));
...
...
@@ -339,10 +356,11 @@ public class SessionActivity extends FragmentActivity implements ListInstruction
addLogMsg
(
getString
(
R
.
string
.
session_log_startingsession
));
SessionWrapper
.
startSession
(
this
.
currentInstruction
,
new
SessionWrapper
.
iStartSession
()
{
@Override
public
void
started
(
int
id_session
)
{
public
void
started
(
int
id_session
,
int
id_first_try
)
{
addLogMsg
(
getString
(
R
.
string
.
session_log_startsession
));
SessionActivity
.
this
.
id_session
=
id_session
;
set_fragment_sesion
();
SessionFragment
session
=
set_fragment_sesion
();
new_try
(
session
,
id_first_try
);
}
@Override
...
...
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/session/SessionFragment.java
View file @
fe7a35d9
...
...
@@ -3,9 +3,10 @@ package com.yottacode.pictogram.tabletlibrary.gui.session;
import
android.app.Activity
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.
Color
;
import
android.graphics.
drawable.BitmapDrawable
;
import
android.os.Bundle
;
import
android.support.v4.app.Fragment
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
...
...
@@ -25,9 +26,8 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
interface
iSessionFragment
{
public
void
newMsg
(
int
msg_pos
);
public
void
selectedMsg
(
int
msg_pos
);
public
void
play_msg
(
int
msg_pos
);
public
void
play_msg
();
}
private
iSessionFragment
mListener
=
null
;
...
...
@@ -39,6 +39,8 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
public
SessionFragment
()
{
super
();
}
...
...
@@ -46,7 +48,9 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
adapter_pictomsg
=
new
PictoAdapter
(
this
.
getContext
());
setRetainInstance
(
true
);
}
@Override
...
...
@@ -55,7 +59,7 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
// Inflate the layout for this fragment
View
view
=
inflater
.
inflate
(
R
.
layout
.
fragment_session
,
container
,
false
);
list_pictomsg
=
(
ListView
)
view
.
findViewById
(
R
.
id
.
session_pictomsg_list
);
adapter_pictomsg
=
new
PictoAdapter
(
this
.
getContext
());
list_pictomsg
.
setAdapter
(
adapter_pictomsg
);
list_pictomsg
.
setOnItemClickListener
(
new
AdapterView
.
OnItemClickListener
()
{
@Override
...
...
@@ -65,7 +69,6 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
((
PictoAdapter
)
list_pictomsg
.
getAdapter
()).
notifyDataSetChanged
();
}
});
mListener
.
newMsg
(
this
.
adapter_pictomsg
.
getCount
());
return
view
;
}
...
...
@@ -106,20 +109,28 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
@Override
public
void
action
(
action
action
,
int
picto_cat
,
int
picto_id
)
{
if
(
action
==
ActionTalk
.
iActionListener
.
action
.
show
)
{
if
(!
paused
)
{
mListener
.
play_msg
(
this
.
adapter_pictomsg
.
getCount
()-
1
);
mListener
.
newMsg
(
this
.
adapter_pictomsg
.
getCount
());
mListener
.
play_msg
();
}
}
else
try
{
}
else
if
(
action
==
ActionTalk
.
iActionListener
.
action
.
add
||
action
==
ActionTalk
.
iActionListener
.
action
.
select
||
action
==
ActionTalk
.
iActionListener
.
action
.
delete
)
try
{
Picto
picto
=
PCBcontext
.
getVocabulary
().
get_picto
(
picto_cat
,
picto_id
);
Bitmap
bmp
=
picto
.
get_bitmap
(
getContext
());
if
(
paused
)
{
if
(
action
==
ActionTalk
.
iActionListener
.
action
.
delete
)
{
bmp
=
bmp
.
copy
(
bmp
.
getConfig
(),
true
);
new
BitmapTools
(
bmp
).
paint
((
BitmapDrawable
)
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
disabled_picto
,
null
),
1
);
}
else
if
(
PCBcontext
.
getVocabulary
().
get_picto
(
picto_cat
,
picto_id
).
is_category
())
{
Log
.
e
(
"CAT"
,
"catcat"
);
bmp
=
bmp
.
copy
(
bmp
.
getConfig
(),
true
);
new
BitmapTools
(
bmp
).
paint
((
BitmapDrawable
)
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
session_category
,
null
),
0.5
);
}
if
(
paused
)
{
bmp
=
bmp
.
copy
(
bmp
.
getConfig
(),
true
);
new
BitmapTools
(
bmp
).
paintPause
();
}
this
.
adapter_pictomsg
.
addItem
(
bmp
,
picto
.
get_translation
());
getActivity
().
runOnUiThread
(
new
Runnable
()
{
public
void
run
()
{
...
...
@@ -162,4 +173,7 @@ public class SessionFragment extends Fragment implements ActionTalk.iActionListe
public
int
get_last_msg_pos
()
{
return
adapter_pictomsg
.
getCount
()-
1
;
}
public
String
get_msg_text
(
int
pos
)
{
return
adapter_pictomsg
.
getMsgText
(
pos
);
}
}
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/net/SessionWrapper.java
View file @
fe7a35d9
...
...
@@ -36,7 +36,7 @@ public class SessionWrapper {
public
interface
iStartSession
{
void
started
(
int
id_session
);
void
started
(
int
id_session
,
int
first_try
);
void
error
(
String
error
);
}
public
interface
iCloseSession
{
...
...
@@ -85,7 +85,7 @@ public class SessionWrapper {
@Override
public
void
result
(
JSONObject
result
)
{
try
{
listener
.
started
(
result
.
getInt
(
"id"
));
listener
.
started
(
result
.
getInt
(
"id"
)
,
result
.
getInt
(
"first_try_id"
)
);
}
catch
(
JSONException
e
)
{
listener
.
error
(
e
.
getMessage
());
}
...
...
@@ -247,10 +247,10 @@ public class SessionWrapper {
Hashtable
<
String
,
String
>
params
=
new
Hashtable
<>(
1
);
try
{
params
.
put
(
"json"
,
new
JSONObject
()
.
put
(
"ws"
,
Integer
.
valueOf
(
ws
).
toString
())
.
put
(
"supervisor"
,
Integer
.
valueOf
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_id_sup
()).
toString
())
.
put
(
"student"
,
Integer
.
valueOf
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_id_stu
()).
toString
())
.
put
(
"begin"
,
nowAsISO
).
toString
());
.
put
(
"ws"
,
Integer
.
valueOf
(
ws
).
toString
())
.
put
(
"supervisor"
,
Integer
.
valueOf
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_id_sup
()).
toString
())
.
put
(
"student"
,
Integer
.
valueOf
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_id_stu
()).
toString
())
.
put
(
"begin"
,
nowAsISO
).
toString
());
}
catch
(
JSONException
e
)
{
Log
.
e
(
SessionWrapper
.
LOG_TAG
,
e
.
getMessage
());
listener
.
error
(
e
.
getMessage
());
...
...
@@ -284,7 +284,8 @@ public class SessionWrapper {
});
}
public
static
void
evaluateTry
(
final
int
try_id
,
boolean
now
,
String
result
,
final
iTryUpdated
listener
)
{
public
static
void
evaluateTry
(
final
int
try_id
,
final
boolean
now
,
String
result
,
final
iTryUpdated
listener
)
{
Hashtable
<
String
,
String
>
params
=
new
Hashtable
<>(
1
);
try
{
JSONObject
jparams
=
new
JSONObject
().
put
(
"result"
,
result
);
...
...
@@ -295,7 +296,6 @@ public class SessionWrapper {
e
.
printStackTrace
();
}
PCBcontext
.
getRestapiWrapper
().
ask
(
"try/"
+
try_id
,
params
,
"put"
,
true
,
new
RestapiWrapper
.
iRestapiListener
()
{
@Override
...
...
@@ -305,12 +305,20 @@ public class SessionWrapper {
@Override
public
void
result
(
JSONArray
result
)
{
listener
.
update
(
try_id
);
try
{
listener
.
update
(
result
.
getJSONObject
(
0
).
getInt
(
"next_try_id"
));
}
catch
(
JSONException
e
)
{
listener
.
error
(
e
.
getMessage
());
}
}
@Override
public
void
result
(
JSONObject
result
)
{
listener
.
update
(
try_id
);
try
{
listener
.
update
(
result
.
getInt
(
"next_try_id"
));
}
catch
(
JSONException
e
)
{
listener
.
error
(
e
.
getMessage
());
}
}
@Override
...
...
android/Pictogram/tabletlibrary/src/main/res/drawable-hdpi/session_category.png
0 → 100644
View file @
fe7a35d9
17.5 KB
android/Pictogram/tabletlibrary/src/main/res/drawable-hdpi/try_border.jpg
0 → 100644
View file @
fe7a35d9
22.9 KB
android/Pictogram/tabletlibrary/src/main/res/layout/activity_session.xml
View file @
fe7a35d9
...
...
@@ -184,26 +184,22 @@
</LinearLayout>
</LinearLayout>
<
Scroll
View
android:id=
"@+id/
SCROLLER_ID
"
<
List
View
android:id=
"@+id/
session_serverlog
"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:scrollbars=
"vertical"
android:layout_toLeftOf=
"@+id/imageView3"
android:layout_toRightOf=
"@+id/view_session_buttons0"
android:layout_below=
"@+id/view_as2"
android:layout_alignBottom=
"@+id/imageView3"
android:layout_alignTop=
"@+id/imageView3"
android:fillViewport=
"true"
>
<TextView
android:layout_width=
"fill_parent"
android:layout_height=
"fill_parent"
android:fillViewport=
"true"
android:ems=
"12"
android:id=
"@+id/session_serverlog"
android:layout_weight=
"1"
android:transcriptMode=
"alwaysScroll"
android:stackFromBottom=
"true"
android:background=
"@color/common_google_signin_btn_text_light_disabled"
/>
</ScrollView>
<ImageView
android:layout_width=
"100dp"
android:layout_height=
"100dp"
...
...
android/Pictogram/tabletlibrary/src/main/res/layout/fragment_session.xml
View file @
fe7a35d9
...
...
@@ -7,6 +7,8 @@
<ListView
android:id=
"@+id/session_pictomsg_list"
android:transcriptMode=
"alwaysScroll"
android:stackFromBottom=
"true"
android:orientation=
"horizontal"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
...
...
android/Pictogram/tabletlibrary/src/main/res/layout/list_logsessions.xml
0 → 100644
View file @
fe7a35d9
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/sessionLogEntry"
android:layout_width=
"wrap_content"
android:layout_height=
"fill_parent"
android:textAppearance=
"@android:style/TextAppearance.Material.Small"
android:gravity=
"left"
/>
android/Pictogram/tabletlibrary/tabletlibrary.iml
View file @
fe7a35d9
...
...
@@ -73,14 +73,6 @@
<sourceFolder
url=
"file://$MODULE_DIR$/src/main/jni"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/main/rs"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/main/shaders"
isTestSource=
"false"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/res"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/resources"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/assets"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/aidl"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/java"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/jni"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/rs"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/shaders"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/res"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/resources"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/assets"
type=
"java-test-resource"
/>
...
...
@@ -89,6 +81,14 @@
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/jni"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/rs"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/androidTest/shaders"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/res"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/resources"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/assets"
type=
"java-test-resource"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/aidl"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/java"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/jni"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/rs"
isTestSource=
"true"
/>
<sourceFolder
url=
"file://$MODULE_DIR$/src/test/shaders"
isTestSource=
"true"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/build/intermediates/annotations"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/build/intermediates/blame"
/>
<excludeFolder
url=
"file://$MODULE_DIR$/build/intermediates/bundles"
/>
...
...
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