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
eeedc14a
authored
Dec 14, 2016
by
german
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Applied changes to repair the legend code and the results on the view of the tablet.
parent
7d70e7db
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
141 additions
and
145 deletions
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/dao/Picto.java
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/PictoItemViewGenerator.java
android/Pictogram/commonlibrary/src/main/java/com/yottacode/pictogram/dao/Picto.java
View file @
eeedc14a
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.Paint
;
import
android.graphics.PorterDuff
;
import
android.util.Log
;
import
android.util.TypedValue
;
import
android.view.Gravity
;
import
android.widget.TextView
;
import
com.yottacode.pictogram.action.VocabularyAction
;
import
com.yottacode.pictogram.net.PictoUploader
;
...
...
@@ -20,9 +13,6 @@ import com.yottacode.pictogram.tools.PCBcontext;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
/**
* A object which represents a pictogram
...
...
@@ -401,137 +391,4 @@ public class Picto extends Img {
PCBcontext
.
getPcbdb
().
modifyPicto
(
this
.
get_id
(),
this
.
get_json_attrs
());
}
}
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
*/
@Override
public
Bitmap
get_bitmap
(
Context
context
)
throws
IOException
{
if
(
bitmap
==
null
)
{
File
file
=
file
(
context
);
if
(
file
.
exists
())
{
FileInputStream
is
=
new
FileInputStream
(
file
);
this
.
bitmap
=
BitmapFactory
.
decodeStream
(
is
);
is
.
close
();
}
}
if
(!
get_legend
().
equals
(
JSON_ATTTR_LEGEND_VALUES
.
NONE
))
set_legend
(
context
);
return
bitmap
;
}
}
android/Pictogram/tabletlibrary/src/main/java/com/yottacode/pictogram/tabletlibrary/gui/PictoItemViewGenerator.java
View file @
eeedc14a
package
com
.
yottacode
.
pictogram
.
tabletlibrary
.
gui
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.Paint
;
import
android.graphics.PorterDuff
;
import
android.util.Log
;
import
android.util.TypedValue
;
import
android.view.Gravity
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.FrameLayout
;
import
android.widget.ImageView
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
com.yottacode.pictogram.dao.Picto
;
import
com.yottacode.pictogram.tabletlibrary.R
;
...
...
@@ -22,6 +31,130 @@ public class PictoItemViewGenerator {
public
static
final
int
LAYOUT
=
R
.
layout
.
picto_grid_item
;
public
static
final
int
LAYOUT_BIG
=
R
.
layout
.
picto_grid_item_big
;
public
static
int
mirror_color
=
0
;
/**
*
* @param picto Pictogram to set the legend text
* @return the text modified
*/
private
static
String
format_legend
(
Picto
picto
)
{
String
texto
=
picto
.
get_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
;
}
/**
* @param context
* @param bitmap Bitmap to add the legend and rescale
* @param picto
* @return the bitmap scaled and with the legend or without changes
*/
private
static
Bitmap
set_legend
(
Context
context
,
Bitmap
bitmap
,
Picto
picto
)
{
{
Paint
paint
=
new
Paint
(
Paint
.
ANTI_ALIAS_FLAG
);
int
width
=
bitmap
.
getWidth
();
//Ancho original
int
height
=
bitmap
.
getHeight
();
//Alto original
String
texto
=
format_legend
(
picto
);
if
(
picto
.
get_legend
().
equals
(
"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
);
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
);
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
);
}
}
return
bitmap
;
}
public
static
View
getPictoView
(
Picto
picto
,
View
convertView
,
ViewGroup
parent
)
{
return
getPictoView
(
picto
,
convertView
,
parent
,
false
);
}
...
...
@@ -68,7 +201,13 @@ public class PictoItemViewGenerator {
}
try
{
pictoImage
.
setImageBitmap
(
picto
.
get_bitmap
(
PCBcontext
.
getContext
()));
Bitmap
bm
=
picto
.
get_bitmap
(
PCBcontext
.
getContext
());
if
(!
picto
.
get_legend
().
equals
(
"none"
))
{
bm
=
set_legend
(
PCBcontext
.
getContext
(),
bm
,
picto
);
}
pictoImage
.
setImageBitmap
(
bm
);
if
(!
picto
.
is_invisible
()
||
PCBcontext
.
getPcbdb
().
getCurrentUser
().
is_supervisor
())
{
layoutWrapper
.
setVisibility
(
View
.
VISIBLE
);
pictoImage
.
setVisibility
(
View
.
VISIBLE
);
...
...
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