Commit 9a2b4543 by german

Code changed to quit the legend_size attributes and "only_legend" code added

parent c110ced3
...@@ -7,6 +7,9 @@ import android.graphics.BitmapFactory; ...@@ -7,6 +7,9 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.util.Log; import android.util.Log;
import android.util.TypedValue; import android.util.TypedValue;
...@@ -53,13 +56,13 @@ public class Picto extends Img { ...@@ -53,13 +56,13 @@ public class Picto extends Img {
/**Modificacion German*/ /**Modificacion German*/
public static String LEGEND="legend"; public static String LEGEND="legend";
public static String LEGEND_SIZE="legend_size";
} }
public final static class JSON_ATTTR_LEGEND_VALUES { public final static class JSON_ATTTR_LEGEND_VALUES {
static String NORMAL = "normal"; static String NONE = "none";
static String ONLY_LEGEND = "only_legend"; static String NORMAL = "normal";
static String FULL = "full";
} }
public final static class JSON_ATTTR_STATUS_VALUES { public final static class JSON_ATTTR_STATUS_VALUES {
...@@ -75,7 +78,7 @@ public class Picto extends Img { ...@@ -75,7 +78,7 @@ public class Picto extends Img {
private JSONObject attributes; private JSONObject attributes;
private String translation; private String translation;
public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn,boolean legend) throws JSONException { public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn) throws JSONException {
this(id, url, translation, new JSONObject() this(id, url, translation, new JSONObject()
.put(JSON_ATTTRS.CATEGORY, cat) .put(JSON_ATTTRS.CATEGORY, cat)
.put(JSON_ATTTRS.COLUMN, column) .put(JSON_ATTTRS.COLUMN, column)
...@@ -83,8 +86,7 @@ public class Picto extends Img { ...@@ -83,8 +86,7 @@ public class Picto extends Img {
.put(JSON_ATTTRS.FREE_ROW, freeRow) .put(JSON_ATTTRS.FREE_ROW, freeRow)
.put(JSON_ATTTRS.FREE_COLUMN, freeColumn) .put(JSON_ATTTRS.FREE_COLUMN, freeColumn)
.put(JSON_ATTTRS.STATUS, JSON_ATTTR_STATUS_VALUES.ENABLED) .put(JSON_ATTTRS.STATUS, JSON_ATTTR_STATUS_VALUES.ENABLED)
.put(JSON_ATTTRS.LEGEND,legend) .put(JSON_ATTTRS.LEGEND,JSON_ATTTR_LEGEND_VALUES.NONE));
.put(JSON_ATTTRS.LEGEND,JSON_ATTTR_LEGEND_VALUES.NORMAL));
} }
public Picto(int id, String url,String translation, String attributes) throws JSONException { public Picto(int id, String url,String translation, String attributes) throws JSONException {
this(id, url, translation, new JSONObject(attributes)); this(id, url, translation, new JSONObject(attributes));
...@@ -249,31 +251,18 @@ public class Picto extends Img { ...@@ -249,31 +251,18 @@ public class Picto extends Img {
} }
} }
/**
*
* @return the legend of a picto (true | false)
*/
public boolean have_legend() {
try {
return this.attributes.getBoolean(JSON_ATTTRS.LEGEND);
} catch (JSONException e) {
return false; // By default
}
}
/** /**
* *
* @return the legend size of a picto (normal | only_legend) * @return the legend of a picto (none | normal | full)
*/ */
public String get_legend_size() { public String get_legend() {
try { try {
return this.attributes.getString(JSON_ATTTRS.LEGEND_SIZE); return this.attributes.getString(JSON_ATTTRS.LEGEND);
} catch (JSONException e) { } catch (JSONException e) {
return "normal"; // By default return "none"; // By default
} }
} }
/** /**
* *
* @return the row of the picto * @return the row of the picto
...@@ -459,50 +448,50 @@ public class Picto extends Img { ...@@ -459,50 +448,50 @@ public class Picto extends Img {
is.close(); is.close();
} }
} }
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
if (have_legend()){ //if(!get_legend().equals(JSON_ATTTR_LEGEND_VALUES.NONE)){
if(get_legend_size().equals(JSON_ATTTR_LEGEND_VALUES.NORMAL)) {
String texto = this.translation.toUpperCase(); String texto = this.translation.toUpperCase();
String[] words = texto.split(" "); String[] words = texto.split(" ");
StringBuffer txt = new StringBuffer(); StringBuffer txt = new StringBuffer();
if (words.length == 1) {//Si solo hay una palabra if (words.length == 1) {//Si solo hay una palabra
if (words[0].length() > 10) { //Si es mayor de 10 caracteres if (words[0].length() > 10) { //Si es mayor de 10 caracteres
texto = ""; texto = "";
int mitad = (words[0].length() / 2) - 1; int mitad = (words[0].length() / 2) - 1;
char r = words[0].charAt(mitad); char r = words[0].charAt(mitad);
char r2 = words[0].charAt(mitad + 1); 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')) { while ((r2 == 'A' || r2 == 'E' || r2 == 'I' || r2 == 'O' || r2 == 'U') && (r != 'A' || r != 'E' || r != 'I' || r != 'O' || r != 'U')) {
mitad++; mitad++;
r = words[0].charAt(mitad); r = words[0].charAt(mitad);
r2 = words[0].charAt(mitad + 1); r2 = words[0].charAt(mitad + 1);
} }
int i = 0; int i = 0;
while (i <= mitad) { while (i <= mitad) {
txt.append(words[0].charAt(i)); txt.append(words[0].charAt(i));
i++; i++;
} }
int diff = 10 - mitad; int diff = 10 - mitad;
diff -= 1; diff -= 1;
txt.append("-"); txt.append("-");
while (diff != 10) { while (diff != 10) {
txt.append(" "); txt.append(" ");
diff++; diff++;
}
while (i < words[0].length()) {
txt.append(words[0].charAt(i));
i++;
}
texto = txt.toString();
} }
while (i < words[0].length()) {
txt.append(words[0].charAt(i));
i++;
}
texto = txt.toString();
}
} }
//if(get_legend().equals(JSON_ATTTR_LEGEND_VALUES.NORMAL)) {
android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
if (bitmapConfig == null) { if (bitmapConfig == null) {
...@@ -511,7 +500,16 @@ public class Picto extends Img { ...@@ -511,7 +500,16 @@ public class Picto extends Img {
bitmap = bitmap.copy(bitmapConfig, true); bitmap = bitmap.copy(bitmapConfig, true);
Canvas canvas = new Canvas(bitmap); Canvas canvas = new Canvas(bitmap);
//Copiar el bitmap a uno nuevo y reescalar
int width = bitmap.getWidth(); //Ancho
int height = bitmap.getHeight(); //Alto
int scaleWidth = 50 / width;
int scaleHeight = 50/ height;
Bitmap bm = Bitmap.createScaledBitmap(bitmap,50,50, false);
canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR);
canvas.drawBitmap(bm,25,0,null);
TextView textView = new TextView(context); TextView textView = new TextView(context);
...@@ -527,10 +525,38 @@ public class Picto extends Img { ...@@ -527,10 +525,38 @@ public class Picto extends Img {
textView.setDrawingCacheEnabled(true); textView.setDrawingCacheEnabled(true);
canvas.drawBitmap(textView.getDrawingCache(), 0, 50, null); canvas.drawBitmap(textView.getDrawingCache(), 0, 50, null);
}else{ //}else{
//Solo texto //Solo texto
/*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, 15);
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; return bitmap;
} }
......
...@@ -366,11 +366,11 @@ public class Vocabulary implements Iterable<Picto> { ...@@ -366,11 +366,11 @@ public class Vocabulary implements Iterable<Picto> {
/* /*
* It saves locally a new picto obtained from the PCB * It saves locally a new picto obtained from the PCB
*/ */
public Picto saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y, int free_category_coord_x, int free_category_coord_y,boolean legend, final iLocalPicto listener) { public Picto saveLocalPicto(String url, String exp, int cat, int coord_x, int coord_y, int free_category_coord_x, int free_category_coord_y, final iLocalPicto listener) {
int id= PCBcontext.getDevice().getNextLocalPictoID(); int id= PCBcontext.getDevice().getNextLocalPictoID();
final Picto picto[]=new Picto[1]; final Picto picto[]=new Picto[1];
try { try {
picto[0] = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y,legend); picto[0] = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y);
addPicto(picto[0], ImgDownloader.tsource.local, new iImgDownloaderListener() { addPicto(picto[0], ImgDownloader.tsource.local, new iImgDownloaderListener() {
@Override @Override
public void loadComplete() { public void loadComplete() {
......
...@@ -860,7 +860,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -860,7 +860,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
col, col,
freeRow, freeRow,
freeColumn, freeColumn,
false,
new iLocalPicto() { new iLocalPicto() {
@Override @Override
public void saved(Picto localPicto) { public void saved(Picto localPicto) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment