Commit 706c14d6 by Arturo Montejo Ráez

conflict resolved

parents 20222578 e12e6357
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;
import com.yottacode.pictogram.action.VocabularyAction;
import com.yottacode.pictogram.net.PictoUploader;
......@@ -11,6 +24,10 @@ 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
* *
......@@ -18,6 +35,8 @@ import org.json.JSONObject;
* @version 1.0
*/
public class Picto extends Img {
int cont = 0;
Bitmap bitmap;
// String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
......@@ -35,6 +54,16 @@ public class Picto extends Img {
public static String PCB_STATUS_MODIFICATION="pcb_status_modification";
public static String EXPRESSION = "expression";
public static String MIRROR = "mirror";
/**Modificacion German*/
public static String LEGEND="legend";
}
public final static class JSON_ATTTR_LEGEND_VALUES {
static String NONE = "none";
static String NORMAL = "normal";
static String FULL = "full";
}
public final static class JSON_ATTTR_STATUS_VALUES {
......@@ -62,7 +91,8 @@ public class Picto extends Img {
.put(JSON_ATTTRS.ROW, row)
.put(JSON_ATTTRS.FREE_ROW, freeRow)
.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,JSON_ATTTR_LEGEND_VALUES.NONE));
}
public Picto(int id, String url,String translation, String attributes) throws JSONException {
this(id, url, translation, new JSONObject(attributes));
......@@ -235,6 +265,18 @@ public class Picto extends Img {
}
}
/**
*
* @return the legend of a picto (none | normal | full)
*/
public String get_legend() {
try {
return this.attributes.getString(JSON_ATTTRS.LEGEND);
} catch (JSONException e) {
return "none"; // By default
}
}
/**
*
* @return the row of the picto
......@@ -361,4 +403,134 @@ public class Picto extends Img {
PCBcontext.getPcbdb().modifyPicto(this.get_id(), this.get_json_attrs());
}
}
/**
* 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();
}
}
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
int width = bitmap.getWidth(); //Ancho original
int height = bitmap.getHeight(); //Alto original
int dens = bitmap.getDensity();
Log.i("TAG_NUEVO","ancho: "+width);
Log.i("TAG_NUEVO","alto: "+height);
Log.i("TAG_NUEVO","densidad: "+dens);
//if(!get_legend().equals(JSON_ATTTR_LEGEND_VALUES.NONE)){ //Si tiene leyenda
String texto = this.translation.toUpperCase();
String[] words = texto.split(" ");
StringBuffer txt = new StringBuffer();
if (words.length == 1) {//Si solo hay una palabra
if (words[0].length() > 10) { //Si es mayor de 10 caracteres
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)) {
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) {
//Copiar el bitmap a uno nuevo y reescalar
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, 15);
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{
//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;
}
}
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