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
15664a9f
authored
Jul 25, 2017
by
Sebastián Collado Montañez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
vocabularymanager
parent
4cb773c3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
1196 additions
and
68 deletions
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/communicator/PictoMenu.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/communicator/VOCA.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/communicator/VocabularyManager.java
android/Pictogram/yotta_tablet/src/main/AndroidManifest.xml
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/communicator/PictoMenu.java
View file @
15664a9f
...
@@ -26,7 +26,7 @@ public class PictoMenu {
...
@@ -26,7 +26,7 @@ public class PictoMenu {
public
static
final
String
IMAGE_PICTO
=
"imagePicto"
;
public
static
final
String
IMAGE_PICTO
=
"imagePicto"
;
public
static
final
String
PATH_SOUND
=
"pathSound"
;
public
static
final
String
PATH_SOUND
=
"pathSound"
;
V
OCA
activity
;
V
ocabularyManager
activity
;
//Variables used on the picto menu (only supervisors)
//Variables used on the picto menu (only supervisors)
private
static
final
int
CAMERA_PIC_REQUEST
=
1
;
private
static
final
int
CAMERA_PIC_REQUEST
=
1
;
...
@@ -40,7 +40,7 @@ public class PictoMenu {
...
@@ -40,7 +40,7 @@ public class PictoMenu {
// TODO describe this variable
// TODO describe this variable
static
final
int
SELECT_PICTURE
=
1
;
static
final
int
SELECT_PICTURE
=
1
;
public
PictoMenu
(
V
OCA
activity
)
{
public
PictoMenu
(
V
ocabularyManager
activity
)
{
this
.
activity
=
activity
;
this
.
activity
=
activity
;
}
}
...
...
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/communicator/VOCA.java
View file @
15664a9f
...
@@ -51,6 +51,7 @@ import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet;
...
@@ -51,6 +51,7 @@ import com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet;
import
com.yottacode.pictogram.tools.Img
;
import
com.yottacode.pictogram.tools.Img
;
import
com.yottacode.pictogram.tools.PCBcontext
;
import
com.yottacode.pictogram.tools.PCBcontext
;
import
com.yottacode.pictogram.tts.TTSHelper
;
import
com.yottacode.pictogram.tts.TTSHelper
;
import
com.yottacode.tools.GUITools
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
...
@@ -923,45 +924,27 @@ public class VOCA extends Activity implements VocabularyTalk.iVocabularyListener
...
@@ -923,45 +924,27 @@ public class VOCA extends Activity implements VocabularyTalk.iVocabularyListener
*/
*/
private
class
OnPictoLongClickListener
implements
AdapterView
.
OnItemLongClickListener
{
private
class
OnPictoLongClickListener
implements
AdapterView
.
OnItemLongClickListener
{
public
boolean
onItemLongClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
public
boolean
onItemLongClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
/*if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor()) {
ClipData
.
Item
item
=
new
ClipData
.
Item
(
""
+
position
);
// Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito
String
[]
mimeTypes
=
{
ClipDescription
.
MIMETYPE_TEXT_PLAIN
};
Picto p = getCurrentPictoGridAdapter().getItem(position);
ClipData
data
=
new
ClipData
(
""
+
position
,
mimeTypes
,
item
);
if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (getCurrentCategory() != null || *//*!PCBcontext.getPcbdb().getCurrentUser().has_categories()*//*!PCBcontext.getVocabulary().has_categories()) {
int cat = getCurrentCategory() != null ? currentCategory.get_id() : Picto.NO_CATEGORY;
new PictoMenu(VOCA.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), cat);
} else
Toast.makeText(VOCA.this, VOCA.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
} else {
Picto
p
=
getCurrentPictoGridAdapter
().
getItem
(
position
);
//Si es supervisor hacer aparecer el menú de opciones del picto
if
(
p
!=
null
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
new PictoMenu(VOCA.this).createMenuForPicto(PCBcontext.getPcbdb().getCurrentUser().is_picto_size_big(),p);
// If is not the blank picto, it isn't invisible or disabled
getCurrentPictoGridAdapter().notifyDataSetChanged();
if
(
p
.
get_id
()
!=
0
&&
}
!
p
.
get_status
().
equalsIgnoreCase
(
"invisible"
)
&&
} else {*/
!
p
.
get_status
().
equalsIgnoreCase
(
"disabled"
)
&&
ClipData
.
Item
item
=
new
ClipData
.
Item
(
""
+
position
);
tapeAdapter
.
getCount
()
<
VOCA
.
this
.
maxInTape
)
{
String
[]
mimeTypes
=
{
ClipDescription
.
MIMETYPE_TEXT_PLAIN
};
View
.
DragShadowBuilder
shadowBuilder
=
new
View
.
DragShadowBuilder
(
view
);
ClipData
data
=
new
ClipData
(
""
+
position
,
mimeTypes
,
item
);
view
.
startDrag
(
data
,
//data to be dragged
Picto
p
=
getCurrentPictoGridAdapter
().
getItem
(
position
);
shadowBuilder
,
//drag shadow
if
(
p
!=
null
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
view
,
//local data about the drag and drop operation
// If is not the blank picto, it isn't invisible or disabled
0
//no needed flags
if
(
p
.
get_id
()
!=
0
&&
);
!
p
.
get_status
().
equalsIgnoreCase
(
"invisible"
)
&&
//view.setVisibility(View.INVISIBLE);
!
p
.
get_status
().
equalsIgnoreCase
(
"disabled"
)
&&
tapeAdapter
.
getCount
()
<
VOCA
.
this
.
maxInTape
)
{
View
.
DragShadowBuilder
shadowBuilder
=
new
View
.
DragShadowBuilder
(
view
);
view
.
startDrag
(
data
,
//data to be dragged
shadowBuilder
,
//drag shadow
view
,
//local data about the drag and drop operation
0
//no needed flags
);
//view.setVisibility(View.INVISIBLE);
}
}
}
//
}
}
return
true
;
return
true
;
}
}
}
}
...
@@ -1131,58 +1114,47 @@ public class VOCA extends Activity implements VocabularyTalk.iVocabularyListener
...
@@ -1131,58 +1114,47 @@ public class VOCA extends Activity implements VocabularyTalk.iVocabularyListener
}
}
}
}
/*
@Override
@Override
public
boolean
dispatchTouchEvent
(
MotionEvent
event
)
{
public
boolean
dispatchTouchEvent
(
MotionEvent
event
)
{
int
in
=
0
,
out
=
0
;
int
in
=
0
,
out
=
0
;
Intent nextActivity
=
null;
Intent
nextActivity
=
null
;
Intent
intent
=
getIntent
();
Intent
intent
=
getIntent
();
boolean student_view=intent.getBooleanExtra("student_view",false);
if (
PCBcontext.getPcbdb()!=null && (PCBcontext.getPcbdb().getCurrentUser().is_supervisor() || student_view
) ) {
if
(
PCBcontext
.
getPcbdb
()
!=
null
&&
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_supervisor
(
)
)
{
switch
(
event
.
getAction
())
{
switch
(
event
.
getAction
())
{
case
MotionEvent
.
ACTION_DOWN
:
case
MotionEvent
.
ACTION_DOWN
:
firstTouchX
=
event
.
getX
();
firstTouchX
=
event
.
getX
();
break
;
break
;
case
MotionEvent
.
ACTION_UP
:
case
MotionEvent
.
ACTION_UP
:
if (event.getX() > firstTouchX + 150) { //izquierda a derecha
if
(
event
.
getX
()
>
firstTouchX
+
150
)
{
// izquierda a derecha
if (!student_view || !PCBcontext.getPcbdb().getCurrentUser().is_teacher()) {
// No action
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(student_view ? PCBcontext.getDevice().getLastSupId() : User.NO_SUPERVISOR);
nextActivity = intent;
} else
if (!PCBcontext.getNetService().online())
GUITools.show_alert(VOCA.this, R.string.session_noinet);
else {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(PCBcontext.getDevice().getLastSupId());
nextActivity = new Intent(this, SessionActivity.class);
}
in = R.anim.rightin;
out = R.anim.rightout;
overridePendingTransition(R.anim.leftin, R.anim.leftout);
}
else
if
(
firstTouchX
>
event
.
getX
()
+
150
)
{
//derecha a izquierda
}
else
if
(
firstTouchX
>
event
.
getX
()
+
150
)
{
//derecha a izquierda
if (!student_view && PCBcontext.getPcbdb().getCurrentUser().is_teacher() ) {
if (!PCBcontext.getNetService().online())
if
(!
PCBcontext
.
getNetService
().
online
())
GUITools.show_alert(VOCA.this, R.string.session_noinet);
GUITools
.
show_alert
(
VOCA
.
this
,
R
.
string
.
session_noinet
);
else
else
nextActivity = new Intent(this, SessionActivity.class);
nextActivity
=
new
Intent
(
this
,
VocabularyManager
.
class
);
} else {
PCBcontext.getPcbdb().getCurrentUser().get_Img_sup().update_id(student_view ? PCBcontext.getDevice().getLastSupId() : User.NO_SUPERVISOR);
nextActivity = intent;
}
in
=
R
.
anim
.
leftin
;
in
=
R
.
anim
.
leftin
;
out
=
R
.
anim
.
leftout
;
out
=
R
.
anim
.
leftout
;
}
}
if
(
nextActivity
!=
null
)
{
if
(
nextActivity
!=
null
)
{
tape_delivered
=
false
;
tape_delivered
=
false
;
intent.putExtra("student_view", !PCBcontext.getPcbdb().getCurrentUser().is_supervisor());
finish
();
finish
();
startActivity
(
nextActivity
);
startActivity
(
nextActivity
);
overridePendingTransition
(
in
,
out
);
overridePendingTransition
(
in
,
out
);
}
}
break
;
break
;
}
}
}
}
return
super
.
dispatchTouchEvent
(
event
);
return
super
.
dispatchTouchEvent
(
event
);
}
*/
}
/**
/**
* Para capturar el evento para abrir camara o galeria y procesar
* Para capturar el evento para abrir camara o galeria y procesar
...
...
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/communicator/VocabularyManager.java
0 → 100644
View file @
15664a9f
package
com
.
yottacode
.
pictogram
.
tabletlibrary
.
gui
.
communicator
;
import
android.annotation.TargetApi
;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.content.ClipData
;
import
android.content.ClipDescription
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.PixelFormat
;
import
android.media.Ringtone
;
import
android.media.RingtoneManager
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.provider.MediaStore
;
import
android.speech.tts.UtteranceProgressListener
;
import
android.util.DisplayMetrics
;
import
android.util.Log
;
import
android.view.DragEvent
;
import
android.view.Gravity
;
import
android.view.HapticFeedbackConstants
;
import
android.view.KeyEvent
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.Window
;
import
android.view.WindowManager
;
import
android.view.animation.AccelerateDecelerateInterpolator
;
import
android.view.animation.Animation
;
import
android.view.animation.TranslateAnimation
;
import
android.widget.AdapterView
;
import
android.widget.CheckBox
;
import
android.widget.EditText
;
import
android.widget.GridView
;
import
android.widget.ImageButton
;
import
android.widget.RelativeLayout
;
import
android.widget.Toast
;
import
com.yottacode.pictogram.action.PictosAction
;
import
com.yottacode.pictogram.action.TalkAction
;
import
com.yottacode.pictogram.dao.Picto
;
import
com.yottacode.pictogram.dao.User
;
import
com.yottacode.pictogram.grammar.Vocabulary
;
import
com.yottacode.pictogram.grammar.iLocalPicto
;
import
com.yottacode.pictogram.net.ImgDownloader
;
import
com.yottacode.pictogram.net.PictoUploader
;
import
com.yottacode.pictogram.net.websockets.ActionTalk
;
import
com.yottacode.pictogram.net.websockets.VocabularyTalk
;
import
com.yottacode.pictogram.tabletlibrary.R
;
import
com.yottacode.pictogram.tabletlibrary.gui.communicator.cropper.EditPictoActivity
;
import
com.yottacode.pictogram.tabletlibrary.gui.session.SessionActivity
;
import
com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet
;
import
com.yottacode.pictogram.tools.Img
;
import
com.yottacode.pictogram.tools.PCBcontext
;
import
com.yottacode.pictogram.tts.TTSHelper
;
import
com.yottacode.tools.BitmapTools
;
import
com.yottacode.tools.GUITools
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.io.File
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Iterator
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.concurrent.ScheduledThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
public
class
VocabularyManager
extends
Activity
implements
VocabularyTalk
.
iVocabularyListener
{
private
static
final
int
CAMERA_PIC_REQUEST
=
1
;
private
static
final
int
GALLERY_PIC_REQUEST
=
2
;
// Main layout for this activity
RelativeLayout
mainLayout
;
// Adapter for de grid showing the categories grid (and main pictos)
PictoGridAdapter
pictoMainGridAdapter
;
// Grid showing the categories grid (and main pictos)
GridView
pictoMainGridView
;
// Adapter for the grid showing pictos from a category (initially hidden)
PictoGridAdapter
pictoCategoryGridAdapter
;
// Grid showing pictos from a category (initially hidden)
GridView
pictoCategoryGridView
;
// Adapter for the tape view (list of pictos to send to the server)
TapeAdapter
tapeAdapter
;
// Tape view (list of pictos to send to the server)
GridView
tapeGridView
;
// Current picto category, if not null the corresponding category grid will be shown
private
Picto
currentCategory
;
// Object used for reading text
TTSHelper
tts
;
// Element used for loading new pictos (while changing categories)
Vocabulary
vocabulary
;
// For disabling volume button (See method at the end of the class)
private
final
List
blockedKeys
=
new
ArrayList
(
Arrays
.
asList
(
KeyEvent
.
KEYCODE_VOLUME_DOWN
,
KeyEvent
.
KEYCODE_VOLUME_UP
));
// String constant for logs
private
final
String
LOG_TAG
=
this
.
getClass
().
getSimpleName
();
// Or .getCanonicalName()
// Count for delete long press (hidden exit)
private
int
count_deletelong
=
0
;
// Animation for hidding the picto category view
Animation
hidePictoMainViewAnimation
;
// Animation for showing the picto category view
Animation
showPictoMainViewAnimation
;
// Button used for showing the picto category view
ImageButton
showPictoCategoriesViewButton
;
ImageButton
deleteButton
;
ImageButton
ttsButton
;
int
maxColumns
,
maxRows
,
maxInTape
;
ScheduledThreadPoolExecutor
exec_mirror
=
null
;
Picto
prev_picto
=
null
;
private
boolean
feedback_read
;
private
boolean
feedback_highlight
;
protected
boolean
deleting
;
protected
boolean
tape_delivered
=
false
;
float
firstTouchX
=
-
1
;
public
boolean
inserting
=
false
;
@TargetApi
(
Build
.
VERSION_CODES
.
M
)
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
// blockNotificationBar();
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
this
.
getWindow
().
setFlags
(
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
,
WindowManager
.
LayoutParams
.
FLAG_FULLSCREEN
);
// after a long inactivity, the pcbdb is discarded
if
(!
PCBcontext
.
is_user_logged
())
{
Log
.
i
(
LOG_TAG
,
"PCBDB was discarded. App restarting"
);
NetServiceTablet
.
restart_PictogramTablet
(
this
);
return
;
}
setContentView
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_picto_size_big
()
?
R
.
layout
.
activity_pictogram_big
:
R
.
layout
.
activity_pictogram
);
this
.
mainLayout
=
(
RelativeLayout
)
findViewById
(
R
.
id
.
pictogramLayout
);
this
.
currentCategory
=
null
;
this
.
count_deletelong
=
0
;
if
(!
PCBcontext
.
is_user_logged
())
{
Log
.
i
(
LOG_TAG
,
"No user logged. Restarting app"
);
NetServiceTablet
.
restart_PictogramTablet
(
this
);
return
;
}
this
.
vocabulary
=
PCBcontext
.
getVocabulary
();
this
.
vocabulary
.
listen
(
PCBcontext
.
getRoom
(),
this
,
new
ActionTalk
.
iActionListener
()
{
@Override
public
void
action
(
action
action
,
int
picto_cat
,
int
picto_id
,
JSONObject
msg
)
{
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
action
+
" from "
+
picto_cat
+
","
+
picto_id
+
" catched"
);
if
(
action
==
ActionTalk
.
iActionListener
.
action
.
show
)
{
Log
.
i
(
"TAG_PRUEBAS"
,
"show message received:"
+
msg
.
toString
());
JSONObject
msg_attrs
=
null
;
JSONArray
pictos
=
null
;
String
mensaje
=
""
;
try
{
msg_attrs
=
msg
.
getJSONObject
(
"attributes"
);
pictos
=
msg_attrs
.
getJSONArray
(
"pictos"
);
String
user
=
pictos
.
getJSONObject
(
0
).
getJSONObject
(
"attributes"
).
getString
(
"user_avatar"
);
if
(
user
.
equals
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_email_sup
())){
//si el primer picto tiene ese sup asociado
mensaje
+=
getResources
().
getString
(
R
.
string
.
message_from
)+
": "
+
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_name_stu
()+
", "
+
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_surname_stu
()+
"\n"
;
mensaje
+=
getResources
().
getString
(
R
.
string
.
says
)+
": "
;
for
(
int
i
=
0
;
i
<
pictos
.
length
();
i
++)
{
JSONObject
picto
=
pictos
.
getJSONObject
(
i
).
getJSONObject
(
"attributes"
);
mensaje
+=
(
i
!=
pictos
.
length
()-
1
?
picto
.
get
(
"expression"
).
toString
()+
" - "
:
picto
.
get
(
"expression"
).
toString
());
}
Log
.
i
(
LOG_TAG
,
"Mensaje: "
+
msg
.
toString
());
final
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
VocabularyManager
.
this
);
builder
.
setMessage
(
mensaje
)
.
setPositiveButton
(
"Vale"
,
new
DialogInterface
.
OnClickListener
()
{
public
void
onClick
(
DialogInterface
dialog
,
int
id
)
{
}
});
// Create the AlertDialog object and return it
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
AlertDialog
alert
=
builder
.
create
();
alert
.
show
();
}
});
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
else
if
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_mirror_on
())
{
Picto
picto
=
vocabulary
.
get_picto
(
picto_cat
,
picto_id
);
VocabularyManager
.
this
.
execHighligthFeeback
(
picto
,
true
);
}
}
});
this
.
vocabulary
.
setImgDownloaderListener
(
new
ImgDownloader
.
iImgDownloaderListener
()
{
@Override
public
void
loadComplete
()
{
VocabularyManager
.
this
.
refresh
();
}
@Override
public
void
loadImg
(
Img
image
)
{
}
@Override
public
void
error
(
Exception
err
)
{
}
});
this
.
tapeAdapter
=
new
TapeAdapter
();
this
.
tapeGridView
=
(
GridView
)
this
.
findViewById
(
R
.
id
.
tape_grid_view
);
this
.
tapeGridView
.
setAdapter
(
this
.
tapeAdapter
);
this
.
pictoMainGridAdapter
=
new
PictoGridAdapter
(
new
LinkedList
<
Picto
>());
this
.
pictoMainGridView
=
(
GridView
)
this
.
findViewById
(
R
.
id
.
picto_main_grid_view
);
this
.
pictoMainGridView
.
setAdapter
(
this
.
pictoMainGridAdapter
);
this
.
pictoCategoryGridAdapter
=
new
PictoGridAdapter
(
new
LinkedList
<
Picto
>());
this
.
pictoCategoryGridView
=
(
GridView
)
this
.
findViewById
(
R
.
id
.
picto_category_grid_view
);
this
.
pictoCategoryGridView
.
setAdapter
(
this
.
pictoCategoryGridAdapter
);
this
.
pictoMainGridView
.
setOnDragListener
(
new
OnPictoDragListener
());
this
.
pictoCategoryGridView
.
setOnDragListener
(
new
OnPictoDragListener
());
this
.
pictoMainGridView
.
setOnItemClickListener
(
new
OnPictoClickListener
());
this
.
pictoCategoryGridView
.
setOnItemClickListener
(
new
OnPictoClickListener
());
this
.
pictoMainGridView
.
setOnItemLongClickListener
(
new
OnPictoLongClickListener
());
this
.
pictoCategoryGridView
.
setOnItemLongClickListener
(
new
OnPictoLongClickListener
());
this
.
deleteButton
=
(
ImageButton
)
findViewById
(
R
.
id
.
button_delete
);
this
.
ttsButton
=
(
ImageButton
)
findViewById
(
R
.
id
.
button_tts
);
ttsButton
.
setOnLongClickListener
(
new
View
.
OnLongClickListener
()
{
@Override
public
boolean
onLongClick
(
View
v
)
{
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
" Changing mirror mode"
);
if
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_supervisor
())
{
int
res_id
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
alter_mirror_mode
()
==
true
?
R
.
string
.
mirror_mode_on
:
R
.
string
.
mirror_mode_off
;
Toast
.
makeText
(
VocabularyManager
.
this
,
res_id
,
Toast
.
LENGTH_SHORT
).
show
();
}
return
true
;
}
});
this
.
deleteButton
.
setOnLongClickListener
(
new
OnDeleteButtonLongClickListener
());
this
.
showPictoCategoriesViewButton
=
(
ImageButton
)
this
.
findViewById
(
R
.
id
.
showPictoCategoriesViewButton
);
this
.
showPictoCategoriesViewButton
.
setOnClickListener
(
new
OnShowPictoCategoriesViewButtonClick
());
this
.
tapeGridView
.
setOnDragListener
(
new
OnPictoDragListener
());
//((NetServiceTablet) PCBcontext.getNetService().getNetServiceDevice()).setVOCA(this);
if
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_picto_size_big
())
{
maxColumns
=
getResources
().
getInteger
(
R
.
integer
.
columns_big
);
maxRows
=
getResources
().
getInteger
(
R
.
integer
.
rows_big
);
maxInTape
=
getResources
().
getInteger
(
R
.
integer
.
maxInTape_big
);
}
else
{
maxColumns
=
getResources
().
getInteger
(
R
.
integer
.
columns
);
maxRows
=
getResources
().
getInteger
(
R
.
integer
.
rows
);
maxInTape
=
getResources
().
getInteger
(
R
.
integer
.
maxInTape
);
}
VocabularyManager
.
this
.
pictoMainGridView
.
setNumColumns
(
VocabularyManager
.
this
.
maxColumns
);
VocabularyManager
.
this
.
pictoCategoryGridView
.
setNumColumns
(
VocabularyManager
.
this
.
maxColumns
);
this
.
generateAnimations
();
if
(
this
.
getCurrentCategory
()
!=
null
)
{
this
.
hidePictoMainGridView
();
}
else
{
this
.
showPictoMainGridView
();
}
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
Log
.
i
(
LOG_TAG
,
"Resuming Pictogram Activity"
);
PCBcontext
.
setActivityContext
(
this
);
setConfig
();
startTTS
();
Toast
.
makeText
(
this
.
getBaseContext
(),
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_name_stu
()+
" "
+
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_surname_stu
()+
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_supervisor
()
?
" ("
+
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_name_sup
()+
" "
+
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_surname_sup
()+
")"
:
""
)
,
Toast
.
LENGTH_SHORT
).
show
();
}
private
void
blockNotificationBar
()
{
WindowManager
manager
=
((
WindowManager
)
getApplicationContext
().
getSystemService
(
Context
.
WINDOW_SERVICE
));
WindowManager
.
LayoutParams
localLayoutParams
=
new
WindowManager
.
LayoutParams
();
localLayoutParams
.
type
=
WindowManager
.
LayoutParams
.
TYPE_SYSTEM_ERROR
;
localLayoutParams
.
gravity
=
Gravity
.
TOP
;
localLayoutParams
.
flags
=
WindowManager
.
LayoutParams
.
FLAG_NOT_FOCUSABLE
|
// this is to enable the notification to recieve touch events
WindowManager
.
LayoutParams
.
FLAG_NOT_TOUCH_MODAL
|
// Draws over status bar
WindowManager
.
LayoutParams
.
FLAG_LAYOUT_IN_SCREEN
;
localLayoutParams
.
width
=
WindowManager
.
LayoutParams
.
MATCH_PARENT
;
localLayoutParams
.
height
=
(
int
)
(
50
*
getResources
().
getDisplayMetrics
().
scaledDensity
);
localLayoutParams
.
format
=
PixelFormat
.
TRANSPARENT
;
customViewGroup
view
=
new
customViewGroup
(
this
);
manager
.
addView
(
view
,
localLayoutParams
);
}
public
void
setConfig
()
{
setFeedback
(
new
View
[]{
deleteButton
,
ttsButton
,
this
.
showPictoCategoriesViewButton
,
this
.
pictoCategoryGridView
,
this
.
pictoMainGridView
});
}
private
void
setFeedback
(
View
views
[])
{
boolean
vibration
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
input_feedback_on
(
User
.
JSON_STUDENT_INPUT_FEEDBACK
.
VIBRATION
);
boolean
click
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
input_feedback_on
(
User
.
JSON_STUDENT_INPUT_FEEDBACK
.
BEEP
);
this
.
feedback_read
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
input_feedback_on
(
User
.
JSON_STUDENT_INPUT_FEEDBACK
.
READ
);
this
.
feedback_highlight
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
input_feedback_on
(
User
.
JSON_STUDENT_INPUT_FEEDBACK
.
HIGHLIGHT
);
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Feedback:"
+
" vibration:"
+
vibration
+
" Beep:"
+
click
+
" Read:"
+
feedback_read
+
" Highlight:"
+
feedback_highlight
);
View
.
OnTouchListener
touchListener
;
touchListener
=
vibration
?
new
View
.
OnTouchListener
()
{
@Override
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
boolean
enable_haptic
;
enable_haptic
=
!(
v
instanceof
GridView
);
if
(!
enable_haptic
)
{
int
x
=
Math
.
round
(
event
.
getX
());
int
y
=
Math
.
round
(
event
.
getY
());
int
position
=
((
GridView
)
v
).
pointToPosition
(
x
,
y
);
Picto
p
=
position
>
-
1
?
(
Picto
)
((
GridView
)
v
).
getItemAtPosition
(
position
)
:
null
;
enable_haptic
=
(
p
!=
null
&&
p
.
get_id
()
!=
0
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
());
}
if
(
enable_haptic
)
v
.
performHapticFeedback
(
HapticFeedbackConstants
.
LONG_PRESS
,
HapticFeedbackConstants
.
FLAG_IGNORE_GLOBAL_SETTING
);
return
false
;
}
}
:
click
?
new
View
.
OnTouchListener
()
{
@Override
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
try
{
Uri
notification
=
RingtoneManager
.
getDefaultUri
(
RingtoneManager
.
TYPE_NOTIFICATION
);
Ringtone
r
=
RingtoneManager
.
getRingtone
(
getApplicationContext
(),
notification
);
r
.
play
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
false
;
}
}
:
new
View
.
OnTouchListener
()
{
@Override
public
boolean
onTouch
(
View
v
,
MotionEvent
event
)
{
return
false
;
}
};
for
(
View
view
:
views
)
view
.
setOnTouchListener
(
touchListener
);
}
public
void
startTTS
()
{
String
engine
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_tts_engine_sup
()
==
null
?
getString
(
R
.
string
.
default_tts_engine
)
:
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_tts_engine_sup
();
String
tts_voice
=
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_json_attr
(
"tts voice"
)
==
null
?
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_gender_stu
().
charAt
(
0
)
==
'M'
?
getString
(
R
.
string
.
default_tts_voice_male
)
:
getString
(
R
.
string
.
default_tts_voice_female
)
:
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_json_attr
(
"tts voice"
);
tts
=
new
TTSHelper
(
this
,
engine
,
new
Locale
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_lang_stu
()),
tts_voice
);
tts
.
setOnUtteranceProgressListener
(
new
UtteranceProgressListener
()
{
@Override
public
void
onStart
(
String
utteranceId
)
{
Log
.
d
(
LOG_TAG
,
"TTS tape read start"
+
utteranceId
);
}
@Override
public
void
onDone
(
String
utteranceId
)
{
Log
.
d
(
LOG_TAG
,
"TTS tape read end"
);
this
.
finishSpeech
();
}
@Override
public
void
onError
(
String
utteranceId
)
{
Log
.
d
(
LOG_TAG
,
"TTS tape read error"
);
this
.
finishSpeech
();
}
private
void
finishSpeech
()
{
}
});
}
@Override
protected
void
onPause
()
{
super
.
onPause
();
this
.
pictoCategoryGridAdapter
.
allPictosInGrid
();
this
.
pictoMainGridAdapter
.
allPictosInGrid
();
}
@Override
protected
void
onStop
()
{
super
.
onStop
();
tts
.
destroy
();
Log
.
e
(
LOG_TAG
,
"Closing Pictogram Activity"
);
PCBcontext
.
getNetService
().
closeNotifyStatus
();
}
@Override
protected
void
onDestroy
()
{
super
.
onDestroy
();
if
(
tts
!=
null
)
{
tts
.
destroy
();
}
}
/**
* Creates the animations for moving the picto view
*/
private
void
generateAnimations
()
{
DisplayMetrics
displayMetrics
=
new
DisplayMetrics
();
this
.
getWindowManager
().
getDefaultDisplay
().
getMetrics
(
displayMetrics
);
int
animationDuration
=
400
;
int
animationWidth
=
displayMetrics
.
widthPixels
;
this
.
hidePictoMainViewAnimation
=
new
TranslateAnimation
(
0
,
-
animationWidth
,
0
,
0
);
this
.
hidePictoMainViewAnimation
.
setDuration
(
animationDuration
);
this
.
hidePictoMainViewAnimation
.
setFillAfter
(
true
);
this
.
hidePictoMainViewAnimation
.
setInterpolator
(
new
AccelerateDecelerateInterpolator
());
this
.
hidePictoMainViewAnimation
.
setAnimationListener
(
new
Animation
.
AnimationListener
()
{
@Override
public
void
onAnimationStart
(
Animation
animation
)
{
}
@Override
public
void
onAnimationEnd
(
Animation
animation
)
{
pictoMainGridView
.
setTranslationZ
(-
1000.0f
);
pictoMainGridView
.
setVisibility
(
View
.
GONE
);
}
@Override
public
void
onAnimationRepeat
(
Animation
animation
)
{
}
});
this
.
showPictoMainViewAnimation
=
new
TranslateAnimation
(-
animationWidth
,
0
,
0
,
0
);
this
.
showPictoMainViewAnimation
.
setDuration
(
animationDuration
);
this
.
showPictoMainViewAnimation
.
setFillAfter
(
true
);
this
.
showPictoMainViewAnimation
.
setInterpolator
(
new
AccelerateDecelerateInterpolator
());
this
.
showPictoMainViewAnimation
.
setAnimationListener
(
new
Animation
.
AnimationListener
()
{
@Override
public
void
onAnimationStart
(
Animation
animation
)
{
pictoMainGridView
.
setTranslationZ
(
1000.0f
);
pictoMainGridView
.
setVisibility
(
View
.
VISIBLE
);
}
@Override
public
void
onAnimationEnd
(
Animation
animation
)
{
}
@Override
public
void
onAnimationRepeat
(
Animation
animation
)
{
}
});
}
/**
* Show the main category grid view and hide the pictoGrid, unloading all pictos
* if necesary.
*/
private
void
showPictoMainGridView
()
{
this
.
pictoMainGridAdapter
.
clear
();
this
.
pictoMainGridAdapter
.
addAll
(
this
.
sort
(
this
.
vocabulary
.
startSentence
()));
this
.
pictoMainGridAdapter
.
notifyDataSetChanged
();
this
.
pictoMainGridView
.
setEnabled
(
true
);
this
.
pictoCategoryGridView
.
setEnabled
(
false
);
if
(
this
.
pictoMainGridView
.
getAnimation
()
==
this
.
hidePictoMainViewAnimation
)
{
this
.
pictoMainGridView
.
startAnimation
(
this
.
showPictoMainViewAnimation
);
}
this
.
currentCategory
=
null
;
}
/**
* Hides the main category grid view and show a concrete category (this.currentCategory)
*/
private
void
hidePictoMainGridView
()
{
this
.
pictoCategoryGridAdapter
.
clear
();
this
.
pictoCategoryGridAdapter
.
addAll
(
this
.
sort
(
this
.
vocabulary
.
next
(
this
.
getCurrentCategory
())));
this
.
pictoCategoryGridAdapter
.
notifyDataSetChanged
();
if
(
this
.
getCurrentCategory
().
get_color
()
!=
-
1
)
this
.
pictoCategoryGridView
.
setBackgroundColor
(
this
.
getCurrentCategory
().
get_color
());
this
.
pictoMainGridView
.
setEnabled
(
false
);
this
.
pictoCategoryGridView
.
setEnabled
(
true
);
if
(
this
.
pictoMainGridView
.
getAnimation
()
!=
this
.
hidePictoMainViewAnimation
)
{
this
.
pictoMainGridView
.
startAnimation
(
this
.
hidePictoMainViewAnimation
);
}
}
/**
* Returns pictoCategoryGridAdapter or pictoMainGridAdapter depending on the current View
*/
protected
PictoGridAdapter
getCurrentPictoGridAdapter
()
{
return
(
getCurrentCategory
()
==
null
)
?
this
.
pictoMainGridAdapter
:
this
.
pictoCategoryGridAdapter
;
}
/**
* Order a linked list of pictos with "blank spaces" between them
*
* @param list
* @return
*/
public
LinkedList
<
Picto
>
sort
(
LinkedList
<
Picto
>
list
)
{
if
(
list
==
null
)
{
list
=
new
LinkedList
<>();
}
LinkedList
<
Picto
>
ll
=
new
LinkedList
<>();
// This is to show the pictos ordered in the 2D Array that represents the panel
Picto
[][]
mp
=
new
Picto
[
maxRows
][
maxColumns
];
Iterator
<
Picto
>
pictos
=
list
.
iterator
();
while
(
pictos
.
hasNext
())
{
Picto
p
=
pictos
.
next
();
if
(
/*PCBcontext.getPcbdb().getCurrentUser().has_categories()*/
PCBcontext
.
getVocabulary
().
has_categories
())
{
if
(
p
.
get_column
()
!=
-
1
&&
p
.
get_row
()
!=
-
1
&&
p
.
get_column
()
<
maxRows
&&
p
.
get_row
()
<
maxColumns
)
{
mp
[
p
.
get_column
()][
p
.
get_row
()]
=
p
;
}
}
else
{
if
(
p
.
getFreeColumn
()
!=
-
1
&&
p
.
getFreeRow
()
!=
-
1
&&
p
.
getFreeColumn
()
<
maxRows
&&
p
.
getFreeRow
()
<
maxColumns
)
{
mp
[
p
.
getFreeColumn
()][
p
.
getFreeRow
()]
=
p
;
}
}
}
try
{
/*
Picto blankPicto = new Picto(0,
"/symbolstx/color/png/arts_crafts/eraser.png", // TODO Definir imagen para picto en blanco
"Blank picto",
"{\"magnify\":false,\"highlight\":false,\"coord_y\":1,\"id_cat\":12303,\"status\":\"invisible\",\"coord_x\":4}");
*/
for
(
int
i
=
0
;
i
<
maxRows
;
i
++)
for
(
int
j
=
0
;
j
<
maxColumns
;
j
++)
ll
.
add
(
mp
[
i
][
j
]);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
ll
;
}
/**
* Background task that updates the ui into the main thread
*/
public
void
refresh
()
{
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
getCurrentCategory
()
!=
null
)
{
hidePictoMainGridView
();
}
else
{
showPictoMainGridView
();
}
}
});
}
/**
* @TODO check documentation
* De la interfaz iVocabularyListener
*/
@Override
public
void
change
(
action
action
,
int
picto_cat
,
int
picto_id
,
JSONObject
args
)
{
Log
.
i
(
LOG_TAG
,
"Vocabulary action listened: "
+
action
);
if
(
args
!=
null
)
Log
.
d
(
LOG_TAG
,
"args: "
+
args
.
toString
());
refresh
();
}
/**
* Disable Back Button --> Kiosk mode
*/
@Override
public
void
onBackPressed
()
{
// Inflate the layout for the AlertDialog
View
dialogEscape
=
View
.
inflate
(
this
,
R
.
layout
.
dialog_escape
,
null
);
final
CheckBox
checkBox
=
(
CheckBox
)
dialogEscape
.
findViewById
(
R
.
id
.
checkBox
);
final
EditText
input
=
(
EditText
)
dialogEscape
.
findViewById
(
R
.
id
.
editText
);
// Build de AlertDialog
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setTitle
(
getResources
().
getString
(
R
.
string
.
exitPictogram
));
builder
.
setView
(
dialogEscape
);
// Set up the buttons
builder
.
setPositiveButton
(
getResources
().
getString
(
R
.
string
.
ok
),
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
String
m_Text
=
input
.
getText
().
toString
();
String
keyword
=
PCBcontext
.
getDevice
().
getKeyword
();
if
(
m_Text
.
equalsIgnoreCase
(
keyword
))
{
// Change the password
if
(
checkBox
.
isChecked
())
{
// Show a new dialog
View
dialogChangeEscapeCode
=
View
.
inflate
(
PCBcontext
.
getContext
(),
R
.
layout
.
dialog_change_escape_code
,
null
);
final
EditText
input1
=
(
EditText
)
dialogChangeEscapeCode
.
findViewById
(
R
.
id
.
editText1
);
final
EditText
input2
=
(
EditText
)
dialogChangeEscapeCode
.
findViewById
(
R
.
id
.
editText2
);
// Build the AlertDialog
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
PCBcontext
.
getContext
());
builder
.
setTitle
(
PCBcontext
.
getContext
().
getResources
().
getString
(
R
.
string
.
newEscapeCode
));
builder
.
setView
(
dialogChangeEscapeCode
);
// Set up the buttons
builder
.
setPositiveButton
(
getResources
().
getString
(
R
.
string
.
ok
),
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
// Retrieve the text of the 2 password inputs
String
m_Text1
=
input1
.
getText
().
toString
();
String
m_Text2
=
input2
.
getText
().
toString
();
// If they are equal
if
(
m_Text1
.
equalsIgnoreCase
(
m_Text2
))
{
// Change the keyword
PCBcontext
.
getDevice
().
setKeyword
(
m_Text1
);
Toast
.
makeText
(
PCBcontext
.
getContext
(),
getResources
().
getString
(
R
.
string
.
codeModified
),
Toast
.
LENGTH_SHORT
).
show
();
// And exit VOCA
finish
();
}
else
Toast
.
makeText
(
PCBcontext
.
getContext
(),
getResources
().
getString
(
R
.
string
.
codesNotEqual
),
Toast
.
LENGTH_SHORT
).
show
();
}
});
builder
.
setNegativeButton
(
getResources
().
getString
(
R
.
string
.
cancel
),
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
dialog
.
cancel
();
}
});
builder
.
show
();
}
else
{
// Finish this Activity it the code is ok and is not checked the checkbox to change the code
finish
();
/*
// Start the main activity
Intent mainActivity = new Intent(context, MainActivity.class);
startActivity(mainActivity);
*/
}
// Wrong code
}
else
Toast
.
makeText
(
PCBcontext
.
getContext
(),
getResources
().
getString
(
R
.
string
.
wrongCode
),
Toast
.
LENGTH_SHORT
).
show
();
}
});
builder
.
setNegativeButton
(
getResources
().
getString
(
R
.
string
.
cancel
),
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
dialog
.
cancel
();
}
});
builder
.
show
();
}
/**
* Disable long power button press (system menu)
*
* @param hasFocus
*/
@Override
public
void
onWindowFocusChanged
(
boolean
hasFocus
)
{
super
.
onWindowFocusChanged
(
hasFocus
);
if
(
hasFocus
)
{
getWindow
().
getDecorView
().
setSystemUiVisibility
(
View
.
SYSTEM_UI_FLAG_LAYOUT_STABLE
|
View
.
SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
View
.
SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
View
.
SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
View
.
SYSTEM_UI_FLAG_FULLSCREEN
|
View
.
SYSTEM_UI_FLAG_IMMERSIVE_STICKY
);
}
}
/**
* Disable volume button on key event
*
* @param event
*/
@Override
public
boolean
dispatchKeyEvent
(
KeyEvent
event
)
{
if
(
blockedKeys
.
contains
(
event
.
getKeyCode
()))
{
return
true
;
}
else
{
return
super
.
dispatchKeyEvent
(
event
);
}
}
/**
*
* @return
*/
public
Picto
getCurrentCategory
()
{
return
currentCategory
;
}
/* *********************************************************************************************
* Event listener classes
* ********************************************************************************************/
/**
* Class used for dragging pictos to the tape
*/
private
class
OnPictoDragListener
implements
View
.
OnDragListener
{
@Override
public
boolean
onDrag
(
View
v
,
DragEvent
event
)
{
// Handles each of the expected events
switch
(
event
.
getAction
())
{
//signal for the start of a drag and drop operation.
case
DragEvent
.
ACTION_DRAG_STARTED
:
// do nothing
break
;
//the drag point has entered the bounding box of the View
case
DragEvent
.
ACTION_DRAG_ENTERED
:
//v.setBackground(targetShape); //change the shape of the view
break
;
//the user has moved the drag shadow outside the bounding box of the View
case
DragEvent
.
ACTION_DRAG_EXITED
:
//v.setBackground(normalShape); //change the shape of the view back to normal
break
;
//drag shadow has been released,the drag point is within the bounding box of the View
case
DragEvent
.
ACTION_DROP
:
View
view
=
(
View
)
event
.
getLocalState
();
ViewGroup
viewgroup
=
(
ViewGroup
)
view
.
getParent
();
int
position
=
Integer
.
parseInt
((
String
)
event
.
getClipDescription
().
getLabel
());
Log
.
d
(
"Drag:"
,
"Posición: "
+
position
+
" es categoria:"
+
v
.
getTransitionName
()+
" "
+
viewgroup
.
getTransitionName
());
// if the view is the tape_grid_view, we accept the drag item
// Destino tape_grid_view y origen panel_grid_view
if
(
v
==
findViewById
(
R
.
id
.
tape_grid_view
)
&&
(
viewgroup
==
findViewById
(
R
.
id
.
picto_category_grid_view
)
||
viewgroup
==
findViewById
(
R
.
id
.
picto_main_grid_view
)))
{
Picto
p
=
viewgroup
==
findViewById
(
R
.
id
.
picto_category_grid_view
)
?
pictoCategoryGridAdapter
.
getItem
(
position
)
:
pictoMainGridAdapter
.
getItem
(
position
);
if
(!
p
.
is_category
())
addPictoWord
(
view
,
p
);
}
// Si el destino es el panel y el origen la cinta de frase
else
if
(
v
==
findViewById
(
R
.
id
.
picto_category_grid_view
)
&&
viewgroup
==
findViewById
(
R
.
id
.
tape_grid_view
))
{
Picto
p
=
tapeAdapter
.
getItem
(
position
);
tapeAdapter
.
deleteItem
(
position
);
tapeAdapter
.
notifyDataSetChanged
();
getCurrentPictoGridAdapter
().
pictoInGrid
(
p
);
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
}
break
;
//the drag and drop operation has concluded.
case
DragEvent
.
ACTION_DRAG_ENDED
:
// v.setBackground(normalShape); //go back to normal shape
default
:
break
;
}
return
false
;
}
}
/**f
* Class used for picto clicking feedback
*/
private
class
OnPictoClickListener
implements
AdapterView
.
OnItemClickListener
{
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
if
(
inserting
)
return
;
Picto
p
=
getCurrentPictoGridAdapter
().
getItem
(
position
);
if
(
p
!=
null
&&
p
.
get_id
()
!=
0
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
p
.
set_mirror
(
false
,
false
);
// If the picto is a category
if
(
p
.
is_category
())
{
currentCategory
=
p
;
PCBcontext
.
getActionLog
().
log
(
new
TalkAction
(
TalkAction
.
SELECT
,
p
));
hidePictoMainGridView
();
}
else
if
(
tapeAdapter
.
getCount
()
<
VocabularyManager
.
this
.
maxInTape
&&
!
VocabularyManager
.
this
.
tapeAdapter
.
play
())
{
addPictoWord
(
parent
.
getChildAt
(
position
),
p
);
}
}
}
}
/**
*
* @param view
* @param p
*/
private
void
addPictoWord
(
View
view
,
Picto
p
)
{
tapeAdapter
.
addItem
(
p
);
getCurrentPictoGridAdapter
().
pictoInTape
(
view
,
p
);
currentCategory
=
null
;
tapeAdapter
.
notifyDataSetChanged
();
showPictoMainGridView
();
PCBcontext
.
getActionLog
().
log
(
new
TalkAction
(
TalkAction
.
ADD
,
p
));
if
(
VocabularyManager
.
this
.
feedback_read
&&
!
VocabularyManager
.
this
.
tapeAdapter
.
play
()
&&
!
p
.
is_category
())
{
File
audioFile
=
p
.
get_audioFile
();
Log
.
e
(
LOG_TAG
,
"AUDIO:"
+(
audioFile
!=
null
)+
":"
+
p
.
get_audioPath
());
if
(
audioFile
!=
null
)
VocabularyManager
.
this
.
tts
.
playRecord
(
audioFile
);
else
VocabularyManager
.
this
.
tts
.
play
(
p
.
get_translation
());
}
if
(
VocabularyManager
.
this
.
feedback_highlight
)
execHighligthFeeback
(
p
,
false
);
}
/**
*
* @param picto
* @param highlight_background
*/
private
void
execHighligthFeeback
(
final
Picto
picto
,
boolean
highlight_background
)
{
boolean
same_picto
=
false
;
picto
.
set_mirror
(
true
,
highlight_background
);
//comienza feedback
if
(
exec_mirror
!=
null
)
{
//se cancela ejecución del feedbcack anterior, si lo hay
exec_mirror
.
shutdown
();
exec_mirror
=
null
;
}
if
(
prev_picto
!=
null
)
{
//se cancela marca de feedback del anterior, si lo hay
prev_picto
.
set_mirror
(
false
,
false
);
same_picto
=
prev_picto
==
picto
;
}
if
(
same_picto
)
prev_picto
=
null
;
//por si se pulsaa el mismo boton varias veces
else
{
prev_picto
=
picto
;
exec_mirror
=
new
ScheduledThreadPoolExecutor
(
1
);
prev_picto
=
picto
;
exec_mirror
.
scheduleAtFixedRate
(
new
Runnable
()
{
int
repeating
=
0
;
@Override
public
void
run
()
{
refresh
();
if
(
repeating
++
==
20
)
{
picto
.
set_mirror
(
false
,
false
);
if
(
exec_mirror
!=
null
)
{
exec_mirror
.
shutdown
();
exec_mirror
=
null
;
}
}
}
},
0
,
250
,
TimeUnit
.
MILLISECONDS
);
}
}
// TODO: REVISAR
/**
* Class used for long pressing on pictos (start drag)
*/
private
class
OnPictoLongClickListener
implements
AdapterView
.
OnItemLongClickListener
{
public
boolean
onItemLongClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
ClipData
.
Item
item
=
new
ClipData
.
Item
(
""
+
position
);
String
[]
mimeTypes
=
{
ClipDescription
.
MIMETYPE_TEXT_PLAIN
};
ClipData
data
=
new
ClipData
(
""
+
position
,
mimeTypes
,
item
);
Picto
p
=
getCurrentPictoGridAdapter
().
getItem
(
position
);
if
(
p
!=
null
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
// If is not the blank picto, it isn't invisible or disabled
if
(
p
.
get_id
()
!=
0
&&
!
p
.
get_status
().
equalsIgnoreCase
(
"invisible"
)
&&
!
p
.
get_status
().
equalsIgnoreCase
(
"disabled"
)
&&
tapeAdapter
.
getCount
()
<
VocabularyManager
.
this
.
maxInTape
)
{
View
.
DragShadowBuilder
shadowBuilder
=
new
View
.
DragShadowBuilder
(
view
);
view
.
startDrag
(
data
,
//data to be dragged
shadowBuilder
,
//drag shadow
view
,
//local data about the drag and drop operation
0
//no needed flags
);
//view.setVisibility(View.INVISIBLE);
}
}
return
true
;
}
}
/**
* Class used for long click on delete button. When a press count reaches 3, the application
* exists.
*/
private
class
OnDeleteButtonLongClickListener
implements
View
.
OnLongClickListener
{
@Override
public
boolean
onLongClick
(
View
v
)
{
count_deletelong
++;
if
(
count_deletelong
>=
3
)
{
//TODO: COMPROBAR SI LOS USUARIOS QUE BUSCO EXISTEN: SI NO PONER LOS DATOS POR DEFECTO*******************************************************************/
//Cojo los id del ultimo estudiante y el ultimo supervisor
int
lastIdStu
=
PCBcontext
.
getDevice
().
getLastStuId
();
User
actual
=
PCBcontext
.
getPcbdb
().
getCurrentUser
();
User
usuario_anterior
;
String
lastUserName
=
null
;
String
lastPassword
=
null
;
if
(
actual
.
is_supervisor
())
//Si el que habia es supervisor busco el ultimo niño
try
{
usuario_anterior
=
PCBcontext
.
getDevice
().
findUser
(
lastIdStu
,
User
.
NO_SUPERVISOR
);
if
(
usuario_anterior
!=
null
)
{
lastUserName
=
usuario_anterior
.
get_nickname_stu
();
lastPassword
=
usuario_anterior
.
get_pwd_stu
();
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
else
{
int
lastIdSup
=
PCBcontext
.
getDevice
().
getLastSupId
();
try
{
usuario_anterior
=
PCBcontext
.
getDevice
().
findUser
(
lastIdStu
,
lastIdSup
);
if
(
usuario_anterior
!=
null
)
{
lastUserName
=
usuario_anterior
.
get_email_sup
();
lastPassword
=
usuario_anterior
.
get_pwd_sup
();
}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
Intent
serialActivity
=
new
Intent
(
getBaseContext
(),
com
.
yottacode
.
pictogram
.
tabletlibrary
.
gui
.
login
.
SerialActivity
.
class
);
if
(
lastUserName
!=
null
)
{
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"Switch user to "
+
lastUserName
);
serialActivity
.
putExtra
(
"switch_usr"
,
lastUserName
);
serialActivity
.
putExtra
(
"switch_pwd"
,
lastPassword
);
}
pictoCategoryGridAdapter
.
notifyDataSetInvalidated
();
pictoMainGridAdapter
.
notifyDataSetInvalidated
();
VocabularyManager
.
this
.
finish
();
if
(
SessionActivity
.
session
!=
null
)
SessionActivity
.
session
.
finish
();
PCBcontext
.
getNetService
().
restart_app
(
true
);
}
return
true
;
}
}
/**
* Listener used for bringing back the picto categories grid when clicked.
*/
private
class
OnShowPictoCategoriesViewButtonClick
implements
View
.
OnClickListener
{
@Override
public
void
onClick
(
View
v
)
{
showPictoMainGridView
();
}
}
@Override
public
boolean
dispatchTouchEvent
(
MotionEvent
event
)
{
int
in
=
0
,
out
=
0
;
Intent
nextActivity
=
null
;
Intent
intent
=
getIntent
();
if
(
PCBcontext
.
getPcbdb
()
!=
null
&&
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_supervisor
()
)
{
switch
(
event
.
getAction
())
{
case
MotionEvent
.
ACTION_DOWN
:
firstTouchX
=
event
.
getX
();
break
;
case
MotionEvent
.
ACTION_UP
:
if
(
event
.
getX
()
>
firstTouchX
+
150
)
{
// izquierda a derecha
// No action
}
else
if
(
firstTouchX
>
event
.
getX
()
+
150
)
{
//derecha a izquierda
if
(!
PCBcontext
.
getNetService
().
online
())
GUITools
.
show_alert
(
VocabularyManager
.
this
,
R
.
string
.
session_noinet
);
else
nextActivity
=
new
Intent
(
this
,
VocabularyManager
.
class
);
in
=
R
.
anim
.
leftin
;
out
=
R
.
anim
.
leftout
;
}
if
(
nextActivity
!=
null
)
{
tape_delivered
=
false
;
finish
();
startActivity
(
nextActivity
);
overridePendingTransition
(
in
,
out
);
}
break
;
}
}
return
super
.
dispatchTouchEvent
(
event
);
}
/**
* Para capturar el evento para abrir camara o galeria y procesar
* @param requestCode
* @param resultCode
* @param data
*/
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
Bitmap
imagen
;
switch
(
requestCode
)
{
case
CAMERA_PIC_REQUEST:
//Captura de foto
if
(
data
!=
null
&&
resultCode
==
RESULT_OK
)
{
imagen
=
(
Bitmap
)
data
.
getExtras
().
get
(
"data"
);
this
.
launchEditPictoActivity
(
imagen
);
}
break
;
case
GALLERY_PIC_REQUEST:
//Galeria
if
(
data
!=
null
){
Uri
selectedImage
=
data
.
getData
();
Bitmap
bitmap
=
null
;
try
{
bitmap
=
MediaStore
.
Images
.
Media
.
getBitmap
(
this
.
getContentResolver
(),
selectedImage
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
this
.
launchEditPictoActivity
(
bitmap
);
}
break
;
case
EditPictoActivity
.
EDIT_PICTO_REQUEST
:
if
(
resultCode
==
RESULT_OK
)
{
boolean
edit
=
data
.
getBooleanExtra
(
PictoMenu
.
IS_EDIT
,
false
);
int
row
=
edit
?
data
.
getExtras
().
getInt
(
Picto
.
JSON_ATTTRS
.
ROW
)
:
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
ROW
,
-
1
);
int
col
=
edit
?
data
.
getExtras
().
getInt
(
Picto
.
JSON_ATTTRS
.
COLUMN
)
:
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
COLUMN
,
-
1
);
int
freeRow
=
edit
?
data
.
getExtras
().
getInt
(
Picto
.
JSON_ATTTRS
.
FREE_ROW
)
:
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
FREE_ROW
,
-
1
);
int
freeColumn
=
edit
?
data
.
getExtras
().
getInt
(
Picto
.
JSON_ATTTRS
.
FREE_COLUMN
)
:
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
FREE_COLUMN
,
-
1
);
String
path_sound
=
data
.
getExtras
().
getString
(
PictoMenu
.
PATH_SOUND
);
String
user_avatar
=
data
.
getExtras
().
getString
(
Picto
.
JSON_ATTTRS
.
USER_AVATAR
);
int
cat
=
edit
?
data
.
getIntExtra
(
Picto
.
JSON_ATTTRS
.
CATEGORY
,
-
1
)
:
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
CATEGORY
,
-
1
);
String
path
=
data
.
getExtras
().
getString
(
PictoMenu
.
PATH
);
String
legend
=
data
.
getExtras
().
getString
(
Picto
.
JSON_ATTTRS
.
EXPRESSION
);
chooseTextAndSavePicto
(
path
,
row
,
col
,
freeRow
,
freeColumn
,
cat
,
legend
,
path_sound
,
user_avatar
);
refresh
();
}
break
;
}
}
/**
* función para la edición de un texto asociado a una nueva imagen y guardar el nuevo picto
*/
public
void
chooseTextAndSavePicto
(
final
String
selectedImagePath
,
final
int
row
,
final
int
col
,
final
int
freeRow
,
final
int
freeColumn
,
final
int
category
,
final
String
legend
,
final
String
path_sound
,
final
String
user_avatar
)
{
// Set up the buttons
PCBcontext
.
getVocabulary
().
saveLocalPicto
(
selectedImagePath
,
legend
,
category
,
row
,
col
,
freeRow
,
freeColumn
,
user_avatar
,
path_sound
,
new
iLocalPicto
()
{
@Override
public
void
saved
(
Picto
localPicto
)
{
refresh
();
try
{
if
(
PCBcontext
.
is_user_online
())
new
PictoUploader
(
localPicto
).
upload
();
}
catch
(
IOException
e
)
{
Log
.
e
(
Vocabulary
.
class
.
getCanonicalName
(),
e
.
getMessage
());
}
}
});
}
/**Para cambiar la activity de VOCA a EditPictoActivity
* @param image
*/
public
void
launchEditPictoActivity
(
Bitmap
image
){
Intent
intent
=
new
Intent
(
this
,
EditPictoActivity
.
class
);
BitmapTools
.
save_temporal
(
image
);
startActivityForResult
(
intent
,
EditPictoActivity
.
EDIT_PICTO_REQUEST
);
}
}
android/Pictogram/yotta_tablet/src/main/AndroidManifest.xml
View file @
15664a9f
...
@@ -55,6 +55,12 @@
...
@@ -55,6 +55,12 @@
android:label=
"@string/app_name"
android:label=
"@string/app_name"
android:launchMode=
"singleTop"
android:launchMode=
"singleTop"
android:screenOrientation=
"landscape"
/>
android:screenOrientation=
"landscape"
/>
<activity
android:name=
"com.yottacode.pictogram.tabletlibrary.gui.communicator.VocabularyManager"
android:exported=
"true"
android:label=
"@string/app_name"
android:launchMode=
"singleTop"
android:screenOrientation=
"landscape"
/>
<!-- Intent Filter to run the app when the boot is completed -->
<!-- Intent Filter to run the app when the boot is completed -->
<receiver
android:name=
".kiosk.BootReceiver"
>
<receiver
android:name=
".kiosk.BootReceiver"
>
<intent-filter>
<intent-filter>
...
...
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