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
7d70e7db
authored
Dec 14, 2016
by
Fernando Martínez Santiago
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
issue #686 y #684 closed
parent
0816363f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
134 additions
and
127 deletions
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/dao/Picto.java
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/tts/TTSHelper.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/PictoItemViewGenerator.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/PictogramActivity.java
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/dao/Picto.java
View file @
7d70e7db
package
com
.
yottacode
.
pictogram
.
dao
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.Matrix
;
import
android.graphics.Paint
;
import
android.graphics.PorterDuff
;
import
android.util.Log
;
import
android.util.TypedValue
;
import
android.view.Gravity
;
import
android.widget.TextView
;
...
...
@@ -77,9 +73,11 @@ public class Picto extends Img {
private
JSONObject
attributes
;
private
String
translation
;
private
boolean
is_mirror
=
false
;
private
boolean
highlight_background
=
false
;
public
boolean
is_mirror
()
{
return
is_mirror
;}
public
void
set_mirror
(
boolean
is_mirror
)
{
public
boolean
is_highlight_background
()
{
return
highlight_background
;}
public
void
set_mirror
(
boolean
is_mirror
,
boolean
highlight_background
)
{
this
.
highlight_background
=
highlight_background
;
this
.
is_mirror
=
is_mirror
;}
public
Picto
(
int
id
,
String
url
,
String
translation
,
int
cat
,
int
row
,
int
column
,
int
freeRow
,
int
freeColumn
)
throws
JSONException
{
...
...
@@ -268,11 +266,13 @@ public class Picto extends Img {
* @return the legend of a picto (none | normal | full)
*/
public
String
get_legend
()
{
String
legend
;
try
{
return
this
.
attributes
.
getString
(
JSON_ATTTRS
.
LEGEND
);
legend
=
this
.
attributes
.
getString
(
JSON_ATTTRS
.
LEGEND
);
}
catch
(
JSONException
e
)
{
return
"none"
;
// By default
legend
=
JSON_ATTTR_LEGEND_VALUES
.
NONE
;
// By default
}
return
legend
.
equalsIgnoreCase
(
"null"
)
?
JSON_ATTTR_LEGEND_VALUES
.
NONE
:
legend
;
}
/**
...
...
@@ -402,6 +402,118 @@ public class Picto extends Img {
}
}
private
String
format_legend
()
{
String
texto
=
this
.
translation
.
toUpperCase
();
String
[]
words
=
texto
.
split
(
" "
);
StringBuffer
txt
=
new
StringBuffer
();
if
(
words
.
length
==
1
)
{
if
(
words
[
0
].
length
()
>
10
)
{
texto
=
""
;
int
mitad
=
(
words
[
0
].
length
()
/
2
)
-
1
;
char
r
=
words
[
0
].
charAt
(
mitad
);
char
r2
=
words
[
0
].
charAt
(
mitad
+
1
);
while
((
r2
==
'A'
||
r2
==
'E'
||
r2
==
'I'
||
r2
==
'O'
||
r2
==
'U'
)
&&
(
r
!=
'A'
||
r
!=
'E'
||
r
!=
'I'
||
r
!=
'O'
||
r
!=
'U'
))
{
mitad
++;
r
=
words
[
0
].
charAt
(
mitad
);
r2
=
words
[
0
].
charAt
(
mitad
+
1
);
}
int
i
=
0
;
while
(
i
<=
mitad
)
{
txt
.
append
(
words
[
0
].
charAt
(
i
));
i
++;
}
int
diff
=
10
-
mitad
;
diff
-=
1
;
txt
.
append
(
"-"
);
while
(
diff
!=
10
)
{
txt
.
append
(
" "
);
diff
++;
}
while
(
i
<
words
[
0
].
length
())
{
txt
.
append
(
words
[
0
].
charAt
(
i
));
i
++;
}
texto
=
txt
.
toString
();
}
}
return
texto
;
}
private
void
set_legend
(
Context
context
)
{
{
Paint
paint
=
new
Paint
(
Paint
.
ANTI_ALIAS_FLAG
);
int
width
=
bitmap
.
getWidth
();
//Ancho original
int
height
=
bitmap
.
getHeight
();
//Alto original
String
texto
=
format_legend
();
if
(
get_legend
().
equals
(
JSON_ATTTR_LEGEND_VALUES
.
NORMAL
))
{
//Normal legend
android
.
graphics
.
Bitmap
.
Config
bitmapConfig
=
bitmap
.
getConfig
();
if
(
bitmapConfig
==
null
)
{
bitmapConfig
=
android
.
graphics
.
Bitmap
.
Config
.
ARGB_8888
;
}
bitmap
=
bitmap
.
copy
(
bitmapConfig
,
true
);
Canvas
canvas
=
new
Canvas
(
bitmap
);
if
(
cont
==
0
)
{
Bitmap
bm
=
Bitmap
.
createScaledBitmap
(
bitmap
,
width
/
2
,
height
/
2
,
false
);
canvas
.
drawColor
(
Color
.
TRANSPARENT
,
PorterDuff
.
Mode
.
CLEAR
);
//Poner en blanco el bitmap original para dibujar encima
canvas
.
drawBitmap
(
bm
,
25
,
0
,
paint
);
cont
++;
TextView
textView
=
new
TextView
(
context
);
textView
.
layout
(
0
,
50
,
100
,
100
);
textView
.
setPadding
(
0
,
0
,
0
,
0
);
textView
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
13
);
textView
.
setTextColor
(
Color
.
BLACK
);
textView
.
setBackgroundColor
(
Color
.
WHITE
);
textView
.
setWidth
(
100
);
textView
.
setGravity
(
Gravity
.
CENTER_HORIZONTAL
);
textView
.
setMaxLines
(
4
);
textView
.
setText
(
texto
);
textView
.
setDrawingCacheEnabled
(
true
);
canvas
.
drawBitmap
(
textView
.
getDrawingCache
(),
0
,
50
,
null
);
}
}
else
{
//Only legend
android
.
graphics
.
Bitmap
.
Config
bitmapConfig
=
bitmap
.
getConfig
();
if
(
bitmapConfig
==
null
)
{
bitmapConfig
=
android
.
graphics
.
Bitmap
.
Config
.
ARGB_8888
;
}
bitmap
=
bitmap
.
copy
(
bitmapConfig
,
true
);
Canvas
canvas
=
new
Canvas
(
bitmap
);
paint
.
setColor
(
Color
.
WHITE
);
canvas
.
drawRect
(
0
,
0
,
100
,
100
,
paint
);
TextView
textView
=
new
TextView
(
context
);
textView
.
layout
(
0
,
0
,
100
,
100
);
textView
.
setPadding
(
0
,
0
,
0
,
0
);
textView
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
13
);
textView
.
setTextColor
(
Color
.
BLACK
);
textView
.
setWidth
(
100
);
textView
.
setGravity
(
Gravity
.
CENTER_HORIZONTAL
);
textView
.
setMaxLines
(
2
);
textView
.
setText
(
texto
);
textView
.
setDrawingCacheEnabled
(
true
);
canvas
.
drawBitmap
(
textView
.
getDrawingCache
(),
0
,
25
,
null
);
}
}
}
/**
* override method that draw the legend on the picto bitmap
*/
...
...
@@ -416,115 +528,9 @@ public class Picto extends Img {
is
.
close
();
}
}
Paint
paint
=
new
Paint
(
Paint
.
ANTI_ALIAS_FLAG
);
int
width
=
bitmap
.
getWidth
();
//Ancho original
int
height
=
bitmap
.
getHeight
();
//Alto original
int
dens
=
bitmap
.
getDensity
();
if
(!
get_legend
().
equals
(
JSON_ATTTR_LEGEND_VALUES
.
NONE
)){
String
texto
=
this
.
translation
.
toUpperCase
();
String
[]
words
=
texto
.
split
(
" "
);
StringBuffer
txt
=
new
StringBuffer
();
if
(
words
.
length
==
1
)
{
if
(
words
[
0
].
length
()
>
10
)
{
texto
=
""
;
int
mitad
=
(
words
[
0
].
length
()
/
2
)
-
1
;
char
r
=
words
[
0
].
charAt
(
mitad
);
char
r2
=
words
[
0
].
charAt
(
mitad
+
1
);
while
((
r2
==
'A'
||
r2
==
'E'
||
r2
==
'I'
||
r2
==
'O'
||
r2
==
'U'
)
&&
(
r
!=
'A'
||
r
!=
'E'
||
r
!=
'I'
||
r
!=
'O'
||
r
!=
'U'
))
{
mitad
++;
r
=
words
[
0
].
charAt
(
mitad
);
r2
=
words
[
0
].
charAt
(
mitad
+
1
);
}
int
i
=
0
;
while
(
i
<=
mitad
)
{
txt
.
append
(
words
[
0
].
charAt
(
i
));
i
++;
}
int
diff
=
10
-
mitad
;
diff
-=
1
;
txt
.
append
(
"-"
);
while
(
diff
!=
10
)
{
txt
.
append
(
" "
);
diff
++;
}
while
(
i
<
words
[
0
].
length
())
{
txt
.
append
(
words
[
0
].
charAt
(
i
));
i
++;
}
texto
=
txt
.
toString
();
}
}
if
(
get_legend
().
equals
(
JSON_ATTTR_LEGEND_VALUES
.
NORMAL
))
{
//Normal legend
android
.
graphics
.
Bitmap
.
Config
bitmapConfig
=
bitmap
.
getConfig
();
if
(
bitmapConfig
==
null
)
{
bitmapConfig
=
android
.
graphics
.
Bitmap
.
Config
.
ARGB_8888
;
}
bitmap
=
bitmap
.
copy
(
bitmapConfig
,
true
);
Canvas
canvas
=
new
Canvas
(
bitmap
);
if
(
cont
==
0
)
{
Bitmap
bm
=
Bitmap
.
createScaledBitmap
(
bitmap
,
width
/
2
,
height
/
2
,
false
);
canvas
.
drawColor
(
Color
.
TRANSPARENT
,
PorterDuff
.
Mode
.
CLEAR
);
//Poner en blanco el bitmap original para dibujar encima
canvas
.
drawBitmap
(
bm
,
25
,
0
,
paint
);
cont
++;
TextView
textView
=
new
TextView
(
context
);
textView
.
layout
(
0
,
50
,
100
,
100
);
textView
.
setPadding
(
0
,
0
,
0
,
0
);
textView
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
13
);
textView
.
setTextColor
(
Color
.
BLACK
);
textView
.
setBackgroundColor
(
Color
.
WHITE
);
textView
.
setWidth
(
100
);
textView
.
setGravity
(
Gravity
.
CENTER_HORIZONTAL
);
textView
.
setMaxLines
(
4
);
textView
.
setText
(
texto
);
textView
.
setDrawingCacheEnabled
(
true
);
canvas
.
drawBitmap
(
textView
.
getDrawingCache
(),
0
,
50
,
null
);
}
}
else
{
//Only legend
android
.
graphics
.
Bitmap
.
Config
bitmapConfig
=
bitmap
.
getConfig
();
if
(
bitmapConfig
==
null
)
{
bitmapConfig
=
android
.
graphics
.
Bitmap
.
Config
.
ARGB_8888
;
}
bitmap
=
bitmap
.
copy
(
bitmapConfig
,
true
);
Canvas
canvas
=
new
Canvas
(
bitmap
);
paint
.
setColor
(
Color
.
WHITE
);
canvas
.
drawRect
(
0
,
0
,
100
,
100
,
paint
);
TextView
textView
=
new
TextView
(
context
);
textView
.
layout
(
0
,
0
,
100
,
100
);
textView
.
setPadding
(
0
,
0
,
0
,
0
);
textView
.
setTextSize
(
TypedValue
.
COMPLEX_UNIT_PX
,
13
);
textView
.
setTextColor
(
Color
.
BLACK
);
textView
.
setWidth
(
100
);
textView
.
setGravity
(
Gravity
.
CENTER_HORIZONTAL
);
textView
.
setMaxLines
(
2
);
textView
.
setText
(
texto
);
textView
.
setDrawingCacheEnabled
(
true
);
canvas
.
drawBitmap
(
textView
.
getDrawingCache
(),
0
,
25
,
null
);
}
}
if
(!
get_legend
().
equals
(
JSON_ATTTR_LEGEND_VALUES
.
NONE
))
set_legend
(
context
);
return
bitmap
;
}
...
...
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/tts/TTSHelper.java
View file @
7d70e7db
...
...
@@ -54,7 +54,7 @@ public class TTSHelper {
Set
<
Voice
>
voices
=
this
.
ttobj
.
getVoices
();
if
(
voices
!=
null
)
for
(
Voice
avoice
:
voices
)
{
for
(
Voice
avoice
:
voices
)
{
Log
.
i
(
context
.
getApplicationInfo
().
processName
,
"Voice "
+
avoice
+
" available"
);
if
(
avoice
.
getName
().
equalsIgnoreCase
(
voice
))
{
this
.
ttobj
.
setVoice
(
avoice
);
this
.
voice_ok
=
true
;
...
...
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/PictoItemViewGenerator.java
View file @
7d70e7db
...
...
@@ -95,7 +95,7 @@ public class PictoItemViewGenerator {
mirror_color
++;
pictoImage
.
setScaleX
(
scale
[
mirror_color
%
scale
.
length
]);
pictoImage
.
setScaleY
(
scale
[
mirror_color
%
scale
.
length
]);
//
layout.setBackgroundColor(color[mirror_color%color.length]);
if
(
picto
.
is_highlight_background
())
layout
.
setBackgroundColor
(
color
[
mirror_color
%
color
.
length
]);
}
}
}
catch
(
IOException
e
)
{
...
...
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/PictogramActivity.java
View file @
7d70e7db
...
...
@@ -132,7 +132,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener {
public
void
action
(
action
action
,
int
picto_cat
,
int
picto_id
)
{
Log
.
i
(
this
.
getClass
().
getCanonicalName
(),
action
+
" from "
+
picto_cat
+
","
+
picto_id
+
" catched"
);
Picto
picto
=
vocabulary
.
get_picto
(
picto_cat
,
picto_id
);
PictogramActivity
.
this
.
execHighligthFeeback
(
picto
);
PictogramActivity
.
this
.
execHighligthFeeback
(
picto
,
true
);
}
});
this
.
vocabulary
.
setImgDownloaderListener
(
new
iImgDownloaderListener
()
{
...
...
@@ -724,12 +724,13 @@ public class PictogramActivity extends Activity implements iVocabularyListener {
if
(
PictogramActivity
.
this
.
feedback_read
)
PictogramActivity
.
this
.
tts
.
play
(
p
.
get_translation
());
if
(
p
!=
null
&&
p
.
get_id
()
!=
0
&&
!
p
.
is_invisible
()
&&
p
.
is_enabled
())
{
Log
.
d
(
LOG_TAG
,
"Clic en picto: "
+
p
.
toString
());
p
.
set_mirror
(
false
);
if
(
PictogramActivity
.
this
.
feedback_read
&&
!
p
.
is_category
())
PictogramActivity
.
this
.
tts
.
play
(
p
.
get_translation
());
p
.
set_mirror
(
false
,
false
);
LinkedList
<
Picto
>
ll
=
sort
(
PCBcontext
.
getVocabulary
().
next
(
p
));
//LinkedList<Picto> ll = vocabulary.next(p);
Log
.
d
(
LOG_TAG
,
"Lista de pictos recuperada: "
+
ll
.
toString
());
...
...
@@ -754,18 +755,18 @@ public class PictogramActivity extends Activity implements iVocabularyListener {
showPictoMainGridView
();
PCBcontext
.
getActionLog
().
log
(
new
TalkAction
(
TalkAction
.
ADD
,
p
));
if
(
PictogramActivity
.
this
.
feedback_read
)
PictogramActivity
.
this
.
tts
.
play
(
p
.
get_translation
());
if
(
PictogramActivity
.
this
.
feedback_highlight
)
execHighligthFeeback
(
p
);
if
(
PictogramActivity
.
this
.
feedback_highlight
)
execHighligthFeeback
(
p
,
false
);
}
private
void
execHighligthFeeback
(
final
Picto
picto
)
{
private
void
execHighligthFeeback
(
final
Picto
picto
,
boolean
highlight_background
)
{
boolean
same_picto
=
false
;
picto
.
set_mirror
(
true
);
//comienza feedback
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
);
prev_picto
.
set_mirror
(
false
,
false
);
same_picto
=
prev_picto
==
picto
;
}
if
(
same_picto
)
...
...
@@ -781,7 +782,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener {
public
void
run
()
{
refresh
();
if
(
repeating
++
==
20
)
{
picto
.
set_mirror
(
false
);
picto
.
set_mirror
(
false
,
false
);
if
(
exec_mirror
!=
null
)
{
exec_mirror
.
shutdown
();
exec_mirror
=
null
;
...
...
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