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 { ...@@ -91,7 +91,7 @@ public class Picto extends Img {
Log.e(LOG_TAG,e.getMessage()); 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() this(id, url, new JSONObject()
.put(JSON_ATTTRS.CATEGORY, cat) .put(JSON_ATTTRS.CATEGORY, cat)
.put(JSON_ATTTRS.COLUMN, column) .put(JSON_ATTTRS.COLUMN, column)
...@@ -104,7 +104,7 @@ public class Picto extends Img { ...@@ -104,7 +104,7 @@ public class Picto extends Img {
.put(JSON_ATTTRS.EXPRESSION,translation) .put(JSON_ATTTRS.EXPRESSION,translation)
.put(JSON_ATTTRS.URI_SOUND,uri_sound) .put(JSON_ATTTRS.URI_SOUND,uri_sound)
.put(JSON_ATTTRS.USER_AVATAR,user_avatar) .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 { public Picto(int id, String url,String translation, String attributes) throws JSONException {
...@@ -306,7 +306,7 @@ public class Picto extends Img { ...@@ -306,7 +306,7 @@ public class Picto extends Img {
* @return the associated person of a picto * @return the associated person of a picto
*/ */
public String get_associated_person() { 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> { ...@@ -419,7 +419,7 @@ public class Vocabulary implements Iterable<Picto> {
int id=PCBcontext.getDevice().getNextLocalPictoID(); int id=PCBcontext.getDevice().getNextLocalPictoID();
try { 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() { addPicto(picto, ImgDownloader.tsource.local, new ImgDownloader.iImgDownloaderListener() {
@Override @Override
public void loadComplete() { public void loadComplete() {
......
...@@ -26,8 +26,11 @@ import static android.graphics.Color.argb; ...@@ -26,8 +26,11 @@ import static android.graphics.Color.argb;
public class PictoMenu { 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 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; PictogramActivity activity;
//Variables used on the picto menu (only supervisors) //Variables used on the picto menu (only supervisors)
...@@ -51,9 +54,8 @@ public class PictoMenu { ...@@ -51,9 +54,8 @@ public class PictoMenu {
* *
* @param row * @param row
* @param col * @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()); ll = new RelativeLayout(PCBcontext.getContext());
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
...@@ -76,16 +78,14 @@ public class PictoMenu { ...@@ -76,16 +78,14 @@ public class PictoMenu {
PieMenu.setCenterCircle(new Close()); PieMenu.setCenterCircle(new Close());
PieMenu.addMenuEntry(new newPickFromCamera(row,col,cat,expression)); PieMenu.addMenuEntry(new newPickFromCamera(row,col,cat/*,expression*/));
PieMenu.addMenuEntry(new newPickFromGallery(row,col,cat,expression)); PieMenu.addMenuEntry(new newPickFromGallery(row,col,cat/*,expression*/));
ll.addView(PieMenu); ll.addView(PieMenu);
} }
public void addPicto(int row, int col, int cat, String expression, int source) { public void addPicto(int row, int col, int cat, int source) {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.EXPRESSION, expression);
//Enviar al PictogramActivity los datos necesarios para crear el picto despues //Enviar al PictogramActivity los datos necesarios para crear el picto despues
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) { if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.CATEGORY, cat); activity.getIntent().putExtra(Picto.JSON_ATTTRS.CATEGORY, cat);
...@@ -96,7 +96,7 @@ public class PictoMenu { ...@@ -96,7 +96,7 @@ public class PictoMenu {
activity.getIntent().putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col); 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); Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
activity.startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST); activity.startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
} else { //Pick from file } else { //Pick from file
...@@ -108,16 +108,9 @@ public class PictoMenu { ...@@ -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 intent = new Intent(activity, EditPictoActivity.class);
intent.putExtra(ID_PICTO_IMAGE,id_picto);
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);
//Enviar al PictogramActivity los datos necesarios para editar el picto despues //Enviar al PictogramActivity los datos necesarios para editar el picto despues
if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) { if (PCBcontext.getPcbdb().getCurrentUser().has_categories()) {
...@@ -129,24 +122,11 @@ public class PictoMenu { ...@@ -129,24 +122,11 @@ public class PictoMenu {
intent.putExtra(Picto.JSON_ATTTRS.FREE_COLUMN, col); 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(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray(); byte[] byteArray = stream.toByteArray();
intent.putExtra(EditPictoActivity.IMAGE_PICTO, byteArray); intent.putExtra(IMAGE_PICTO, byteArray);
} intent.putExtra(IS_EDIT,true);
intent.putExtra("tipo",true);
activity.startActivityForResult(intent,EditPictoActivity.EDIT_PICTO_REQUEST); activity.startActivityForResult(intent,EditPictoActivity.EDIT_PICTO_REQUEST);
} }
...@@ -305,67 +285,22 @@ public class PictoMenu { ...@@ -305,67 +285,22 @@ public class PictoMenu {
ll.removeAllViewsInLayout(); ll.removeAllViewsInLayout();
try { 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) { } catch (IOException e) {
e.printStackTrace(); 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 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 public class newPickFromCamera implements RadialMenuWidget.RadialMenuEntry
{ {
int row,col,cat; int row,col,cat;
String expression; public newPickFromCamera(int row, int col,int cat){
public newPickFromCamera(int row, int col,int cat,String expression){
this.row = row; this.row = row;
this.col = col; this.col = col;
this.cat = cat; this.cat = cat;
this.expression = expression;
} }
public String getName() { return ""; } public String getName() { return ""; }
public String getLabel() { return null; } public String getLabel() { return null; }
...@@ -376,7 +311,7 @@ public class PictoMenu { ...@@ -376,7 +311,7 @@ public class PictoMenu {
ll.setVisibility(View.GONE); ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout(); ll.removeAllViewsInLayout();
addPicto(row,col,cat,expression,0); addPicto(row,col,cat,0);
} }
public void menuDisabled(){} public void menuDisabled(){}
} }
...@@ -384,12 +319,10 @@ public class PictoMenu { ...@@ -384,12 +319,10 @@ public class PictoMenu {
public class newPickFromGallery implements RadialMenuWidget.RadialMenuEntry public class newPickFromGallery implements RadialMenuWidget.RadialMenuEntry
{ {
int row,col,cat; int row,col,cat;
String expression; public newPickFromGallery(int row, int col,int cat){
public newPickFromGallery(int row, int col,int cat,String expression){
this.row = row; this.row = row;
this.col = col; this.col = col;
this.cat = cat; this.cat = cat;
this.expression = expression;
} }
public String getName() { return ""; } public String getName() { return ""; }
public String getLabel() { return null; } public String getLabel() { return null; }
...@@ -399,7 +332,7 @@ public class PictoMenu { ...@@ -399,7 +332,7 @@ public class PictoMenu {
{ {
ll.setVisibility(View.GONE); ll.setVisibility(View.GONE);
ll.removeAllViewsInLayout(); ll.removeAllViewsInLayout();
addPicto(row,col,cat,expression,1); addPicto(row,col,cat,1);
} }
public void menuDisabled(){} public void menuDisabled(){}
} }
......
...@@ -869,7 +869,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab ...@@ -869,7 +869,7 @@ public class PictogramActivity extends Activity implements VocabularyTalk.iVocab
if (p == null) { if (p == null) {
// No tengo pictograma. Abro una nueva ventana de selección desde el Carrete del device si no es categoria // 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()) { 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 } else
Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show(); Toast.makeText(PictogramActivity.this, PictogramActivity.this.getResources().getString(R.string.notNewCats), Toast.LENGTH_SHORT).show();
...@@ -1149,7 +1149,7 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1149,7 +1149,7 @@ protected void showOnlyTape(boolean onlyTape) {
break; break;
case EditPictoActivity.EDIT_PICTO_REQUEST: case EditPictoActivity.EDIT_PICTO_REQUEST:
if (resultCode == RESULT_OK) { 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 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 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); 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) { ...@@ -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 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); 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); 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); String legend = data.getExtras().getString(Picto.JSON_ATTTRS.EXPRESSION);
//TODO: COGER URI DEL SONIDO,EL USER AVATAR Y LA PERSONA ASOCIADA AL PICTO //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(); refresh();
} }
break; break;
...@@ -1213,26 +1214,12 @@ protected void showOnlyTape(boolean onlyTape) { ...@@ -1213,26 +1214,12 @@ protected void showOnlyTape(boolean onlyTape) {
Intent intent = new Intent(this, EditPictoActivity.class); 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(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream); image.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray(); 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); startActivityForResult(intent, EditPictoActivity.EDIT_PICTO_REQUEST);
}
} }
} }
...@@ -68,21 +68,20 @@ import static java.lang.Thread.sleep; ...@@ -68,21 +68,20 @@ import static java.lang.Thread.sleep;
public class EditPictoActivity extends Activity { public class EditPictoActivity extends Activity {
Picto p;
private boolean editar; private boolean editar;
private int id_picto;
Random nRandom = new Random(); Random nRandom = new Random();
int pathNumber; int pathNumber;
//Sonidos de sistema para grabar
final MediaActionSound recordSoundOn = new MediaActionSound(); 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 CAMERA_PIC_REQUEST = 1;
private static final int GALLERY_PIC_REQUEST = 2; private static final int GALLERY_PIC_REQUEST = 2;
public static final String DEBUG_MESSAGE = "TAG_PRUEBAS"; public static final String DEBUG_MESSAGE = "TAG_PRUEBAS";
public static final int EDIT_PICTO_REQUEST = 2288; public static final int EDIT_PICTO_REQUEST = 2288;
public static final int FINISH_EDIT = 2500;
//Botones Final///////////////////////////////////////////////////////////////////// //Botones Final/////////////////////////////////////////////////////////////////////
Button okButton; Button okButton;
...@@ -96,14 +95,12 @@ public class EditPictoActivity extends Activity { ...@@ -96,14 +95,12 @@ public class EditPictoActivity extends Activity {
BotonCircular camara; BotonCircular camara;
BotonCircular galeria; BotonCircular galeria;
public static final String PATH = "pathImage";
public static final String IMAGE_PICTO = "imagePicto";
//For Legend////////////////////////////////////////////////////////////////////////// //For Legend//////////////////////////////////////////////////////////////////////////
EditText legend; EditText legend;
//For Associated Supervisors///////////////////////////////////////////////////////// //For Associated Supervisors/////////////////////////////////////////////////////////
Button desplegableSupervisores; Button desplegableSupervisores;
TextView supAsociado;
private ListView mDrawerList; private ListView mDrawerList;
private ArrayAdapter<String> mAdapter; private ArrayAdapter<String> mAdapter;
...@@ -126,8 +123,6 @@ public class EditPictoActivity extends Activity { ...@@ -126,8 +123,6 @@ public class EditPictoActivity extends Activity {
BotonCircular botonReproducir; BotonCircular botonReproducir;
BotonCircular botonBorrar; BotonCircular botonBorrar;
GifTextView gifRecord; GifTextView gifRecord;
SeekBar barraReproducir; SeekBar barraReproducir;
...@@ -146,7 +141,7 @@ public class EditPictoActivity extends Activity { ...@@ -146,7 +141,7 @@ public class EditPictoActivity extends Activity {
int tiempoReproducir; int tiempoReproducir;
int tiempoTotal; int tiempoTotal;
int id_pic, id_cat; int id_pic;
// Requesting permission to RECORD_AUDIO // Requesting permission to RECORD_AUDIO
private boolean permissionToRecordAccepted = false; private boolean permissionToRecordAccepted = false;
private String [] permissions = {Manifest.permission.RECORD_AUDIO}; private String [] permissions = {Manifest.permission.RECORD_AUDIO};
...@@ -228,15 +223,30 @@ public class EditPictoActivity extends Activity { ...@@ -228,15 +223,30 @@ public class EditPictoActivity extends Activity {
// Activity Methods //////////////////////////////////////////////////////////////////////////// // Activity Methods ////////////////////////////////////////////////////////////////////////////
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.edit_picto_layout); 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); mDrawerList = (ListView)findViewById(R.id.navList);
/**Obtener la lista de supervisores y aplicarle formato*/ /**Obtener la lista de supervisores y aplicarle formato*/
String supervisors = PCBcontext.getPcbdb().getCurrentUser().get_Supervisors(); String supervisors = PCBcontext.getPcbdb().getCurrentUser().get_Supervisors();
Log.i(DEBUG_MESSAGE,"Supervisores: "+ supervisors);
ArrayList<String> supervisores = new ArrayList<>(); ArrayList<String> supervisores = new ArrayList<>();
if(supervisors != null) { if(supervisors != null) {
...@@ -245,9 +255,10 @@ public class EditPictoActivity extends Activity { ...@@ -245,9 +255,10 @@ public class EditPictoActivity extends Activity {
String[] detalles = supervisor.split(","); String[] detalles = supervisor.split(",");
supervisores.add(detalles[0] + "\n" + detalles[1]); 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); mDrawerList.setAdapter(mAdapter);
mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout); mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
...@@ -272,6 +283,7 @@ public class EditPictoActivity extends Activity { ...@@ -272,6 +283,7 @@ public class EditPictoActivity extends Activity {
mDrawerToggle.setDrawerIndicatorEnabled(true); mDrawerToggle.setDrawerIndicatorEnabled(true);
mDrawerLayout.setDrawerListener(mDrawerToggle); mDrawerLayout.setDrawerListener(mDrawerToggle);
//Definir rutas de almacenado de imagen y audio
dirImagePath = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DCIM; dirImagePath = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_DCIM;
dirImagePath += "/PictoImages"; dirImagePath += "/PictoImages";
File fileImage = new File(dirImagePath); File fileImage = new File(dirImagePath);
...@@ -279,7 +291,6 @@ public class EditPictoActivity extends Activity { ...@@ -279,7 +291,6 @@ public class EditPictoActivity extends Activity {
fileImage.mkdirs(); fileImage.mkdirs();
} }
//Record to the external cache directory for visibility
dirAudioPath = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_MUSIC; dirAudioPath = Environment.getExternalStorageDirectory() + File.separator + Environment.DIRECTORY_MUSIC;
dirAudioPath += "/PictoAudio"; dirAudioPath += "/PictoAudio";
File fileAudio = new File(dirAudioPath); File fileAudio = new File(dirAudioPath);
...@@ -288,15 +299,6 @@ public class EditPictoActivity extends Activity { ...@@ -288,15 +299,6 @@ public class EditPictoActivity extends Activity {
} }
previewAudioPath = dirAudioPath+File.separator+"test.3gp"; 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. // Initialize Views.
titulo = (TextView) findViewById(R.id.crop_title); titulo = (TextView) findViewById(R.id.crop_title);
...@@ -306,37 +308,8 @@ public class EditPictoActivity extends Activity { ...@@ -306,37 +308,8 @@ public class EditPictoActivity extends Activity {
cancelButton = (Button) findViewById(R.id.cancelButton); cancelButton = (Button) findViewById(R.id.cancelButton);
desplegableSupervisores = (Button) findViewById(R.id.botonDesplegable); 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); botonGrabar = (BotonCircular) findViewById(R.id.botonGrabar);
botonReproducir = (BotonCircular) findViewById(R.id.reproducir); botonReproducir = (BotonCircular) findViewById(R.id.reproducir);
botonBorrar = (BotonCircular) findViewById(R.id.botonBorrar); botonBorrar = (BotonCircular) findViewById(R.id.botonBorrar);
...@@ -359,7 +332,36 @@ public class EditPictoActivity extends Activity { ...@@ -359,7 +332,36 @@ public class EditPictoActivity extends Activity {
tiempoReproducir = 0; tiempoReproducir = 0;
tiempoTotal = 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 //TODO: Aqui comprobar si ya hay grabación
//if (hayGrabacionAnterior){ //if (hayGrabacionAnterior){
layoutGrabacion.setVisibility(View.VISIBLE); layoutGrabacion.setVisibility(View.VISIBLE);
...@@ -370,7 +372,6 @@ public class EditPictoActivity extends Activity { ...@@ -370,7 +372,6 @@ public class EditPictoActivity extends Activity {
//} //}
pathNumber = nRandom.nextInt(); pathNumber = nRandom.nextInt();
desplegableSupervisores.setOnClickListener(new View.OnClickListener() { desplegableSupervisores.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
...@@ -386,15 +387,13 @@ public class EditPictoActivity extends Activity { ...@@ -386,15 +387,13 @@ public class EditPictoActivity extends Activity {
@Override @Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String[] assocciated_person = mDrawerList.getAdapter().getItem(position).toString().split("\n"); 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), //Log.i(DEBUG_MESSAGE, "Supervisor Asociado Actual: " + p.get_associated_person());
(int)getIntent().getExtras().get(PictoMenu.ID_PICTO_IMAGE)); //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 Actual: " + p.get_associated_person()); //Log.i(DEBUG_MESSAGE, "Supervisor Asociado Nuevo: " + 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 { ...@@ -408,10 +407,10 @@ public class EditPictoActivity extends Activity {
String filepath = null; String filepath = null;
String audioPath = null; String audioPath = null;
try { 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"; : dirImagePath + File.separator + legend.getText().toString() + "_new_" + pathNumber+ ".png";
File imageFile = new File(filepath); File imageFile = new File(filepath);
...@@ -441,23 +440,24 @@ public class EditPictoActivity extends Activity { ...@@ -441,23 +440,24 @@ public class EditPictoActivity extends Activity {
if (file.exists()) { if (file.exists()) {
File from = new File(previewAudioPath); 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"); dirAudioPath + File.separator + legend.getText().toString() + "_new_" + pathNumber + "_audio.3gp");
if (from.exists()){ if (from.exists()){
from.renameTo(to); from.renameTo(to);
Log.i(DEBUG_MESSAGE,to.getPath().toString()); Log.i(DEBUG_MESSAGE,to.getPath().toString());
audioPath = to.getPath().toString(); audioPath = to.getPath().toString();
} }
} }
} }
Intent intent = getIntent(); //Mandar a pictogram activity el path y el texto de la imagen 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.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.CATEGORY, getIntent().getIntExtra(Picto.JSON_ATTTRS.CATEGORY, -1));
intent.putExtra(Picto.JSON_ATTTRS.URI_SOUND,audioPath); //Mandar el path del audio intent.putExtra(Picto.JSON_ATTTRS.ASSOCIATED_PERSON, supAsociado.getText());
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
setResult(RESULT_OK, intent); setResult(RESULT_OK, intent);
finish(); //Termina la actividad de editar finish(); //Termina la actividad de editar
...@@ -671,30 +671,19 @@ public class EditPictoActivity extends Activity { ...@@ -671,30 +671,19 @@ public class EditPictoActivity extends Activity {
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
Bitmap imagen = null; Bitmap imagen;
Bitmap rescaled = null;
switch(requestCode) { switch(requestCode) {
case CAMERA_PIC_REQUEST: //Captura de foto case CAMERA_PIC_REQUEST: //Captura de foto
if (data != null && resultCode==RESULT_OK) { if (data != null && resultCode==RESULT_OK) {
imagen = (Bitmap) data.getExtras().get("data"); imagen = (Bitmap) data.getExtras().get("data");
if(imagen!=null) { Bitmap rescaled = scale_image(imagen);
Point size= GUITools.getScreenSize(EditPictoActivity.this); cropImageView.setImageBitmap(rescaled);
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);
ByteArrayOutputStream stream = new ByteArrayOutputStream(); ByteArrayOutputStream stream = new ByteArrayOutputStream();
rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream); rescaled.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray(); byte[] byteArray = stream.toByteArray();
getIntent().putExtra(EditPictoActivity.IMAGE_PICTO, byteArray); getIntent().putExtra(PictoMenu.IMAGE_PICTO, byteArray);
}
cropImageView.setImageBitmap(rescaled);
} }
break; break;
...@@ -707,6 +696,22 @@ public class EditPictoActivity extends Activity { ...@@ -707,6 +696,22 @@ public class EditPictoActivity extends Activity {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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) { if(bitmap!=null) {
Point size= GUITools.getScreenSize(EditPictoActivity.this); Point size= GUITools.getScreenSize(EditPictoActivity.this);
float bWidth = bitmap.getWidth(); float bWidth = bitmap.getWidth();
...@@ -719,15 +724,7 @@ public class EditPictoActivity extends Activity { ...@@ -719,15 +724,7 @@ public class EditPictoActivity extends Activity {
bHeight=bHeight*factor; bHeight=bHeight*factor;
rescaled = Bitmap.createScaledBitmap(bitmap,(int) bWidth, (int) bHeight, true); 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 @@ ...@@ -106,10 +106,16 @@
android:layout_gravity="center" android:layout_gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView <TextView
android:id="@+id/textAssociated" android:id="@+id/textAssociated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Asociar a:" android:text="Asociar a:"
android:textColor="@color/gray" android:textColor="@color/gray"
android:textSize="20sp" /> android:textSize="20sp" />
...@@ -118,9 +124,20 @@ ...@@ -118,9 +124,20 @@
android:id="@+id/botonDesplegable" android:id="@+id/botonDesplegable"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="15dp" android:layout_weight="1"
android:text="Ver" /> 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 <TextView
android:id="@+id/textLegend" android:id="@+id/textLegend"
android:layout_width="match_parent" 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