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
6ab36ce0
authored
Jan 23, 2017
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
working on PictogramActivity refactorization
(class PictoMenu created regarding radial menu)
parent
ac2bd08a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
536 additions
and
540 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/PictogramActivity.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/login/SerialActivity.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/communicator/PictoMenu.java
0 → 100644
View file @
6ab36ce0
package
com
.
yottacode
.
pictogram
.
tabletlibrary
.
gui
.
communicator
;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.database.Cursor
;
import
android.net.Uri
;
import
android.provider.MediaStore
;
import
android.text.InputType
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.inputmethod.InputMethodManager
;
import
android.widget.EditText
;
import
android.widget.ImageButton
;
import
android.widget.ImageView
;
import
android.widget.RelativeLayout
;
import
android.widget.Toast
;
import
com.yottacode.pictogram.action.VocabularyAction
;
import
com.yottacode.pictogram.dao.Picto
;
import
com.yottacode.pictogram.grammar.Vocabulary
;
import
com.yottacode.pictogram.grammar.iLocalPicto
;
import
com.yottacode.pictogram.net.PictoUploader
;
import
com.yottacode.pictogram.tabletlibrary.R
;
import
com.yottacode.pictogram.tools.PCBcontext
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
static
android
.
graphics
.
Color
.
BLACK
;
import
static
android
.
graphics
.
Color
.
argb
;
import
static
android
.
graphics
.
Color
.
rgb
;
/**
* Created by Fernando on 23/01/2017.
*/
public
class
PictoMenu
{
PictogramActivity
activity
;
//Variables used on the picto menu (only supervisors)
private
RadialMenuWidget
PieMenu
;
private
ImageView
detail
;
private
RelativeLayout
ll
;
// TODO describe this variable
static
final
int
SELECT_PICTURE
=
1
;
public
PictoMenu
(
PictogramActivity
activity
)
{
this
.
activity
=
activity
;
}
/**
* add a local picto from pcb
*
* @param row
* @param col
*/
public
void
addPicto
(
int
row
,
int
col
)
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_PICK
);
intent
.
setType
(
"image/*"
);
if
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
has_categories
())
{
activity
.
getIntent
().
putExtra
(
Picto
.
JSON_ATTTRS
.
ROW
,
row
);
activity
.
getIntent
().
putExtra
(
Picto
.
JSON_ATTTRS
.
COLUMN
,
col
);
}
else
{
activity
.
getIntent
().
putExtra
(
Picto
.
JSON_ATTTRS
.
FREE_ROW
,
row
);
activity
.
getIntent
().
putExtra
(
Picto
.
JSON_ATTTRS
.
FREE_COLUMN
,
col
);
}
activity
.
startActivityForResult
(
intent
,
SELECT_PICTURE
);
}
/**
* 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
)
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
activity
);
builder
.
setTitle
(
activity
.
getResources
().
getString
(
R
.
string
.
enterImgLabel
));
// Set up the input
final
EditText
input
=
new
EditText
(
activity
);
input
.
setInputType
(
InputType
.
TYPE_CLASS_TEXT
);
builder
.
setView
(
input
);
// Set up the buttons
builder
.
setPositiveButton
(
"OK"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
int
cat
=
activity
.
currentCategory
!=
null
?
activity
.
currentCategory
.
get_id
()
:
Picto
.
NO_CATEGORY
;
PCBcontext
.
getVocabulary
().
saveLocalPicto
(
selectedImagePath
,
input
.
getText
().
toString
(),
cat
,
row
,
col
,
freeRow
,
freeColumn
,
new
iLocalPicto
()
{
@Override
public
void
saved
(
Picto
localPicto
)
{
activity
.
refresh
();
try
{
if
(
PCBcontext
.
is_user_online
())
new
PictoUploader
(
localPicto
).
upload
(
activity
);
}
catch
(
IOException
e
)
{
Log
.
e
(
Vocabulary
.
class
.
getCanonicalName
(),
e
.
getMessage
());
}
}
});
}
});
builder
.
show
();
}
/**
* Función para la selección de una foto del carrete
*
* @param requestCode
* @param resultCode
* @param data
*/
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
if
(
requestCode
==
SELECT_PICTURE
)
{
String
selectedImagePath
;
Uri
selectedImageUri
=
data
.
getData
();
selectedImagePath
=
getPath
(
selectedImageUri
);
int
row
=
activity
.
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
ROW
,
-
1
);
int
col
=
activity
.
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
COLUMN
,
-
1
);
int
freeRow
=
activity
.
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
FREE_ROW
,
-
1
);
int
freeColumn
=
activity
.
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
FREE_COLUMN
,
-
1
);
Log
.
i
(
activity
.
getClass
().
getCanonicalName
(),
"0 Picto x y "
+
" "
+
row
+
" "
+
col
);
activity
.
getIntent
().
removeExtra
(
Picto
.
JSON_ATTTRS
.
ROW
);
activity
.
getIntent
().
removeExtra
(
Picto
.
JSON_ATTTRS
.
COLUMN
);
activity
.
getIntent
().
removeExtra
(
Picto
.
JSON_ATTTRS
.
FREE_ROW
);
activity
.
getIntent
().
removeExtra
(
Picto
.
JSON_ATTTRS
.
FREE_COLUMN
);
chooseTextAndSavePicto
(
selectedImagePath
,
row
,
col
,
freeRow
,
freeColumn
);
}
}
}
/**
* Función para la selección de una foto del carrete
*
* @param uri
* @return
*/
static
public
String
getPath
(
Uri
uri
)
{
if
(
uri
==
null
)
{
return
null
;
}
// this will only work for images selected from gallery
String
[]
projection
=
{
MediaStore
.
Images
.
Media
.
DATA
};
Cursor
cursor
=
PCBcontext
.
getContext
().
getContentResolver
().
query
(
uri
,
projection
,
null
,
null
,
null
);
if
(
cursor
!=
null
)
{
int
column_index
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
);
cursor
.
moveToFirst
();
return
cursor
.
getString
(
column_index
);
}
return
uri
.
getPath
();
}
/**Function for open a new View for change the expression of a picto
*
* @param picto
*/
public
void
createViewForExpression
(
final
Picto
picto
){
ll
=
new
RelativeLayout
(
PCBcontext
.
getContext
());
RelativeLayout
.
LayoutParams
params
=
new
RelativeLayout
.
LayoutParams
(
RelativeLayout
.
LayoutParams
.
MATCH_PARENT
,
RelativeLayout
.
LayoutParams
.
MATCH_PARENT
);
activity
.
addContentView
(
ll
,
params
);
ll
.
setBackgroundColor
(
argb
(
180
,
0
,
0
,
0
));
ll
.
setClickable
(
false
);
//Parameters for hide navigation bar when u save or cancel
final
View
decorView
=
activity
.
getWindow
().
getDecorView
();
final
int
uiOptions
=
View
.
SYSTEM_UI_FLAG_HIDE_NAVIGATION
/*| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE*/
;
final
EditText
leyenda
=
new
EditText
(
PCBcontext
.
getContext
());
leyenda
.
setBackgroundColor
(
rgb
(
221
,
221
,
211
));
leyenda
.
setWidth
(
400
);
leyenda
.
setMaxLines
(
1
);
leyenda
.
setClickable
(
true
);
leyenda
.
setTextSize
(
25
);
leyenda
.
setX
(
activity
.
getResources
().
getDisplayMetrics
().
widthPixels
/
2
-
300
);
leyenda
.
setY
(
activity
.
getResources
().
getDisplayMetrics
().
heightPixels
/
2
-
50
);
leyenda
.
setTextColor
(
BLACK
);
if
(
picto
.
get_translation
()!=
null
&&
picto
!=
null
){
leyenda
.
setText
(
picto
.
get_translation
());
}
else
{
leyenda
.
setText
(
"Sin Descripción"
);
}
//Mostrar teclado automaticamente
final
InputMethodManager
imm
=
(
InputMethodManager
)
activity
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
ImageButton
botonOk
=
new
ImageButton
(
PCBcontext
.
getContext
());
botonOk
.
setImageResource
(
android
.
R
.
drawable
.
ic_menu_save
);
botonOk
.
setX
(
activity
.
getResources
().
getDisplayMetrics
().
widthPixels
/
2
+
110
);
botonOk
.
setY
(
activity
.
getResources
().
getDisplayMetrics
().
heightPixels
/
2
-
50
);
botonOk
.
setBackgroundColor
(
rgb
(
221
,
221
,
221
));
botonOk
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
picto
.
set_translation
(
leyenda
.
getText
().
toString
());
imm
.
hideSoftInputFromWindow
(
leyenda
.
getWindowToken
(),
0
);
picto
.
set_local_status
(
true
);
if
(!
picto
.
is_local
())
{
new
PictoUploader
(
picto
).
uploadState
();
PCBcontext
.
getActionLog
().
log
(
new
VocabularyAction
(
VocabularyAction
.
ALTERATTRS
,
picto
));
}
activity
.
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
ll
.
setVisibility
(
View
.
GONE
);
ll
.
removeAllViewsInLayout
();
//Hide navigation bar
//activity.refresh();
decorView
.
setSystemUiVisibility
(
uiOptions
);
}
});
ImageButton
botonSalir
=
new
ImageButton
(
PCBcontext
.
getContext
());
botonSalir
.
setImageResource
(
android
.
R
.
drawable
.
ic_menu_close_clear_cancel
);
botonSalir
.
setX
(
activity
.
getResources
().
getDisplayMetrics
().
widthPixels
/
2
+
150
);
botonSalir
.
setY
(
activity
.
getResources
().
getDisplayMetrics
().
heightPixels
/
2
-
50
);
botonSalir
.
setBackgroundColor
(
rgb
(
221
,
221
,
221
));
botonSalir
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
imm
.
hideSoftInputFromWindow
(
leyenda
.
getWindowToken
(),
0
);
ll
.
setVisibility
(
View
.
GONE
);
ll
.
removeAllViewsInLayout
();
//Hide navigation bar
//activity.refresh();
decorView
.
setSystemUiVisibility
(
uiOptions
);
}
});
ll
.
addView
(
leyenda
);
ll
.
addView
(
botonOk
);
ll
.
addView
(
botonSalir
);
leyenda
.
requestFocus
();
imm
.
showSoftInput
(
leyenda
,
InputMethodManager
.
SHOW_FORCED
);
}
/**Function for build a radial menu
*
* @param is_picto_big
* @param picto
*/
public
void
createMenuForPicto
(
boolean
is_picto_big
,
Picto
picto
){
ll
=
new
RelativeLayout
(
PCBcontext
.
getContext
());
RelativeLayout
.
LayoutParams
params
=
new
RelativeLayout
.
LayoutParams
(
RelativeLayout
.
LayoutParams
.
MATCH_PARENT
,
RelativeLayout
.
LayoutParams
.
MATCH_PARENT
);
activity
.
addContentView
(
ll
,
params
);
ll
.
setBackgroundColor
(
argb
(
180
,
0
,
0
,
0
));
detail
=
new
ImageView
(
PCBcontext
.
getContext
());
int
centerX
=
activity
.
getResources
().
getDisplayMetrics
().
widthPixels
/
2
;
int
centerY
=
activity
.
getResources
().
getDisplayMetrics
().
heightPixels
/
2
;
if
(!
is_picto_big
){
centerY
+=
100
;
detail
.
setMaxWidth
(
90
);
}
else
{
centerY
+=
135
;
detail
.
setMaxWidth
(
115
);
}
PieMenu
=
new
RadialMenuWidget
(
PCBcontext
.
getContext
());
PieMenu
.
setAnimationSpeed
(
0L
);
PieMenu
.
setCenterLocation
(
centerX
-
(
PieMenu
.
getcRadius
()*
2
)
-
50
,
centerY
-(
PieMenu
.
getcRadius
()*
2
));
PieMenu
.
setIconSize
(
20
,
35
);
//Tamaño del icono
PieMenu
.
setCenterCircle
(
new
Close
(
picto
));
PieMenu
.
addMenuEntry
(
new
UnlockPictoMenu
(
picto
));
PieMenu
.
addMenuEntry
(
new
DisablePictoMenu
(
picto
));
PieMenu
.
addMenuEntry
(
new
SetInvisibleMenu
(
picto
));
//PieMenu.addMenuEntry(new EditMenu(picto));
ll
.
addView
(
PieMenu
);
try
{
detail
.
setImageBitmap
(
picto
.
get_bitmap
(
PCBcontext
.
getContext
()));
detail
.
setBackgroundColor
(
picto
.
get_color
());
detail
.
setX
(
centerX
+
10
);
detail
.
setY
(
centerY
-
(
picto
.
get_bitmap
(
PCBcontext
.
getContext
()).
getHeight
()));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
ll
.
addView
(
detail
);
}
/** Menu of picto classes */
//Close menu button
public
class
Close
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
Close
(
Picto
picto
){
p
=
picto
;
}
public
String
getName
()
{
return
"Close"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
android
.
R
.
drawable
.
ic_menu_close_clear_cancel
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
//Metodo para realizar acciones si se pulsa
public
void
menuActiviated
()
{
ll
.
setVisibility
(
View
.
GONE
);
((
RelativeLayout
)
PieMenu
.
getParent
()).
removeView
(
PieMenu
);
}
public
void
menuDisabled
(){}
}
//Disable menu button
public
class
DisablePictoMenu
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
DisablePictoMenu
(
Picto
picto
){
p
=
picto
;
}
public
String
getName
()
{
return
"disable"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
disabled_picto
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
public
void
menuActiviated
()
{
p
.
alter_status
(
"disabled"
);
activity
.
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
ll
.
setVisibility
(
View
.
GONE
);
((
RelativeLayout
)
PieMenu
.
getParent
()).
removeView
(
PieMenu
);
}
public
void
menuDisabled
(){}
}
//Change image of picto menu button
public
class
SetInvisibleMenu
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
SetInvisibleMenu
(
Picto
picto
){
p
=
picto
;
}
public
String
getName
()
{
return
"invisible"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
eye_blocked
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
public
void
menuActiviated
()
{
p
.
alter_status
(
"invisible"
);
activity
.
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
ll
.
setVisibility
(
View
.
GONE
);
((
RelativeLayout
)
PieMenu
.
getParent
()).
removeView
(
PieMenu
);
}
public
void
menuDisabled
(){}
}
//Activate/enable picto on vocabulary menu button
public
class
UnlockPictoMenu
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
UnlockPictoMenu
(
Picto
picto
){
p
=
picto
;
}
public
String
getName
()
{
return
"enable"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
unlock
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
public
void
menuActiviated
()
{
p
.
alter_status
(
"enabled"
);
activity
.
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
ll
.
setVisibility
(
View
.
GONE
);
((
RelativeLayout
)
PieMenu
.
getParent
()).
removeView
(
PieMenu
);
}
public
void
menuDisabled
(){}
}
//Edit menu button
public
class
EditMenu
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
EditMenu
(
Picto
picto
){
p
=
picto
;
}
public
String
getName
()
{
return
"edit"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
edit
;
}
private
List
<
RadialMenuWidget
.
RadialMenuEntry
>
children
;
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
children
;
}
public
void
menuActiviated
()
{
ll
.
getChildAt
(
1
).
setX
(
ll
.
getChildAt
(
1
).
getX
()
+
30
);
children
=
new
ArrayList
<>(
Arrays
.
asList
(
new
EditTextPicto
(
p
),
new
EditImage
(
p
)));
}
public
void
menuDisabled
(){
ll
.
getChildAt
(
1
).
setX
(
ll
.
getChildAt
(
1
).
getX
()
-
30
);
}
}
//Edit legend text of picto button
public
class
EditTextPicto
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
EditTextPicto
(
Picto
picto
){
p
=
picto
;
}
public
String
getName
()
{
return
"editText"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
edit_text
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
public
void
menuActiviated
()
{
ll
.
setVisibility
(
View
.
GONE
);
ll
.
removeAllViewsInLayout
();
createViewForExpression
(
p
);
}
public
void
menuDisabled
(){}
}
public
class
EditImage
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
EditImage
(
Picto
picto
){
p
=
picto
;
}
public
String
getName
()
{
return
"editImage"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
edit_picture
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
public
void
menuActiviated
()
{
/**TODO: Llamar a la interfaz de editar foto*/
Toast
.
makeText
(
PCBcontext
.
getContext
(),
"Editar Imagen"
,
Toast
.
LENGTH_SHORT
).
show
();
}
public
void
menuDisabled
(){}
}
}
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/communicator/PictogramActivity.java
View file @
6ab36ce0
...
@@ -11,7 +11,6 @@ import android.content.ClipDescription;
...
@@ -11,7 +11,6 @@ import android.content.ClipDescription;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.DialogInterface
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.database.Cursor
;
import
android.graphics.Color
;
import
android.graphics.Color
;
import
android.graphics.PixelFormat
;
import
android.graphics.PixelFormat
;
import
android.graphics.PorterDuff
;
import
android.graphics.PorterDuff
;
...
@@ -20,10 +19,8 @@ import android.media.RingtoneManager;
...
@@ -20,10 +19,8 @@ import android.media.RingtoneManager;
import
android.net.Uri
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.provider.MediaStore
;
import
android.speech.tts.UtteranceProgressListener
;
import
android.speech.tts.UtteranceProgressListener
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.text.InputType
;
import
android.util.DisplayMetrics
;
import
android.util.DisplayMetrics
;
import
android.util.Log
;
import
android.util.Log
;
import
android.view.DragEvent
;
import
android.view.DragEvent
;
...
@@ -38,7 +35,6 @@ import android.view.WindowManager;
...
@@ -38,7 +35,6 @@ import android.view.WindowManager;
import
android.view.animation.AccelerateDecelerateInterpolator
;
import
android.view.animation.AccelerateDecelerateInterpolator
;
import
android.view.animation.Animation
;
import
android.view.animation.Animation
;
import
android.view.animation.TranslateAnimation
;
import
android.view.animation.TranslateAnimation
;
import
android.view.inputmethod.InputMethodManager
;
import
android.widget.AdapterView
;
import
android.widget.AdapterView
;
import
android.widget.CheckBox
;
import
android.widget.CheckBox
;
import
android.widget.EditText
;
import
android.widget.EditText
;
...
@@ -51,13 +47,10 @@ import android.widget.Toast;
...
@@ -51,13 +47,10 @@ import android.widget.Toast;
import
com.yottacode.pictogram.action.PictosAction
;
import
com.yottacode.pictogram.action.PictosAction
;
import
com.yottacode.pictogram.action.TalkAction
;
import
com.yottacode.pictogram.action.TalkAction
;
import
com.yottacode.pictogram.action.VocabularyAction
;
import
com.yottacode.pictogram.dao.Picto
;
import
com.yottacode.pictogram.dao.Picto
;
import
com.yottacode.pictogram.dao.User
;
import
com.yottacode.pictogram.dao.User
;
import
com.yottacode.pictogram.grammar.Vocabulary
;
import
com.yottacode.pictogram.grammar.Vocabulary
;
import
com.yottacode.pictogram.grammar.iLocalPicto
;
import
com.yottacode.pictogram.net.ImgDownloader
;
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.ActionTalk
;
import
com.yottacode.pictogram.net.websockets.VocabularyTalk
;
import
com.yottacode.pictogram.net.websockets.VocabularyTalk
;
import
com.yottacode.pictogram.tabletlibrary.R
;
import
com.yottacode.pictogram.tabletlibrary.R
;
...
@@ -71,7 +64,6 @@ import com.yottacode.pictogram.tts.TTSHelper;
...
@@ -71,7 +64,6 @@ import com.yottacode.pictogram.tts.TTSHelper;
import
org.json.JSONException
;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.json.JSONObject
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.LinkedList
;
import
java.util.LinkedList
;
...
@@ -80,13 +72,11 @@ import java.util.Locale;
...
@@ -80,13 +72,11 @@ import java.util.Locale;
import
java.util.concurrent.ScheduledThreadPoolExecutor
;
import
java.util.concurrent.ScheduledThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
static
android
.
graphics
.
Color
.
BLACK
;
import
static
android
.
graphics
.
Color
.
argb
;
import
static
android
.
graphics
.
Color
.
argb
;
import
static
android
.
graphics
.
Color
.
rgb
;
public
class
PictogramActivity
extends
Activity
implements
VocabularyTalk
.
iVocabularyListener
{
public
class
PictogramActivity
extends
Activity
implements
VocabularyTalk
.
iVocabularyListener
{
float
firstTouchX
=
-
1
;
// Main layout for this activity
// Main layout for this activity
RelativeLayout
mainLayout
;
RelativeLayout
mainLayout
;
// Adapter for de grid showing the categories grid (and main pictos)
// Adapter for de grid showing the categories grid (and main pictos)
...
@@ -107,8 +97,6 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
...
@@ -107,8 +97,6 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
TTSHelper
tts
;
TTSHelper
tts
;
// Element used for loading new pictos (while changing categories)
// Element used for loading new pictos (while changing categories)
Vocabulary
vocabulary
;
Vocabulary
vocabulary
;
// TODO describe this variable
static
final
int
SELECT_PICTURE
=
1
;
// For disabling volume button (See method at the end of the class)
// 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
));
private
final
List
blockedKeys
=
new
ArrayList
(
Arrays
.
asList
(
KeyEvent
.
KEYCODE_VOLUME_DOWN
,
KeyEvent
.
KEYCODE_VOLUME_UP
));
// String constant for logs
// String constant for logs
...
@@ -131,12 +119,9 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
...
@@ -131,12 +119,9 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
private
boolean
feedback_highlight
;
private
boolean
feedback_highlight
;
private
boolean
deleting
;
private
boolean
deleting
;
//Variables used on the picto menu (only supervisors)
private
RadialMenuWidget
PieMenu
;
private
ImageView
detail
;
private
RelativeLayout
ll
;
private
boolean
tape_delivered
=
false
;
private
boolean
tape_delivered
=
false
;
float
firstTouchX
=
-
1
;
@TargetApi
(
Build
.
VERSION_CODES
.
M
)
@TargetApi
(
Build
.
VERSION_CODES
.
M
)
@Override
@Override
...
@@ -475,15 +460,13 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
...
@@ -475,15 +460,13 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
*/
*/
private
void
hidePictoMainGridView
()
{
private
void
hidePictoMainGridView
()
{
if
(!
tape_delivered
)
{
this
.
pictoCategoryGridAdapter
.
clear
();
this
.
pictoCategoryGridAdapter
.
clear
();
this
.
pictoCategoryGridAdapter
.
addAll
(
this
.
sort
(
this
.
vocabulary
.
next
(
this
.
currentCategory
)));
this
.
pictoCategoryGridAdapter
.
addAll
(
this
.
sort
(
this
.
vocabulary
.
next
(
this
.
currentCategory
)));
this
.
pictoCategoryGridAdapter
.
notifyDataSetChanged
();
this
.
pictoCategoryGridAdapter
.
notifyDataSetChanged
();
if
(
this
.
currentCategory
.
get_color
()
!=
-
1
)
this
.
pictoCategoryGridView
.
setBackgroundColor
(
this
.
currentCategory
.
get_color
());
if
(
this
.
currentCategory
.
get_color
()
!=
-
1
)
{
this
.
pictoCategoryGridView
.
setBackgroundColor
(
this
.
currentCategory
.
get_color
());
}
}
this
.
pictoMainGridView
.
setEnabled
(
false
);
this
.
pictoMainGridView
.
setEnabled
(
false
);
this
.
pictoCategoryGridView
.
setEnabled
(
true
);
this
.
pictoCategoryGridView
.
setEnabled
(
true
);
...
@@ -495,7 +478,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
...
@@ -495,7 +478,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
/**
/**
* Returns pictoCategoryGridAdapter or pictoMainGridAdapter depending on the current View
* Returns pictoCategoryGridAdapter or pictoMainGridAdapter depending on the current View
*/
*/
pr
ivate
PictoGridAdapter
getCurrentPictoGridAdapter
()
{
pr
otected
PictoGridAdapter
getCurrentPictoGridAdapter
()
{
return
(
currentCategory
==
null
)
?
this
.
pictoMainGridAdapter
:
this
.
pictoCategoryGridAdapter
;
return
(
currentCategory
==
null
)
?
this
.
pictoMainGridAdapter
:
this
.
pictoCategoryGridAdapter
;
}
}
...
@@ -773,7 +756,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
...
@@ -773,7 +756,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
@Override
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
Picto
p
=
getCurrentPictoGridAdapter
().
getItem
(
position
);
Picto
p
=
getCurrentPictoGridAdapter
().
getItem
(
position
);
Log
.
e
(
"clicklistener"
,
p
+(
p
==
null
?
"NULL"
:
p
.
toString
()+
" "
+
p
.
get_row
()));
if
(
p
!=
null
&&
p
.
get_id
()
!=
0
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
if
(
p
!=
null
&&
p
.
get_id
()
!=
0
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
p
.
set_mirror
(
false
,
false
);
p
.
set_mirror
(
false
,
false
);
...
@@ -787,10 +770,7 @@ Log.e("clicklistener",p+(p==null ? "NULL" : p.toString()+" "+p.get_row()));
...
@@ -787,10 +770,7 @@ Log.e("clicklistener",p+(p==null ? "NULL" : p.toString()+" "+p.get_row()));
addPictoWord
(
p
);
addPictoWord
(
p
);
}
}
}
}
if
(
tape_delivered
)
{
tapeAdapter
.
clear
();
showOnlyTape
(
false
);
}
}
}
}
}
...
@@ -853,20 +833,14 @@ Log.e("clicklistener",p+(p==null ? "NULL" : p.toString()+" "+p.get_row()));
...
@@ -853,20 +833,14 @@ Log.e("clicklistener",p+(p==null ? "NULL" : p.toString()+" "+p.get_row()));
if
(
currentCategory
!=
null
||
!
PCBcontext
.
getPcbdb
().
getCurrentUser
().
has_categories
())
{
if
(
currentCategory
!=
null
||
!
PCBcontext
.
getPcbdb
().
getCurrentUser
().
has_categories
())
{
Log
.
d
(
LOG_TAG
,
"No tengo pictograma. Abro carrete..."
);
Log
.
d
(
LOG_TAG
,
"No tengo pictograma. Abro carrete..."
);
addPicto
(
position
%
maxColumns
,
(
int
)
(
position
/
maxColumns
));
new
PictoMenu
(
PictogramActivity
.
this
).
addPicto
(
position
%
maxColumns
,
(
int
)
(
position
/
maxColumns
));
}
else
}
else
Toast
.
makeText
(
PictogramActivity
.
this
,
PictogramActivity
.
this
.
getResources
().
getString
(
R
.
string
.
notNewCats
),
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
PictogramActivity
.
this
,
PictogramActivity
.
this
.
getResources
().
getString
(
R
.
string
.
notNewCats
),
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
}
else
{
//Si es supervisor hacer aparecer el menú de opciones del picto
//Si es supervisor hacer aparecer el menú de opciones del picto
View
pictoSquare
=
getCurrentPictoGridAdapter
().
getView
(
position
,
view
,
parent
);
new
PictoMenu
(
PictogramActivity
.
this
).
createMenuForPicto
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_picto_size_big
(),
p
);
if
(
pictoSquare
.
getWidth
()
==
100
){
//Si esta en formato de pictos normal
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
createMenuForPicto
(
0
,
p
);
}
else
{
createMenuForPicto
(
1
,
p
);
}
//p.alter_status();
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
}
}
}
else
{
}
else
{
ClipData
.
Item
item
=
new
ClipData
.
Item
(
""
+
position
);
ClipData
.
Item
item
=
new
ClipData
.
Item
(
""
+
position
);
...
@@ -908,8 +882,6 @@ Log.e("clicklistener",p+(p==null ? "NULL" : p.toString()+" "+p.get_row()));
...
@@ -908,8 +882,6 @@ Log.e("clicklistener",p+(p==null ? "NULL" : p.toString()+" "+p.get_row()));
tapeAdapter
.
ttsAllNew
(
tts
);
tapeAdapter
.
ttsAllNew
(
tts
);
if
(!
PCBcontext
.
getPcbdb
().
getCurrentUser
().
delete_tape_after_delivery
())
{
if
(!
PCBcontext
.
getPcbdb
().
getCurrentUser
().
delete_tape_after_delivery
())
{
showOnlyTape
(
true
);
showOnlyTape
(
true
);
animateTapeView
(
0
,(
ViewGroup
)
arg0
.
getParent
());
}
}
}
}
}
}
...
@@ -918,16 +890,40 @@ Log.e("clicklistener",p+(p==null ? "NULL" : p.toString()+" "+p.get_row()));
...
@@ -918,16 +890,40 @@ Log.e("clicklistener",p+(p==null ? "NULL" : p.toString()+" "+p.get_row()));
private
void
showOnlyTape
(
boolean
onlyTape
)
{
private
void
showOnlyTape
(
boolean
onlyTape
)
{
this
.
tape_delivered
=
onlyTape
;
this
.
tape_delivered
=
onlyTape
;
if
(
onlyTape
)
{
if
(
onlyTape
)
{
hidePictoMainGridView
();
ttsButton
.
setEnabled
(
false
);
this
.
pictoCategoryGridAdapter
.
clear
();
if
(
this
.
pictoMainGridView
.
getAnimation
()
!=
this
.
hidePictoMainViewAnimation
)
{
this
.
pictoCategoryGridAdapter
.
addAll
(
this
.
sort
(
null
));
this
.
showPictoCategoriesViewButton
.
setVisibility
(
View
.
INVISIBLE
);
this
.
pictoCategoryGridAdapter
.
notifyDataSetChanged
();
this
.
pictoCategoryGridView
.
setVisibility
(
View
.
INVISIBLE
);
this
.
pictoCategoryGridView
.
setBackgroundColor
(
Color
.
WHITE
);
this
.
pictoMainGridView
.
setAlpha
(
0.25f
);
this
.
showPictoCategoriesViewButton
.
setVisibility
(
View
.
GONE
);
this
.
pictoMainGridView
.
setEnabled
(
false
);
}
else
{
this
.
pictoCategoryGridView
.
setAlpha
(
0.25f
);
this
.
pictoCategoryGridView
.
setEnabled
(
false
);
this
.
showPictoCategoriesViewButton
.
setAlpha
(
0
f
);
}
animateTapeViewVertical
(
false
);
}
}
else
{
else
{
this
.
showPictoCategoriesViewButton
.
setVisibility
(
View
.
VISIBLE
);
ttsButton
.
setEnabled
(
true
);
showPictoMainGridView
();
animateTapeViewVertical
(
true
);
if
(
this
.
pictoMainGridView
.
getAnimation
()
!=
this
.
hidePictoMainViewAnimation
)
{
this
.
showPictoCategoriesViewButton
.
setVisibility
(
View
.
VISIBLE
);
this
.
pictoCategoryGridView
.
setVisibility
(
View
.
VISIBLE
);
this
.
pictoMainGridView
.
setAlpha
(
1
f
);
this
.
pictoMainGridView
.
setEnabled
(
true
);
this
.
showPictoCategoriesViewButton
.
setAlpha
(
1
f
);
}
else
{
this
.
pictoCategoryGridView
.
setAlpha
(
1
f
);
this
.
pictoCategoryGridView
.
setEnabled
(
true
);
this
.
showPictoCategoriesViewButton
.
setAlpha
(
1
f
);
}
}
}
}
}
...
@@ -1027,139 +1023,11 @@ private void showOnlyTape(boolean onlyTape) {
...
@@ -1027,139 +1023,11 @@ private void showOnlyTape(boolean onlyTape) {
}
}
}
}
/* *********************************************************************************************
* Methods for adding a new picto from pcb
* ********************************************************************************************/
/**
* add a local picto from pcb
*
* @param row
* @param col
*/
public
void
addPicto
(
int
row
,
int
col
)
{
Intent
intent
=
new
Intent
(
Intent
.
ACTION_PICK
);
intent
.
setType
(
"image/*"
);
if
(
PCBcontext
.
getPcbdb
().
getCurrentUser
().
has_categories
())
{
this
.
getIntent
().
putExtra
(
Picto
.
JSON_ATTTRS
.
ROW
,
row
);
this
.
getIntent
().
putExtra
(
Picto
.
JSON_ATTTRS
.
COLUMN
,
col
);
}
else
{
this
.
getIntent
().
putExtra
(
Picto
.
JSON_ATTTRS
.
FREE_ROW
,
row
);
this
.
getIntent
().
putExtra
(
Picto
.
JSON_ATTTRS
.
FREE_COLUMN
,
col
);
}
startActivityForResult
(
intent
,
SELECT_PICTURE
);
}
/**
* 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
)
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
builder
.
setTitle
(
getResources
().
getString
(
R
.
string
.
enterImgLabel
));
// Set up the input
final
EditText
input
=
new
EditText
(
this
);
input
.
setInputType
(
InputType
.
TYPE_CLASS_TEXT
);
builder
.
setView
(
input
);
// Set up the buttons
builder
.
setPositiveButton
(
"OK"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
int
cat
=
PictogramActivity
.
this
.
currentCategory
!=
null
?
PictogramActivity
.
this
.
currentCategory
.
get_id
()
:
Picto
.
NO_CATEGORY
;
PCBcontext
.
getVocabulary
().
saveLocalPicto
(
selectedImagePath
,
input
.
getText
().
toString
(),
cat
,
row
,
col
,
freeRow
,
freeColumn
,
new
iLocalPicto
()
{
@Override
public
void
saved
(
Picto
localPicto
)
{
PictogramActivity
.
this
.
refresh
();
try
{
if
(
PCBcontext
.
is_user_online
())
new
PictoUploader
(
localPicto
).
upload
(
PictogramActivity
.
this
);
}
catch
(
IOException
e
)
{
Log
.
e
(
Vocabulary
.
class
.
getCanonicalName
(),
e
.
getMessage
());
}
}
});
}
});
builder
.
show
();
}
/**
* Función para la selección de una foto del carrete
*
* @param requestCode
* @param resultCode
* @param data
*/
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
if
(
resultCode
==
Activity
.
RESULT_OK
)
{
if
(
requestCode
==
SELECT_PICTURE
)
{
String
selectedImagePath
;
Uri
selectedImageUri
=
data
.
getData
();
selectedImagePath
=
getPath
(
selectedImageUri
);
int
row
=
this
.
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
ROW
,
-
1
);
int
col
=
this
.
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
COLUMN
,
-
1
);
int
freeRow
=
this
.
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
FREE_ROW
,
-
1
);
int
freeColumn
=
this
.
getIntent
().
getIntExtra
(
Picto
.
JSON_ATTTRS
.
FREE_COLUMN
,
-
1
);
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"0 Picto x y "
+
" "
+
row
+
" "
+
col
);
this
.
getIntent
().
removeExtra
(
Picto
.
JSON_ATTTRS
.
ROW
);
this
.
getIntent
().
removeExtra
(
Picto
.
JSON_ATTTRS
.
COLUMN
);
this
.
getIntent
().
removeExtra
(
Picto
.
JSON_ATTTRS
.
FREE_ROW
);
this
.
getIntent
().
removeExtra
(
Picto
.
JSON_ATTTRS
.
FREE_COLUMN
);
chooseTextAndSavePicto
(
selectedImagePath
,
row
,
col
,
freeRow
,
freeColumn
);
}
}
}
/**
* Función para la selección de una foto del carrete
*
* @param uri
* @return
*/
static
public
String
getPath
(
Uri
uri
)
{
if
(
uri
==
null
)
{
return
null
;
}
// this will only work for images selected from gallery
String
[]
projection
=
{
MediaStore
.
Images
.
Media
.
DATA
};
Cursor
cursor
=
PCBcontext
.
getContext
().
getContentResolver
().
query
(
uri
,
projection
,
null
,
null
,
null
);
if
(
cursor
!=
null
)
{
int
column_index
=
cursor
.
getColumnIndexOrThrow
(
MediaStore
.
Images
.
Media
.
DATA
);
cursor
.
moveToFirst
();
return
cursor
.
getString
(
column_index
);
}
return
uri
.
getPath
();
}
@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
);
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
()
||
student_view
)
)
{
switch
(
event
.
getAction
())
{
switch
(
event
.
getAction
())
{
...
@@ -1167,9 +1035,7 @@ private void showOnlyTape(boolean onlyTape) {
...
@@ -1167,9 +1035,7 @@ private void showOnlyTape(boolean onlyTape) {
firstTouchX
=
event
.
getX
();
firstTouchX
=
event
.
getX
();
break
;
break
;
case
MotionEvent
.
ACTION_UP
:
case
MotionEvent
.
ACTION_UP
:
if
(
this
.
tape_delivered
)
if
(
event
.
getX
()
>
firstTouchX
+
100
)
{
//izquierda a derecha
showOnlyTape
(
false
);
if
(
event
.
getX
()
>
firstTouchX
+
100
)
{
//izquierda a derecha
if
(!
student_view
)
{
if
(!
student_view
)
{
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_Img_sup
().
update_id
(
User
.
NO_SUPERVISOR
);
PCBcontext
.
getPcbdb
().
getCurrentUser
().
get_Img_sup
().
update_id
(
User
.
NO_SUPERVISOR
);
nextActivity
=
intent
;
nextActivity
=
intent
;
...
@@ -1191,6 +1057,7 @@ private void showOnlyTape(boolean onlyTape) {
...
@@ -1191,6 +1057,7 @@ private void showOnlyTape(boolean onlyTape) {
out
=
R
.
anim
.
leftout
;
out
=
R
.
anim
.
leftout
;
}
}
if
(
nextActivity
!=
null
)
{
if
(
nextActivity
!=
null
)
{
tape_delivered
=
false
;
intent
.
putExtra
(
"student_view"
,
!
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_supervisor
());
intent
.
putExtra
(
"student_view"
,
!
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_supervisor
());
finish
();
finish
();
startActivity
(
nextActivity
);
startActivity
(
nextActivity
);
...
@@ -1207,7 +1074,7 @@ private void showOnlyTape(boolean onlyTape) {
...
@@ -1207,7 +1074,7 @@ private void showOnlyTape(boolean onlyTape) {
public
void
animateImageView
(
View
view
,
final
int
position
)
{
public
void
animateImageView
(
View
view
,
final
int
position
)
{
if
(
PictogramActivity
.
this
.
deleting
)
return
;
if
(
deleting
)
return
;
View
borderlayout
=((
RelativeLayout
)
view
).
getChildAt
(
0
);
View
borderlayout
=((
RelativeLayout
)
view
).
getChildAt
(
0
);
final
ImageView
v
=((
ImageView
)((
FrameLayout
)
borderlayout
).
getChildAt
(
0
));
final
ImageView
v
=((
ImageView
)((
FrameLayout
)
borderlayout
).
getChildAt
(
0
));
...
@@ -1235,17 +1102,16 @@ private void showOnlyTape(boolean onlyTape) {
...
@@ -1235,17 +1102,16 @@ private void showOnlyTape(boolean onlyTape) {
@Override
@Override
public
void
onAnimationStart
(
Animator
animation
)
{
public
void
onAnimationStart
(
Animator
animation
)
{
PictogramActivity
.
this
.
deleting
=
true
;
deleting
=
true
;
}
}
@Override
@Override
public
void
onAnimationEnd
(
Animator
animation
)
{
public
void
onAnimationEnd
(
Animator
animation
)
{
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
"DELETING "
+
position
);
tapeAdapter
.
deleteItem
(
position
);
tapeAdapter
.
deleteItem
(
position
);
tapeAdapter
.
notifyDataSetChanged
();
tapeAdapter
.
notifyDataSetChanged
();
v
.
setColorFilter
(
0
);
v
.
setColorFilter
(
0
);
v
.
setBackgroundColor
(
ContextCompat
.
getColor
(
PCBcontext
.
getContext
(),
R
.
color
.
picto_default_background
));
v
.
setBackgroundColor
(
ContextCompat
.
getColor
(
PCBcontext
.
getContext
(),
R
.
color
.
picto_default_background
));
PictogramActivity
.
this
.
deleting
=
false
;
deleting
=
false
;
if
(
tapeAdapter
.
getCount
()==
0
)
{
if
(
tapeAdapter
.
getCount
()==
0
)
{
showOnlyTape
(
false
);
showOnlyTape
(
false
);
}
}
...
@@ -1266,59 +1132,6 @@ private void showOnlyTape(boolean onlyTape) {
...
@@ -1266,59 +1132,6 @@ private void showOnlyTape(boolean onlyTape) {
}
}
public
void
animateTapeView
(
final
int
position
,
final
ViewGroup
view
)
{
GridView
gridview
=
(
GridView
)
view
.
getChildAt
(
1
);
RelativeLayout
relativeLayout
=(
RelativeLayout
)(
gridview
.
getChildAt
(
position
));
FrameLayout
layout
=(
FrameLayout
)(
relativeLayout
.
getChildAt
(
0
));
final
ImageView
v
=(
ImageView
)(
layout
.
getChildAt
(
0
));
final
int
orange
=
ContextCompat
.
getColor
(
PCBcontext
.
getContext
(),
R
.
color
.
red
);
final
ValueAnimator
colorAnim
=
ObjectAnimator
.
ofFloat
(
0
f
,
1
f
,
0
f
);
colorAnim
.
addUpdateListener
(
new
ValueAnimator
.
AnimatorUpdateListener
()
{
@Override
public
void
onAnimationUpdate
(
ValueAnimator
animation
)
{
float
mul
=
(
Float
)
animation
.
getAnimatedValue
();
int
alphaOrange
=
adjustAlpha
(
orange
,
mul
);
v
.
setColorFilter
(
alphaOrange
,
PorterDuff
.
Mode
.
SRC_ATOP
);
v
.
setBackgroundColor
(
alphaOrange
);
v
.
setPadding
(
0
,
0
,
0
,
0
);
if
(
mul
==
0.0
)
{
v
.
setColorFilter
(
0
);
}
}
});
colorAnim
.
addListener
(
new
ValueAnimator
.
AnimatorListener
()
{
@Override
public
void
onAnimationStart
(
Animator
animation
)
{
}
@Override
public
void
onAnimationEnd
(
Animator
animation
)
{
v
.
setColorFilter
(
0
);
v
.
setBackgroundColor
(
ContextCompat
.
getColor
(
PCBcontext
.
getContext
(),
R
.
color
.
picto_default_background
));
if
(
position
<(
tapeAdapter
.
getCount
()-
1
))
animateTapeView
(
position
+
1
,
view
);
else
animateTapeView
(
false
);
}
@Override
public
void
onAnimationCancel
(
Animator
animation
)
{
}
@Override
public
void
onAnimationRepeat
(
Animator
animation
)
{
}
});
colorAnim
.
setDuration
(
tapeAdapter
.
getItem
(
position
).
get_translation
().
length
()*
100
);
colorAnim
.
start
();
}
public
static
int
adjustAlpha
(
int
color
,
float
factor
)
{
public
static
int
adjustAlpha
(
int
color
,
float
factor
)
{
int
alpha
=
Math
.
round
(
Color
.
alpha
(
color
)
*
factor
);
int
alpha
=
Math
.
round
(
Color
.
alpha
(
color
)
*
factor
);
int
red
=
Color
.
red
(
color
);
int
red
=
Color
.
red
(
color
);
...
@@ -1328,309 +1141,24 @@ private void showOnlyTape(boolean onlyTape) {
...
@@ -1328,309 +1141,24 @@ private void showOnlyTape(boolean onlyTape) {
}
}
/**Function for open a new View for change the expression of a picto
public
void
animateTapeViewVertical
(
final
boolean
up
)
{
*
final
View
v
=
findViewById
(
R
.
id
.
pictogramLayout
);
* @param picto
int
y
=
v
.
getHeight
()/
2
-
this
.
tapeGridView
.
getHeight
()/
2
;
*/
final
ValueAnimator
moveAnim
=
up
public
void
createViewForExpression
(
final
Picto
picto
){
?
ObjectAnimator
.
ofInt
(
y
,
0
)
ll
=
new
RelativeLayout
(
PCBcontext
.
getContext
());
:
ObjectAnimator
.
ofInt
(
0
,
y
);
RelativeLayout
.
LayoutParams
params
=
new
RelativeLayout
.
LayoutParams
(
RelativeLayout
.
LayoutParams
.
MATCH_PARENT
,
moveAnim
.
addUpdateListener
(
new
ValueAnimator
.
AnimatorUpdateListener
()
{
RelativeLayout
.
LayoutParams
.
MATCH_PARENT
);
addContentView
(
ll
,
params
);
ll
.
setBackgroundColor
(
argb
(
180
,
0
,
0
,
0
));
ll
.
setClickable
(
false
);
//Parameters for hide navigation bar when u save or cancel
final
View
decorView
=
getWindow
().
getDecorView
();
final
int
uiOptions
=
View
.
SYSTEM_UI_FLAG_HIDE_NAVIGATION
/*| View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE*/
;
final
EditText
leyenda
=
new
EditText
(
PCBcontext
.
getContext
());
leyenda
.
setBackgroundColor
(
rgb
(
221
,
221
,
211
));
leyenda
.
setWidth
(
400
);
leyenda
.
setMaxLines
(
1
);
leyenda
.
setClickable
(
true
);
leyenda
.
setTextSize
(
25
);
leyenda
.
setX
(
PictogramActivity
.
this
.
getResources
().
getDisplayMetrics
().
widthPixels
/
2
-
300
);
leyenda
.
setY
(
PictogramActivity
.
this
.
getResources
().
getDisplayMetrics
().
heightPixels
/
2
-
50
);
leyenda
.
setTextColor
(
BLACK
);
if
(
picto
.
get_translation
()!=
null
&&
picto
!=
null
){
leyenda
.
setText
(
picto
.
get_translation
());
}
else
{
leyenda
.
setText
(
"Sin Descripción"
);
}
//Mostrar teclado automaticamente
final
InputMethodManager
imm
=
(
InputMethodManager
)
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
ImageButton
botonOk
=
new
ImageButton
(
PCBcontext
.
getContext
());
botonOk
.
setImageResource
(
android
.
R
.
drawable
.
ic_menu_save
);
botonOk
.
setX
(
PictogramActivity
.
this
.
getResources
().
getDisplayMetrics
().
widthPixels
/
2
+
110
);
botonOk
.
setY
(
PictogramActivity
.
this
.
getResources
().
getDisplayMetrics
().
heightPixels
/
2
-
50
);
botonOk
.
setBackgroundColor
(
rgb
(
221
,
221
,
221
));
botonOk
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
public
void
onClick
(
View
v
)
{
public
void
onAnimationUpdate
(
ValueAnimator
animation
)
{
picto
.
set_translation
(
leyenda
.
getText
().
toString
());
int
i
=(
int
)
animation
.
getAnimatedValue
();
imm
.
hideSoftInputFromWindow
(
leyenda
.
getWindowToken
(),
0
);
v
.
setTranslationY
(
i
);
picto
.
set_local_status
(
true
);
if
(
i
<=
255
)
ttsButton
.
setImageAlpha
(
255
-
i
);
if
(!
picto
.
is_local
())
{
new
PictoUploader
(
picto
).
uploadState
();
PCBcontext
.
getActionLog
().
log
(
new
VocabularyAction
(
VocabularyAction
.
ALTERATTRS
,
picto
));
}
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
ll
.
setVisibility
(
View
.
GONE
);
ll
.
removeAllViewsInLayout
();
//Hide navigation bar
//PictogramActivity.this.refresh();
decorView
.
setSystemUiVisibility
(
uiOptions
);
}
});
ImageButton
botonSalir
=
new
ImageButton
(
PCBcontext
.
getContext
());
botonSalir
.
setImageResource
(
android
.
R
.
drawable
.
ic_menu_close_clear_cancel
);
botonSalir
.
setX
(
PictogramActivity
.
this
.
getResources
().
getDisplayMetrics
().
widthPixels
/
2
+
150
);
botonSalir
.
setY
(
PictogramActivity
.
this
.
getResources
().
getDisplayMetrics
().
heightPixels
/
2
-
50
);
botonSalir
.
setBackgroundColor
(
rgb
(
221
,
221
,
221
));
botonSalir
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
imm
.
hideSoftInputFromWindow
(
leyenda
.
getWindowToken
(),
0
);
ll
.
setVisibility
(
View
.
GONE
);
ll
.
removeAllViewsInLayout
();
//Hide navigation bar
//PictogramActivity.this.refresh();
decorView
.
setSystemUiVisibility
(
uiOptions
);
}
}
});
ll
.
addView
(
leyenda
);
ll
.
addView
(
botonOk
);
ll
.
addView
(
botonSalir
);
leyenda
.
requestFocus
();
imm
.
showSoftInput
(
leyenda
,
InputMethodManager
.
SHOW_FORCED
);
}
/**Function for build a radial menu
*
* @param tamPicto
* @param picto
*/
private
void
createMenuForPicto
(
int
tamPicto
,
Picto
picto
){
ll
=
new
RelativeLayout
(
PCBcontext
.
getContext
());
RelativeLayout
.
LayoutParams
params
=
new
RelativeLayout
.
LayoutParams
(
RelativeLayout
.
LayoutParams
.
MATCH_PARENT
,
RelativeLayout
.
LayoutParams
.
MATCH_PARENT
);
addContentView
(
ll
,
params
);
ll
.
setBackgroundColor
(
argb
(
180
,
0
,
0
,
0
));
detail
=
new
ImageView
(
PCBcontext
.
getContext
());
int
centerX
=
PictogramActivity
.
this
.
getResources
().
getDisplayMetrics
().
widthPixels
/
2
;
int
centerY
=
PictogramActivity
.
this
.
getResources
().
getDisplayMetrics
().
heightPixels
/
2
;
if
(
tamPicto
==
0
){
centerY
+=
100
;
detail
.
setMaxWidth
(
90
);
}
else
{
centerY
+=
135
;
detail
.
setMaxWidth
(
115
);
}
PieMenu
=
new
RadialMenuWidget
(
PCBcontext
.
getContext
());
PieMenu
.
setAnimationSpeed
(
0L
);
PieMenu
.
setCenterLocation
(
centerX
-
(
PieMenu
.
getcRadius
()*
2
)
-
50
,
centerY
-(
PieMenu
.
getcRadius
()*
2
));
PieMenu
.
setIconSize
(
20
,
35
);
//Tamaño del icono
PieMenu
.
setCenterCircle
(
new
Close
(
picto
));
PieMenu
.
addMenuEntry
(
new
UnlockPictoMenu
(
picto
));
PieMenu
.
addMenuEntry
(
new
DisablePictoMenu
(
picto
));
PieMenu
.
addMenuEntry
(
new
SetInvisibleMenu
(
picto
));
//PieMenu.addMenuEntry(new EditMenu(picto));
ll
.
addView
(
PieMenu
);
try
{
detail
.
setImageBitmap
(
picto
.
get_bitmap
(
PCBcontext
.
getContext
()));
detail
.
setBackgroundColor
(
picto
.
get_color
());
detail
.
setX
(
centerX
+
10
);
detail
.
setY
(
centerY
-
(
picto
.
get_bitmap
(
PCBcontext
.
getContext
()).
getHeight
()));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
ll
.
addView
(
detail
);
}
/** Menu of picto classes */
//Close menu button
public
class
Close
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
Close
(
Picto
picto
){
this
.
p
=
picto
;
}
public
String
getName
()
{
return
"Close"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
android
.
R
.
drawable
.
ic_menu_close_clear_cancel
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
//Metodo para realizar acciones si se pulsa
public
void
menuActiviated
()
{
ll
.
setVisibility
(
View
.
GONE
);
((
RelativeLayout
)
PieMenu
.
getParent
()).
removeView
(
PieMenu
);
}
public
void
menuDisabled
(){}
}
//Disable menu button
public
class
DisablePictoMenu
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
DisablePictoMenu
(
Picto
picto
){
this
.
p
=
picto
;
}
public
String
getName
()
{
return
"disable"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
disabled_picto
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
public
void
menuActiviated
()
{
p
.
alter_status
(
"disabled"
);
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
ll
.
setVisibility
(
View
.
GONE
);
((
RelativeLayout
)
PieMenu
.
getParent
()).
removeView
(
PieMenu
);
}
public
void
menuDisabled
(){}
}
//Change image of picto menu button
public
class
SetInvisibleMenu
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
SetInvisibleMenu
(
Picto
picto
){
this
.
p
=
picto
;
}
public
String
getName
()
{
return
"invisible"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
eye_blocked
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
public
void
menuActiviated
()
{
p
.
alter_status
(
"invisible"
);
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
ll
.
setVisibility
(
View
.
GONE
);
((
RelativeLayout
)
PieMenu
.
getParent
()).
removeView
(
PieMenu
);
}
public
void
menuDisabled
(){}
}
//Activate/enable picto on vocabulary menu button
public
class
UnlockPictoMenu
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
UnlockPictoMenu
(
Picto
picto
){
this
.
p
=
picto
;
}
public
String
getName
()
{
return
"enable"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
unlock
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
public
void
menuActiviated
()
{
p
.
alter_status
(
"enabled"
);
getCurrentPictoGridAdapter
().
notifyDataSetChanged
();
ll
.
setVisibility
(
View
.
GONE
);
((
RelativeLayout
)
PieMenu
.
getParent
()).
removeView
(
PieMenu
);
}
public
void
menuDisabled
(){}
}
//Edit menu button
public
class
EditMenu
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
EditMenu
(
Picto
picto
){
this
.
p
=
picto
;
}
public
String
getName
()
{
return
"edit"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
edit
;
}
private
List
<
RadialMenuWidget
.
RadialMenuEntry
>
children
;
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
children
;
}
public
void
menuActiviated
()
{
ll
.
getChildAt
(
1
).
setX
(
ll
.
getChildAt
(
1
).
getX
()
+
30
);
children
=
new
ArrayList
<>(
Arrays
.
asList
(
new
EditTextPicto
(
p
),
new
EditImage
(
p
)));
}
public
void
menuDisabled
(){
ll
.
getChildAt
(
1
).
setX
(
ll
.
getChildAt
(
1
).
getX
()
-
30
);
}
}
//Edit legend text of picto button
public
class
EditTextPicto
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
EditTextPicto
(
Picto
picto
){
this
.
p
=
picto
;
}
public
String
getName
()
{
return
"editText"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
edit_text
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
public
void
menuActiviated
()
{
ll
.
setVisibility
(
View
.
GONE
);
ll
.
removeAllViewsInLayout
();
createViewForExpression
(
this
.
p
);
}
public
void
menuDisabled
(){}
}
public
class
EditImage
implements
RadialMenuWidget
.
RadialMenuEntry
{
Picto
p
;
public
EditImage
(
Picto
picto
){
this
.
p
=
picto
;
}
public
String
getName
()
{
return
"editImage"
;
}
public
String
getLabel
()
{
return
null
;
}
public
int
getIcon
()
{
return
R
.
drawable
.
edit_picture
;
}
public
List
<
RadialMenuWidget
.
RadialMenuEntry
>
getChildren
()
{
return
null
;
}
public
void
menuActiviated
()
{
/**TODO: Llamar a la interfaz de editar foto*/
Toast
.
makeText
(
PCBcontext
.
getContext
(),
"Editar Imagen"
,
Toast
.
LENGTH_SHORT
).
show
();
}
public
void
menuDisabled
(){}
}
public
void
animateTapeView
(
final
boolean
up
)
{
final
View
v
=
(
View
)
this
.
tapeGridView
.
getParent
();
Log
.
e
(
"WEE"
,
"W:"
+
findViewById
(
R
.
id
.
pictogramLayout
).
getWidth
()/
2
);
final
ValueAnimator
colorAnim
=
ObjectAnimator
.
ofInt
(
0
,
300
);
colorAnim
.
addUpdateListener
(
new
ValueAnimator
.
AnimatorUpdateListener
()
{
@Override
public
void
onAnimationUpdate
(
ValueAnimator
animation
)
{
v
.
setTop
(
v
.
getTop
()+(
up
?
1
:
-
1
));
}
});
});
color
Anim
.
setDuration
(
500
);
move
Anim
.
setDuration
(
500
);
color
Anim
.
start
();
move
Anim
.
start
();
}
}
}
}
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/login/SerialActivity.java
View file @
6ab36ce0
...
@@ -21,8 +21,6 @@ import com.yottacode.pictogram.dao.User;
...
@@ -21,8 +21,6 @@ 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
;
import
com.yottacode.pictogram.tabletlibrary.gui.communicator.PictogramActivity
;
import
com.yottacode.pictogram.tabletlibrary.gui.communicator.PictogramActivity
;
import
com.yottacode.pictogram.tabletlibrary.gui.login.CustomListLogin
;
import
com.yottacode.pictogram.tabletlibrary.gui.login.LoginActivity
;
import
com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet
;
import
com.yottacode.pictogram.tabletlibrary.net.NetServiceTablet
;
import
com.yottacode.pictogram.tools.PCBcontext
;
import
com.yottacode.pictogram.tools.PCBcontext
;
...
...
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