Refactorizado el modo de escalar la imagen, ahora se reescala una vez esta en…

Refactorizado el modo de escalar la imagen, ahora se reescala una vez esta en EditPictoActivity y no antes de pasarla por los intent
parent bf4a834a
......@@ -91,7 +91,7 @@ public class Picto extends Img {
Log.e(LOG_TAG,e.getMessage());
}
}
public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn, int stupicto_id, String uri_sound, String user_avatar) throws JSONException {
public Picto(int id, String url, String translation, int cat, int row, int column, int freeRow, int freeColumn, int stupicto_id, String uri_sound, String user_avatar, String associated_person) throws JSONException {
this(id, url, new JSONObject()
.put(JSON_ATTTRS.CATEGORY, cat)
.put(JSON_ATTTRS.COLUMN, column)
......@@ -104,7 +104,7 @@ public class Picto extends Img {
.put(JSON_ATTTRS.EXPRESSION,translation)
.put(JSON_ATTTRS.URI_SOUND,uri_sound)
.put(JSON_ATTTRS.USER_AVATAR,user_avatar)
.put(JSON_ATTTRS.ASSOCIATED_PERSON,null)
.put(JSON_ATTTRS.ASSOCIATED_PERSON,associated_person)
);
}
public Picto(int id, String url,String translation, String attributes) throws JSONException {
......@@ -306,7 +306,7 @@ public class Picto extends Img {
* @return the associated person of a picto
*/
public String get_associated_person() {
return JSON_ATTTRS.ASSOCIATED_PERSON;
return JSON_ATTTRS.ASSOCIATED_PERSON != "associated_person" ? JSON_ATTTRS.ASSOCIATED_PERSON : null;
}
/**
......
......@@ -419,7 +419,7 @@ public class Vocabulary implements Iterable<Picto> {
int id=PCBcontext.getDevice().getNextLocalPictoID();
try {
final Picto picto = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y,prev_picto!=null ? prev_picto.get_stupicto_id() : Picto.STUPICTO_NULL,uri_sound,user_avatar);
final Picto picto = new Picto(id, url, exp, cat, coord_x, coord_y, free_category_coord_x, free_category_coord_y,prev_picto!=null ? prev_picto.get_stupicto_id() : Picto.STUPICTO_NULL,uri_sound,user_avatar,associated_person);
addPicto(picto, ImgDownloader.tsource.local, new ImgDownloader.iImgDownloaderListener() {
@Override
public void loadComplete() {
......
......@@ -26,8 +26,11 @@ import static android.graphics.Color.argb;
public class PictoMenu {
private static final String LOG_TAG = PictoMenu.class.getName();
public static final String ID_PICTO_IMAGE = "id_imagen_picto";
public static final String IS_EDIT = "is_edit";
public static final String PATH = "pathImage";
public static final String IMAGE_PICTO = "imagePicto";
PictogramActivity activity;
//Variables used on the picto menu (only supervisors)
......@@ -51,9 +54,8 @@ public class PictoMenu {
*
* @param row
* @param col
* @param expression
*/
public void createMenuForNewPicto(final int row, final int col, final int cat, final String expression) {
public void createMenuForNewPicto(final int row, final int col, final int cat) {
ll = new RelativeLayout(PCBcontext.getContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
......@@ -76,16 +78,14 @@ public class PictoMenu {
PieMenu.setCenterCircle(new Close());
PieMenu.addMenuEntry(new newPickFromCamera(row,col,cat,expression));
PieMenu.addMenuEntry(new newPickFromGallery(row,col,cat,expression));
PieMenu.addMenuEntry(new newPickFromCamera(row,col,cat/*,expression*/));
PieMenu.addMenuEntry(new newPickFromGallery(row,col,cat/*,expression*/));
ll.addView(PieMenu);
}
public void addPicto(int row, int col, int cat, String expression, int source) {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.EXPRESSION, expression);
public void addPicto(int row, int col, int cat, int source) {
//Enviar al PictogramActivity los datos necesarios para crear el picto despues
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.CATEGORY, cat);
......@@ -96,7 +96,7 @@ public class PictoMenu {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col);
}
if (source== 0) { //Pick from camera
if (source == 0) { //Pick from camera
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
activity.startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
} else { //Pick from file
......@@ -108,16 +108,9 @@ public class PictoMenu {
}
public void setPicto(int row, int col, int cat, String expression, Bitmap bitmap, int id_picto, String uri_sound, String user_avatar, int id_imagen_picto/*, String associated_person*/){
public void setPicto(int row, int col, int cat, Bitmap bitmap, int id_picto){
Intent intent = new Intent(activity, EditPictoActivity.class);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, expression);
intent.putExtra(Picto.JSON_ATTTRS.STUPICTO_ID,id_picto);
intent.putExtra(Picto.JSON_ATTTRS.URI_SOUND,uri_sound);
intent.putExtra(ID_PICTO_IMAGE,id_imagen_picto);
//intent.putExtra(Picto.JSON_ATTTRS.ASSOCIATED_PERSON,associated_person);
Log.i(EditPictoActivity.DEBUG_MESSAGE,"Guarda en los intents: id_cat: " +cat+"---id_pic: "+id_picto + "---id_imag: "+id_imagen_picto);
intent.putExtra(ID_PICTO_IMAGE,id_picto);
//Enviar al PictogramActivity los datos necesarios para editar el picto despues
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
......@@ -129,24 +122,11 @@ public class PictoMenu {
intent.putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col);
}
if(bitmap!=null) {
Point size= GUITools.getScreenSize(activity);
float bWidth = bitmap.getWidth();
float bHeight = bitmap.getHeight();
float factorX=size.x*0.7f/bWidth;
float factorY=size.y*0.7f/bHeight;
float factor= factorY>factorX ? factorX : factorY;
bWidth=bWidth*factor;
bHeight=bHeight*factor;
Bitmap rescaled = Bitmap.createScaledBitmap(bitmap,(int) bWidth, (int) bHeight, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
intent.putExtra(EditPictoActivity.IMAGE_PICTO, byteArray);
}
intent.putExtra("tipo",true);
intent.putExtra(IMAGE_PICTO, byteArray);
intent.putExtra(IS_EDIT,true);
activity.startActivityForResult(intent,EditPictoActivity.EDIT_PICTO_REQUEST);
}
......@@ -305,67 +285,22 @@ public class PictoMenu {
ll.removeAllViewsInLayout();
try {
setPicto(p.get_row(),p.get_column(),p.get_category(),p.get_translation(),p.get_bitmap(PCBcontext.getContext()),p.get_stupicto_id(),p.getUriSound(),p.getUserAvatar(),p.get_id());
setPicto(p.get_row(),p.get_column(),p.get_category(),p.get_bitmap(PCBcontext.getContext()),p.get_id());
} catch (IOException e) {
e.printStackTrace();
}
//ll.getChildAt(1).setX(ll.getChildAt(1).getX() + 30);
//children = new ArrayList<>(Arrays.asList(new PickFromCamera(p),new PickFromGallery(p)));
}
public void menuDisabled(){
//ll.getChildAt(1).setX(ll.getChildAt(1).getX() - 30);
}
}
/*public class PickFromCamera implements RadialMenuWidget.RadialMenuEntry
{
Picto p;
public PickFromCamera(Picto picto){
p = picto;
}
public String getName() { return "editText"; }
public String getLabel() { return null; }
public int getIcon() { return R.drawable.camera; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated()
{
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
addPicto(p.get_row(),p.get_column(),p.get_category(),p.get_translation(),0);
}
public void menuDisabled(){}
}
public class PickFromGallery implements RadialMenuWidget.RadialMenuEntry
{
Picto p;
public PickFromGallery(Picto picto){
p = picto;
}
public String getName() { return "editImage"; }
public String getLabel() { return null; }
public int getIcon() { return R.drawable.gallery; }
public List<RadialMenuWidget.RadialMenuEntry> getChildren() { return null; }
public void menuActiviated()
{
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
addPicto(p.get_row(),p.get_column(),p.get_category(),p.get_translation(),1);
}
public void menuDisabled(){}
}*/
public class newPickFromCamera implements RadialMenuWidget.RadialMenuEntry
{
int row,col,cat;
String expression;
public newPickFromCamera(int row, int col,int cat,String expression){
public newPickFromCamera(int row, int col,int cat){
this.row = row;
this.col = col;
this.cat = cat;
this.expression = expression;
}
public String getName() { return ""; }
public String getLabel() { return null; }
......@@ -376,7 +311,7 @@ public class PictoMenu {
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
addPicto(row,col,cat,expression,0);
addPicto(row,col,cat,0);
}
public void menuDisabled(){}
}
......@@ -384,12 +319,10 @@ public class PictoMenu {
public class newPickFromGallery implements RadialMenuWidget.RadialMenuEntry
{
int row,col,cat;
String expression;
public newPickFromGallery(int row, int col,int cat,String expression){
public newPickFromGallery(int row, int col,int cat){
this.row = row;
this.col = col;
this.cat = cat;
this.expression = expression;
}
public String getName() { return ""; }
public String getLabel() { return null; }
......@@ -399,7 +332,7 @@ public class PictoMenu {
{
ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout();
addPicto(row,col,cat,expression,1);
addPicto(row,col,cat,1);
}
public void menuDisabled(){}
}
......
......@@ -869,7 +869,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria
if (getCurrentCategory() != null || !PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), currentCategory.get_id(),null);
new PictoMenu(PictogramActivity.this).createMenuForNewPicto(position % maxColumns, (int) (position / maxColumns), currentCategory.get_id());
} else
Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
......@@ -1149,7 +1149,7 @@ protected void showOnlyTape(boolean onlyTape) {
break;
case EditPictoActivity.EDIT_PICTO_REQUEST:
if (resultCode == RESULT_OK) {
boolean edit = data.getBooleanExtra("tipo",false);
boolean edit = data.getBooleanExtra(PictoMenu.IS_EDIT,false);
int row = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.ROW) : getIntent().getIntExtra(Picto.JSON_ATTTRS.ROW, -1);
int col = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.COLUMN) : getIntent().getIntExtra(Picto.JSON_ATTTRS.COLUMN, -1);
int freeRow = edit ? data.getExtras().getInt(Picto.JSON_ATTTRS.FREE_ROW) : getIntent().getIntExtra(Picto.JSON_ATTTRS.FREE_ROW, -1);
......@@ -1157,13 +1157,14 @@ protected void showOnlyTape(boolean onlyTape) {
String uri_sound = edit ? data.getExtras().getString(Picto.JSON_ATTTRS.URI_SOUND) : getIntent().getStringExtra(Picto.JSON_ATTTRS.URI_SOUND);
String associated_person = edit ? data.getExtras().getString(Picto.JSON_ATTTRS.ASSOCIATED_PERSON) : getIntent().getStringExtra(Picto.JSON_ATTTRS.ASSOCIATED_PERSON);
Log.i(EditPictoActivity.DEBUG_MESSAGE,"Antes de chooseText..."+associated_person);
int cat = edit ? data.getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1) : getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1);
String path = data.getExtras().getString(EditPictoActivity.PATH);
String path = data.getExtras().getString(PictoMenu.PATH);
String legend = data.getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
//TODO: COGER URI DEL SONIDO,EL USER AVATAR Y LA PERSONA ASOCIADA AL PICTO
chooseTextAndSavePicto(path, row, col, freeRow, freeColumn, cat, legend, uri_sound, null,associated_person);
chooseTextAndSavePicto(path, row, col, freeRow, freeColumn, cat, legend, uri_sound, null, associated_person);
refresh();
}
break;
......@@ -1213,26 +1214,12 @@ protected void showOnlyTape(boolean onlyTape) {
Intent intent = new Intent(this, EditPictoActivity.class);
if(image!=null) {
Point size=GUITools.getScreenSize(this);
float bWidth = image.getWidth();
float bHeight = image.getHeight();
float factorX=size.x*0.7f/bWidth;
float factorY=size.y*0.7f/bHeight;
float factor= factorY>factorX ? factorX : factorY;
bWidth=bWidth*factor;
bHeight=bHeight*factor;
Bitmap rescaled = Bitmap.createScaledBitmap(image,(int) bWidth, (int) bHeight, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream);
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
intent.putExtra(EditPictoActivity.IMAGE_PICTO, byteArray);
intent.putExtra(PictoMenu.IMAGE_PICTO, byteArray);
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, getIntent().getStringExtra(Picto.JSON_ATTTRS.EXPRESSION));
startActivityForResult(intent, EditPictoActivity.EDIT_PICTO_REQUEST);
}
}
}
......@@ -68,21 +68,20 @@ import static java.lang.Thread.sleep;
public class EditPictoActivity extends Activity {
Picto p;
private boolean editar;
private int id_picto;
Random nRandom = new Random();
int pathNumber;
//Sonidos de sistema para grabar
final MediaActionSound recordSoundOn = new MediaActionSound();
final MediaActionSound recordSoundOff = new MediaActionSound();;
final MediaActionSound recordSoundOff = new MediaActionSound();
private static final int CAMERA_PIC_REQUEST = 1;
private static final int GALLERY_PIC_REQUEST = 2;
public static final String DEBUG_MESSAGE = "TAG_PRUEBAS";
public static final int EDIT_PICTO_REQUEST = 2288;
public static final int FINISH_EDIT = 2500;
//Botones Final/////////////////////////////////////////////////////////////////////
Button okButton;
......@@ -96,14 +95,12 @@ public class EditPictoActivity extends Activity {
BotonCircular camara;
BotonCircular galeria;
public static final String PATH = "pathImage";
public static final String IMAGE_PICTO = "imagePicto";
//For Legend//////////////////////////////////////////////////////////////////////////
EditText legend;
//For Associated Supervisors/////////////////////////////////////////////////////////
Button desplegableSupervisores;
TextView supAsociado;
private ListView mDrawerList;
private ArrayAdapter<String> mAdapter;
......@@ -126,8 +123,6 @@ public class EditPictoActivity extends Activity {
BotonCircular botonReproducir;
BotonCircular botonBorrar;
GifTextView gifRecord;
SeekBar barraReproducir;
......@@ -146,7 +141,7 @@ public class EditPictoActivity extends Activity {
int tiempoReproducir;
int tiempoTotal;
int id_pic, id_cat;
int id_pic;
// Requesting permission to RECORD_AUDIO
private boolean permissionToRecordAccepted = false;
private String [] permissions = {Manifest.permission.RECORD_AUDIO};
......@@ -228,15 +223,30 @@ public class EditPictoActivity extends Activity {
// Activity Methods ////////////////////////////////////////////////////////////////////////////
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.edit_picto_layout);
//Persmisos para grabar audio
ActivityCompat.requestPermissions(this, permissions, REQUEST_RECORD_AUDIO_PERMISSION);
//Aplicar medidas a los elementos de la vista
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
LinearLayout ll = (LinearLayout) findViewById(R.id.image_layout);
ll.getLayoutParams().width = (int) (metrics.widthPixels * 0.65) - (int) getResources().getDimension(R.dimen.activity_vertical_margin) * 2;
ll.requestLayout();
FrameLayout fl = (FrameLayout) findViewById(R.id.legend_menu);
fl.getLayoutParams().width = (int) (metrics.widthPixels * 0.25) - (int) getResources().getDimension(R.dimen.activity_vertical_margin);
fl.requestLayout();
//Editar la lista desplegable de supervisores asociados
mDrawerList = (ListView)findViewById(R.id.navList);
/**Obtener la lista de supervisores y aplicarle formato*/
String supervisors = PCBcontext.getPcbdb().getCurrentUser().get_Supervisors();
Log.i(DEBUG_MESSAGE,"Supervisores: "+ supervisors);
ArrayList<String> supervisores = new ArrayList<>();
if(supervisors != null) {
......@@ -245,9 +255,10 @@ public class EditPictoActivity extends Activity {
String[] detalles = supervisor.split(",");
supervisores.add(detalles[0] + "\n" + detalles[1]);
}
}
}else
Log.i(DEBUG_MESSAGE,"No tiene supervisores...");
mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, supervisores);
mAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, supervisores);
mDrawerList.setAdapter(mAdapter);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
......@@ -272,6 +283,7 @@ public class EditPictoActivity extends Activity {
mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle);
//Definir rutas de almacenado de imagen y audio
dirImagePath = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DCIM;
dirImagePath += "/PictoImages";
File fileImage = new File(dirImagePath);
......@@ -279,7 +291,6 @@ public class EditPictoActivity extends Activity {
fileImage.mkdirs();
}
//Record to the external cache directory for visibility
dirAudioPath = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_MUSIC;
dirAudioPath += "/PictoAudio";
File fileAudio = new File(dirAudioPath);
......@@ -288,15 +299,6 @@ public class EditPictoActivity extends Activity {
}
previewAudioPath = dirAudioPath+File.separator+"test.3gp";
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
LinearLayout ll = (LinearLayout) findViewById(R.id.image_layout);
ll.getLayoutParams().width = (int) (metrics.widthPixels * 0.65) - (int) getResources().getDimension(R.dimen.activity_vertical_margin) * 2;
ll.requestLayout();
FrameLayout fl = (FrameLayout) findViewById(R.id.legend_menu);
fl.getLayoutParams().width = (int) (metrics.widthPixels * 0.25) - (int) getResources().getDimension(R.dimen.activity_vertical_margin);
fl.requestLayout();
// Initialize Views.
titulo = (TextView) findViewById(R.id.crop_title);
......@@ -306,37 +308,8 @@ public class EditPictoActivity extends Activity {
cancelButton = (Button) findViewById(R.id.cancelButton);
desplegableSupervisores = (Button) findViewById(R.id.botonDesplegable);
supAsociado = (TextView) findViewById(R.id.sup_actual);
String transcription = getIntent().getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
cropImageView.setFixedAspectRatio(true);
cropImageView.setGuidelines(2);
if (transcription != null && transcription.length() > 0)
legend.setText(transcription);
legend.setHorizontallyScrolling(false);
legend.setMaxLines(1);
legend.setSingleLine(true);
editar = getIntent().getBooleanExtra("tipo",false);
titulo.setText(editar ? R.string.titleCropperEdit : R.string.titleCropperNew);
//Obtener imagen del intent
byte[] byteArray = getIntent().getByteArrayExtra(EditPictoActivity.IMAGE_PICTO);
Bitmap imagePicto = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
cropImageView.setAspectRatio(editar ? imagePicto.getWidth() : 4,editar ? imagePicto.getHeight() : 3); //Si es editar un picto la ventana de recorte mantiene el tamaño de la imagen, sino 4:3
cropImageView.setImageBitmap(imagePicto);
cropImageView.setMaxWidth(imagePicto.getWidth());
cropImageView.setMaxHeight(imagePicto.getHeight());
if (transcription != null && transcription.length() > 0)
legend.setText(transcription);
editar = getIntent().getBooleanExtra("tipo",false);
titulo.setText(editar ? R.string.titleCropperEdit : R.string.titleCropperNew);
ActivityCompat.requestPermissions(this, permissions, REQUEST_RECORD_AUDIO_PERMISSION);
//Initialize elements and variables
botonGrabar = (BotonCircular) findViewById(R.id.botonGrabar);
botonReproducir = (BotonCircular) findViewById(R.id.reproducir);
botonBorrar = (BotonCircular) findViewById(R.id.botonBorrar);
......@@ -359,7 +332,36 @@ public class EditPictoActivity extends Activity {
tiempoReproducir = 0;
tiempoTotal = 0;
Log.i(DEBUG_MESSAGE,getIntent().getExtras().get(Picto.JSON_ATTTRS.URI_SOUND).toString()!=null ? "Tiene Sonido"+getIntent().getExtras().get(Picto.JSON_ATTTRS.URI_SOUND).toString(): "No tiene sonido");
//String transcription = getIntent().getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
cropImageView.setFixedAspectRatio(true);
cropImageView.setGuidelines(2);
//Para ver si la vista es para editar uno ya existente o para añadir uno nuevo
editar = getIntent().getBooleanExtra(PictoMenu.IS_EDIT,false);
titulo.setText(editar ? R.string.titleCropperEdit : R.string.titleCropperNew);
//Obtener el picto a editar
if(editar){
p = PCBcontext.getVocabulary().get_picto(getIntent().getExtras().getInt(Picto.JSON_ATTTRS.CATEGORY),getIntent().getExtras().getInt(PictoMenu.ID_PICTO_IMAGE));
legend.setText(p.get_translation());
supAsociado.setText(p.get_associated_person());
}
legend.setHorizontallyScrolling(false);
legend.setMaxLines(1);
legend.setSingleLine(true);
//Obtener imagen del intent
byte[] byteArray = getIntent().getByteArrayExtra(PictoMenu.IMAGE_PICTO);
Bitmap imagePicto = scale_image(BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length));
cropImageView.setAspectRatio(editar ? imagePicto.getWidth() : 4,editar ? imagePicto.getHeight() : 3); //Si es editar un picto la ventana de recorte mantiene el tamaño de la imagen, sino 4:3
cropImageView.setImageBitmap(imagePicto);
cropImageView.setMaxWidth(imagePicto.getWidth());
cropImageView.setMaxHeight(imagePicto.getHeight());
/*if (transcription != null && transcription.length() > 0)
legend.setText(transcription);*/
//TODO: Aqui comprobar si ya hay grabación
//if (hayGrabacionAnterior){
layoutGrabacion.setVisibility(View.VISIBLE);
......@@ -370,7 +372,6 @@ public class EditPictoActivity extends Activity {
//}
pathNumber = nRandom.nextInt();
desplegableSupervisores.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
......@@ -386,15 +387,13 @@ public class EditPictoActivity extends Activity {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String[] assocciated_person = mDrawerList.getAdapter().getItem(position).toString().split("\n");
supAsociado.setText(assocciated_person[1]);
mDrawerLayout.closeDrawer(Gravity.RIGHT);
Picto p = PCBcontext.getVocabulary().get_picto((int)getIntent().getExtras().get(Picto.JSON_ATTTRS.CATEGORY),
(int)getIntent().getExtras().get(PictoMenu.ID_PICTO_IMAGE));
Log.i(DEBUG_MESSAGE, "Supervisor Asociado Actual: " + p.get_associated_person());
p.alter_associated_person(assocciated_person[1]); //cambiar el la persona asociada
Log.i(DEBUG_MESSAGE,"String: "+assocciated_person[1]);
Log.i(DEBUG_MESSAGE, "Supervisor Asociado Nuevo: " + p.get_associated_person());
//Log.i(DEBUG_MESSAGE, "Supervisor Asociado Actual: " + p.get_associated_person());
//p.alter_associated_person(assocciated_person[1]); //cambiar el la persona asociada
//Log.i(DEBUG_MESSAGE,"String: "+assocciated_person[1]);
//Log.i(DEBUG_MESSAGE, "Supervisor Asociado Nuevo: " + p.get_associated_person());
}
});
......@@ -408,10 +407,10 @@ public class EditPictoActivity extends Activity {
String filepath = null;
String audioPath = null;
try {
id_picto = getIntent().getExtras().getInt(PictoMenu.ID_PICTO_IMAGE);
id_pic = getIntent().getExtras().getInt(PictoMenu.ID_PICTO_IMAGE);
filepath = editar ? dirImagePath + File.separator + legend.getText().toString() + "_" + id_picto + ".png"
filepath = editar ? dirImagePath + File.separator + legend.getText().toString() + "_" + id_pic + ".png"
: dirImagePath + File.separator + legend.getText().toString() + "_new_" + pathNumber+ ".png";
File imageFile = new File(filepath);
......@@ -441,23 +440,24 @@ public class EditPictoActivity extends Activity {
if (file.exists()) {
File from = new File(previewAudioPath);
File to = new File(editar ? dirAudioPath + File.separator + legend.getText().toString() + "_" + id_picto + "_audio.3gp" :
File to = new File(editar ? dirAudioPath + File.separator + legend.getText().toString() + "_" + id_pic + "_audio.3gp" :
dirAudioPath + File.separator + legend.getText().toString() + "_new_" + pathNumber + "_audio.3gp");
if (from.exists()){
from.renameTo(to);
Log.i(DEBUG_MESSAGE,to.getPath().toString());
audioPath = to.getPath().toString();
}
}
}
Intent intent = getIntent(); //Mandar a pictogram activity el path y el texto de la imagen
intent.putExtra(PATH, filepath); //Mandar Path imagen
intent.putExtra(PictoMenu.IS_EDIT, editar); //Para saber despues si estas editando o añadiendo nuevo y coger los datos de intent o de data en OnActivityResult
intent.putExtra(PictoMenu.PATH, filepath); //Mandar Path imagen
intent.putExtra(Picto.JSON_ATTTRS.URI_SOUND,audioPath); //Mandar el path del audio
intent.putExtra(Picto.JSON_ATTTRS.EXPRESSION, legend.getText().toString()); //Mandar expresion nueva
intent.putExtra(Picto.JSON_ATTTRS.CATEGORY, getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1));
intent.putExtra(Picto.JSON_ATTTRS.URI_SOUND,audioPath); //Mandar el path del audio
intent.putExtra("tipo", editar); //Para saber despues si estas editando o añadiendo nuevo y coger los datos de intent o de data en OnActivityResult
intent.putExtra(Picto.JSON_ATTTRS.ASSOCIATED_PERSON, supAsociado.getText());
setResult(RESULT_OK, intent);
finish(); //Termina la actividad de editar
......@@ -671,30 +671,19 @@ public class EditPictoActivity extends Activity {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Bitmap imagen = null;
Bitmap rescaled = null;
Bitmap imagen;
switch(requestCode) {
case CAMERA_PIC_REQUEST: //Captura de foto
if (data != null && resultCode==RESULT_OK) {
imagen = (Bitmap) data.getExtras().get("data");
if(imagen!=null) {
Point size= GUITools.getScreenSize(EditPictoActivity.this);
float bWidth = imagen.getWidth();
float bHeight = imagen.getHeight();
float factorX=size.x*0.7f/bWidth;
float factorY=size.y*0.7f/bHeight;
float factor= factorY>factorX ? factorX : factorY;
bWidth=bWidth*factor;
bHeight=bHeight*factor;
rescaled = Bitmap.createScaledBitmap(imagen,(int) bWidth, (int) bHeight, true);
Bitmap rescaled = scale_image(imagen);
cropImageView.setImageBitmap(rescaled);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
getIntent().putExtra(EditPictoActivity.IMAGE_PICTO, byteArray);
}
cropImageView.setImageBitmap(rescaled);
getIntent().putExtra(PictoMenu.IMAGE_PICTO, byteArray);
}
break;
......@@ -707,6 +696,22 @@ public class EditPictoActivity extends Activity {
} catch (IOException e) {
e.printStackTrace();
}
Bitmap rescaled = scale_image(bitmap);
cropImageView.setImageBitmap(rescaled);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
getIntent().putExtra(PictoMenu.IMAGE_PICTO, byteArray);
}
break;
}
}
public Bitmap scale_image(Bitmap bitmap){
Bitmap rescaled = null;
if(bitmap!=null) {
Point size= GUITools.getScreenSize(EditPictoActivity.this);
float bWidth = bitmap.getWidth();
......@@ -719,15 +724,7 @@ public class EditPictoActivity extends Activity {
bHeight=bHeight*factor;
rescaled = Bitmap.createScaledBitmap(bitmap,(int) bWidth, (int) bHeight, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
getIntent().putExtra(EditPictoActivity.IMAGE_PICTO, byteArray);
}
cropImageView.setImageBitmap(rescaled);
}
break;
}
return rescaled;
}
}
......@@ -106,10 +106,16 @@
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/textAssociated"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Asociar a:"
android:textColor="@color/gray"
android:textSize="20sp" />
......@@ -118,9 +124,20 @@
android:id="@+id/botonDesplegable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_weight="1"
android:text="Ver" />
</LinearLayout>
<TextView
android:id="@+id/sup_actual"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="18sp" />
<TextView
android:id="@+id/textLegend"
android:layout_width="match_parent"
......
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