Commit c110ced3 by german

Legend code added (Missing the "only_legend" code)

parent 2de3ba70
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.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 +21,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
* *
......@@ -19,6 +33,8 @@ import org.json.JSONObject;
*/
public class Picto extends Img {
Bitmap bitmap;
// String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
......@@ -35,6 +51,15 @@ public class Picto extends Img {
public static String PCB_STATUS_MODIFICATION="pcb_status_modification";
public static String EXPRESSION = "expression";
/**Modificacion German*/
public static String LEGEND="legend";
public static String LEGEND_SIZE="legend_size";
}
public final static class JSON_ATTTR_LEGEND_VALUES {
static String NORMAL = "normal";
static String ONLY_LEGEND = "only_legend";
}
public final static class JSON_ATTTR_STATUS_VALUES {
......@@ -50,14 +75,16 @@ public class Picto extends Img {
private JSONObject attributes;
private String translation;
public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn) throws JSONException {
public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn,boolean legend) throws JSONException {
this(id, url, translation, new JSONObject()
.put(JSON_ATTTRS.CATEGORY, cat)
.put(JSON_ATTTRS.COLUMN, column)
.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,legend)
.put(JSON_ATTTRS.LEGEND,JSON_ATTTR_LEGEND_VALUES.NORMAL));
}
public Picto(int id, String url,String translation, String attributes) throws JSONException {
this(id, url, translation, new JSONObject(attributes));
......@@ -223,6 +250,31 @@ 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)
*/
public String get_legend_size() {
try {
return this.attributes.getString(JSON_ATTTRS.LEGEND_SIZE);
} catch (JSONException e) {
return "normal"; // By default
}
}
/**
*
* @return the row of the picto
*/
......@@ -392,4 +444,94 @@ 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();
}
}
if (have_legend()){
if(get_legend_size().equals(JSON_ATTTR_LEGEND_VALUES.NORMAL)) {
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();
}
}
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);
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.WHITE);
textView.setBackgroundColor(Color.argb(150, 0, 0, 0));
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
}
}
return bitmap;
}
}
......@@ -366,11 +366,11 @@ public class Vocabulary implements Iterable<Picto> {
/*
* 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, 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,boolean legend, final iLocalPicto listener) {
int id= PCBcontext.getDevice().getNextLocalPictoID();
final Picto picto[]=new Picto[1];
try {
picto[0] = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y);
picto[0] = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y,legend);
addPicto(picto[0], ImgDownloader.tsource.local, new iImgDownloaderListener() {
@Override
public void loadComplete() {
......
......@@ -860,6 +860,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
col,
freeRow,
freeColumn,
false,
new iLocalPicto() {
@Override
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